Search in sources :

Example 1 with EntityReferenceInitializer

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;
}
Also used : CollectionReferenceInitializer(org.hibernate.loader.plan.exec.process.spi.CollectionReferenceInitializer) EntityReferenceInitializer(org.hibernate.loader.plan.exec.process.spi.EntityReferenceInitializer)

Example 2 with EntityReferenceInitializer

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);
        }
    }
}
Also used : CompositeFetch(org.hibernate.loader.plan.spi.CompositeFetch) Fetch(org.hibernate.loader.plan.spi.Fetch) EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) CompositeFetch(org.hibernate.loader.plan.spi.CompositeFetch) BidirectionalEntityReference(org.hibernate.loader.plan.spi.BidirectionalEntityReference) EntityReferenceInitializer(org.hibernate.loader.plan.exec.process.spi.EntityReferenceInitializer)

Aggregations

EntityReferenceInitializer (org.hibernate.loader.plan.exec.process.spi.EntityReferenceInitializer)2 CollectionReferenceInitializer (org.hibernate.loader.plan.exec.process.spi.CollectionReferenceInitializer)1 BidirectionalEntityReference (org.hibernate.loader.plan.spi.BidirectionalEntityReference)1 CompositeFetch (org.hibernate.loader.plan.spi.CompositeFetch)1 EntityFetch (org.hibernate.loader.plan.spi.EntityFetch)1 Fetch (org.hibernate.loader.plan.spi.Fetch)1