HHH-12413 Made ParameterTranslationsImpl public again so that it can be instantiated

This commit is contained in:
Christian Beikov 2018-03-21 08:08:20 +01:00 committed by Vlad Mihalcea
parent 6b3bbfcd19
commit 62347cde01
2 changed files with 43 additions and 7 deletions

View File

@ -627,10 +627,6 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
);
}
if ( parameterListBindingMap != null ) {
parameterListBindingMap.clear();
}
return queryString;
}

View File

@ -6,19 +6,25 @@
*/
package org.hibernate.test.queryplan;
import java.util.Arrays;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.engine.query.spi.HQLQueryPlan;
import org.hibernate.engine.query.spi.QueryPlanCache;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.internal.ParameterMetadataImpl;
import org.hibernate.query.internal.QueryParameterBindingsImpl;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.*;
/**
* Tests for HQL query plans
@ -63,6 +69,40 @@ public class GetHqlQueryPlanTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Test
@TestForIssue(jiraKey = "HHH-12413")
public void testExpandingQueryStringMultipleTimesWorks() {
doInHibernate( this::sessionFactory, session -> {
QueryPlanCache cache = ( ( SessionImplementor ) session ).getFactory().getQueryPlanCache();
String queryString = "from Person where name in :names";
HQLQueryPlan plan = cache.getHQLQueryPlan( queryString, false, getEnabledFilters( session ) );
QueryParameterBindings queryParameterBindings = QueryParameterBindingsImpl.from(
plan.getParameterMetadata(),
(SessionFactoryImplementor) session.getSessionFactory(),
false
);
queryParameterBindings.getQueryParameterListBinding( "names" ).setBindValues( Arrays.asList( "a", "b" ) );
String actualQueryString = queryParameterBindings.expandListValuedParameters(queryString, (SharedSessionContractImplementor) session);
String expectedQueryString = "from Person where name in (:names_0, :names_1)";
assertEquals(
expectedQueryString,
actualQueryString
);
// Expanding the same query again should work as before
actualQueryString = queryParameterBindings.expandListValuedParameters(queryString, (SharedSessionContractImplementor) session);
assertEquals(
expectedQueryString,
actualQueryString
);
} );
}
@Test
public void testHqlQueryPlanWithEnabledFilter() {
Session s = openSession();