HHH-10297 : Cache HashMap in AbstractRowReader instead of re-creating for each row that is read
(cherry picked from commit ccc99c690f
)
This commit is contained in:
parent
fa7a675490
commit
3d89a9d118
|
@ -46,14 +46,33 @@ public abstract class AbstractRowReader implements RowReader {
|
||||||
private final List<CollectionReferenceInitializer> arrayReferenceInitializers;
|
private final List<CollectionReferenceInitializer> arrayReferenceInitializers;
|
||||||
private final List<CollectionReferenceInitializer> collectionReferenceInitializers;
|
private final List<CollectionReferenceInitializer> collectionReferenceInitializers;
|
||||||
|
|
||||||
|
// cache map for looking up EntityReferenceInitializer by EntityReference to help with resolving
|
||||||
|
// bidirectional EntityReference and fetches.
|
||||||
|
private final Map<EntityReference,EntityReferenceInitializer> entityInitializerByEntityReference;
|
||||||
|
|
||||||
public AbstractRowReader(ReaderCollector readerCollector) {
|
public AbstractRowReader(ReaderCollector readerCollector) {
|
||||||
this.entityReferenceInitializers = readerCollector.getEntityReferenceInitializers() != null
|
if ( CollectionHelper.isNotEmpty( readerCollector.getEntityReferenceInitializers() ) ) {
|
||||||
? new ArrayList<EntityReferenceInitializer>( readerCollector.getEntityReferenceInitializers() )
|
entityReferenceInitializers = new ArrayList<EntityReferenceInitializer>(
|
||||||
: Collections.<EntityReferenceInitializer>emptyList();
|
readerCollector.getEntityReferenceInitializers()
|
||||||
this.arrayReferenceInitializers = readerCollector.getArrayReferenceInitializers() != null
|
);
|
||||||
|
entityInitializerByEntityReference =
|
||||||
|
new HashMap<EntityReference, EntityReferenceInitializer>( entityReferenceInitializers.size() );
|
||||||
|
for ( EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers ) {
|
||||||
|
entityInitializerByEntityReference.put(
|
||||||
|
entityReferenceInitializer.getEntityReference(),
|
||||||
|
entityReferenceInitializer
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
entityReferenceInitializers = Collections.<EntityReferenceInitializer>emptyList();
|
||||||
|
entityInitializerByEntityReference = Collections.<EntityReference,EntityReferenceInitializer>emptyMap();
|
||||||
|
}
|
||||||
|
this.arrayReferenceInitializers = CollectionHelper.isNotEmpty( readerCollector.getArrayReferenceInitializers() )
|
||||||
? new ArrayList<CollectionReferenceInitializer>( readerCollector.getArrayReferenceInitializers() )
|
? new ArrayList<CollectionReferenceInitializer>( readerCollector.getArrayReferenceInitializers() )
|
||||||
: Collections.<CollectionReferenceInitializer>emptyList();
|
: Collections.<CollectionReferenceInitializer>emptyList();
|
||||||
this.collectionReferenceInitializers = readerCollector.getNonArrayCollectionReferenceInitializers() != null
|
this.collectionReferenceInitializers =
|
||||||
|
CollectionHelper.isNotEmpty ( readerCollector.getNonArrayCollectionReferenceInitializers() )
|
||||||
? new ArrayList<CollectionReferenceInitializer>( readerCollector.getNonArrayCollectionReferenceInitializers() )
|
? new ArrayList<CollectionReferenceInitializer>( readerCollector.getNonArrayCollectionReferenceInitializers() )
|
||||||
: Collections.<CollectionReferenceInitializer>emptyList();
|
: Collections.<CollectionReferenceInitializer>emptyList();
|
||||||
}
|
}
|
||||||
|
@ -71,17 +90,11 @@ public abstract class AbstractRowReader implements RowReader {
|
||||||
for ( EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers ) {
|
for ( EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers ) {
|
||||||
entityReferenceInitializer.hydrateIdentifier( resultSet, context );
|
entityReferenceInitializer.hydrateIdentifier( resultSet, context );
|
||||||
}
|
}
|
||||||
final Map<EntityReference,EntityReferenceInitializer> initializerByEntityReference =
|
|
||||||
new HashMap<EntityReference, EntityReferenceInitializer>( entityReferenceInitializers.size() );
|
|
||||||
for ( EntityReferenceInitializer entityReferenceInitializerFromMap : entityReferenceInitializers ) {
|
|
||||||
initializerByEntityReference.put( entityReferenceInitializerFromMap.getEntityReference(), entityReferenceInitializerFromMap );
|
|
||||||
}
|
|
||||||
for ( EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers ) {
|
for ( EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers ) {
|
||||||
resolveEntityKey(
|
resolveEntityKey(
|
||||||
resultSet,
|
resultSet,
|
||||||
context,
|
context,
|
||||||
entityReferenceInitializer,
|
entityReferenceInitializer
|
||||||
initializerByEntityReference
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,13 +133,12 @@ public abstract class AbstractRowReader implements RowReader {
|
||||||
private void resolveEntityKey(
|
private void resolveEntityKey(
|
||||||
ResultSet resultSet,
|
ResultSet resultSet,
|
||||||
ResultSetProcessingContextImpl context,
|
ResultSetProcessingContextImpl context,
|
||||||
EntityReferenceInitializer entityReferenceInitializer,
|
EntityReferenceInitializer entityReferenceInitializer) throws SQLException {
|
||||||
Map<EntityReference,EntityReferenceInitializer> initializerByEntityReference) throws SQLException {
|
|
||||||
final EntityReference entityReference = entityReferenceInitializer.getEntityReference();
|
final EntityReference entityReference = entityReferenceInitializer.getEntityReference();
|
||||||
final EntityIdentifierDescription identifierDescription = entityReference.getIdentifierDescription();
|
final EntityIdentifierDescription identifierDescription = entityReference.getIdentifierDescription();
|
||||||
|
|
||||||
if ( identifierDescription.hasFetches() || identifierDescription.hasBidirectionalEntityReferences() ) {
|
if ( identifierDescription.hasFetches() || identifierDescription.hasBidirectionalEntityReferences() ) {
|
||||||
resolveEntityKey( resultSet, context, (FetchSource) identifierDescription, initializerByEntityReference );
|
resolveEntityKey( resultSet, context, (FetchSource) identifierDescription );
|
||||||
}
|
}
|
||||||
entityReferenceInitializer.resolveEntityKey( resultSet, context );
|
entityReferenceInitializer.resolveEntityKey( resultSet, context );
|
||||||
}
|
}
|
||||||
|
@ -134,31 +146,30 @@ public abstract class AbstractRowReader implements RowReader {
|
||||||
private void resolveEntityKey(
|
private void resolveEntityKey(
|
||||||
ResultSet resultSet,
|
ResultSet resultSet,
|
||||||
ResultSetProcessingContextImpl context,
|
ResultSetProcessingContextImpl context,
|
||||||
FetchSource fetchSource,
|
FetchSource fetchSource) throws SQLException {
|
||||||
Map<EntityReference,EntityReferenceInitializer> initializerByEntityReference) throws SQLException {
|
|
||||||
// Resolve any bidirectional entity references first.
|
// Resolve any bidirectional entity references first.
|
||||||
for ( BidirectionalEntityReference bidirectionalEntityReference : fetchSource.getBidirectionalEntityReferences() ) {
|
for ( BidirectionalEntityReference bidirectionalEntityReference : fetchSource.getBidirectionalEntityReferences() ) {
|
||||||
final EntityReferenceInitializer targetEntityReferenceInitializer = initializerByEntityReference.get(
|
final EntityReferenceInitializer targetEntityReferenceInitializer = entityInitializerByEntityReference.get(
|
||||||
bidirectionalEntityReference.getTargetEntityReference()
|
bidirectionalEntityReference.getTargetEntityReference()
|
||||||
);
|
);
|
||||||
resolveEntityKey(
|
resolveEntityKey(
|
||||||
resultSet,
|
resultSet,
|
||||||
context,
|
context,
|
||||||
targetEntityReferenceInitializer,
|
targetEntityReferenceInitializer
|
||||||
initializerByEntityReference
|
|
||||||
);
|
);
|
||||||
targetEntityReferenceInitializer.hydrateEntityState( resultSet, context );
|
targetEntityReferenceInitializer.hydrateEntityState( resultSet, context );
|
||||||
}
|
}
|
||||||
for ( Fetch fetch : fetchSource.getFetches() ) {
|
for ( Fetch fetch : fetchSource.getFetches() ) {
|
||||||
if ( EntityFetch.class.isInstance( fetch ) ) {
|
if ( EntityFetch.class.isInstance( fetch ) ) {
|
||||||
final EntityFetch entityFetch = (EntityFetch) fetch;
|
final EntityFetch entityFetch = (EntityFetch) fetch;
|
||||||
final EntityReferenceInitializer entityReferenceInitializer = initializerByEntityReference.get( entityFetch );
|
final EntityReferenceInitializer entityReferenceInitializer = entityInitializerByEntityReference.get(
|
||||||
|
entityFetch
|
||||||
|
);
|
||||||
if ( entityReferenceInitializer != null ) {
|
if ( entityReferenceInitializer != null ) {
|
||||||
resolveEntityKey(
|
resolveEntityKey(
|
||||||
resultSet,
|
resultSet,
|
||||||
context,
|
context,
|
||||||
entityReferenceInitializer,
|
entityReferenceInitializer
|
||||||
initializerByEntityReference
|
|
||||||
);
|
);
|
||||||
entityReferenceInitializer.hydrateEntityState( resultSet, context );
|
entityReferenceInitializer.hydrateEntityState( resultSet, context );
|
||||||
}
|
}
|
||||||
|
@ -167,8 +178,8 @@ public abstract class AbstractRowReader implements RowReader {
|
||||||
resolveEntityKey(
|
resolveEntityKey(
|
||||||
resultSet,
|
resultSet,
|
||||||
context,
|
context,
|
||||||
(CompositeFetch) fetch,
|
(CompositeFetch) fetch
|
||||||
initializerByEntityReference );
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue