Java 类org.hibernate.criterion.CriteriaQuery 实例源码
项目:Equella
文件:ConfigurationServiceImpl.java
@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();
}
项目:gorm-hibernate5
文件:RlikeExpression.java
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());
}
项目:eurocarbdb
文件:SubstructureQueryCriterion.java
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;
}
项目:gisgraphy
文件:ProjectionOrderTest.java
@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);
}
项目:gisgraphy
文件:ProjectionOrderTest.java
@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);
}
项目:gisgraphy
文件:ProjectionOrderTest.java
@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);
}
项目:gisgraphy
文件:DistanceRestrictionTest.java
@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);
}
项目:karaku
文件:NumberLike.java
@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 ?";
}
}
项目:karaku
文件:Regex.java
@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] + " ~ ?";
}
}
项目:breeze.server.java
文件:LikePropertyExpression.java
@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);
}
}
项目:further-open-core
文件:GroupByHavingProjection.java
/**
* 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(", ");
}
}
}
项目:Equella
文件:ConfigurationServiceImpl.java
@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()]);
}
项目:lams
文件:CriteriaQueryTranslator.java
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;
}
项目:Layer-Query
文件:CustomCriteriaQueryTranslator.java
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;
}
项目:cacheonix-core
文件:CriteriaQueryTranslator.java
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;
}
项目:gisgraphy
文件:DistanceRestriction.java
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();
}
项目:gisgraphy
文件:IntersectsRestriction.java
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
String columnName = criteriaQuery.getColumn(criteria,
this.columnName);
StringBuffer result = new StringBuffer(columnName).append(
" && ").append(" ? ");
return result.toString();
}
项目:gisgraphy
文件:FulltextRestriction.java
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
String columnName = criteriaQuery.getColumn(criteria,
ts_vectorColumnName);
StringBuffer result = new StringBuffer("(").append(columnName).append(
" @@ plainto_tsquery('simple',?)").append(")");
return result.toString();
}
项目:gisgraphy
文件:ProjectionOrder.java
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
Order nso = new NativeSQLOrder(criteriaQuery.getColumnsUsingProjection(
criteria, aliasName)[0], this.ascending);
return nso.toSqlString(criteria, criteriaQuery);
}
项目:gisgraphy
文件:NativeSQLOrder.java
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
StringBuilder fragment = new StringBuilder();
fragment.append("(");
fragment.append(sql);
fragment.append(")");
fragment.append(ascending ? " asc" : " desc");
return StringHelper.replace(fragment.toString(), "{alias}",
criteriaQuery.getSQLAlias(criteria));
}
项目:gisgraphy
文件:PartialWordSearchRestriction.java
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
String columnName = criteriaQuery.getColumn(criteria,
ts_vectorColumnName);
StringBuffer result = new StringBuffer("(").append(columnName).append(
" @@ plainto_tsquery('simple',?)").append(")");
return result.toString();
}
项目:gisgraphy
文件:DistanceOrder.java
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
StringBuilder fragment = new StringBuilder();
fragment.append(" st_distance_sphere(");
fragment.append(criteriaQuery.getSQLAlias(criteria));
fragment.append(".location, st_geometryfromtext('");
fragment.append(point.toText());
fragment.append("',");
fragment.append(SRID.WGS84_SRID.getSRID());
fragment.append(ascending ? ")) asc" : ")) desc");
return fragment.toString();
}
项目:gisgraphy
文件:DistanceOrderTest.java
@Test
public void distanceOrderPointBooleanShouldTakeAscOrderIntoAccount() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
EasyMock.expect(
criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
.andReturn("alias ").once();
EasyMock.replay(criteriaQuery);
DistanceOrder distanceOrder = new DistanceOrder(GisgraphyTestHelper.createPoint(
3F, 4F), true);
String sqlString = distanceOrder.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("asc"));
assertTrue(sqlString.contains("st_distance_sphere"));
EasyMock.verify(criteriaQuery);
}
项目:gisgraphy
文件:DistanceOrderTest.java
@Test
public void distanceOrderShouldHaveAscOrderByDefault() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
EasyMock.expect(
criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
.andReturn("alias ").once();
EasyMock.replay(criteriaQuery);
DistanceOrder dorder = new DistanceOrder(GisgraphyTestHelper.createPoint(
3F, 4F));
String sqlString = dorder.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("asc"));
assertTrue(sqlString.contains("st_distance_sphere"));
EasyMock.verify(criteriaQuery);
}
项目:gisgraphy
文件:DistanceOrderTest.java
@Test
public void distanceOrderPointBooleanShouldTakeDescOrderIntoAccount() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
EasyMock.expect(
criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
.andReturn(" alias ").once();
EasyMock.replay(criteriaQuery);
DistanceOrder dorder = new DistanceOrder(GisgraphyTestHelper.createPoint(
3F, 4F), false);
String sqlString = dorder.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("desc"));
assertTrue(sqlString.contains("st_distance_sphere"));
EasyMock.verify(criteriaQuery);
}
项目:gisgraphy
文件:DistanceRestrictionTest.java
@Test
public void testDistanceRestrictionPointDoubleBooleanShouldNotUseIndexIfUseIndexFalse() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
EasyMock.expect(
criteriaQuery.getColumn((Criteria) EasyMock.anyObject(),
EasyMock.eq(GisFeature.LOCATION_COLUMN_NAME)))
.andReturn(" test ").once();
EasyMock.replay(criteriaQuery);
DistanceRestriction dr = new DistanceRestriction(GisgraphyTestHelper
.createPoint(3F, 4F), 4D, false);
String sqlString = dr.toSqlString(null, criteriaQuery);
assertTrue(!sqlString.contains(" && "));
EasyMock.verify(criteriaQuery);
}
项目:gisgraphy
文件:NativeSQLOrderTest.java
@Test
public void testToSqlStringCriteriaCriteriaQueryShouldReplaceAlias() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
EasyMock.expect(
criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
.andReturn("sqlname").once();
EasyMock.replay(criteriaQuery);
NativeSQLOrder nso = new NativeSQLOrder("{alias}.name", true);
String sqlString = nso.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("sqlname.name"));
EasyMock.verify(criteriaQuery);
}
项目:gisgraphy
文件:NativeSQLOrderTest.java
@Test
public void testToSqlStringCriteriaCriteriaQueryShouldTakeTheAscOrderIntoAcount() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
EasyMock.expect(
criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
.andReturn("sqlname").once();
EasyMock.replay(criteriaQuery);
NativeSQLOrder nso = new NativeSQLOrder("{alias}.name", true);
String sqlString = nso.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("asc"));
EasyMock.verify(criteriaQuery);
}
项目:gisgraphy
文件:NativeSQLOrderTest.java
@Test
public void testToSqlStringCriteriaCriteriaQueryShouldTakeTheDescOrderIntoAcount() {
CriteriaQuery criteriaQuery = EasyMock.createMock(CriteriaQuery.class);
EasyMock.expect(
criteriaQuery.getSQLAlias((Criteria) EasyMock.anyObject()))
.andReturn("sqlname").once();
EasyMock.replay(criteriaQuery);
NativeSQLOrder nso = new NativeSQLOrder("{alias}.name", false);
String sqlString = nso.toSqlString(null, criteriaQuery);
assertTrue(sqlString.contains("desc"));
EasyMock.verify(criteriaQuery);
}
项目:scheduling
文件:GroupByStatusSortOrder.java
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
String column = criteriaQuery.getColumnsUsingProjection(criteria, propertyName)[0];
return " case " +
// pending first
" when " + column + " = " + JobStatus.PENDING.ordinal() + " then 0 " +
// running, stalled, paused then
" when " + column + " = " + JobStatus.RUNNING.ordinal() + " then 1 " + " when " + column + " = " +
JobStatus.STALLED.ordinal() + " then 1 " + " when " + column + " = " + JobStatus.PAUSED.ordinal() +
" then 1 " +
// and the rest (killed, finished, etc)
" else 2 end " + (ascending ? " asc" : " desc");
}
项目:Cindy
文件:FulltextSearch.java
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
String[] columns = criteriaQuery.findColumns(propertyName, criteria);
if (columns.length != 1) {
throw new HibernateException("FulltextSearch may only be used with single-column properties");
}
String searchModeStr = null;
switch (this.searchMode) {
case BOOLEAN:
searchModeStr = "BOOLEAN";
break;
case NATURAL_LANGUAGE:
searchModeStr = "NATURAL_LANGUAGE";
break;
default:
throw new HibernateException("Null SearchMode set");
}
String columnsStr = columns[0];
for (int i = 1; i < columns.length; i++) {
columnsStr += ", " + columns[i];
}
return "match (" + columnsStr + ") against (? IN " + searchModeStr + " MODE)";
}
项目:karaku
文件:NumberLike.java
/**
* {@inheritDoc}
*/
@Override
public TypedValue[] getTypedValues(Criteria criteria,
CriteriaQuery criteriaQuery) {
TypedValue tv = new TypedValue(new org.hibernate.type.StringType(),
matchMode.toString(valor), EntityMode.POJO);
return new TypedValue[] { tv };
}
项目:karaku
文件:Regex.java
/**
* {@inheritDoc}
*/
@Override
public TypedValue[] getTypedValues(Criteria criteria,
CriteriaQuery criteriaQuery) {
TypedValue tv = new TypedValue(new org.hibernate.type.StringType(),
value, EntityMode.POJO);
return new TypedValue[] { tv };
}
项目:further-open-core
文件:GroupByHavingProjection.java
@Override
public String toSqlString(final Criteria criteria, final int position,
final CriteriaQuery criteriaQuery) throws HibernateException
{
final Type identifierType = criteriaQuery.getIdentifierType(criteria);
if (identifierType.isComponentType())
{
final StringBuffer sb = new StringBuffer();
appendComponentIds(sb, (ComponentType) identifierType, criteriaQuery,
criteria, new Integer(position));
return sb.toString();
}
return super.toSqlString(criteria, position, criteriaQuery);
}
项目:further-open-core
文件:GroupByHavingProjection.java
@Override
public String toGroupSqlString(final Criteria criteria,
final CriteriaQuery criteriaQuery) throws HibernateException
{
final StringBuffer sb = new StringBuffer(50);
final Type identifierType = criteriaQuery.getIdentifierType(criteria);
if (identifierType.isComponentType())
{
appendComponentIds(sb, (ComponentType) identifierType, criteriaQuery,
criteria, null);
}
else
{
sb.append(criteriaQuery.getColumn(criteria, groupByProperty));
}
// Append HAVING clause
sb.append(" having ");
sb.append("(");
// Remove the alias
final String proj = projection.toSqlString(criteria, 0xCAFEBABE, criteriaQuery);
sb.append(proj.substring(0, proj.indexOf("as")).trim());
sb.append(")");
sb.append(SPACE_STRING)
.append(op.getSqloperator())
.append(SPACE_STRING)
.append(value);
return sb.toString();
}
项目:gorm-hibernate5
文件:RlikeExpression.java
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, value.toString()) };
}
项目:eurocarbdb
文件:SubstructureQueryCriterion.java
/** Irrelevant; not used. */
public TypedValue[] getTypedValues( Criteria c, CriteriaQuery q )
{
return new TypedValue[0];
}
项目:gisgraphy
文件:DistanceRestriction.java
public TypedValue[] getTypedValues(Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] { criteriaQuery.getTypedValue(criteria,
GisFeature.LOCATION_COLUMN_NAME, point) };
}
项目:gisgraphy
文件:IntersectsRestriction.java
public TypedValue[] getTypedValues(Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] { criteriaQuery.getTypedValue(criteria,
GisFeature.LOCATION_COLUMN_NAME, polygon) };
}
项目:gisgraphy
文件:FulltextRestriction.java
public TypedValue[] getTypedValues(Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] { new TypedValue( Hibernate.STRING, StringHelper.normalize(searchedText), EntityMode.POJO )};
}