List of usage examples for org.hibernate.criterion DetachedCriteria setProjection
public DetachedCriteria setProjection(Projection projection)
From source file:org.generationcp.middleware.dao.GermplasmListDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<GermplasmList> getByGIDandProgramUUID(final Integer gid, final int start, final int numOfRows, final String programUUID) { try {/*from w w w .j a v a 2 s .com*/ if (gid != null) { final Criteria criteria = this.getSession().createCriteria(GermplasmList.class, "germplasmList"); final DetachedCriteria gidCriteria = DetachedCriteria.forClass(GermplasmListData.class, "listData"); gidCriteria.add(Restrictions.eq("listData.gid", gid)); gidCriteria.add(Property.forName("germplasmList.id").eqProperty("listData.list.id")); criteria.add(Subqueries.exists(gidCriteria.setProjection(Projections.property("listData.gid")))); criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED)); this.addCriteriaForProgramUUIDInLists(programUUID, criteria); criteria.setFirstResult(start); criteria.setMaxResults(numOfRows); criteria.addOrder(Order.asc("name")); this.hideSnapshotListTypes(criteria); return criteria.list(); } } catch (final HibernateException e) { final String errorMessage = "Error with getByGIDandProgramUUID(gid=" + gid + ",programUUID=" + programUUID + ") query from GermplasmList: " + e.getMessage(); GermplasmListDAO.LOG.error(errorMessage); throw new MiddlewareQueryException(errorMessage, e); } return new ArrayList<>(); }
From source file:org.generationcp.middleware.dao.GermplasmListDAO.java
License:Open Source License
public long countByGIDandProgramUUID(final Integer gid, final String programUUID) { try {/* ww w .j a v a 2s .c o m*/ if (gid != null) { final Criteria criteria = this.getSession().createCriteria(GermplasmList.class, "germplasmList"); final DetachedCriteria gidCriteria = DetachedCriteria.forClass(GermplasmListData.class, "listData"); gidCriteria.add(Restrictions.eq("listData.gid", gid)); gidCriteria.add(Property.forName("germplasmList.id").eqProperty("listData.list.id")); criteria.add(Subqueries.exists(gidCriteria.setProjection(Projections.property("listData.gid")))); criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED)); this.addCriteriaForProgramUUIDInLists(programUUID, criteria); this.hideSnapshotListTypes(criteria); criteria.setProjection(Projections.countDistinct("id")); return ((Long) criteria.uniqueResult()).longValue(); // count } } catch (final HibernateException e) { final String errorMessage = "Error with countByGIDandProgramUUID(gid=" + gid + ",programUUID=" + programUUID + ") query from GermplasmList: " + e.getMessage(); GermplasmListDAO.LOG.error(errorMessage); throw new MiddlewareQueryException(errorMessage, e); } return 0; }
From source file:org.hoteia.qalingo.core.dao.ProductDao.java
License:Apache License
public List<ProductSku> findProductSkusNotInThisMasterCatalogCategoryId(final Long categoryId, Object... params) {//w ww . java 2 s . c o m DetachedCriteria subquery = DetachedCriteria.forClass(ProductSku.class); subquery.createAlias("catalogCategoryMasterProductSkuRels", "catalogCategoryProductSkuRel", JoinType.LEFT_OUTER_JOIN); subquery.add(Restrictions.eq("catalogCategoryProductSkuRel.pk.catalogCategoryMaster.id", categoryId)); subquery.setProjection(Projections.property("id")); Criteria criteria = createDefaultCriteria(ProductSku.class); handleSpecificProductSkuFetchMode(criteria, params); criteria.add(Subqueries.notIn("id", subquery)); criteria.addOrder(Order.asc("id")); @SuppressWarnings("unchecked") List<ProductSku> productSkus = criteria.list(); return productSkus; }
From source file:org.infoscoop.dao.StaticTabDAO.java
License:Open Source License
/** * get tabId list without commandbar and portalHeader. * /*from w ww .j a v a2 s . c om*/ * @return */ public List getTabIdList() { DetachedCriteria c = DetachedCriteria.forClass(StaticTab.class); c.add(Expression.ne(StaticTab.PROP_ID, StaticTab.COMMANDBAR_TAB_ID)); c.add(Expression.ne(StaticTab.PROP_ID, StaticTab.PORTALHEADER_TAB_ID)); c.add(Expression.eq(StaticTab.PROP_DELETEFLAG, StaticTab.DELETEFLAG_FALSE)); c.setProjection(Projections.property("Tabid")); c.addOrder(Order.asc(StaticTab.PROP_TABNUMBER)); return super.getHibernateTemplate().findByCriteria(c); }
From source file:org.jasig.ssp.dao.PersonDao.java
License:Apache License
public PagingWrapper<Person> getAllAssignedCoaches(SortingAndPaging sAndP) { DetachedCriteria coach_ids = DetachedCriteria.forClass(Person.class, "coach_ids"); final ProjectionList projections = Projections.projectionList(); projections.add(Projections.distinct(Projections.property("coach.id"))); coach_ids.setProjection(projections); coach_ids.add(Restrictions.isNotNull("coach")); Criteria criteria = createCriteria().add(Subqueries.propertiesIn(new String[] { "id" }, coach_ids)); if (sAndP != null && sAndP.isFilteredByStatus()) { sAndP.addStatusFilterToCriteria(criteria); }/*from w w w. j a v a 2 s . com*/ // item count Long totalRows = 0L; if ((sAndP != null) && sAndP.isPaged()) { totalRows = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); } criteria.setProjection(null); if (sAndP == null || !(sAndP.isSorted())) { criteria.addOrder(Order.asc("lastName")).addOrder(Order.asc("firstName")); } else { if (sAndP.isSorted()) { sAndP.addSortingToCriteria(criteria); } sAndP.addPagingToCriteria(criteria); } return new PagingWrapper<Person>(totalRows, criteria.list()); }
From source file:org.jasig.ssp.dao.PersonDao.java
License:Apache License
public PagingWrapper<CoachPersonLiteTO> getAllAssignedCoachesLite(SortingAndPaging sAndP, String homeDepartment) {//from ww w . j a va 2 s. c om DetachedCriteria coach_ids = DetachedCriteria.forClass(Person.class, "coach_ids"); final ProjectionList projections = Projections.projectionList(); projections.add(Projections.distinct(Projections.property("coach.id"))); coach_ids.setProjection(projections); coach_ids.add(Restrictions.isNotNull("coach")); Criteria criteria = createCriteria().add(Subqueries.propertiesIn(new String[] { "id" }, coach_ids)); if (sAndP != null && sAndP.isFilteredByStatus()) { sAndP.addStatusFilterToCriteria(criteria); } if (homeDepartment != null && homeDepartment.length() >= 0) { criteria.createAlias("staffDetails", "personStaffDetails"); criteria.add(Restrictions.eq("personStaffDetails.departmentName", homeDepartment)); } else { criteria.createAlias("staffDetails", "personStaffDetails", JoinType.LEFT_OUTER_JOIN); } // item count Long totalRows = 0L; if ((sAndP != null) && sAndP.isPaged()) { totalRows = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); } criteria.setProjection(null); criteria.setProjection(Projections.projectionList().add(Projections.property("id").as("person_id")) .add(Projections.property("firstName").as("person_firstName")) .add(Projections.property("lastName").as("person_lastName")) .add(Projections.property("primaryEmailAddress").as("person_primaryEmailAddress")) .add(Projections.property("workPhone").as("person_workPhone")) .add(Projections.property("personStaffDetails.departmentName").as("person_departmentName"))) .setResultTransformer( new NamespacedAliasToBeanResultTransformer(CoachPersonLiteTO.class, "person_")); return new PagingWrapper<CoachPersonLiteTO>(totalRows, criteria.list()); }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.GridCQLToDetachedCriteria.java
License:Open Source License
private DetachedCriteria handleQueryOptions(DetachedCriteria criteria, QueryModifier modifiers) { if (modifiers == null) { return criteria; }/* w w w .j a v a 2 s.c om*/ ProjectionList projectionList = Projections.projectionList(); String[] projectionProperties = modifiers.getAttributeNames(); if (projectionProperties != null) { for (String prop : projectionProperties) { projectionList.add(Projections.property(prop)); } } String distinctAttribute = modifiers.getDistinctAttribute(); if (distinctAttribute != null) { projectionList.add(Projections.distinct(Projections.property(distinctAttribute))); } boolean isCount = modifiers.isCountOnly(); if (isCount) { projectionList.add(Projections.rowCount()); } //Only add the Projection List if it was populated with something. if (projectionList.getLength() > 0) { criteria.setProjection(projectionList); } return criteria; }
From source file:org.linagora.linshare.core.repository.hibernate.AccountQuotaRepositoryImpl.java
License:Open Source License
@Override public List<String> findDomainUuidByBatchModificationDate(Date startDate) { DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.add(Restrictions.ge("batchModificationDate", startDate)); criteria.add(Restrictions.le("batchModificationDate", new Date())); criteria.createAlias("domain", "do"); criteria.setProjection(Projections.distinct(Projections.property("do.uuid"))); @SuppressWarnings("unchecked") List<String> listIdentifier = (List<String>) getHibernateTemplate().findByCriteria(criteria); return listIdentifier; }
From source file:org.linagora.linshare.core.repository.hibernate.AccountQuotaRepositoryImpl.java
License:Open Source License
@Override public Long sumOfCurrentValue(ContainerQuota containerQuota) { DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.add(Restrictions.eq("containerQuota", containerQuota)); criteria.add(Restrictions.ge("batchModificationDate", getTodayBegin())); criteria.setProjection(Projections.sum("currentValue")); List<AccountQuota> list = findByCriteria(criteria); if (list.size() > 0 && list.get(0) != null) { return DataAccessUtils.longResult(findByCriteria(criteria)); }//from ww w .jav a 2s . co m return (long) 0; }
From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java
License:Open Source License
@Override public Long sumOfCurrentValue(DomainQuota domainQuota) { DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.add(Restrictions.eq("domainQuota", domainQuota)); criteria.add(Restrictions.ge("batchModificationDate", getTodayBegin())); criteria.setProjection(Projections.sum("currentValue")); List<ContainerQuota> list = findByCriteria(criteria); if (list.size() > 0 && list.get(0) != null) { return DataAccessUtils.longResult(findByCriteria(criteria)); }// w ww .j a v a 2s.c o m return 0L; }