org.hibernate.criterion.Expression#and ( )源码实例Demo

下面列出了org.hibernate.criterion.Expression#and ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Knowage-Server   文件: DomainDAOHibImpl.java
/**
 * Same as loadDomainByCodeAndValue but with (optional) external session
 *
 * @param codeDomain
 * @param codeValue
 * @param aSession
 * @return
 * @throws EMFUserError
 */
@Override
public Domain loadDomainByCodeAndValue(String codeDomain, String codeValue, Session aSession) throws EMFUserError {
	if (aSession == null) {
		return loadDomainByCodeAndValue(codeDomain, codeValue);
	} else {
		Criterion aCriterion = Expression.and(Expression.eq("domainCd", codeDomain), Expression.eq("valueCd", codeValue));
		Criteria criteria = aSession.createCriteria(SbiDomains.class);
		criteria.add(aCriterion);

		SbiDomains aSbiDomains = (SbiDomains) criteria.uniqueResult();
		if (aSbiDomains == null)
			return null;

		return toDomain(aSbiDomains);
	}
}
 
源代码2 项目: Knowage-Server   文件: DomainDAOHibImpl.java
/**
 * Load domain by code and value.
 *
 * @param codeDomain
 *            the code domain
 * @param codeValue
 *            the code value
 *
 * @return the domain
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.commons.dao.IDomainDAO#loadDomainByCodeAndValue(java.lang.String, java.lang.String)
 */
@Override
public SbiDomains loadSbiDomainByCodeAndValue(String codeDomain, String codeValue) throws EMFUserError {
	/*
	 * <STATEMENT name="SELECT_DOMAIN_FROM_CODE_VALUE" query="SELECT D.VALUE_NM AS VALUE_NAME, D.VALUE_ID AS VALUE_ID, D.VALUE_CD AS VALUE_CD FROM
	 * SBI_DOMAINS D WHERE DOMAIN_CD = ? AND VALUE_CD = ? "/>
	 */
	SbiDomains aSbiDomains = null;
	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();

		Criterion aCriterion = Expression.and(Expression.eq("domainCd", codeDomain), Expression.eq("valueCd", codeValue));
		Criteria criteria = aSession.createCriteria(SbiDomains.class);
		criteria.add(aCriterion);

		aSbiDomains = (SbiDomains) criteria.uniqueResult();
		if (aSbiDomains == null)
			return null;

		tx.commit();
	} catch (HibernateException he) {
		logException(he);

		if (tx != null)
			tx.rollback();

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}

	return aSbiDomains;
}
 
@Override
public boolean checkUserRootExists(String userId) throws EMFUserError {
	logger.debug("IN");
	boolean exists = false;
	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		Criterion userfunctANDnullparent = Expression.and(Expression.isNull("parentFunct"), Expression.eq("functTypeCd", "USER_FUNCT"));
		Criterion filters = Expression.and(userfunctANDnullparent, Expression.like("path", "/" + userId));
		Criteria criteria = aSession.createCriteria(SbiFunctions.class);
		criteria.add(filters);
		SbiFunctions hibFunct = (SbiFunctions) criteria.uniqueResult();
		if (hibFunct != null)
			exists = true;
		tx.commit();
	} catch (HibernateException he) {
		logger.error("HibernateException", he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
	logger.debug("OUT");
	return exists;
}
 
/**
 * Load root low functionality.
 *
 * @param recoverBIObjects
 *            the recover bi objects
 *
 * @return the low functionality
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.analiticalmodel.functionalitytree.dao.ILowFunctionalityDAO#loadRootLowFunctionality(boolean)
 */
@Override
public LowFunctionality loadRootLowFunctionality(boolean recoverBIObjects) throws EMFUserError {
	logger.debug("IN");
	LowFunctionality funct = null;
	funct = getFromCache(ROOT);
	if (funct == null) {
		Session aSession = null;
		Transaction tx = null;
		try {
			aSession = getSession();
			tx = aSession.beginTransaction();
			/* ********* start luca changes *************** */
			// Criterion filters = Expression.isNull("parentFunct");
			Criterion filters = Expression.and(Expression.isNull("parentFunct"), Expression.eq("functTypeCd", "LOW_FUNCT"));
			/* ************ end luca changes ************** */
			Criteria criteria = aSession.createCriteria(SbiFunctions.class);
			criteria.add(filters);
			SbiFunctions hibFunct = (SbiFunctions) criteria.uniqueResult();
			if (hibFunct == null)
				return null;
			funct = toLowFunctionality(hibFunct, recoverBIObjects);
			tx.commit();
		} catch (HibernateException he) {
			logger.error("HibernateException", he);
			if (tx != null)
				tx.rollback();
			throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
		} finally {
			if (aSession != null) {
				if (aSession.isOpen())
					aSession.close();
			}
		}
		putIntoCache(ROOT, funct);
	}
	logger.debug("OUT");
	return funct;
}
 
/**
 * Saves all roles for a functionality, using session and permission information. The permission for a functionality can be DEVELOPMENT, TEST, EXECUTION AND
 * CREATE and each permission has its own roles.
 *
 * @param aSession
 *            The current session object
 * @param hibFunct
 *            The functionality hibernate object
 * @param aLowFunctionality
 *            The Low Functionality object
 * @param permission
 *            The string defining the permission
 * @return A collection object containing all roles
 * @throws EMFUserError
 *
 */
private Set saveRolesFunctionality(Session aSession, SbiFunctions hibFunct, LowFunctionality aLowFunctionality, String permission) throws EMFUserError {
	Set functRoleToSave = new HashSet();
	Criterion domainCdCriterrion = null;
	Criteria criteria = null;
	criteria = aSession.createCriteria(SbiDomains.class);
	domainCdCriterrion = Expression.and(Expression.eq("valueCd", permission), Expression.eq("domainCd", SpagoBIConstants.PERMISSION_ON_FOLDER));
	criteria.add(domainCdCriterrion);
	SbiDomains permissionDomain = (SbiDomains) criteria.uniqueResult();
	if (permissionDomain == null) {
		logger.error("The Domain with value_cd=" + permission + " and domain_cd=" + SpagoBIConstants.PERMISSION_ON_FOLDER + " does not exist.");
		throw new EMFUserError(EMFErrorSeverity.ERROR, 1039);
	}
	Role[] roles = null;
	if (permission.equalsIgnoreCase(SpagoBIConstants.PERMISSION_ON_FOLDER_TO_DEVELOP)) {
		roles = aLowFunctionality.getDevRoles();
	} else if (permission.equalsIgnoreCase(SpagoBIConstants.PERMISSION_ON_FOLDER_TO_TEST)) {
		roles = aLowFunctionality.getTestRoles();
	} else if (permission.equalsIgnoreCase(SpagoBIConstants.PERMISSION_ON_FOLDER_TO_EXECUTE)) {
		roles = aLowFunctionality.getExecRoles();
	} else if (permission.equalsIgnoreCase(SpagoBIConstants.PERMISSION_ON_FOLDER_TO_CREATE)) {
		roles = aLowFunctionality.getCreateRoles();
	}
	for (int i = 0; i < roles.length; i++) {
		Role role = roles[i];
		domainCdCriterrion = Expression.eq("name", role.getName());
		criteria = aSession.createCriteria(SbiExtRoles.class);
		criteria.add(domainCdCriterrion);
		SbiExtRoles hibRole = (SbiExtRoles) criteria.uniqueResult();
		SbiFuncRoleId sbifuncroleid = new SbiFuncRoleId();
		sbifuncroleid.setFunction(hibFunct);
		sbifuncroleid.setState(permissionDomain);
		sbifuncroleid.setRole(hibRole);
		SbiFuncRole sbifuncrole = new SbiFuncRole();
		sbifuncrole.setId(sbifuncroleid);
		sbifuncrole.setStateCd(permissionDomain.getValueCd());

		updateSbiCommonInfo4Update(sbifuncrole, true);

		aSession.save(sbifuncrole);
		functRoleToSave.add(sbifuncrole);
	}
	logger.debug("The [saveRolesFunctionality] occurs. LowFunctionality cache will be cleaned.");
	this.clearCache();
	return functRoleToSave;
}
 
源代码6 项目: Knowage-Server   文件: DataSourceDAOHibImpl.java
/**
 * Insert data source.
 *
 * @param aDataSource
 *            the a data source
 * @throws EMFUserError
 *             the EMF user error
 * @see it.eng.spagobi.tools.datasource.dao.IDataSourceDAO#insertDataSource(it.eng.spagobi.tools.datasource.bo.IDataSource)
 */
@Override
public Integer insertDataSource(IDataSource aDataSource, String organization) throws EMFUserError {
	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;
	Integer id = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();

		Criterion aCriterion = Expression.and(Expression.eq("domainCd", "DIALECT_HIB"), Expression.eq("valueCd", aDataSource.getDialectName()));
		Criteria criteria = aSession.createCriteria(SbiDomains.class);
		criteria.add(aCriterion);

		SbiDomains dialect = (SbiDomains) criteria.uniqueResult();

		if (dialect == null) {
			logger.error("The Domain with value_cd=" + aDataSource.getDialectName() + " does not exist.");
			throw new EMFUserError(EMFErrorSeverity.ERROR, 1035);
		}

		SbiDataSource hibDataSource = toSbiDataSource(aDataSource);
		hibDataSource.setDialect(dialect);
		hibDataSource.setDialectDescr(dialect.getValueNm());
		hibDataSource.setReadOnly(aDataSource.checkIsReadOnly());

		disableOtherWriteDefault(aDataSource, hibDataSource, aSession);

		hibDataSource.setWriteDefault(aDataSource.checkIsWriteDefault());

		hibDataSource.getCommonInfo().setOrganization(organization);

		updateSbiCommonInfo4Insert(hibDataSource);
		id = (Integer) aSession.save(hibDataSource);
		tx.commit();
		aSession.flush();
		tx.begin();
		SbiTenant sbiOrganizations = DAOFactory.getTenantsDAO().loadTenantByName(hibDataSource.getCommonInfo().getOrganization());

		SbiOrganizationDatasource sbiOrganizationDatasource = new SbiOrganizationDatasource();
		sbiOrganizationDatasource.setSbiDataSource(hibDataSource);
		sbiOrganizationDatasource.setSbiOrganizations(sbiOrganizations);
		SbiOrganizationDatasourceId idRel = new SbiOrganizationDatasourceId();
		idRel.setDatasourceId(id);
		idRel.setOrganizationId(sbiOrganizations.getId());
		sbiOrganizationDatasource.setId(idRel);

		sbiOrganizationDatasource.getCommonInfo().setOrganization(organization);

		updateSbiCommonInfo4Insert(sbiOrganizationDatasource);

		aSession.save(sbiOrganizationDatasource);

		tx.commit();
	} catch (HibernateException he) {
		logger.error("Error while inserting the data source with id " + ((aDataSource == null) ? "" : String.valueOf(aDataSource.getDsId())), he);

		if (tx != null)
			tx.rollback();

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
			logger.debug("OUT");
		}

	}
	return id;
}
 
 同类方法