HHH-7841 - Redesign Loader
This commit is contained in:
parent
5ea40ce3f5
commit
a5862017d8
|
@ -57,17 +57,13 @@ public abstract class AbstractEntityLoader extends OuterJoinLoader
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object load(Serializable id, Object optionalObject, SessionImplementor session) {
|
||||
// this form is deprecated!
|
||||
return load( id, optionalObject, session, LockOptions.NONE );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object load(Serializable id, Object optionalObject, SessionImplementor session, LockOptions lockOptions) {
|
||||
return load( session, id, optionalObject, id, lockOptions );
|
||||
}
|
||||
|
|
|
@ -25,53 +25,62 @@ package org.hibernate.persister.entity;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.AbstractQueryImpl;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.loader.entity.UniqueEntityLoader;
|
||||
|
||||
/**
|
||||
* Not really a <tt>Loader</tt>, just a wrapper around a
|
||||
* named query.
|
||||
* Not really a Loader, just a wrapper around a named query. Used when the metadata has named a query to use for
|
||||
* loading an entity (using {@link org.hibernate.annotations.Loader} or {@code <loader/>}).
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public final class NamedQueryLoader implements UniqueEntityLoader {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( NamedQueryLoader.class );
|
||||
|
||||
private final String queryName;
|
||||
private final EntityPersister persister;
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, NamedQueryLoader.class.getName());
|
||||
|
||||
/**
|
||||
* Constructs the NamedQueryLoader
|
||||
*
|
||||
* @param queryName The name of the named query to use
|
||||
* @param persister The corresponding persister for the entity we are loading
|
||||
*/
|
||||
public NamedQueryLoader(String queryName, EntityPersister persister) {
|
||||
super();
|
||||
this.queryName = queryName;
|
||||
this.persister = persister;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object load(Serializable id, Object optionalObject, SessionImplementor session, LockOptions lockOptions) {
|
||||
if (lockOptions != null) LOG.debug("Ignoring lock-options passed to named query loader");
|
||||
if ( lockOptions != null ) {
|
||||
LOG.debug( "Ignoring lock-options passed to named query loader" );
|
||||
}
|
||||
return load( id, optionalObject, session );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object load(Serializable id, Object optionalObject, SessionImplementor session) {
|
||||
LOG.debugf( "Loading entity: %s using named query: %s", persister.getEntityName(), queryName );
|
||||
|
||||
AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedQuery(queryName);
|
||||
// IMPL NOTE: essentially we perform the named query (which loads the entity into the PC), and then
|
||||
// do an internal lookup of the entity from the PC.
|
||||
|
||||
final AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedQuery( queryName );
|
||||
if ( query.hasNamedParameters() ) {
|
||||
query.setParameter(
|
||||
query.getNamedParameters()[0],
|
||||
id,
|
||||
persister.getIdentifierType()
|
||||
);
|
||||
query.setParameter( query.getNamedParameters()[0], id, persister.getIdentifierType() );
|
||||
}
|
||||
else {
|
||||
query.setParameter( 0, id, persister.getIdentifierType() );
|
||||
}
|
||||
|
||||
query.setOptionalId( id );
|
||||
query.setOptionalEntityName( persister.getEntityName() );
|
||||
query.setOptionalObject( optionalObject );
|
||||
|
|
Loading…
Reference in New Issue