use of org.hibernate.loader.criteria.CriteriaQueryTranslator in project hibernate-orm by hibernate.
the class SubqueryExpression method createAndSetInnerQuery.
/**
* Creates the inner query used to extract some useful information about types, since it is needed in both methods.
*
* @param criteriaQuery The criteria query
* @param factory The session factory.
*/
private void createAndSetInnerQuery(CriteriaQuery criteriaQuery, SessionFactoryImplementor factory) {
if (innerQuery == null) {
//with two-deep subqueries, the same alias would get generated for
//both using the old method (criteriaQuery.generateSQLAlias()), so
//that is now used as a fallback if the main criteria alias isn't set
String alias;
if (this.criteriaImpl.getAlias() == null) {
alias = criteriaQuery.generateSQLAlias();
} else {
alias = this.criteriaImpl.getAlias() + "_";
}
innerQuery = new CriteriaQueryTranslator(factory, criteriaImpl, criteriaImpl.getEntityOrClassName(), alias, criteriaQuery);
params = innerQuery.getQueryParameters();
types = innerQuery.getProjectedTypes();
}
}
use of org.hibernate.loader.criteria.CriteriaQueryTranslator in project hibernate-orm by hibernate.
the class CriterionTest method testIlikeRendering.
@Test
public void testIlikeRendering() {
SessionFactory sf = new Configuration().addAnnotatedClass(IrrelevantEntity.class).setProperty(AvailableSettings.DIALECT, IlikeSupportingDialect.class.getName()).setProperty(Environment.HBM2DDL_AUTO, "create-drop").buildSessionFactory();
try {
final Criteria criteria = sf.openSession().createCriteria(IrrelevantEntity.class);
final CriteriaQueryTranslator translator = new CriteriaQueryTranslator((SessionFactoryImplementor) sf, (CriteriaImpl) criteria, IrrelevantEntity.class.getName(), "a");
final Criterion ilikeExpression = Restrictions.ilike("name", "abc");
final String ilikeExpressionSqlFragment = ilikeExpression.toSqlString(criteria, translator);
assertEquals("a.name insensitiveLike ?", ilikeExpressionSqlFragment);
} finally {
sf.close();
}
}
use of org.hibernate.loader.criteria.CriteriaQueryTranslator in project hibernate-orm by hibernate.
the class CriterionTest method testIlikeMimicing.
@Test
public void testIlikeMimicing() {
SessionFactory sf = new Configuration().addAnnotatedClass(IrrelevantEntity.class).setProperty(AvailableSettings.DIALECT, NonIlikeSupportingDialect.class.getName()).setProperty(Environment.HBM2DDL_AUTO, "create-drop").buildSessionFactory();
try {
final Criteria criteria = sf.openSession().createCriteria(IrrelevantEntity.class);
final CriteriaQueryTranslator translator = new CriteriaQueryTranslator((SessionFactoryImplementor) sf, (CriteriaImpl) criteria, IrrelevantEntity.class.getName(), "a");
final Criterion ilikeExpression = Restrictions.ilike("name", "abc");
final String ilikeExpressionSqlFragment = ilikeExpression.toSqlString(criteria, translator);
assertEquals("lowLowLow(a.name) like ?", ilikeExpressionSqlFragment);
} finally {
sf.close();
}
}
Aggregations