From 04c5160e0265fff81074a6ee4a73734533375db6 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 21 Nov 2019 15:29:13 -0600 Subject: [PATCH] pull over "legacy 6.0" tests --- .../hql/internal/SemanticQueryBuilder.java | 7 +- .../internal/ConcreteSqmSelectQueryPlan.java | 8 +- .../query/hql/MultiValuedParameterTest.java | 88 +++++++++++++++++++ 3 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/MultiValuedParameterTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 533c922b3a..3ebf0c6880 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -84,12 +84,12 @@ import org.hibernate.query.sqm.tree.expression.SqmBinaryArithmetic; import org.hibernate.query.sqm.tree.expression.SqmCaseSearched; import org.hibernate.query.sqm.tree.expression.SqmCaseSimple; import org.hibernate.query.sqm.tree.expression.SqmCollectionSize; -import org.hibernate.query.sqm.tree.expression.SqmParameterizedEntityType; import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.expression.SqmLiteral; import org.hibernate.query.sqm.tree.expression.SqmLiteralNull; import org.hibernate.query.sqm.tree.expression.SqmNamedParameter; import org.hibernate.query.sqm.tree.expression.SqmParameter; +import org.hibernate.query.sqm.tree.expression.SqmParameterizedEntityType; import org.hibernate.query.sqm.tree.expression.SqmPathEntityType; import org.hibernate.query.sqm.tree.expression.SqmPositionalParameter; import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; @@ -727,6 +727,10 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre if ( sqmFrom != null ) { return sqmFrom; } + + final DotIdentifierConsumer dotIdentifierConsumer = dotIdentifierConsumerStack.getCurrent(); + dotIdentifierConsumer.consumeIdentifier( ctx.getText(), true, true ); + return (SqmExpression) dotIdentifierConsumer.getConsumedPart(); } return (SqmExpression) ctx.expression().accept( this ); @@ -2707,7 +2711,6 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre // return result; // } - @Override public SemanticPathPart visitDotIdentifierSequence(HqlParser.DotIdentifierSequenceContext ctx) { final int numberOfContinuations = ctx.dotIdentifierSequenceContinuation().size(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java index 8dd5b67b13..b80b5bfa8f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java @@ -157,9 +157,9 @@ public class ConcreteSqmSelectQueryPlan implements SelectQueryPlan { public List performList(ExecutionContext executionContext) { final SharedSessionContractImplementor session = executionContext.getSession(); - if ( jdbcSelect == null ) { - // todo (6.0) : for cases where we have no "load query influencers" we could use a cached SQL AST - // - this is similar to the plan for loaders +// if ( jdbcSelect == null ) { +// // todo (6.0) : for cases where we have no "load query influencers" we could use a cached SQL AST +// // - this is similar to the plan for loaders final SessionFactoryImplementor sessionFactory = session.getFactory(); final QueryEngine queryEngine = sessionFactory.getQueryEngine(); @@ -189,7 +189,7 @@ public class ConcreteSqmSelectQueryPlan implements SelectQueryPlan { domainParameterXref, interpretation::getJdbcParamsBySqmParam ); - } +// } final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings( diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/MultiValuedParameterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/MultiValuedParameterTest.java new file mode 100644 index 0000000000..eecfc44f0b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/MultiValuedParameterTest.java @@ -0,0 +1,88 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.query.hql; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.hibernate.boot.MetadataSources; +import org.hibernate.query.Query; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.domain.contacts.Contact; +import org.hibernate.testing.orm.domain.contacts.ContactsDomainModel; +import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Andrea Boriero + */ +@SuppressWarnings("WeakerAccess") +@TestForIssue(jiraKey = "HHH-10893") +public class MultiValuedParameterTest extends BaseSessionFactoryFunctionalTest { + + @Override + protected void applyMetadataSources(MetadataSources metadataSources) { + super.applyMetadataSources( metadataSources ); + ContactsDomainModel.applyContactsModel( metadataSources ); + } + + @BeforeAll + public void prepareData() { + inTransaction( + session -> { + for ( int i = 0; i < 20; i++ ) { + Contact p1 = new Contact( + i, + new Contact.Name( "first[" + i + "]", "last[" + i + "]" ), + Contact.Gender.MALE, + LocalDate.now() + ); + session.save( p1 ); + } + } + ); + } + + @Test + public void testParameterListIn() { + inTransaction( + session -> { + Collection ids = new ArrayList<>(); + Query q = session.createQuery( "select id from Contact where id in (:ids) order by id" ); + for ( int i = 0; i < 10; i++ ) { + ids.add( i ); + } + q.setParameterList( "ids", ids ); + q.list(); + + ids.clear(); + for ( int i = 10; i < 20; i++ ) { + ids.add( i ); + } + // reuse the same query, but set new collection parameter + q.setParameterList( "ids", ids ); + List foundIds = q.list(); + + assertThat( "Wrong number of results", foundIds.size(), is( ids.size() ) ); + assertThat( foundIds, is( ids ) ); + } + ); + } + + @AfterAll + public void cleanupData() { + inTransaction( session -> session.createQuery( "delete Contact" ).executeUpdate() ); + } +}