Search in sources :

Example 1 with CriteriaQueryTranslator

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();
    }
}
Also used : CriteriaQueryTranslator(org.hibernate.loader.criteria.CriteriaQueryTranslator)

Example 2 with CriteriaQueryTranslator

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();
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Criterion(org.hibernate.criterion.Criterion) IrrelevantEntity(org.hibernate.IrrelevantEntity) Criteria(org.hibernate.Criteria) CriteriaQueryTranslator(org.hibernate.loader.criteria.CriteriaQueryTranslator) Test(org.junit.Test)

Example 3 with CriteriaQueryTranslator

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();
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Criterion(org.hibernate.criterion.Criterion) IrrelevantEntity(org.hibernate.IrrelevantEntity) Criteria(org.hibernate.Criteria) CriteriaQueryTranslator(org.hibernate.loader.criteria.CriteriaQueryTranslator) Test(org.junit.Test)

Aggregations

CriteriaQueryTranslator (org.hibernate.loader.criteria.CriteriaQueryTranslator)3 Criteria (org.hibernate.Criteria)2 IrrelevantEntity (org.hibernate.IrrelevantEntity)2 SessionFactory (org.hibernate.SessionFactory)2 Configuration (org.hibernate.cfg.Configuration)2 Criterion (org.hibernate.criterion.Criterion)2 Test (org.junit.Test)2