Skip to content

Commit

Permalink
HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
Browse files Browse the repository at this point in the history
  • Loading branch information
stliu authored and sebersole committed Oct 9, 2013
1 parent 6f8fddd commit c83fd30
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 42 deletions.
6 changes: 3 additions & 3 deletions hibernate-core/src/main/java/org/hibernate/LockMode.java
Expand Up @@ -84,7 +84,7 @@ public enum LockMode {
WRITE( 10 ),

/**
* Similiar to {@link #UPGRADE} except that, for versioned entities,
* Similar to {@link #UPGRADE} except that, for versioned entities,
* it results in a forced version increment.
*
* @deprecated instead use PESSIMISTIC_FORCE_INCREMENT
Expand All @@ -97,13 +97,13 @@ public enum LockMode {
*/

/**
* Optimisticly assume that transaction will not experience contention for
* Optimistically assume that transaction will not experience contention for
* entities. The entity version will be verified near the transaction end.
*/
OPTIMISTIC( 6 ),

/**
* Optimisticly assume that transaction will not experience contention for
* Optimistically assume that transaction will not experience contention for
* entities. The entity version will be verified and incremented near the transaction end.
*/
OPTIMISTIC_FORCE_INCREMENT( 7 ),
Expand Down
Expand Up @@ -170,7 +170,7 @@ public boolean hasEnabledFetchProfiles() {
return !enabledFetchProfileNames.isEmpty();
}

public Set getEnabledFetchProfileNames() {
public Set<String> getEnabledFetchProfileNames() {
return enabledFetchProfileNames;
}

Expand Down
Expand Up @@ -172,9 +172,7 @@ protected final boolean isJoinFetchEnabledByProfile(OuterJoinLoadable persister,
: rootPropertyName;
String fetchRole = persister.getEntityName() + "." + relativePropertyPath;

Iterator profiles = getLoadQueryInfluencers().getEnabledFetchProfileNames().iterator();
while ( profiles.hasNext() ) {
final String profileName = ( String ) profiles.next();
for ( String profileName : getLoadQueryInfluencers().getEnabledFetchProfileNames() ) {
final FetchProfile profile = getFactory().getFetchProfile( profileName );
final Fetch fetch = profile.getFetchByRole( fetchRole );
if ( fetch != null && Fetch.Style.JOIN == fetch.getStyle() ) {
Expand Down
Expand Up @@ -63,7 +63,7 @@ protected UniqueEntityLoader buildBatchingLoader(
return new LegacyBatchingEntityLoader( persister, batchSize, lockOptions, factory, influencers );
}

public static class LegacyBatchingEntityLoader extends BatchingEntityLoader implements UniqueEntityLoader {
public static class LegacyBatchingEntityLoader extends BatchingEntityLoader {
private final int[] batchSizes;
private final EntityLoader[] loaders;

Expand Down
Expand Up @@ -55,8 +55,7 @@
* @author Steve Ebersole
*/
public class SingleRootReturnLoadPlanBuilderStrategy
extends AbstractLoadPlanBuilderStrategy
implements LoadPlanBuilderStrategy {
extends AbstractLoadPlanBuilderStrategy {

private final LoadQueryInfluencers loadQueryInfluencers;

Expand Down
Expand Up @@ -50,8 +50,7 @@
* @author Steve Ebersole
*/
public class FetchStyleLoadPlanBuildingAssociationVisitationStrategy
extends AbstractLoadPlanBuildingAssociationVisitationStrategy
implements LoadPlanBuildingAssociationVisitationStrategy {
extends AbstractLoadPlanBuildingAssociationVisitationStrategy {
private static final Logger log = CoreLogging.logger( FetchStyleLoadPlanBuildingAssociationVisitationStrategy.class );

private final LoadQueryInfluencers loadQueryInfluencers;
Expand Down
Expand Up @@ -43,7 +43,7 @@
/**
* @author Steve Ebersole
*/
public class QuerySpacesImpl implements QuerySpaces, ExpandingQuerySpaces {
public class QuerySpacesImpl implements ExpandingQuerySpaces {
private static final Logger log = CoreLogging.logger( QuerySpacesImpl.class );

private final SessionFactoryImplementor sessionFactory;
Expand Down
Expand Up @@ -53,11 +53,11 @@ public class LoadPlanTreePrinter {
*/
public static final LoadPlanTreePrinter INSTANCE = new LoadPlanTreePrinter();

public String toString(LoadPlan loadPlan) {
private String toString(LoadPlan loadPlan) {
return toString( loadPlan, null );
}

public String toString(LoadPlan loadPlan, AliasResolutionContextImpl aliasResolutionContext) {
private String toString(LoadPlan loadPlan, AliasResolutionContextImpl aliasResolutionContext) {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final PrintStream printStream = new PrintStream( byteArrayOutputStream );
final PrintWriter printWriter = new PrintWriter( printStream );
Expand All @@ -83,8 +83,9 @@ public void logTree(LoadPlan loadPlan, AliasResolutionContextImpl aliasResolutio

printWriter.flush();
printStream.flush();
log.debug( new String( byteArrayOutputStream.toByteArray() ) );

log.debug( toString( loadPlan, aliasResolutionContext ) );
// log.debug( toString( loadPlan, aliasResolutionContext ) );
}

private void logTree(
Expand Down
Expand Up @@ -102,7 +102,7 @@ private void writeQuerySpace(
writeJoins( querySpace.getJoins(), depth + 1, aliasResolutionContext, printWriter );
}

final int detailDepthOffset = 4;
final int detailDepthOffset = 1;

private void generateDetailLines(
QuerySpace querySpace,
Expand Down
Expand Up @@ -64,9 +64,14 @@ public EntityKey interpretEntityKey(
else {
entityPersister = session.getFactory().getEntityPersister( optionalEntityName );
}
if ( entityPersister.isInstance( optionalId ) ) {
if ( entityPersister.isInstance( optionalId ) && !entityPersister.getEntityMetamodel()
.getIdentifierProperty()
.isVirtual() && entityPersister.getEntityMetamodel().getIdentifierProperty().isEmbedded() ) {
// embedded (non-encapsulated) composite identifier
final Serializable identifierState = ( (CompositeType) entityPersister.getIdentifierType() ).getPropertyValues( optionalId, session );
final Serializable identifierState = ((CompositeType) entityPersister.getIdentifierType()).getPropertyValues(
optionalId,
session
);
return session.generateEntityKey( identifierState, entityPersister );
}
else {
Expand Down
Expand Up @@ -121,10 +121,12 @@ protected EntityLoadQueryDetails(
QueryBuildingParameters buildingParameters,
SessionFactoryImplementor factory) {
this.loadPlan = loadPlan;
final AliasResolutionContextImpl aliasResolutionContext = new AliasResolutionContextImpl( factory );

if ( log.isDebugEnabled() ) {
log.debug( LoadPlanTreePrinter.INSTANCE.toString( loadPlan ) );
}
// LoadPlanTreePrinter.INSTANCE.logTree( loadPlan, aliasResolutionContext );
// if ( log.isDebugEnabled() ) {
// log.debug( LoadPlanTreePrinter.INSTANCE.toString( loadPlan ) );
// }

// There are 2 high-level requirements to perform here:
// 1) Determine the SQL required to carry out the given LoadPlan (and fulfill
Expand All @@ -136,7 +138,6 @@ protected EntityLoadQueryDetails(

final SelectStatementBuilder select = new SelectStatementBuilder( factory.getDialect() );
final EntityReturn rootReturn = Helper.INSTANCE.extractRootReturn( loadPlan, EntityReturn.class );
final AliasResolutionContextImpl aliasResolutionContext = new AliasResolutionContextImpl( factory );
final ReaderCollectorImpl readerCollector = new ReaderCollectorImpl();

final LoadQueryJoinAndFetchProcessor helper = new LoadQueryJoinAndFetchProcessor( aliasResolutionContext , buildingParameters, factory );
Expand Down Expand Up @@ -386,7 +387,7 @@ public void setRootReturnReader(EntityReturnReader entityReturnReader) {
}
}

public static class EntityLoaderRowReader extends AbstractRowReader implements RowReader {
public static class EntityLoaderRowReader extends AbstractRowReader {
private final EntityReturnReader rootReturnReader;
private final List<EntityReferenceInitializer> entityReferenceInitializers;
private final List<CollectionReferenceInitializer> arrayReferenceInitializers;
Expand Down
Expand Up @@ -23,18 +23,8 @@
*/
package org.hibernate.loader.plan2.spi;

import org.hibernate.engine.FetchStrategy;
import org.hibernate.loader.PropertyPath;

import org.hibernate.loader.plan.spi.SqlSelectFragmentResolver;
import org.hibernate.loader.plan.spi.build.LoadPlanBuildingContext;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.walking.spi.AnyMappingDefinition;
import org.hibernate.persister.walking.spi.AssociationAttributeDefinition;
import org.hibernate.persister.walking.spi.AttributeDefinition;
import org.hibernate.persister.walking.spi.CompositionDefinition;
import org.hibernate.type.Type;

/**
* Contract for a FetchSource (aka, the thing that owns the fetched attribute).
*
Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.hibernate.persister.entity.PropertyMapping;

/**
* Defines a persister reference (either entity or collection) or a composite reference. JPA terms this
* Defines a persister reference (either entity or collection) or a composite reference. In JPA terms this is
* an "abstract schema type" when discussing JPQL or JPA Criteria queries. This models a single source of attributes
* (and fetches).
*
Expand Down
Expand Up @@ -228,7 +228,7 @@ public abstract class AbstractEntityPersister
// dynamic filters attached to the class-level
private final FilterHelper filterHelper;

private final Set affectingFetchProfileNames = new HashSet();
private final Set<String> affectingFetchProfileNames = new HashSet<String>();

private final Map uniqueKeyLoaders = new HashMap();
private final Map lockers = new HashMap();
Expand Down Expand Up @@ -3973,9 +3973,8 @@ public void registerAffectingFetchProfile(String fetchProfileName) {
}

private boolean isAffectedByEnabledFetchProfiles(SessionImplementor session) {
Iterator itr = session.getLoadQueryInfluencers().getEnabledFetchProfileNames().iterator();
while ( itr.hasNext() ) {
if ( affectingFetchProfileNames.contains( itr.next() ) ) {
for ( String s : session.getLoadQueryInfluencers().getEnabledFetchProfileNames() ) {
if ( affectingFetchProfileNames.contains( s ) ) {
return true;
}
}
Expand Down
Expand Up @@ -76,9 +76,7 @@ public static FetchStyle determineFetchStyleByProfile(
: rootPropertyName;
final String fetchRole = persister.getEntityName() + "." + relativePropertyPath;

Iterator profiles = loadQueryInfluencers.getEnabledFetchProfileNames().iterator();
while ( profiles.hasNext() ) {
final String profileName = ( String ) profiles.next();
for ( String profileName : loadQueryInfluencers.getEnabledFetchProfileNames() ) {
final FetchProfile profile = loadQueryInfluencers.getSessionFactory().getFetchProfile( profileName );
final Fetch fetch = profile.getFetchByRole( fetchRole );
if ( fetch != null && Fetch.Style.JOIN == fetch.getStyle() ) {
Expand Down

0 comments on commit c83fd30

Please sign in to comment.