HHH-13763 : Update all load-by-key handling to use SQL AST
* Cleanup * Prep for dropping LoadPlan
This commit is contained in:
parent
264224a49e
commit
10cdb47a97
|
@ -179,4 +179,13 @@ public class SingleIdEntityLoaderDynamicBatch<T> extends SingleIdEntityLoaderSup
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (T) session.getPersistenceContext().getEntity( entityKey );
|
return (T) session.getPersistenceContext().getEntity( entityKey );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T load(
|
||||||
|
Object pkValue,
|
||||||
|
Object entityInstance,
|
||||||
|
LockOptions lockOptions,
|
||||||
|
SharedSessionContractImplementor session) {
|
||||||
|
return singleIdLoader.load( pkValue, entityInstance, lockOptions, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,18 @@ public class SingleIdEntityLoaderProvidedQueryImpl<T> implements SingleIdEntityL
|
||||||
return query.uniqueResult();
|
return query.uniqueResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T load(
|
||||||
|
Object pkValue,
|
||||||
|
Object entityInstance,
|
||||||
|
LockOptions lockOptions,
|
||||||
|
SharedSessionContractImplementor session) {
|
||||||
|
if ( entityInstance != null ) {
|
||||||
|
throw new UnsupportedOperationException( );
|
||||||
|
}
|
||||||
|
return load( pkValue, lockOptions, session );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] loadDatabaseSnapshot(Object id, SharedSessionContractImplementor session) {
|
public Object[] loadDatabaseSnapshot(Object id, SharedSessionContractImplementor session) {
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
|
|
|
@ -59,7 +59,22 @@ public class SingleIdEntityLoaderStandardImpl<T> extends SingleIdEntityLoaderSup
|
||||||
session.getFactory()
|
session.getFactory()
|
||||||
);
|
);
|
||||||
|
|
||||||
return loadPlan.load( key, lockOptions, session );
|
return loadPlan.load( key, lockOptions, null, session );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T load(
|
||||||
|
Object key,
|
||||||
|
Object entityInstance,
|
||||||
|
LockOptions lockOptions,
|
||||||
|
SharedSessionContractImplementor session) {
|
||||||
|
final SingleIdLoadPlan<T> loadPlan = resolveLoadPlan(
|
||||||
|
lockOptions,
|
||||||
|
session.getLoadQueryInfluencers(),
|
||||||
|
session.getFactory()
|
||||||
|
);
|
||||||
|
|
||||||
|
return loadPlan.load( key, lockOptions, entityInstance, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
|
|
|
@ -21,12 +21,12 @@ import org.hibernate.query.spi.QueryOptions;
|
||||||
import org.hibernate.query.spi.QueryParameterBindings;
|
import org.hibernate.query.spi.QueryParameterBindings;
|
||||||
import org.hibernate.sql.ast.Clause;
|
import org.hibernate.sql.ast.Clause;
|
||||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||||
|
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
||||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||||
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
|
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
|
||||||
import org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl;
|
import org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl;
|
||||||
import org.hibernate.sql.exec.spi.Callback;
|
import org.hibernate.sql.exec.spi.Callback;
|
||||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
|
||||||
import org.hibernate.sql.exec.spi.JdbcParameterBinding;
|
import org.hibernate.sql.exec.spi.JdbcParameterBinding;
|
||||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||||
import org.hibernate.sql.exec.spi.JdbcSelect;
|
import org.hibernate.sql.exec.spi.JdbcSelect;
|
||||||
|
@ -70,7 +70,18 @@ public class SingleIdLoadPlan<T> implements SingleEntityLoadPlan {
|
||||||
return sqlAst;
|
return sqlAst;
|
||||||
}
|
}
|
||||||
|
|
||||||
T load(Object restrictedValue, LockOptions lockOptions, SharedSessionContractImplementor session) {
|
T load(
|
||||||
|
Object restrictedValue,
|
||||||
|
LockOptions lockOptions,
|
||||||
|
SharedSessionContractImplementor session) {
|
||||||
|
return load( restrictedValue, lockOptions, null, session );
|
||||||
|
}
|
||||||
|
|
||||||
|
T load(
|
||||||
|
Object restrictedValue,
|
||||||
|
LockOptions lockOptions,
|
||||||
|
Object entityInstance,
|
||||||
|
SharedSessionContractImplementor session) {
|
||||||
final SessionFactoryImplementor sessionFactory = session.getFactory();
|
final SessionFactoryImplementor sessionFactory = session.getFactory();
|
||||||
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||||
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
||||||
|
@ -118,6 +129,11 @@ public class SingleIdLoadPlan<T> implements SingleEntityLoadPlan {
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getEntityInstance() {
|
||||||
|
return entityInstance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryOptions getQueryOptions() {
|
public QueryOptions getQueryOptions() {
|
||||||
return QueryOptions.NONE;
|
return QueryOptions.NONE;
|
||||||
|
@ -130,7 +146,8 @@ public class SingleIdLoadPlan<T> implements SingleEntityLoadPlan {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Callback getCallback() {
|
public Callback getCallback() {
|
||||||
return null;
|
return afterLoadAction -> {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
RowTransformerPassThruImpl.instance()
|
RowTransformerPassThruImpl.instance()
|
||||||
|
|
|
@ -21,6 +21,12 @@ public interface SingleIdEntityLoader<T> extends SingleEntityLoader<T> {
|
||||||
@Override
|
@Override
|
||||||
T load(Object pkValue, LockOptions lockOptions, SharedSessionContractImplementor session);
|
T load(Object pkValue, LockOptions lockOptions, SharedSessionContractImplementor session);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load by primary key value, populating the passed entity instance. Used to initialize an uninitialized
|
||||||
|
* bytecode-proxy. The passed instance is the enhanced proxy
|
||||||
|
*/
|
||||||
|
T load(Object pkValue, Object entityInstance, LockOptions lockOptions, SharedSessionContractImplementor session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load database snapshot by primary key value
|
* Load database snapshot by primary key value
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4616,11 +4616,11 @@ public abstract class AbstractEntityPersister
|
||||||
|
|
||||||
final EntityKey entityKey = proxyInterceptor.getEntityKey();
|
final EntityKey entityKey = proxyInterceptor.getEntityKey();
|
||||||
final Serializable identifier = entityKey.getIdentifier();
|
final Serializable identifier = entityKey.getIdentifier();
|
||||||
final Object loaded = readLockLoader.load(
|
final Object loaded = singleIdEntityLoader.load(
|
||||||
identifier,
|
identifier,
|
||||||
entity,
|
entity,
|
||||||
session,
|
LockOptions.READ,
|
||||||
LockOptions.READ
|
session
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( loaded == null ) {
|
if ( loaded == null ) {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.sql.exec.internal;
|
package org.hibernate.sql.exec.internal;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -129,7 +128,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
||||||
ExecutionContext executionContext,
|
ExecutionContext executionContext,
|
||||||
RowTransformer<R> rowTransformer,
|
RowTransformer<R> rowTransformer,
|
||||||
Function<String, PreparedStatement> statementCreator,
|
Function<String, PreparedStatement> statementCreator,
|
||||||
ResultsConsumer<T,R> resultsConsumer) {
|
ResultsConsumer<T, R> resultsConsumer) {
|
||||||
|
|
||||||
final JdbcValues jdbcValues = resolveJdbcValuesSource(
|
final JdbcValues jdbcValues = resolveJdbcValuesSource(
|
||||||
jdbcSelect,
|
jdbcSelect,
|
||||||
|
@ -148,7 +147,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
||||||
final JdbcValuesSourceProcessingOptions processingOptions = new JdbcValuesSourceProcessingOptions() {
|
final JdbcValuesSourceProcessingOptions processingOptions = new JdbcValuesSourceProcessingOptions() {
|
||||||
@Override
|
@Override
|
||||||
public Object getEffectiveOptionalObject() {
|
public Object getEffectiveOptionalObject() {
|
||||||
return null;
|
return executionContext.getEntityInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -157,7 +156,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Serializable getEffectiveOptionalId() {
|
public Object getEffectiveOptionalId() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,13 @@ public interface ExecutionContext {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should only be used when initializing a bytecode-proxy
|
||||||
|
*/
|
||||||
|
default Object getEntityInstance() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
default void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
|
default void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
|
||||||
// by default do nothing
|
// by default do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.sql.results.jdbc.spi;
|
package org.hibernate.sql.results.jdbc.spi;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Essentially processing options only for entity loading
|
* Essentially processing options only for entity loading
|
||||||
*
|
*
|
||||||
|
@ -16,7 +14,7 @@ import java.io.Serializable;
|
||||||
public interface JdbcValuesSourceProcessingOptions {
|
public interface JdbcValuesSourceProcessingOptions {
|
||||||
Object getEffectiveOptionalObject();
|
Object getEffectiveOptionalObject();
|
||||||
String getEffectiveOptionalEntityName();
|
String getEffectiveOptionalEntityName();
|
||||||
Serializable getEffectiveOptionalId();
|
Object getEffectiveOptionalId();
|
||||||
|
|
||||||
boolean shouldReturnProxies();
|
boolean shouldReturnProxies();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue