6 - SQM based on JPA type system
This commit is contained in:
parent
40fb8dc254
commit
c50c95a691
|
@ -17,7 +17,8 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory;
|
||||
import org.hibernate.query.hql.SemanticQueryProducer;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
|
@ -54,7 +55,7 @@ public class ASTParserLoadingOrderByTest extends BaseCoreFunctionalTestCase {
|
|||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.USE_QUERY_CACHE, "false" );
|
||||
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
||||
cfg.setProperty( Environment.QUERY_TRANSLATOR, ASTQueryTranslatorFactory.class.getName() );
|
||||
cfg.setProperty( Environment.SEMANTIC_QUERY_PRODUCER, SemanticQueryProducer.class.getName() );
|
||||
}
|
||||
|
||||
private void createData() {
|
||||
|
|
|
@ -14,14 +14,11 @@ import javax.persistence.Table;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.hql.internal.ast.QuerySyntaxException;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
|
|
|
@ -15,6 +15,7 @@ import javax.persistence.JoinColumn;
|
|||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.annotations.NaturalId;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
|
||||
|
@ -154,24 +155,25 @@ public class EntityJoinTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-11538")
|
||||
public void testNoImpliedJoinGeneratedForEqualityComparison() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
final HQLQueryPlan plan = sessionFactory().getQueryInterpretationCache().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 );
|
||||
} );
|
||||
// doInHibernate( this::sessionFactory, session -> {
|
||||
// final HQLQueryPlan plan = sessionFactory().getQueryInterpretationCache().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 );
|
||||
// } );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -8,13 +8,17 @@ package org.hibernate.test.hql;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.dialect.PostgresPlusDialect;
|
||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
|
@ -84,7 +88,13 @@ public class FunctionNameAsColumnTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
e = ( EntityWithArgFunctionAsColumn ) s.createCriteria( EntityWithArgFunctionAsColumn.class ).uniqueResult();
|
||||
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<EntityWithArgFunctionAsColumn> criteria = criteriaBuilder.createQuery( EntityWithArgFunctionAsColumn.class );
|
||||
criteria.from( EntityWithArgFunctionAsColumn.class );
|
||||
|
||||
e = s.createQuery( criteria ).uniqueResult();
|
||||
|
||||
// e = ( EntityWithArgFunctionAsColumn ) s.createCriteria( EntityWithArgFunctionAsColumn.class ).uniqueResult();
|
||||
assertEquals( 3, e.getLower() );
|
||||
assertEquals( " abc ", e.getUpper() );
|
||||
t.commit();
|
||||
|
@ -157,12 +167,23 @@ public class FunctionNameAsColumnTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
holder1 = ( EntityWithFunctionAsColumnHolder ) s.createCriteria( EntityWithFunctionAsColumnHolder.class )
|
||||
.add( Restrictions.isNotNull( "nextHolder" ))
|
||||
.setFetchMode( "entityWithArgFunctionAsColumns", FetchMode.JOIN )
|
||||
.setFetchMode( "nextHolder", FetchMode.JOIN )
|
||||
.setFetchMode( "nextHolder.entityWithArgFunctionAsColumns", FetchMode.JOIN )
|
||||
.uniqueResult();
|
||||
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<EntityWithFunctionAsColumnHolder> criteria = criteriaBuilder.createQuery(
|
||||
EntityWithFunctionAsColumnHolder.class );
|
||||
Root<EntityWithFunctionAsColumnHolder> root = criteria.from( EntityWithFunctionAsColumnHolder.class );
|
||||
root.join( "entityWithArgFunctionAsColumns", JoinType.LEFT );
|
||||
Join<Object, Object> nextHolder = root.join( "nextHolder", JoinType.LEFT );
|
||||
nextHolder.join( "entityWithArgFunctionAsColumns", JoinType.LEFT );
|
||||
criteria.where( criteriaBuilder.isNotNull( root.get( "nextHolder" ) ) );
|
||||
|
||||
holder1 = s.createQuery( criteria ).uniqueResult();
|
||||
|
||||
// holder1 = ( EntityWithFunctionAsColumnHolder ) s.createCriteria( EntityWithFunctionAsColumnHolder.class )
|
||||
// .add( Restrictions.isNotNull( "nextHolder" ))
|
||||
// .setFetchMode( "entityWithArgFunctionAsColumns", FetchMode.JOIN )
|
||||
// .setFetchMode( "nextHolder", FetchMode.JOIN )
|
||||
// .setFetchMode( "nextHolder.entityWithArgFunctionAsColumns", FetchMode.JOIN )
|
||||
// .uniqueResult();
|
||||
assertTrue( Hibernate.isInitialized( holder1.getEntityWithArgFunctionAsColumns() ) );
|
||||
assertTrue( Hibernate.isInitialized( holder1.getNextHolder() ) );
|
||||
assertTrue( Hibernate.isInitialized( holder1.getNextHolder().getEntityWithArgFunctionAsColumns() ) );
|
||||
|
@ -181,7 +202,7 @@ public class FunctionNameAsColumnTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetMultiColumnSameNameAsNoArgFunctionHQL() throws Exception {
|
||||
public void testGetMultiColumnSameNameAsNoArgFunctionHQL() {
|
||||
SQLFunction function = sessionFactory().getSqlFunctionRegistry().findSQLFunction( "current_date" );
|
||||
if ( function == null || function.hasParenthesesIfNoArguments() ) {
|
||||
SkipLog.reportSkip( "current_date reuires ()", "tests noarg function that does not require ()" );
|
||||
|
@ -251,12 +272,22 @@ public class FunctionNameAsColumnTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
holder1 = ( EntityWithFunctionAsColumnHolder ) s.createCriteria( EntityWithFunctionAsColumnHolder.class )
|
||||
.add( Restrictions.isNotNull( "nextHolder" ))
|
||||
.setFetchMode( "entityWithNoArgFunctionAsColumns", FetchMode.JOIN )
|
||||
.setFetchMode( "nextHolder", FetchMode.JOIN )
|
||||
.setFetchMode( "nextHolder.entityWithNoArgFunctionAsColumns", FetchMode.JOIN )
|
||||
.uniqueResult();
|
||||
|
||||
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<EntityWithFunctionAsColumnHolder> criteria = criteriaBuilder.createQuery(
|
||||
EntityWithFunctionAsColumnHolder.class );
|
||||
Root<EntityWithFunctionAsColumnHolder> root = criteria.from( EntityWithFunctionAsColumnHolder.class );
|
||||
root.join( "entityWithArgFunctionAsColumns", JoinType.LEFT );
|
||||
Join<Object, Object> nextHolder = root.join( "nextHolder", JoinType.LEFT );
|
||||
nextHolder.join( "entityWithArgFunctionAsColumns", JoinType.LEFT );
|
||||
criteria.where( criteriaBuilder.isNotNull( root.get( "nextHolder" ) ) );
|
||||
|
||||
// holder1 = ( EntityWithFunctionAsColumnHolder ) s.createCriteria( EntityWithFunctionAsColumnHolder.class )
|
||||
// .add( Restrictions.isNotNull( "nextHolder" ))
|
||||
// .setFetchMode( "entityWithNoArgFunctionAsColumns", FetchMode.JOIN )
|
||||
// .setFetchMode( "nextHolder", FetchMode.JOIN )
|
||||
// .setFetchMode( "nextHolder.entityWithNoArgFunctionAsColumns", FetchMode.JOIN )
|
||||
// .uniqueResult();
|
||||
assertTrue( Hibernate.isInitialized( holder1.getEntityWithNoArgFunctionAsColumns() ) );
|
||||
assertTrue( Hibernate.isInitialized( holder1.getNextHolder() ) );
|
||||
assertTrue( Hibernate.isInitialized( holder1.getNextHolder().getEntityWithNoArgFunctionAsColumns() ) );
|
||||
|
|
|
@ -17,7 +17,6 @@ import javax.persistence.OneToMany;
|
|||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
|
@ -33,7 +32,6 @@ import static org.junit.Assert.assertEquals;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class MapFunctionExpressionsTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
private final ASTQueryTranslatorFactory queryTranslatorFactory = new ASTQueryTranslatorFactory();
|
||||
|
||||
@Before
|
||||
public void prepareTestData() {
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
package org.hibernate.test.hql;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.annotations.NaturalId;
|
||||
import org.hibernate.hql.spi.FilterTranslator;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
@ -281,17 +281,18 @@ public class NaturalIdDereferenceTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
private String getSQLQuery(Query query) {
|
||||
FilterTranslator naturalIdJoinGenerationTest1 = this.sessionFactory()
|
||||
.getSettings()
|
||||
.getQueryTranslatorFactory()
|
||||
.createFilterTranslator(
|
||||
"nid",
|
||||
query.getQueryString(),
|
||||
Collections.emptyMap(),
|
||||
this.sessionFactory()
|
||||
);
|
||||
naturalIdJoinGenerationTest1.compile( Collections.emptyMap(), false );
|
||||
return naturalIdJoinGenerationTest1.getSQLString();
|
||||
// FilterTranslator naturalIdJoinGenerationTest1 = this.sessionFactory()
|
||||
// .getSettings()
|
||||
// .getQueryTranslatorFactory()
|
||||
// .createFilterTranslator(
|
||||
// "nid",
|
||||
// query.getQueryString(),
|
||||
// Collections.emptyMap(),
|
||||
// this.sessionFactory()
|
||||
// );
|
||||
// naturalIdJoinGenerationTest1.compile( Collections.emptyMap(), false );
|
||||
// return naturalIdJoinGenerationTest1.getSQLString();
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,7 @@ package org.hibernate.test.hql;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
|
|
@ -8,11 +8,9 @@ package org.hibernate.test.hql;
|
|||
|
||||
import java.util.List;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
|
@ -44,10 +42,10 @@ public class HibernateFirstResultMaxResultsTest extends BaseNonConfigCoreFunctio
|
|||
assertNull( query.getHibernateFirstResult() );
|
||||
|
||||
// the following is special case; when initialized to -1, getHibernateFirstResult returns 0
|
||||
assertEquals( Integer.valueOf( 0 ), query.setHibernateFirstResult( -1 ).getHibernateFirstResult() );
|
||||
assertEquals( 0 , query.setFirstResult( -1 ).getFirstResult() );
|
||||
|
||||
assertEquals( Integer.valueOf( 0 ), query.setHibernateFirstResult( 0 ).getHibernateFirstResult() );
|
||||
assertEquals( Integer.valueOf( 1 ), query.setHibernateFirstResult( 1 ).getHibernateFirstResult() );
|
||||
assertEquals( Integer.valueOf( 0 ), query.setFirstResult( 0 ).getHibernateFirstResult() );
|
||||
assertEquals( Integer.valueOf( 1 ), query.setFirstResult( 1 ).getHibernateFirstResult() );
|
||||
|
||||
assertEquals( Integer.valueOf( 10 ), query.setFirstResult( 10 ).getHibernateFirstResult() );
|
||||
}
|
|
@ -10,7 +10,8 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.hql.internal.QuerySplitter;
|
||||
|
||||
import org.hibernate.query.hql.internal.QuerySplitter;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
Loading…
Reference in New Issue