List of usage examples for org.hibernate.criterion DetachedCriteria addOrder
public DetachedCriteria addOrder(Order order)
From source file:com.emergya.persistenceGeo.dao.impl.AbstractGenericDaoHibernateImpl.java
License:Open Source License
/** * Use this inside subclasses as a convenience method. * * @param orders/* w ww. ja va 2 s. c om*/ * @param detachedCriterias * * @return List with detachedCriterias ordered by orders[0..N] */ @SuppressWarnings("unchecked") protected List<T> findByCriteriaOrdered(Order[] orders, Criterion... detachedCriterias) { DetachedCriteria crit = DetachedCriteria.forClass(persistentClass); for (Criterion c : detachedCriterias) { crit.add(c); } if (orders != null) { for (Order order : orders) { crit.addOrder(order); } } return getHibernateTemplate().findByCriteria(crit); }
From source file:com.emergya.persistenceGeo.dao.impl.AbstractGenericDaoHibernateImpl.java
License:Open Source License
/** * Use this inside subclasses as a convenience method. *//* w w w . j ava2s . c om*/ @SuppressWarnings("unchecked") protected List<T> findByCriteria(int firstResult, int maxResults, Order order, Criterion... detachedCriterias) { DetachedCriteria crit = DetachedCriteria.forClass(persistentClass); for (Criterion c : detachedCriterias) { crit.add(c); } crit.addOrder(order); return getHibernateTemplate().findByCriteria(crit, firstResult, maxResults); }
From source file:com.emergya.persistenceGeo.dao.impl.AbstractGenericDaoHibernateImpl.java
License:Open Source License
/** * Use this inside subclasses as a convenience method. */// w ww .j a v a 2 s. co m @SuppressWarnings("unchecked") protected List<T> findByCriteria(int firstResult, int maxResults, Order[] orders, Criterion... detachedCriterias) { DetachedCriteria crit = DetachedCriteria.forClass(persistentClass); for (Criterion c : detachedCriterias) { crit.add(c); } if (orders != null) { for (Order order : orders) { crit.addOrder(order); } } return getHibernateTemplate().findByCriteria(crit, firstResult, maxResults); }
From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassDaoImpl.java
License:Open Source License
/** * This API will fetch all the batch classes of current user role. * /*from ww w. j av a 2 s . c o m*/ * @param userRoles Set<String> * @return List<BatchClass> */ @Override public List<BatchClass> getAllBatchClassesByUserRoles(final Set<String> userRoles) { DetachedCriteria criteria = criteria(); List<BatchClass> batchClassList = null; if (userRoles == null) { batchClassList = new ArrayList<BatchClass>(); } else { List<String> roleList = new ArrayList<String>(); for (String userRole : userRoles) { if (null == userRole || userRole.isEmpty()) { continue; } roleList.add(userRole); } criteria.createAlias(ASSIGNED_GROUPS, ASSIGNED_GROUPS); criteria.add(Restrictions.in(ASSIGNED_GROUPS_NAME, roleList)); criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false))); criteria.addOrder(org.hibernate.criterion.Order.asc(BATCH_ID)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); batchClassList = find(criteria); } return batchClassList; }
From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassDaoImpl.java
License:Open Source License
/** * API to fetch the UNC folders for a batch class by name. * //w w w . j a va 2 s. c o m * @param batchClassName {@link String} * @return List<String> */ @Override public List<String> getAllAssociatedUNCFolders(String batchClassName) { DetachedCriteria criteria = criteria(); criteria.setProjection(Projections.property(UNC_FOLDER)); criteria.add(Restrictions.eq(NAME, batchClassName)); criteria.addOrder(org.hibernate.criterion.Order.asc(IDENTIFIER)); criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false))); return this.find(criteria); }
From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassDaoImpl.java
License:Open Source License
/** * API to get all batch classes on the basis of excluding the deleted batch class and on the basis of ascending or desending order * of specified property.//from w w w .j a va 2 s . c o m * * @param isExcludeDeleted boolean * @param isAsc boolean * @param propertyName {@link String} * @return List<{@link BatchClass}> */ @Override public List<BatchClass> getAllBatchClasses(boolean isExcludeDeleted, boolean isAsc, String propertyName) { DetachedCriteria criteria = criteria(); if (isExcludeDeleted) { criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false))); } if (propertyName != null) { if (isAsc) { criteria.addOrder(org.hibernate.criterion.Order.asc(propertyName)); } else { criteria.addOrder(org.hibernate.criterion.Order.desc(propertyName)); } } return this.find(criteria); }
From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassDaoImpl.java
License:Open Source License
/** * API to the batch class with respect to the given batch class id and the roles provided. * //from w w w . jav a2 s . c o m * @param userRoles {@link Set<{@link String}>} * @param batchClassID {@link String} * @return {@link BatchClass} */ @Override public BatchClass getBatchClassByUserRoles(final Set<String> userRoles, String batchClassID) { DetachedCriteria criteria = criteria(); List<BatchClass> batchClassList = null; BatchClass batchClass = null; if (userRoles == null) { batchClassList = new ArrayList<BatchClass>(); } else { List<String> roleList = new ArrayList<String>(); for (String userRole : userRoles) { if (null == userRole || userRole.isEmpty()) { continue; } roleList.add(userRole); } criteria.createAlias(ASSIGNED_GROUPS, ASSIGNED_GROUPS); criteria.add(Restrictions.in(ASSIGNED_GROUPS_NAME, roleList)); criteria.add(Restrictions.eq(IDENTIFIER, batchClassID)); criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false))); criteria.addOrder(org.hibernate.criterion.Order.asc(BATCH_ID)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); batchClassList = find(criteria); if (batchClassList != null && !batchClassList.isEmpty()) { batchClass = batchClassList.get(0); } } return batchClass; }
From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassGroupsDaoImpl.java
License:Open Source License
/** * API for getting the batch class identifiers having the user roles. * @param userRoles Set<String>/* ww w . j a va2s .c o m*/ * @param includeDeleted boolean * @return Set<String> */ @Override public Set<String> getBatchClassIdentifierForUserRoles(Set<String> userRoles, boolean includeDeleted) { boolean isValid = true; if (userRoles == null || userRoles.size() == 0) { isValid = false; } Set<String> batchClassIdentifiers = null; // New version of fetching. if (isValid) { batchClassIdentifiers = new LinkedHashSet<String>(); DetachedCriteria criteria = criteria(); Disjunction disjunction = Restrictions.disjunction(); for (String userRole : userRoles) { disjunction.add(Restrictions.eq(GROUP_NAME, userRole)); } criteria.add(disjunction); criteria.addOrder(Order.asc(BATCH_CLASS)); List<BatchClassGroups> batchClassGroups = find(criteria); for (BatchClassGroups batchClassGroup : batchClassGroups) { if (includeDeleted) { batchClassIdentifiers.add(batchClassGroup.getBatchClass().getIdentifier()); } else { if (!batchClassGroup.getBatchClass().isDeleted()) { batchClassIdentifiers.add(batchClassGroup.getBatchClass().getIdentifier()); } } } } return batchClassIdentifiers; }
From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassModuleDaoImpl.java
License:Open Source License
/** * API to fetch Modules starting from firstIndex and as many results as MaxResults from a batch class. * /* w w w. j ava 2 s. c o m*/ * @param batchClassId * @param firstIndex * @param maxResults * @return List<Module> */ @Override public List<Module> getModules(String batchClassIdentifier, int firstIndex, int maxResults) { DetachedCriteria criteria = criteria(); criteria.createAlias(BATCH_CLASS, BATCH_CLASS); criteria.add(Restrictions.eq(BATCH_CLASS_IDENTIFIER, batchClassIdentifier)); criteria.setProjection(Projections.property(MODULE)); criteria.addOrder(Order.asc("orderNumber")); return find(criteria, firstIndex, maxResults); }
From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassModuleDaoImpl.java
License:Open Source License
/** * API to fetch all batch class modules in order. * @param order Order/*from w ww. j a v a2 s . co m*/ * @return List<BatchClassModule> */ @Override public List<BatchClassModule> getAllBatchClassModulesInOrder(com.ephesoft.dcma.core.common.Order order) { DetachedCriteria criteria = criteria(); if (order != null) { if (order.isAscending()) { criteria.addOrder(Order.asc(order.getSortProperty().getProperty())); } else { criteria.addOrder(Order.desc(order.getSortProperty().getProperty())); } } return find(criteria); }