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


Java CriteriaQuery类代码示例

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


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

示例1: toSqlString

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException
{
	StringBuilder buffer = new StringBuilder();
	buffer.append('(');
	int i = 0;
	for( Criterion crit : criterion )
	{
		if( i != 0 )
		{
			buffer.append(' ');
			buffer.append(op);
			buffer.append(' ');
		}
		buffer.append(crit.toSqlString(criteria, criteriaQuery));
		i++;
	}
	buffer.append(')');
	return buffer.toString();
}
 
开发者ID:equella,项目名称:Equella,代码行数:21,代码来源:ConfigurationServiceImpl.java

示例2: toSqlString

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    Dialect dialect = criteriaQuery.getFactory().getDialect();
    String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);
    if (columns.length != 1) {
        throw new HibernateException("rlike may only be used with single-column properties");
    }

    if (dialect instanceof MySQLDialect) {
        return columns[0] + " rlike ?";
    }

    if (isOracleDialect(dialect)) {
        return " REGEXP_LIKE (" + columns[0] + ", ?)";
    }

    if (dialect instanceof PostgreSQL81Dialect) {
        return columns[0] + " ~* ?";
    }

    if (dialect instanceof H2Dialect) {
        return columns[0] + " REGEXP ?";
    }

    throw new HibernateException("rlike is not supported with the configured dialect " + dialect.getClass().getCanonicalName());
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:26,代码来源:RlikeExpression.java

示例3: toSqlString

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
public String toSqlString( Criteria c, CriteriaQuery q )
{
    String initial_hql = query.getQueryString();
    
    //  default query selects whole GlycanSequence objects, which
    //  aren't needed if the Criterion we're returning is just 
    //  going to be used in a subselect.
    int i = initial_hql.indexOf("from ");
    assert i != -1 : initial_hql;
    
    //  so, narrow the select clause:
    // String hql = "select gs.id " + initial_hql.substring( i );
    String hql = "select gs.glycan_sequence_id " + initial_hql.substring( i );
    
    //  translate to SQL
    String subquery_expr_sql = hql; //translateHql2Sql( hql );

    String sql = propertyName 
               + " in ("
               + subquery_expr_sql
               + ")";
               
    return sql;
}
 
开发者ID:glycoinfo,项目名称:eurocarbdb,代码行数:25,代码来源:SubstructureQueryCriterion.java

示例4: testProjectionOrderShouldTakeAscOrderIntoAccount

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Test
   public void testProjectionOrderShouldTakeAscOrderIntoAccount() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
String[] projectionAlias = { "colProjalias" };
EasyMock.expect(
	criteriaQuery.getColumnsUsingProjection((Criteria) EasyMock
		.anyObject(), EasyMock.eq(alias))).andReturn(
	projectionAlias).once();
EasyMock.expect(
	criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
	.andReturn("this_alias").once();
EasyMock.replay(criteriaQuery);
ProjectionOrder dorder = new ProjectionOrder(alias, true);
String sqlString = dorder.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("asc"));
EasyMock.verify(criteriaQuery);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:18,代码来源:ProjectionOrderTest.java

示例5: testProjectionOrderShouldHaveAscOrderByDefault

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Test
   public void testProjectionOrderShouldHaveAscOrderByDefault() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
String[] projectionAlias = { "colProjalias" };
EasyMock.expect(
	criteriaQuery.getColumnsUsingProjection((Criteria) EasyMock
		.anyObject(), EasyMock.eq(alias))).andReturn(
	projectionAlias).once();
EasyMock.expect(
	criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
	.andReturn("this_alias").once();
EasyMock.replay(criteriaQuery);
ProjectionOrder dorder = new ProjectionOrder(alias);
String sqlString = dorder.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("asc"));
EasyMock.verify(criteriaQuery);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:18,代码来源:ProjectionOrderTest.java

示例6: testProjectionOrderShouldTakeDescOrderIntoAccount

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Test
   public void testProjectionOrderShouldTakeDescOrderIntoAccount() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
String[] projectionAlias = { "colProjalias" };
EasyMock.expect(
	criteriaQuery.getColumnsUsingProjection((Criteria) EasyMock
		.anyObject(), EasyMock.eq(alias))).andReturn(
	projectionAlias).once();
EasyMock.expect(
	criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
	.andReturn("this_alias").once();
EasyMock.replay(criteriaQuery);
ProjectionOrder dorder = new ProjectionOrder(alias, false);
String sqlString = dorder.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("desc"));
EasyMock.verify(criteriaQuery);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:18,代码来源:ProjectionOrderTest.java

示例7: testDistanceRestrictionPointDoubleBooleanShouldUseIndexIfUseIndexTrue

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Test
   public void testDistanceRestrictionPointDoubleBooleanShouldUseIndexIfUseIndexTrue() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
EasyMock.expect(
	criteriaQuery.getColumn((Criteria) EasyMock.anyObject(),
		EasyMock.eq(GisFeature.LOCATION_COLUMN_NAME)))
	.andReturn("").once();
EasyMock.expect(
	criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
	.andReturn("").once();
EasyMock.replay(criteriaQuery);
DistanceRestriction dr = new DistanceRestriction(GisgraphyTestHelper
	.createPoint(3F, 4F), 4D, true);
String sqlString = dr.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains(" && "));
EasyMock.verify(criteriaQuery);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:18,代码来源:DistanceRestrictionTest.java

示例8: toSqlString

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {

	String[] columns = criteriaQuery.findColumns(getPropiedad(), criteria);
	if (columns.length != 1) {
		throw new HibernateException(
				"NumberLike may only be used with single-column properties");
	}
	SessionFactoryImplementor factory = criteriaQuery.getFactory();

	if (factory.getDialect() instanceof H2Dialect) {
		return "cast(cast(" + columns[0] + " as int) as VARCHAR) "
				+ "like ?";
	} else {
		// XXX ver consistencia entre bases de datos
		return columns[0] + "::text like ?";
	}
}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:19,代码来源:NumberLike.java

示例9: toSqlString

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {

	String[] columns = criteriaQuery.findColumns(getPath(), criteria);
	if (columns.length != 1) {
		throw new HibernateException(
				"Regex may only be used with single-column properties");
	}
	SessionFactoryImplementor factory = criteriaQuery.getFactory();

	if (factory.getDialect() instanceof H2Dialect) {
		return columns[0] + " regexp ?";
	} else {
		// XXX ver consistencia entre bases de datos
		return columns[0] + " ~ ?";
	}
}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:18,代码来源:Regex.java

示例10: toSqlString

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
	final String[] lhsColumns = criteriaQuery.findColumns( propertyName, criteria );
	final String[] rhsColumns = criteriaQuery.findColumns( otherPropertyName, criteria );

	List<String> comparisons = new ArrayList<String>(); 
	for (int i = 0; i<lhsColumns.length; i++) {
		String comp = formatExpr(lhsColumns[0], rhsColumns[0], mode);
		comparisons.add(comp);
		
	}
	if ( comparisons.size() > 1 ) {
		return '(' + StringHelper.join( " and ", comparisons.toArray(new String[comparisons.size()]) ) + ')';
	} else {
		return comparisons.get(0);
	}
}
 
开发者ID:Breeze,项目名称:breeze.server.java,代码行数:18,代码来源:LikePropertyExpression.java

示例11: appendComponentIds

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
/**
 * Private helper method to construct component ids with an optional alias.
 *
 * @param sb
 *            a {@link StringBuffer}
 * @param componentType
 *            the {@link ComponentType}
 * @param criteriaQuery
 *            the {@link CriteriaQuery}
 * @param criteria
 *            the {@link Criteria}
 * @param position
 *            the position of the alias, appened if >= 0
 */
private void appendComponentIds(final StringBuffer sb,
		final ComponentType componentType, final CriteriaQuery criteriaQuery,
		final Criteria criteria, final Integer position)
{
	final String[] idProperties = componentType.getPropertyNames();
	int currPos = position != null ? position.intValue() : -1;
	for (int i = 0; i < idProperties.length; i++)
	{
		sb.append(criteriaQuery.getColumn(criteria, groupByProperty + "."
				+ idProperties[i]));

		if (currPos >= 0)
		{
			sb.append(" as y").append(currPos).append('_');
			currPos++;
		}

		if (i + 1 < idProperties.length)
		{
			sb.append(", ");
		}
	}
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:38,代码来源:GroupByHavingProjection.java

示例12: getTypedValues

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException
{
	List<TypedValue> values = new ArrayList<TypedValue>();
	for( Criterion crit : criterion )
	{
		values.addAll(Arrays.asList(crit.getTypedValues(criteria, criteriaQuery)));
	}
	return values.toArray(new TypedValue[values.size()]);
}
 
开发者ID:equella,项目名称:Equella,代码行数:11,代码来源:ConfigurationServiceImpl.java

示例13: CriteriaQueryTranslator

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
public CriteriaQueryTranslator(
		final SessionFactoryImplementor factory,
        final CriteriaImpl criteria,
        final String rootEntityName,
        final String rootSQLAlias,
        CriteriaQuery outerQuery) throws HibernateException {
	this( factory, criteria, rootEntityName, rootSQLAlias );
	outerQueryTranslator = outerQuery;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:CriteriaQueryTranslator.java

示例14: CustomCriteriaQueryTranslator

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
public CustomCriteriaQueryTranslator(
		final SessionFactoryImplementor factory,
		final CustomCriteriaImpl criteria,
		final String rootEntityName,
		final String rootSQLAlias,
		CriteriaQuery outerQuery) throws HibernateException {
	this( factory, criteria, rootEntityName, rootSQLAlias );
	outerQueryTranslator = outerQuery;
}
 
开发者ID:geodir,项目名称:Layer-Query,代码行数:10,代码来源:CustomCriteriaQueryTranslator.java

示例15: toSqlString

import org.hibernate.criterion.CriteriaQuery; //导入依赖的package包/类
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
    throws HibernateException {
String columnName = criteriaQuery.getColumn(criteria,
	GisFeature.LOCATION_COLUMN_NAME);
StringBuffer result = new StringBuffer("( st_distance_sphere(").append(
	columnName).append(", ?) <=").append(this.distance).append(")");
return useIndex ? result.append(" AND ").append(
		GisHelper.getBoundingBox(criteriaQuery.getSQLAlias(criteria), this.point
		.getY(), this.point.getX(), distance)).toString()
	: result.toString();

   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:13,代码来源:DistanceRestriction.java


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