Java Code Examples for org.hibernate.criterion.DetachedCriteria#setProjection()

The following examples show how to use org.hibernate.criterion.DetachedCriteria#setProjection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: K8sApiStatusDaoImpl.java    From kardio with Apache License 2.0 6 votes vote down vote up
@Override
public long getCurrentNumberOfApis(int envId,String componentIdsStrg) throws ParseException {
	
	List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg);
	
	Session session = sessionFactory.openSession();
	DetachedCriteria subMaxDate = DetachedCriteria.forClass(K8sApiStatusEntity.class);
	subMaxDate.setProjection(Projections.max("statusDate"));
	Criteria crtCurrenrApi = session.createCriteria(K8sApiStatusEntity.class);
	crtCurrenrApi.add(Property.forName("statusDate").eq(subMaxDate));
	DaoUtil.addEnvironmentToCriteria(envId, comIdList, crtCurrenrApi);
	crtCurrenrApi.setProjection(Projections.sum("totalApi"));
	long currentNumberOfApi = (long) (crtCurrenrApi.uniqueResult() == null ? (long)0 : crtCurrenrApi.uniqueResult());
	session.close();
	return currentNumberOfApi;
}
 
Example 2
Source File: TrialDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Collection<Trial> handleFindBySignup(Long departmentId, boolean ignoreSignupInquiries, PSFVO psf) throws Exception {
	org.hibernate.Criteria trialCriteria = createTrialCriteria("trial0");
	SubCriteriaMap criteriaMap = new SubCriteriaMap(Trial.class, trialCriteria);
	if (departmentId != null) {
		trialCriteria.add(Restrictions.eq("department.id", departmentId.longValue()));
	}
	org.hibernate.Criteria statusCriteria = trialCriteria.createCriteria("status", "trialStatus", CriteriaSpecification.INNER_JOIN);
	statusCriteria.add(Restrictions.eq("lockdown", false));
	DetachedCriteria subQuery = DetachedCriteria.forClass(InquiryImpl.class, "inquiry"); // IMPL!!!!
	subQuery.setProjection(Projections.rowCount());
	subQuery.add(Restrictions.eqProperty("trial.id", "trial0.id"));
	subQuery.add(Restrictions.eq("activeSignup", true));
	trialCriteria.add(
			Restrictions.or(
					Restrictions.eq("signupProbandList", true),
					Restrictions.and(
							ignoreSignupInquiries ? Subqueries.lt(0l, subQuery)
									: Restrictions.and(
											Restrictions.eq("signupInquiries", true),
											Subqueries.lt(0l, subQuery)),
							Restrictions.eq("trialStatus.inquiryValueInputEnabled", true))));
	CriteriaUtil.applyPSFVO(criteriaMap, psf);
	return trialCriteria.list();
}
 
Example 3
Source File: ECRFFieldStatusEntryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static DetachedCriteria createEcrfFieldStatusEntryDetachedCriteriaMaxId(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria,
		org.hibernate.Criteria probandListEntryCriteria,
		ECRFFieldStatusQueue queue, Long probandListEntryId, Long ecrfFieldId) {
	DetachedCriteria subQuery = createEcrfFieldStatusEntryDetachedCriteria(ecrfFieldStatusEntryCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId,
			ecrfFieldId);
	if (queue != null) {
		subQuery.add(Restrictions.eq("queue", queue));
		subQuery.setProjection(Projections.max("id"));
	} else {
		ProjectionList proj = Projections.projectionList();
		proj.add(Projections.sqlGroupProjection(
				"max({alias}.id) as maxId",
				"{alias}.queue",
				new String[] { "maxId" },
				new org.hibernate.type.Type[] { Hibernate.LONG }));
		subQuery.setProjection(proj);
	}
	return subQuery;
}
 
Example 4
Source File: ApiStatusDaoImpl.java    From kardio with Apache License 2.0 6 votes vote down vote up
@Override
public long getCurrentNumberOfApis(int envId,String componentIdsStrg) throws ParseException {
	
	List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg);
	
	Session session = sessionFactory.openSession();
	DetachedCriteria subMaxDate = DetachedCriteria.forClass(ApiStatusEntity.class);
	subMaxDate.setProjection(Projections.max("statusDate"));
	Criteria crtCurrenrApi = session.createCriteria(ApiStatusEntity.class);
	crtCurrenrApi.add(Property.forName("statusDate").eq(subMaxDate));
	DaoUtil.addEnvironmentToCriteria(envId, comIdList, crtCurrenrApi);
	crtCurrenrApi.setProjection(Projections.sum("totalApi"));
	long currentNumberOfApi = (long) (crtCurrenrApi.uniqueResult() == null ? (long)0 : crtCurrenrApi.uniqueResult());
	session.close();
	return currentNumberOfApi;
}
 
Example 5
Source File: ProductService.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Odata dedicated Services
 */
@Transactional(readOnly = true)
@Cacheable (value = "product_count", key = "{#criteria, #uuid}")
public int countProducts (DetachedCriteria criteria, String uuid)
{
   if (criteria == null)
   {
      criteria = DetachedCriteria.forClass (Product.class);
   }

   // count only processed products
   criteria.add (Restrictions.eq ("processed", true));

   if (uuid != null)
   {
      List<Long> product_ids = collectionService.getProductIds (uuid);
      criteria.add (Restrictions.in ("id", product_ids));
   }
   criteria.setProjection (Projections.rowCount ());
   return productDao.count (criteria);
}
 
Example 6
Source File: PermissionDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<Permission> handleFindByServiceMethodUser(
		String serviceMethod, Long userId, Boolean profilePermissionActive,
		Boolean userPermissionProfileActive) throws Exception {
	org.hibernate.Criteria permissionCritria = createPermissionCriteria();
	if (serviceMethod != null) {
		permissionCritria.add(Restrictions.eq("serviceMethod", serviceMethod));
	}
	if (userId != null || profilePermissionActive != null || userPermissionProfileActive != null) {
		org.hibernate.Criteria profilePermissionCritria = permissionCritria.createCriteria("profilePermissions", CriteriaSpecification.LEFT_JOIN);
		if (profilePermissionActive != null) {
			profilePermissionCritria.add(Restrictions.eq("active", profilePermissionActive.booleanValue()));
		}
		if (userId != null || userPermissionProfileActive != null) {
			DetachedCriteria subQuery = DetachedCriteria.forClass(UserPermissionProfileImpl.class, "userPermissionProfile"); // IMPL!!!!
			subQuery.setProjection(Projections.projectionList().add(Projections.property("profile")));
			if (userId != null) {
				subQuery.add(Restrictions.eq("user.id", userId.longValue()));
			}
			if (userPermissionProfileActive != null) {
				subQuery.add(Restrictions.eq("active", userPermissionProfileActive.booleanValue()));
			}
			profilePermissionCritria.add(Subqueries.propertyIn("profile", subQuery));
		}
	}
	return permissionCritria.list();
}
 
Example 7
Source File: UserService.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Counts corresponding users at the given criteria.
 *
 * @param criteria criteria contains filter of required collection.
 * @return number of corresponding users.
 */
@Transactional(readOnly = true)
public int countUsers (DetachedCriteria criteria)
{
   if (criteria == null)
   {
      criteria = DetachedCriteria.forClass (User.class);
   }
   criteria.setResultTransformer (Criteria.DISTINCT_ROOT_ENTITY);
   criteria.setProjection (Projections.rowCount ());
   return userDao.count (criteria);
}
 
Example 8
Source File: ECRFFieldValueDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<ECRFFieldValue> handleGetLog(Long trialId, Long probandListEntryId, Long ecrfId, String section, boolean sort, PSFVO psf) throws Exception {
	org.hibernate.Criteria ecrfFieldValueCriteria = createEcrfFieldValueCriteria("ecrfFieldValue0");
	org.hibernate.Criteria listEntryCriteria = ecrfFieldValueCriteria.createCriteria("listEntry", "probandListEntry0");
	if (trialId != null || probandListEntryId != null) {
		if (trialId != null) {
			listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
		}
		if (probandListEntryId != null) {
			listEntryCriteria.add(Restrictions.idEq(probandListEntryId.longValue()));
		}
	}
	org.hibernate.Criteria ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0");
	if (ecrfId != null) {
		ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
	}
	if (section != null && section.length() > 0) {
		ecrfFieldCriteria.add(Restrictions.eq("section", section));
	} else {
		ecrfFieldCriteria.add(Restrictions.or(Restrictions.eq("section", ""), Restrictions.isNull("section")));
	}
	DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, listEntryCriteria, probandListEntryId, null);
	subQuery.setProjection(Projections.rowCount());
	subQuery.add(Restrictions.or(Restrictions.isNull("index"),
			Restrictions.eqProperty("index", "ecrfFieldValue0" + ".index")));
	ecrfFieldValueCriteria.add(Subqueries.lt(1l, subQuery));
	SubCriteriaMap criteriaMap = new SubCriteriaMap(ECRFFieldValue.class, ecrfFieldValueCriteria);
	criteriaMap.registerCriteria("listEntry", listEntryCriteria);
	criteriaMap.registerCriteria("ecrfField", ecrfFieldCriteria);
	CriteriaUtil.applyPSFVO(criteriaMap, psf);
	if (sort) {
		applySortOrders(listEntryCriteria, ecrfFieldCriteria, ecrfFieldValueCriteria);
	}
	return ecrfFieldValueCriteria.list();
}
 
Example 9
Source File: ECRFFieldValueDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<ECRFFieldValue> handleGetLog(Long trialId, Long probandListEntryId, Long ecrfId, boolean sort, PSFVO psf) throws Exception {
	org.hibernate.Criteria ecrfFieldValueCriteria = createEcrfFieldValueCriteria("ecrfFieldValue0");
	org.hibernate.Criteria listEntryCriteria = ecrfFieldValueCriteria.createCriteria("listEntry", "probandListEntry0");
	if (trialId != null || probandListEntryId != null) {
		if (trialId != null) {
			listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
		}
		if (probandListEntryId != null) {
			listEntryCriteria.add(Restrictions.idEq(probandListEntryId.longValue()));
		}
	}
	org.hibernate.Criteria ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0");
	if (ecrfId != null) {
		ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
	}
	DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, listEntryCriteria, probandListEntryId, null);
	subQuery.setProjection(Projections.rowCount());
	subQuery.add(Restrictions.or(Restrictions.isNull("index"),
			Restrictions.eqProperty("index", "ecrfFieldValue0" + ".index")));
	ecrfFieldValueCriteria.add(Subqueries.lt(1l, subQuery));
	SubCriteriaMap criteriaMap = new SubCriteriaMap(ECRFFieldValue.class, ecrfFieldValueCriteria);
	criteriaMap.registerCriteria("listEntry", listEntryCriteria);
	criteriaMap.registerCriteria("ecrfField", ecrfFieldCriteria);
	CriteriaUtil.applyPSFVO(criteriaMap, psf);
	if (sort) {
		applySortOrders(listEntryCriteria, ecrfFieldCriteria, ecrfFieldValueCriteria);
	}
	return ecrfFieldValueCriteria.list();
}
 
Example 10
Source File: ECRFFieldValueDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static DetachedCriteria createEcrfFieldValueDetachedCriteriaMaxId(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria,
		org.hibernate.Criteria probandListEntryCriteria,
		Long probandListEntryId, Long ecrfFieldId) {
	DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId, ecrfFieldId);
	subQuery.setProjection(Projections.max("id"));
	return subQuery;
}
 
Example 11
Source File: ProbandDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<Proband> handleFindByMoneyTransferNoParticipation(Long trialId,
		PaymentMethod method, String costType, Boolean paid, boolean total,
		Boolean person, PSFVO psf)
		throws Exception {
	org.hibernate.Criteria probandCriteria = createProbandCriteria("proband0");
	if (person != null) {
		probandCriteria.add(Restrictions.eq("person", person.booleanValue()));
	}
	SubCriteriaMap criteriaMap = new SubCriteriaMap(Proband.class, probandCriteria);
	Criteria moneyTransferCriteria = criteriaMap.createCriteria("moneyTransfers");
	moneyTransferCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	if (method != null) {
		moneyTransferCriteria.add(Restrictions.eq("method", method));
	}
	if (paid != null) {
		moneyTransferCriteria.add(Restrictions.eq("paid", paid.booleanValue()));
	}
	CategoryCriterion.apply(moneyTransferCriteria, new CategoryCriterion(costType, "costType", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS));
	DetachedCriteria subQuery = DetachedCriteria.forClass(ProbandListEntryImpl.class, "probandListEntry"); // IMPL!!!!
	subQuery.setProjection(Projections.rowCount());
	subQuery.add(Restrictions.eqProperty("proband.id", "proband0.id"));
	subQuery.add(Restrictions.eq("trial.id", trialId.longValue()));
	if (!total) {
		subQuery.createCriteria("lastStatus", CriteriaSpecification.INNER_JOIN).createCriteria("status", CriteriaSpecification.INNER_JOIN)
				.add(Restrictions.eq("count", true));
	}
	probandCriteria.add(Subqueries.eq(0l, subQuery));
	return CriteriaUtil.listDistinctRootPSFVO(criteriaMap, psf, this);
}
 
Example 12
Source File: GoodsCommentDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public int getCount() {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsComment.class);
    criteria.setProjection(Projections.rowCount());
    Object obj  = template.findByCriteria(criteria).get(0);
    Long longObj = (Long) obj;
    int count = longObj.intValue();
    return count;
}
 
Example 13
Source File: ProbandListEntryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<ProbandListEntry> handleGetProbandList(
		Long trialId, org.phoenixctms.ctsms.enumeration.ProbandListStatusLogLevel logLevel, boolean last)
		throws Exception {
	// http://stackoverflow.com/questions/1648426/hibernate-detached-queries-as-a-part-of-the-criteria-query
	// https://forum.hibernate.org/viewtopic.php?p=2317841#2317841
	org.hibernate.Criteria listEntryCriteria = createListEntryCriteria();
	boolean distinctRoot = false;
	if (trialId != null) {
		listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	}
	if (logLevel != null) {
		org.hibernate.Criteria statusEntryCriteria;
		if (last) {
			statusEntryCriteria = listEntryCriteria.createCriteria("statusEntries", "probandListStatusEntry0", CriteriaSpecification.INNER_JOIN);
		} else {
			statusEntryCriteria = listEntryCriteria.createCriteria("statusEntries", CriteriaSpecification.INNER_JOIN);
		}
		org.hibernate.Criteria statusTypeCriteria = statusEntryCriteria.createCriteria("status", CriteriaSpecification.INNER_JOIN);
		org.hibernate.Criteria logLevelCriteria = statusTypeCriteria.createCriteria("logLevels", CriteriaSpecification.INNER_JOIN);
		logLevelCriteria.add(Restrictions.eq("logLevel", logLevel));
		if (last) {
			DetachedCriteria subQuery = DetachedCriteria.forClass(ProbandListStatusEntryImpl.class, "probandListStatusEntry1"); // IMPL!!!!
			subQuery.add(Restrictions.eqProperty("probandListStatusEntry1.listEntry", "probandListStatusEntry0.listEntry"));
			subQuery.setProjection(Projections.max("id"));
			statusEntryCriteria.add(Subqueries.propertyEq("id", subQuery));
		} else {
			distinctRoot = true;
		}
	}
	listEntryCriteria.addOrder(Order.asc("trial"));
	listEntryCriteria.addOrder(Order.asc("position"));
	if (distinctRoot) {
		return CriteriaUtil.listDistinctRoot(listEntryCriteria, this, "trial.id", "position");
	} else {
		return listEntryCriteria.list();
	}
}
 
Example 14
Source File: PasswordDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<Password> handleFindExpiring(Date today,
		Long departmentId, AuthenticationType authMethod, VariablePeriod reminderPeriod,
		Long reminderPeriodDays, Boolean notify, boolean includeAlreadyPassed, PSFVO psf) throws Exception {
	org.hibernate.Criteria passwordCriteria = createPasswordCriteria("password0");
	SubCriteriaMap criteriaMap = new SubCriteriaMap(Password.class, passwordCriteria);
	if (departmentId != null) {
		criteriaMap.createCriteria("user").add(Restrictions.eq("department.id", departmentId.longValue()));
	}
	if (authMethod != null) {
		criteriaMap.createCriteria("user").add(Restrictions.eq("authMethod", authMethod));
	}
	DetachedCriteria subQuery = DetachedCriteria.forClass(PasswordImpl.class, "password1"); // IMPL!!!!
	subQuery.add(Restrictions.eqProperty("password1.user", "password0.user"));
	subQuery.setProjection(Projections.max("id"));
	passwordCriteria.add(Subqueries.propertyEq("id", subQuery));
	passwordCriteria.add(Restrictions.eq("expires", true)); // performance only...
	if (notify != null) {
		passwordCriteria.add(Restrictions.eq("prolongable", notify.booleanValue())); // performance only...
	}
	if (psf != null) {
		PSFVO sorterFilter = new PSFVO();
		sorterFilter.setFilters(psf.getFilters());
		sorterFilter.setSortField(psf.getSortField());
		sorterFilter.setSortOrder(psf.getSortOrder());
		CriteriaUtil.applyPSFVO(criteriaMap, sorterFilter);
	}
	ArrayList<Password> resultSet = CriteriaUtil.listExpirations(passwordCriteria, today, notify, includeAlreadyPassed, null, null, reminderPeriod, reminderPeriodDays);
	return CriteriaUtil.applyPVO(resultSet, psf, false); // no dupes by default
}
 
Example 15
Source File: GoodsCommentDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public int getCountByCommentLevel(int commentLevel) {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsComment.class);

    criteria.add(Restrictions.eq("commentLevel", commentLevel));
    criteria.setProjection(Projections.rowCount());

    Object obj  = template.findByCriteria(criteria).get(0);
    Long longObj = (Long) obj;
    int count = longObj.intValue();
    return count;
}
 
Example 16
Source File: JournalEntryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected Collection<JournalEntry> handleFindRecent(JournalModule module, Long modifiedUserId, DBModule criteriaModule, Long entityDepartmentId, boolean limit, PSFVO psf)
		throws Exception {
	org.hibernate.Criteria journalCriteria = createJournalEntryCriteria("journalEntry0");
	SubCriteriaMap criteriaMap = new SubCriteriaMap(JournalEntry.class, journalCriteria);
	if (modifiedUserId != null) {
		journalCriteria.add(Restrictions.eq("modifiedUser.id", modifiedUserId.longValue()));
	}
	if (limit) {
		applyRecentJournalEntryTimestampCriterion(journalCriteria, null);
	}
	journalCriteria.add(Restrictions.or(
			Restrictions.eq("systemMessage", false),
			Restrictions.and(Restrictions.eq("systemMessage", true), Restrictions.eq("systemMessageModule", module))));
	criteriaMap.createCriteria("category", CriteriaSpecification.LEFT_JOIN).add(Restrictions.or(Restrictions.eq("module", module), Restrictions.isNull("module")));
	DetachedCriteria subQuery = DetachedCriteria.forClass(JournalEntryImpl.class, "journalEntry1"); // IMPL!!!!
	subQuery.setProjection(Projections.max("id"));
	journalCriteria.add(Subqueries.propertyEq("id", subQuery));
	switch (module) {
		case INVENTORY_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.inventory", "journalEntry0.inventory"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("inventory").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case STAFF_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.staff", "journalEntry0.staff"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("staff").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case COURSE_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.course", "journalEntry0.course"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("course").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case USER_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.user", "journalEntry0.user"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("user").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case TRIAL_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.trial", "journalEntry0.trial"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("trial").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case PROBAND_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.proband", "journalEntry0.proband"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("proband").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case CRITERIA_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.criteria", "journalEntry0.criteria"));
			if (criteriaModule != null) {
				subQuery.createCriteria("criteria", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("module", criteriaModule));
			}
			break;
		case INPUT_FIELD_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.inputField", "journalEntry0.inputField"));
			break;
		case MASS_MAIL_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.massMail", "journalEntry0.massMail"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("massMail").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		default:
	}
	CriteriaUtil.applyPSFVO(criteriaMap, psf);
	return journalCriteria.list();
}
 
Example 17
Source File: DetachedCriteriaUtil.java    From jeewx with Apache License 2.0 4 votes vote down vote up
/**
 * 该方法提供DetachedCriteria对查询字段的封装, 2008-9-29
 * 2009.9.9修改后,可支持无限级联取部分字段,如取如下字段 
 * user.organization.parentOrganization.parentOrganization.orgName
 * 但请注意1点 ,连接采用内联,级联越多,结果集可能就越少;
 * @author
 * @param columnNames
 *            字符串数组,以数据的形式接收要查询的字段属性,如String[] column={"属性1","属性2","属性3"};
 * @param pojoClass
 *            实体类的Class,如Mobile.class;
 * @param aials
 *            为要查询的POJO对象指定一个别名
 * @return DetachedCriteria 的一个对象,如果需要查询条件,在些对象后追加查询条件。
 * 
 * @param forJoinTable 是否多表连接查询
 */
public static void selectColumn(DetachedCriteria criteria, String[] columnNames,
		Class<?> pojoClass,boolean forJoinTable) {
	if (null == columnNames) {
		return;
	}

	//使用这个临时变量集合,是因为dinstinct关键字要放在最前面,而distinct关键字要在下面才决定放不放,
	List<Projection> tempProjectionList = new ArrayList<Projection>();
	
	Set<String> aliases = getAliasesFromRequest();
	boolean hasJoniTable = false;
	String rootAlias = criteria.getAlias();
	for (String property : columnNames) {
		if(property.contains("_")){
			String[] propertyChain = property.split("_");
			createAlias(criteria,rootAlias,aliases,propertyChain,0);
			tempProjectionList.add(Projections.property(StringUtil.getProperty(property)).as(StringUtil.getProperty(property)));
			hasJoniTable = true;
		}else{
			tempProjectionList.add(Projections.property(rootAlias + POINT + property).as(property));
		}
	}
	
	 projectionList = Projections.projectionList();
	if(hasJoniTable || forJoinTable ||  getHasJoinTatleFromRequest()){//这个一定要放在tempProjectionList的前面,因为distinct要在最前面
		projectionList.add(Projections.distinct(Projections.id()));
	}
	
	for (Projection proj : tempProjectionList) {
		projectionList.add(proj);
	}
	
	criteria.setProjection(projectionList);
	
	
	if(!hasJoniTable){
		criteria.setResultTransformer(Transformers.aliasToBean(pojoClass));
	}else{//下面这个是自定义的结果转换器
		criteria.setResultTransformer(new AliasToBean(pojoClass));
	}
}
 
Example 18
Source File: BaseController.java    From jeewx with Apache License 2.0 4 votes vote down vote up
/**
 * 分页公共方法(非easyui)
 * 
 * @author Alexander
 * @date 20131022
 */
public List<?> pageBaseMethod(HttpServletRequest request,
		DetachedCriteria dc, CommonService commonService, int pageRow) {
	// 当前页
	// 总条数
	// 总页数

	int currentPage = 1;

	int totalRow = 0;
	int totalPage = 0;
	// 获取当前页
	String str_currentPage = request.getParameter("str_currentPage");
	currentPage = str_currentPage == null || "".equals(str_currentPage) ? 1
			: Integer.parseInt(str_currentPage);
	// 获取每页的条数
	String str_pageRow = request.getParameter("str_pageRow");
	pageRow = str_pageRow == null || "".equals(str_pageRow) ? pageRow
			: Integer.parseInt(str_pageRow);

	// 统计的总行数
	dc.setProjection(Projections.rowCount());

	totalRow = Integer.parseInt(commonService.findByDetached(dc).get(0)
			.toString());
	totalPage = (totalRow + pageRow - 1) / pageRow;

	currentPage = currentPage < 1 ? 1 : currentPage;
	currentPage = currentPage > totalPage ? totalPage : currentPage;
	// 清空统计函数
	dc.setProjection(null);
	// dc.setResultTransformer(dc.DISTINCT_ROOT_ENTITY);
	List<?> list = commonService.pageList(dc, (currentPage - 1) * pageRow,
			pageRow);

	request.setAttribute("currentPage", currentPage);
	request.setAttribute("pageRow", pageRow);
	request.setAttribute("totalRow", totalRow);
	request.setAttribute("totalPage", totalPage);
	return list;
}
 
Example 19
Source File: BaseController.java    From jeecg with Apache License 2.0 4 votes vote down vote up
/**
 * 分页公共方法(非easyui)
 * 
 * @author Alexander
 * @date 20131022
 */
public List<?> pageBaseMethod(HttpServletRequest request,
		DetachedCriteria dc, CommonService commonService, int pageRow) {
	// 当前页
	// 总条数
	// 总页数

	int currentPage = 1;

	int totalRow = 0;
	int totalPage = 0;
	// 获取当前页
	String str_currentPage = request.getParameter("str_currentPage");
	currentPage = str_currentPage == null || "".equals(str_currentPage) ? 1
			: Integer.parseInt(str_currentPage);
	// 获取每页的条数
	String str_pageRow = request.getParameter("str_pageRow");
	pageRow = str_pageRow == null || "".equals(str_pageRow) ? pageRow
			: Integer.parseInt(str_pageRow);

	// 统计的总行数
	dc.setProjection(Projections.rowCount());

	totalRow = Integer.parseInt(commonService.findByDetached(dc).get(0)
			.toString());
	totalPage = (totalRow + pageRow - 1) / pageRow;

	currentPage = currentPage < 1 ? 1 : currentPage;
	currentPage = currentPage > totalPage ? totalPage : currentPage;
	// 清空统计函数
	dc.setProjection(null);
	// dc.setResultTransformer(dc.DISTINCT_ROOT_ENTITY);
	List<?> list = commonService.pageList(dc, (currentPage - 1) * pageRow,
			pageRow);

	request.setAttribute("currentPage", currentPage);
	request.setAttribute("pageRow", pageRow);
	request.setAttribute("totalRow", totalRow);
	request.setAttribute("totalPage", totalPage);
	return list;
}
 
Example 20
Source File: HibernateIdentifiableObjectStore.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a detached criteria with sharing restrictions relative to the given
 * user and access string.
 *
 * @param user   the user.
 * @param access the access string.
 * @return a DetachedCriteria.
 */
private DetachedCriteria getSharingDetachedCriteria( UserInfo user, String access )
{
    DetachedCriteria criteria = DetachedCriteria.forClass( getClazz(), "c" );

    preProcessDetachedCriteria( criteria );

    if ( !sharingEnabled( user ) || user == null )
    {
        return criteria;
    }

    Assert.notNull( user, "User argument can't be null." );

    Disjunction disjunction = Restrictions.disjunction();

    disjunction.add( Restrictions.like( "c.publicAccess", access ) );
    disjunction.add( Restrictions.isNull( "c.publicAccess" ) );
    disjunction.add( Restrictions.isNull( "c.user.id" ) );
    disjunction.add( Restrictions.eq( "c.user.id", user.getId() ) );

    DetachedCriteria userGroupDetachedCriteria = DetachedCriteria.forClass( getClazz(), "ugdc" );
    userGroupDetachedCriteria.createCriteria( "ugdc.userGroupAccesses", "uga" );
    userGroupDetachedCriteria.createCriteria( "uga.userGroup", "ug" );
    userGroupDetachedCriteria.createCriteria( "ug.members", "ugm" );

    userGroupDetachedCriteria.add( Restrictions.eqProperty( "ugdc.id", "c.id" ) );
    userGroupDetachedCriteria.add( Restrictions.eq( "ugm.id", user.getId() ) );
    userGroupDetachedCriteria.add( Restrictions.like( "uga.access", access ) );

    userGroupDetachedCriteria.setProjection( Property.forName( "uga.id" ) );

    disjunction.add( Subqueries.exists( userGroupDetachedCriteria ) );

    DetachedCriteria userDetachedCriteria = DetachedCriteria.forClass( getClazz(), "udc" );
    userDetachedCriteria.createCriteria( "udc.userAccesses", "ua" );
    userDetachedCriteria.createCriteria( "ua.user", "u" );

    userDetachedCriteria.add( Restrictions.eqProperty( "udc.id", "c.id" ) );
    userDetachedCriteria.add( Restrictions.eq( "u.id", user.getId() ) );
    userDetachedCriteria.add( Restrictions.like( "ua.access", access ) );

    userDetachedCriteria.setProjection( Property.forName( "ua.id" ) );

    disjunction.add( Subqueries.exists( userDetachedCriteria ) );

    criteria.add( disjunction );

    return criteria;
}