当前位置: 首页>>代码示例>>Java>>正文


Java Projection类代码示例

本文整理汇总了Java中org.hibernate.criterion.Projection的典型用法代码示例。如果您正苦于以下问题:Java Projection类的具体用法?Java Projection怎么用?Java Projection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Projection类属于org.hibernate.criterion包,在下文中一共展示了Projection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findByCriteria

import org.hibernate.criterion.Projection; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private List findByCriteria(Criteria crit, int pageNo, int pageSize, Projection projection, Order... orders) {
	if ((pageNo <= 0 && pageNo != -1) || pageSize < 1) {
		return new ArrayList();
	}
	crit.setProjection(projection);
	if (projection == null) {
		crit.setResultTransformer(Criteria.ROOT_ENTITY);
	}
	if (orders != null) {
		for (Order order : orders) {
			crit.addOrder(order);
		}
	}
	if (pageNo != -1) {
		crit.setFirstResult((pageNo - 1) * pageSize);
		crit.setMaxResults(pageSize);
	}
	return crit.list();
}
 
开发者ID:xushaomin,项目名称:apple-orm,代码行数:21,代码来源:HibernateBaseDAO2.java

示例2: createAliasedProjectionList

import org.hibernate.criterion.Projection; //导入依赖的package包/类
/**
 * @deprecated This method does not work well due to Hibernate bug HHH-817, nor does
 *             AliasToBeanResultTransformer handle multi-level property values.
 *             Therefore it should not be used.
 *
 * @param propertyNames
 * @param alias
 * @param aliasPath
 * @param domainClass
 * @return
 *
 * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
 */
@Deprecated
public static Projection createAliasedProjectionList(final String[] propertyNames,
		final String alias, final String aliasPath, final Class<?> domainClass)
{
	final ProjectionList projectionList = Projections.projectionList();
	for (final String propertyName : propertyNames)
	{
		final Field field = ReflectionUtils.findField(domainClass, propertyName);
		if (!hasAssociationAnnotation(field))
		{
			final String aliasedProperty = alias + "." + propertyName;
			projectionList
					.add(Projections.property(aliasedProperty), aliasedProperty);
		}
	}
	return projectionList;
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:31,代码来源:HibernateUtil.java

示例3: getCriteria

import org.hibernate.criterion.Projection; //导入依赖的package包/类
protected <T, R> Criteria getCriteria(Query<T, R> query) {
    final Criterion translated = queryTranslator.translate(query);
    if (log.isDebugEnabled()) {
        log.debug(translated);
    }
    final Criteria criteria = getSession().createCriteria(query.getEntityClass());
    criteria.add(translated);
    final List<Order> orders = queryTranslator.translateOrder(query).get();
    for (final Order order : orders) {
        criteria.addOrder(order);
    }
    final Projection projection = queryTranslator.translateProjection(query);
    if (projection != null) {
        criteria.setProjection(projection);
    }
    if (query.getMaxResults() != null) {
        criteria.setMaxResults(query.getMaxResults());
    }
    return criteria;
}
 
开发者ID:eHarmony,项目名称:seeking,代码行数:21,代码来源:HibernateQueryExecutor.java

示例4: getUnassignedDocumentIDsByCrisisID

import org.hibernate.criterion.Projection; //导入依赖的package包/类
@Override
public List<Long> getUnassignedDocumentIDsByCrisisID(Long crisisID, Integer count) {
	
	List<Long> docIDList = new ArrayList<Long>();
	Criteria criteria = null;
	try {
		String aliasTable = "taskAssignments";
		String order = "ASC";
		String aliasTableKey = "taskAssignments.id.documentId";
		String[] orderBy = {"valueAsTrainingSample", "documentId"};
		Criterion criterion = Restrictions.conjunction()
				.add(Restrictions.eq("collection.id",crisisID))
				.add(Restrictions.eq("hasHumanLabels",false));

		// get just the documentIDs
		Projection projection = Projections.property("documentId");
		Criterion aliasCriterion =  (Restrictions.isNull(aliasTableKey));
		criteria = createCriteria(criterion, order, orderBy, count, aliasTable, aliasCriterion, new Projection[] {projection}, JoinType.LEFT_OUTER_JOIN);
		docIDList = criteria.list();
		return docIDList;
			
	} catch (Exception e) {
		logger.error("getByCriteriaWithAliasByOrder failed, criteria = " + criteria.toString(), e);
		throw new HibernateException("getByCriteriaWithAliasByOrder failed, criteria = " + criteria.toString());
	}
}
 
开发者ID:qcri-social,项目名称:AIDR,代码行数:27,代码来源:DocumentResourceFacadeImp.java

示例5: findProjection

import org.hibernate.criterion.Projection; //导入依赖的package包/类
/**
 * find projection from criteria.
 * 
 * @param criteria
 *            Criteria
 * @return Projection
 */
public static Projection findProjection(Criteria criteria) {
    if (criteria instanceof CriteriaImpl) {
        return ((CriteriaImpl) criteria).getProjection();
    } else {
        throw new IllegalArgumentException(criteria
                + " is not a CriteriaImpl");
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:16,代码来源:HibernateUtils.java

示例6: pagedQuery

import org.hibernate.criterion.Projection; //导入依赖的package包/类
/**
 * 分页查询函数,使用已设好查询条件与排序的<code>Criteria</code>.
 * 
 * @param criteria
 *            条件
 * @param pageNo
 *            当前页号
 * @param pageSize
 *            每页最大记录数
 * @return 含总记录数和当前页数据的Page对象.
 */
@Transactional(readOnly = true)
public Page pagedQuery(Criteria criteria, int pageNo, int pageSize) {
    Assert.notNull(criteria);
    Assert.isTrue(pageNo >= 1, "pageNo should be eg 1");
    Assert.isTrue(criteria instanceof CriteriaImpl);

    // 先把Projection和OrderBy条件取出来,清空两者来执行Count操作
    Projection projection = HibernateUtils.findProjection(criteria);

    List orderEntries = HibernateUtils.findOrderEntries(criteria);
    HibernateUtils.setOrderEntries(criteria, Collections.EMPTY_LIST);

    // 执行查询
    Integer totalCount = this.getCount(criteria);
    // 将之前的Projection和OrderBy条件重新设回去
    criteria.setProjection(projection);

    if (projection == null) {
        criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
    }

    HibernateUtils.setOrderEntries(criteria, orderEntries);

    // 返回分页对象
    if (totalCount < 1) {
        return new Page();
    }

    int start = (pageNo - 1) * pageSize;
    List result = criteria.setFirstResult(start).setMaxResults(pageSize)
            .list();

    Page page = new Page(result, totalCount);
    page.setPageNo(pageNo);
    page.setPageSize(pageSize);

    return page;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:50,代码来源:HibernatePagingDao.java

示例7: getColumnsUsingProjection

import org.hibernate.criterion.Projection; //导入依赖的package包/类
/**
 * Get the names of the columns constrained
 * by this criterion.
 */
@Override
public String[] getColumnsUsingProjection(
		Criteria subcriteria,
        String propertyName) throws HibernateException {

	//first look for a reference to a projection alias
	final Projection projection = rootCriteria.getProjection();
	String[] projectionColumns = null;
	if ( projection != null ) {
		projectionColumns = ( projection instanceof EnhancedProjection ?
				( ( EnhancedProjection ) projection ).getColumnAliases( propertyName, 0, rootCriteria, this ) :
				projection.getColumnAliases( propertyName, 0 )
		);
	}
	if ( projectionColumns == null ) {
		//it does not refer to an alias of a projection,
		//look for a property
		try {
			return getColumns( propertyName, subcriteria );
		}
		catch ( HibernateException he ) {
			//not found in inner query , try the outer query
			if ( outerQueryTranslator != null ) {
				return outerQueryTranslator.getColumnsUsingProjection( subcriteria, propertyName );
			}
			else {
				throw he;
			}
		}
	}
	else {
		//it refers to an alias of a projection
		return projectionColumns;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:CriteriaQueryTranslator.java

示例8: getTypeUsingProjection

import org.hibernate.criterion.Projection; //导入依赖的package包/类
@Override
public Type getTypeUsingProjection(Criteria subcriteria, String propertyName)
		throws HibernateException {

	//first look for a reference to a projection alias
	final Projection projection = rootCriteria.getProjection();
	Type[] projectionTypes = projection == null ?
	                         null :
	                         projection.getTypes( propertyName, subcriteria, this );

	if ( projectionTypes == null ) {
		try {
			//it does not refer to an alias of a projection,
			//look for a property
			return getType( subcriteria, propertyName );
		}
		catch ( HibernateException he ) {
			//not found in inner query , try the outer query
			if ( outerQueryTranslator != null ) {
				return outerQueryTranslator.getType( subcriteria, propertyName );
			}
			else {
				throw he;
			}
		}
	}
	else {
		if ( projectionTypes.length != 1 ) {
			//should never happen, i think
			throw new QueryException( "not a single-length projection: " + propertyName );
		}
		return projectionTypes[0];
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:CriteriaQueryTranslator.java

示例9: setProjection

import org.hibernate.criterion.Projection; //导入依赖的package包/类
@Override
public Criteria setProjection(Projection projection) {
	this.projection = projection;
	this.projectionCriteria = this;
	setResultTransformer( PROJECTION );
	return this;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:CriteriaImpl.java

示例10: getColumnsUsingProjection

import org.hibernate.criterion.Projection; //导入依赖的package包/类
/**
 * Get the names of the columns constrained
 * by this criterion.
 */
@Override
public String[] getColumnsUsingProjection(
		Criteria subcriteria,
		String propertyName) throws HibernateException {

	//first look for a reference to a projection alias
	final Projection projection = rootCriteria.getProjection();
	String[] projectionColumns = null;
	if ( projection != null ) {
		projectionColumns = ( projection instanceof EnhancedProjection ?
				( (EnhancedProjection) projection ).getColumnAliases( propertyName, 0, rootCriteria, this ) :
				projection.getColumnAliases( propertyName, 0 )
		);
	}
	if ( projectionColumns == null ) {
		//it does not refer to an alias of a projection,
		//look for a property
		try {
			return getColumns( propertyName, subcriteria );
		}
		catch (HibernateException he) {
			//not found in inner query , try the outer query
			if ( outerQueryTranslator != null ) {
				return outerQueryTranslator.getColumnsUsingProjection( subcriteria, propertyName );
			}
			else {
				throw he;
			}
		}
	}
	else {
		//it refers to an alias of a projection
		return projectionColumns;
	}
}
 
开发者ID:geodir,项目名称:Layer-Query,代码行数:40,代码来源:CustomCriteriaQueryTranslator.java

示例11: getTypeUsingProjection

import org.hibernate.criterion.Projection; //导入依赖的package包/类
@Override
	public Type getTypeUsingProjection(Criteria subcriteria, String propertyName)
			throws HibernateException {
//		propertyName = "columnId";
		//first look for a reference to a projection alias
		final Projection projection = rootCriteria.getProjection();
		Type[] projectionTypes = projection == null ?
				null :
				projection.getTypes( propertyName, subcriteria, this );

		if ( projectionTypes == null ) {
			try {
				//it does not refer to an alias of a projection,
				//look for a property
				return getType( subcriteria, propertyName );
			}
			catch (HibernateException he) {
				//not found in inner query , try the outer query
				if ( outerQueryTranslator != null ) {
					return outerQueryTranslator.getType( subcriteria, propertyName );
				}
				else {
					throw he;
				}
			}
		}
		else {
			if ( projectionTypes.length != 1 ) {
				//should never happen, i think
				throw new QueryException( "not a single-length projection: " + propertyName );
			}
			return projectionTypes[0];
		}
	}
 
开发者ID:geodir,项目名称:Layer-Query,代码行数:35,代码来源:CustomCriteriaQueryTranslator.java

示例12: setProjection

import org.hibernate.criterion.Projection; //导入依赖的package包/类
@Override
public Criteria setProjection(Projection projection) {
	this.projection = projection;
	this.projectionCriteria = this;
	setResultTransformer(PROJECTION);
	return this;
}
 
开发者ID:geodir,项目名称:Layer-Query,代码行数:8,代码来源:CustomCriteriaImpl.java

示例13: getOfficialSigSha1

import org.hibernate.criterion.Projection; //导入依赖的package包/类
@Override
public String getOfficialSigSha1(String pkname) {
    Projection officialSigSha1 = Projections.property("officialSigSha1");

    Criteria cri = getSession().createCriteria(App.class);
    cri.setProjection(officialSigSha1);
    cri.add(Restrictions.eq("pkname", pkname));
    cri.add(Restrictions.isNotNull("officialSigSha1"));
    List<String> list = HibernateHelper.list(cri);
    if (list != null && !list.isEmpty()) {
        return list.get(0);
    }
    return null;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:15,代码来源:AppDaoImpl.java

示例14: getOfficialSigSha1

import org.hibernate.criterion.Projection; //导入依赖的package包/类
@Override
public String getOfficialSigSha1(Session session, String pkname) {
    Projection officialSigSha1 = Projections.property("officialSigSha1");
    Criteria cri = session.createCriteria(App.class);
    cri.setProjection(officialSigSha1);
    cri.add(Restrictions.eq("pkname", pkname));
    cri.add(Restrictions.isNotNull("officialSigSha1"));
    List<String> list = HibernateHelper.list(cri);
    if (list != null && !list.isEmpty()) {
        return list.get(0);
    }
    return null;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:14,代码来源:AppDaoImpl.java

示例15: getColumnsUsingProjection

import org.hibernate.criterion.Projection; //导入依赖的package包/类
/**
 * Get the names of the columns constrained
 * by this criterion.
 */
public String[] getColumnsUsingProjection(
		Criteria subcriteria,
        String propertyName) throws HibernateException {

	//first look for a reference to a projection alias
	final Projection projection = rootCriteria.getProjection();
	String[] projectionColumns = projection == null ?
	                             null :
	                             projection.getColumnAliases( propertyName, 0 );

	if ( projectionColumns == null ) {
		//it does not refer to an alias of a projection,
		//look for a property
		try {
			return getColumns( propertyName, subcriteria );
		}
		catch ( HibernateException he ) {
			//not found in inner query , try the outer query
			if ( outerQueryTranslator != null ) {
				return outerQueryTranslator.getColumnsUsingProjection( subcriteria, propertyName );
			}
			else {
				throw he;
			}
		}
	}
	else {
		//it refers to an alias of a projection
		return projectionColumns;
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:36,代码来源:CriteriaQueryTranslator.java


注:本文中的org.hibernate.criterion.Projection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。