Examples of DaoRegister


Examples of org.milyn.scribe.register.DaoRegister

    ParameterManager.initializeParameterContainer(id, parameterListType, executionContext);
  }

  @SuppressWarnings("unchecked")
  public void lookup(ExecutionContext executionContext, Fragment source) {
    final DaoRegister emr = PersistenceUtil.getDAORegister(executionContext);

    Object dao = null;
    try {
      if(daoName == null) {
        dao = emr.getDefaultDao();
      } else {
        dao = emr.getDao(daoName);
      }

      if(dao == null) {
        throw new IllegalStateException("The DAO register returned null while getting the DAO '" + daoName + "'");
      }

      Object result = lookup(dao, executionContext);

      if(result != null && uniqueResult == true) {
        if(result instanceof Collection){
          Collection<Object> resultCollection = (Collection<Object>) result;

          if(resultCollection.size() == 0) {
            result = null;
          } else if(resultCollection.size() == 1) {
            for(Object value : resultCollection) {
              result = value;
            }
          } else {
            String exception;
            if(daoName == null) {
              exception = "The " + getDaoNameFromAdapter(dao) + " DAO";
            } else {
              exception = "The DAO '" + daoName + "'";
            }
            exception += " returned multiple results for the ";
            if(lookupName != null) {
              exception += "lookup '" + lookupName + "'";
            } else {
              exception += "query '" + query + "'";
            }
            throw new NonUniqueResultException(exception);
          }

        } else {
          throw new SmooksConfigurationException("The returned result doesn't implement the '" + Collection.class.getName() + "' interface " +
              "and there for the unique result check can't be done.");
        }
      }

      if(result == null && onNoResult == OnNoResult.EXCEPTION) {
        String exception;
        if(daoName == null) {
          exception = "The " + getDaoNameFromAdapter(dao) + " DAO";
        } else {
          exception = "The DAO '" + daoName + "'";
        }
        exception += " returned no results for lookup ";
        if(lookupName != null) {
          exception += "lookup '" + query + "'";
        } else {
          exception += "query '" + query + "'";
        }
        throw new NoLookupResultException(exception);
      }

      BeanContext beanContext = executionContext.getBeanContext();

      if(result == null) {
        beanContext.removeBean(beanId, source);
      } else {
        beanContext.addBean(beanId, result, source);
      }
    } finally {
      if(dao != null) {
        emr.returnDao(dao);
      }
    }
  }
View Full Code Here

Examples of org.milyn.scribe.register.DaoRegister

    BeanContext beanContext = executionContext.getBeanContext();

    Object bean = beanContext.getBean(beanId);

    final DaoRegister emr = PersistenceUtil.getDAORegister(executionContext);

    Object dao = null;
    try {
      if(daoName == null) {
        dao = emr.getDefaultDao();
      } else {
        dao = emr.getDao(daoName);
      }

      if(dao == null) {
        String msg = "The DAO register returned null while getting the ";

        if(daoName == null) {
          msg += "default DAO";
        } else {
          msg += "DAO '" + daoName + "'";
        }

        throw new NullPointerException(msg);
      }

      DaoInvoker daoInvoker = DaoInvokerFactory.getInstance().create(dao, objectStore);

      Object result = (name != null) ? daoInvoker.delete(name, bean) : daoInvoker.delete(bean);

      if(deletedBeanId != null) {
        if(result == null) {
          result = bean;
        }
        beanContext.addBean(deletedBeanId, result, source);
      } else if(result != null && bean != result) {
        beanContext.changeBean(beanId, bean, source);
      }


    } finally {
      if(dao != null) {
        emr.returnDao(dao);
      }
    }
  }
View Full Code Here

Examples of org.milyn.scribe.register.DaoRegister

    BeanContext beanRepository = executionContext.getBeanContext();

    Object bean = beanRepository.getBean(beanId);

    final DaoRegister emr = PersistenceUtil.getDAORegister(executionContext);

    Object dao = null;
    try {
      if(daoName == null) {
        dao = emr.getDefaultDao();
      } else {
        dao = emr.getDao(daoName);
      }

      if(dao == null) {
        throw new IllegalStateException("The DAO register returned null while getting the DAO '" + daoName + "'");
      }

      final DaoInvoker daoInvoker = DaoInvokerFactory.getInstance().create(dao, objectStore);

      Object result = name == null ? daoInvoker.insert(bean) : daoInvoker.insert(name, bean) ;

      if(insertedBeanId != null) {
        if(result == null) {
          result = bean;
        }
        beanRepository.addBean(insertedBeanId, result, source);
      } else if(result != null && bean != result) {
        beanRepository.changeBean(beanId, bean, source);
      }
    } finally {
      if(dao != null) {
        emr.returnDao(dao);
      }
    }
  }
View Full Code Here

Examples of org.milyn.scribe.register.DaoRegister

    BeanContext beanContext = executionContext.getBeanContext();

    Object bean = beanContext.getBean(beanId);

    final DaoRegister emr = PersistenceUtil.getDAORegister(executionContext);

    Object dao = null;
    try {
      if(daoName == null) {
        dao = emr.getDefaultDao();
      } else {
        dao = emr.getDao(daoName);
      }

      if(dao == null) {
        throw new IllegalStateException("The DAO register returned null while getting the DAO '" + daoName + "'");
      }

      final DaoInvoker daoInvoker = DaoInvokerFactory.getInstance().create(dao, objectStore);

      Object result = name == null ? daoInvoker.update(bean) : daoInvoker.update(name, bean) ;

      if(updatedBeanId != null) {
        if(result == null) {
          result = bean;
        }
        beanContext.addBean(updatedBeanId, result, source);
      } else if(result != null && bean != result) {
        beanContext.changeBean(beanId, bean, source);
      }
    } finally {
      if(dao != null) {
        emr.returnDao(dao);
      }
    }
  }
View Full Code Here

Examples of org.milyn.scribe.register.DaoRegister

      }
      msg += ".";
      logger.debug(msg);
    }

    final DaoRegister emr = PersistenceUtil.getDAORegister(executionContext);

    Object dao = null;
    try {
      if(daoName == null) {
        dao = emr.getDefaultDao();
      } else {
        dao = emr.getDao(daoName);
      }

      if(dao == null) {
        throw new IllegalStateException("The DAO register returned null while getting the DAO [" + daoName + "]");
      }

      flush(dao);

    } finally {
      if(dao != null) {
        emr.returnDao(dao);
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.