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
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T load(
|
||||
Object pkValue,
|
||||
Object entityInstance,
|
||||
LockOptions lockOptions,
|
||||
SharedSessionContractImplementor session) {
|
||||
if ( entityInstance != null ) {
|
||||
throw new UnsupportedOperationException( );
|
||||
}
|
||||
return load( pkValue, lockOptions, session );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] loadDatabaseSnapshot(Object id, SharedSessionContractImplementor session) {
|
||||
return new Object[0];
|
||||
|
|
|
@ -59,7 +59,22 @@ public class SingleIdEntityLoaderStandardImpl<T> extends SingleIdEntityLoaderSup
|
|||
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
|
||||
|
|
|
@ -21,12 +21,12 @@ import org.hibernate.query.spi.QueryOptions;
|
|||
import org.hibernate.query.spi.QueryParameterBindings;
|
||||
import org.hibernate.sql.ast.Clause;
|
||||
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.exec.internal.JdbcParameterBindingsImpl;
|
||||
import org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl;
|
||||
import org.hibernate.sql.exec.spi.Callback;
|
||||
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.JdbcParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.JdbcSelect;
|
||||
|
@ -70,7 +70,18 @@ public class SingleIdLoadPlan<T> implements SingleEntityLoadPlan {
|
|||
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 JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
||||
|
@ -118,6 +129,11 @@ public class SingleIdLoadPlan<T> implements SingleEntityLoadPlan {
|
|||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getEntityInstance() {
|
||||
return entityInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryOptions getQueryOptions() {
|
||||
return QueryOptions.NONE;
|
||||
|
@ -130,7 +146,8 @@ public class SingleIdLoadPlan<T> implements SingleEntityLoadPlan {
|
|||
|
||||
@Override
|
||||
public Callback getCallback() {
|
||||
return null;
|
||||
return afterLoadAction -> {
|
||||
};
|
||||
}
|
||||
},
|
||||
RowTransformerPassThruImpl.instance()
|
||||
|
|
|
@ -21,6 +21,12 @@ public interface SingleIdEntityLoader<T> extends SingleEntityLoader<T> {
|
|||
@Override
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -4616,11 +4616,11 @@ public abstract class AbstractEntityPersister
|
|||
|
||||
final EntityKey entityKey = proxyInterceptor.getEntityKey();
|
||||
final Serializable identifier = entityKey.getIdentifier();
|
||||
final Object loaded = readLockLoader.load(
|
||||
final Object loaded = singleIdEntityLoader.load(
|
||||
identifier,
|
||||
entity,
|
||||
session,
|
||||
LockOptions.READ
|
||||
LockOptions.READ,
|
||||
session
|
||||
);
|
||||
|
||||
if ( loaded == null ) {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.sql.exec.internal;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -129,7 +128,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
|||
ExecutionContext executionContext,
|
||||
RowTransformer<R> rowTransformer,
|
||||
Function<String, PreparedStatement> statementCreator,
|
||||
ResultsConsumer<T,R> resultsConsumer) {
|
||||
ResultsConsumer<T, R> resultsConsumer) {
|
||||
|
||||
final JdbcValues jdbcValues = resolveJdbcValuesSource(
|
||||
jdbcSelect,
|
||||
|
@ -148,7 +147,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
|||
final JdbcValuesSourceProcessingOptions processingOptions = new JdbcValuesSourceProcessingOptions() {
|
||||
@Override
|
||||
public Object getEffectiveOptionalObject() {
|
||||
return null;
|
||||
return executionContext.getEntityInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,7 +156,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Serializable getEffectiveOptionalId() {
|
||||
public Object getEffectiveOptionalId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,13 @@ public interface ExecutionContext {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be used when initializing a bytecode-proxy
|
||||
*/
|
||||
default Object getEntityInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
|
||||
// by default do nothing
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.sql.results.jdbc.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Essentially processing options only for entity loading
|
||||
*
|
||||
|
@ -16,7 +14,7 @@ import java.io.Serializable;
|
|||
public interface JdbcValuesSourceProcessingOptions {
|
||||
Object getEffectiveOptionalObject();
|
||||
String getEffectiveOptionalEntityName();
|
||||
Serializable getEffectiveOptionalId();
|
||||
Object getEffectiveOptionalId();
|
||||
|
||||
boolean shouldReturnProxies();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue