下面列出了org.hibernate.engine.spi.TypedValue#org.hibernate.criterion.CriteriaQuery 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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()]);
}
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());
}
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;
}
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;
}
@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");
}
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, value.toString()) };
}