HHH-16981 Improve JdbcOperation caching
This commit is contained in:
parent
bf9a8283dc
commit
0c7c68fe5a
|
@ -41,6 +41,7 @@ public class CollectionLoaderSingleKey implements CollectionLoader {
|
|||
private final int keyJdbcCount;
|
||||
|
||||
private final SelectStatement sqlAst;
|
||||
private final JdbcOperationQuerySelect jdbcSelect;
|
||||
private final JdbcParametersList jdbcParameters;
|
||||
|
||||
public CollectionLoaderSingleKey(
|
||||
|
@ -64,6 +65,11 @@ public class CollectionLoaderSingleKey implements CollectionLoader {
|
|||
sessionFactory
|
||||
);
|
||||
this.jdbcParameters = jdbcParametersBuilder.build();
|
||||
this.jdbcSelect = sessionFactory.getJdbcServices()
|
||||
.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildSelectTranslator( sessionFactory, sqlAst )
|
||||
.translate( JdbcParameterBindings.NO_BINDINGS, QueryOptions.NONE );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,10 +93,7 @@ public class CollectionLoaderSingleKey implements CollectionLoader {
|
|||
public PersistentCollection<?> load(Object key, SharedSessionContractImplementor session) {
|
||||
final CollectionKey collectionKey = new CollectionKey( attributeMapping.getCollectionDescriptor(), key );
|
||||
|
||||
final SessionFactoryImplementor sessionFactory = session.getFactory();
|
||||
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
||||
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
|
||||
final JdbcServices jdbcServices = session.getFactory().getJdbcServices();
|
||||
|
||||
final JdbcParameterBindings jdbcParameterBindings = new JdbcParameterBindingsImpl( keyJdbcCount );
|
||||
int offset = jdbcParameterBindings.registerParametersForEachJdbcValue(
|
||||
|
@ -101,10 +104,6 @@ public class CollectionLoaderSingleKey implements CollectionLoader {
|
|||
);
|
||||
assert offset == jdbcParameters.size();
|
||||
|
||||
final JdbcOperationQuerySelect jdbcSelect = sqlAstTranslatorFactory
|
||||
.buildSelectTranslator( sessionFactory, sqlAst )
|
||||
.translate( jdbcParameterBindings, QueryOptions.NONE );
|
||||
|
||||
final SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler = SubselectFetch.createRegistrationHandler(
|
||||
session.getPersistenceContext().getBatchFetchQueue(),
|
||||
sqlAst,
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.loader.ast.internal.NoCallbackExecutionContext;
|
|||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.query.spi.QueryOptions;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
|
||||
|
@ -46,6 +45,7 @@ import static org.hibernate.sql.results.spi.ListResultsConsumer.UniqueSemantic.F
|
|||
@Incubating
|
||||
public class GeneratedValuesProcessor {
|
||||
private final SelectStatement selectStatement;
|
||||
private final JdbcOperationQuerySelect jdbcSelect;
|
||||
private final List<AttributeMapping> generatedValuesToSelect;
|
||||
private final JdbcParametersList jdbcParameters;
|
||||
|
||||
|
@ -62,6 +62,7 @@ public class GeneratedValuesProcessor {
|
|||
generatedValuesToSelect = getGeneratedAttributes( entityDescriptor, timing );
|
||||
if ( generatedValuesToSelect.isEmpty() ) {
|
||||
selectStatement = null;
|
||||
jdbcSelect = null;
|
||||
this.jdbcParameters = JdbcParametersList.empty();
|
||||
}
|
||||
else {
|
||||
|
@ -78,6 +79,9 @@ public class GeneratedValuesProcessor {
|
|||
builder::add,
|
||||
sessionFactory
|
||||
);
|
||||
jdbcSelect = sessionFactory.getJdbcServices().getJdbcEnvironment().getSqlAstTranslatorFactory()
|
||||
.buildSelectTranslator( sessionFactory, selectStatement )
|
||||
.translate( JdbcParameterBindings.NO_BINDINGS, QueryOptions.NONE );
|
||||
this.jdbcParameters = builder.build();
|
||||
}
|
||||
}
|
||||
|
@ -116,10 +120,6 @@ public class GeneratedValuesProcessor {
|
|||
|
||||
private List<Object[]> executeSelect(Object id, SharedSessionContractImplementor session) {
|
||||
final JdbcParameterBindings jdbcParamBindings = getJdbcParameterBindings( id, session );
|
||||
final JdbcOperationQuerySelect jdbcSelect =
|
||||
sessionFactory.getJdbcServices().getJdbcEnvironment().getSqlAstTranslatorFactory()
|
||||
.buildSelectTranslator( sessionFactory, selectStatement )
|
||||
.translate( jdbcParamBindings, QueryOptions.NONE );
|
||||
return session.getFactory().getJdbcServices().getJdbcSelectExecutor()
|
||||
.list( jdbcSelect, jdbcParamBindings, new NoCallbackExecutionContext(session), (row) -> row, FILTER );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue