org.hibernate.criterion.CriteriaQuery Java Examples

The following examples show how to use org.hibernate.criterion.CriteriaQuery. 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: InExpressionIgnoringCase.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
	List<TypedValue> list = new ArrayList<>();
	Type type = criteriaQuery.getTypeUsingProjection(criteria, propertyName);
	if (type.isComponentType()) {
		CompositeType actype = (CompositeType) type;
		Type[] types = actype.getSubtypes();
		for (int j = 0; j < values.length; j++) {
			for (int i = 0; i < types.length; i++) {
				Object subval = values[j] == null ? null : actype.getPropertyValues(values[j], EntityMode.POJO)[i];
				list.add(new TypedValue(types[i], subval, EntityMode.POJO));
			}
		}
	} else {
		for (int j = 0; j < values.length; j++) {
			list.add(new TypedValue(type, values[j], EntityMode.POJO));
		}
	}
	return list.toArray(new TypedValue[list.size()]);
}
 
Example #2
Source File: RlikeExpression.java    From gorm-hibernate5 with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #3
Source File: CriteriaQueryTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: CriteriaQueryTranslator.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example #5
Source File: GroupByStatusSortOrder.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@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");
}
 
Example #6
Source File: RlikeExpression.java    From gorm-hibernate5 with Apache License 2.0 4 votes vote down vote up
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, value.toString()) };
}