Search in sources :

Example 1 with QueryTranslator

use of org.hibernate.hql.spi.QueryTranslator in project hibernate-orm by hibernate.

the class EJBQLTest method toSql.

private String toSql(String hql) {
    QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
    QueryTranslator queryTranslator = ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, sessionFactory(), null);
    queryTranslator.compile(Collections.EMPTY_MAP, true);
    return queryTranslator.getSQLString();
}
Also used : QueryTranslatorFactory(org.hibernate.hql.spi.QueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory)

Example 2 with QueryTranslator

use of org.hibernate.hql.spi.QueryTranslator in project hibernate-orm by hibernate.

the class EntityJoinTest method testNoImpliedJoinGeneratedForEqualityComparison.

@Test
@TestForIssue(jiraKey = "HHH-11538")
public void testNoImpliedJoinGeneratedForEqualityComparison() {
    doInHibernate(this::sessionFactory, session -> {
        final HQLQueryPlan plan = sessionFactory().getQueryPlanCache().getHQLQueryPlan("select r.id, cust.name " + "from FinancialRecord r " + "	join Customer cust on r.customer = cust" + "   order by r.id", false, Collections.EMPTY_MAP);
        assertEquals(1, plan.getTranslators().length);
        final QueryTranslator translator = plan.getTranslators()[0];
        final String generatedSql = translator.getSQLString();
        int tableReferenceIndex = generatedSql.indexOf(" customer ");
        assertNotEquals("Generated SQL doesn't contain a table reference for customer", -1, tableReferenceIndex);
        int nextTableReferenceIndex = generatedSql.indexOf(" customer ", tableReferenceIndex + 1);
        assertEquals("Generated SQL wrongly joined customer twice", -1, nextTableReferenceIndex);
    });
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with QueryTranslator

use of org.hibernate.hql.spi.QueryTranslator in project hibernate-orm by hibernate.

the class LocaleTest method testAliasWithLocale.

@Test
@TestForIssue(jiraKey = "HHH-8579")
public void testAliasWithLocale() {
    // Without the HHH-8579 fix, this will generate non-ascii query aliases.
    String hql = "from IAmAFoo";
    QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
    QueryTranslator queryTranslator = ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, sessionFactory(), null);
    queryTranslator.compile(Collections.EMPTY_MAP, false);
    String sql = queryTranslator.getSQLString();
    assertTrue(sql.matches(asciiRegex));
}
Also used : QueryTranslatorFactory(org.hibernate.hql.spi.QueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 4 with QueryTranslator

use of org.hibernate.hql.spi.QueryTranslator in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateQueryTranslator.

@Test
public void testCreateQueryTranslator() {
    QueryTranslator queryTranslator = (QueryTranslator) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { QueryTranslator.class }, new TestInvocationHandler());
    IQueryTranslator facade = facadeFactory.createQueryTranslator(queryTranslator);
    Assert.assertSame(queryTranslator, ((IFacade) facade).getTarget());
}
Also used : PersistentClass(org.hibernate.mapping.PersistentClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) IQueryTranslator(org.jboss.tools.hibernate.runtime.spi.IQueryTranslator) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) IQueryTranslator(org.jboss.tools.hibernate.runtime.spi.IQueryTranslator) Test(org.junit.Test)

Example 5 with QueryTranslator

use of org.hibernate.hql.spi.QueryTranslator in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateQueryTranslator.

@Test
public void testCreateQueryTranslator() {
    QueryTranslator queryTranslator = (QueryTranslator) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { QueryTranslator.class }, new TestInvocationHandler());
    IQueryTranslator facade = facadeFactory.createQueryTranslator(queryTranslator);
    Assert.assertSame(queryTranslator, ((IFacade) facade).getTarget());
}
Also used : PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) IQueryTranslator(org.jboss.tools.hibernate.runtime.spi.IQueryTranslator) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) IQueryTranslator(org.jboss.tools.hibernate.runtime.spi.IQueryTranslator) Test(org.junit.Test)

Aggregations

QueryTranslator (org.hibernate.hql.spi.QueryTranslator)21 Test (org.junit.Test)11 QueryTranslatorFactory (org.hibernate.hql.spi.QueryTranslatorFactory)9 ASTQueryTranslatorFactory (org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory)8 PersistentClass (org.hibernate.mapping.PersistentClass)6 RootClass (org.hibernate.mapping.RootClass)6 POJOClass (org.hibernate.tool.hbm2x.pojo.POJOClass)6 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)6 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)6 IQueryTranslator (org.jboss.tools.hibernate.runtime.spi.IQueryTranslator)6 HQLQueryPlan (org.hibernate.engine.query.spi.HQLQueryPlan)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 HashMap (java.util.HashMap)3 ClassicQueryTranslatorFactory (org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory)3 Map (java.util.Map)2 MappingException (org.hibernate.MappingException)2 QueryException (org.hibernate.QueryException)2 QueryTranslatorImpl (org.hibernate.hql.internal.ast.QueryTranslatorImpl)2 TestForIssue (org.hibernate.testing.TestForIssue)2 ArrayList (java.util.ArrayList)1