use of org.hibernate.loader.plan.exec.process.spi.EntityReferenceInitializer in project hibernate-orm by hibernate.
the class AbstractRowReader method readRow.
@Override
public Object readRow(ResultSet resultSet, ResultSetProcessingContextImpl context) throws SQLException {
final boolean hasEntityReferenceInitializers = CollectionHelper.isNotEmpty(entityReferenceInitializers);
if (hasEntityReferenceInitializers) {
// 1) allow entity references to resolve identifiers (in 2 steps)
for (EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers) {
entityReferenceInitializer.hydrateIdentifier(resultSet, context);
}
for (EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers) {
resolveEntityKey(resultSet, context, entityReferenceInitializer);
}
// 2) allow entity references to resolve their non-identifier hydrated state and entity instance
for (EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers) {
entityReferenceInitializer.hydrateEntityState(resultSet, context);
}
}
// 3) read the logical row
Object logicalRow = readLogicalRow(resultSet, context);
// 4) allow arrays, entities and collections afterQuery row callbacks
if (hasEntityReferenceInitializers) {
for (EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers) {
entityReferenceInitializer.finishUpRow(resultSet, context);
}
}
if (collectionReferenceInitializers != null) {
for (CollectionReferenceInitializer collectionReferenceInitializer : collectionReferenceInitializers) {
collectionReferenceInitializer.finishUpRow(resultSet, context);
}
}
if (arrayReferenceInitializers != null) {
for (CollectionReferenceInitializer arrayReferenceInitializer : arrayReferenceInitializers) {
arrayReferenceInitializer.finishUpRow(resultSet, context);
}
}
return logicalRow;
}
use of org.hibernate.loader.plan.exec.process.spi.EntityReferenceInitializer in project hibernate-orm by hibernate.
the class AbstractRowReader method resolveEntityKey.
private void resolveEntityKey(ResultSet resultSet, ResultSetProcessingContextImpl context, FetchSource fetchSource) throws SQLException {
// Resolve any bidirectional entity references first.
for (BidirectionalEntityReference bidirectionalEntityReference : fetchSource.getBidirectionalEntityReferences()) {
final EntityReferenceInitializer targetEntityReferenceInitializer = entityInitializerByEntityReference.get(bidirectionalEntityReference.getTargetEntityReference());
resolveEntityKey(resultSet, context, targetEntityReferenceInitializer);
targetEntityReferenceInitializer.hydrateEntityState(resultSet, context);
}
for (Fetch fetch : fetchSource.getFetches()) {
if (EntityFetch.class.isInstance(fetch)) {
final EntityFetch entityFetch = (EntityFetch) fetch;
final EntityReferenceInitializer entityReferenceInitializer = entityInitializerByEntityReference.get(entityFetch);
if (entityReferenceInitializer != null) {
resolveEntityKey(resultSet, context, entityReferenceInitializer);
entityReferenceInitializer.hydrateEntityState(resultSet, context);
}
} else if (CompositeFetch.class.isInstance(fetch)) {
resolveEntityKey(resultSet, context, (CompositeFetch) fetch);
}
}
}
Aggregations