@Override public EntityPersister getEntityPersister() { return targetEntityReference.getEntityPersister(); }
private String extractDetails(EntityReference entityReference) { return String.format( "%s(entity=%s, querySpaceUid=%s, path=%s)", entityReference.getClass().getSimpleName(), entityReference.getEntityPersister().getEntityName(), entityReference.getQuerySpaceUid(), entityReference.getPropertyPath().getFullPath() ); }
private void checkPoppedEntity(ExpandingFetchSource fetchSource, EntityDefinition entityDefinition) { // make sure what we just fetchSource represents entityDefinition if ( ! EntityReference.class.isInstance( fetchSource ) ) { throw new WalkingException( String.format( "Mismatched FetchSource from stack on pop. Expecting EntityReference(%s), but found %s", entityDefinition.getEntityPersister().getEntityName(), fetchSource ) ); } final EntityReference entityReference = (EntityReference) fetchSource; // NOTE : this is not the most exhaustive of checks because of hierarchical associations (employee/manager) if ( ! entityReference.getEntityPersister().equals( entityDefinition.getEntityPersister() ) ) { throw new WalkingException( "Mismatched FetchSource from stack on pop" ); } }
private void createSubselects() { if ( subselectLoadableEntityKeyMap == null || nRowsRead <= 1 ) { LOG.tracef( "Skipping create subselects because there are fewer than 2 results, so query by key is more efficient.", getClass().getName() ); return; // early return } final Map<String, int[]> namedParameterLocMap = ResultSetProcessorHelper.buildNamedParameterLocMap( queryParameters, namedParameterContext ); final String subselectQueryString = SubselectFetch.createSubselectFetchQueryFragment( queryParameters ); for ( Map.Entry<EntityReference, Set<EntityKey>> entry : subselectLoadableEntityKeyMap.entrySet() ) { if ( ! entry.getKey().getEntityPersister().hasSubselectLoadableCollections() ) { continue; } SubselectFetch subselectFetch = new SubselectFetch( subselectQueryString, aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid( entry.getKey().getQuerySpaceUid() ), (Loadable) entry.getKey().getEntityPersister(), queryParameters, entry.getValue(), namedParameterLocMap ); for ( EntityKey key : entry.getValue() ) { session.getPersistenceContext().getBatchFetchQueue().addSubselect( key, subselectFetch ); } } }
/** * Read the identifier state for the entity reference for the currently processing row in the ResultSet * * @param resultSet The ResultSet being processed * @param context The processing context * * @return The hydrated state * * @throws java.sql.SQLException Indicates a problem accessing the ResultSet */ private Object readIdentifierHydratedState(ResultSet resultSet, ResultSetProcessingContext context) throws SQLException { try { return entityReference.getEntityPersister().getIdentifierType().hydrate( resultSet, entityReferenceAliases.getColumnAliases().getSuffixedKeyAliases(), context.getSession(), null ); } catch (Exception e) { throw new HibernateException( "Encountered problem trying to hydrate identifier for entity [" + entityReference.getEntityPersister() + "]", e ); } }
@Override protected void applyRootReturnTableFragments(SelectStatementBuilder selectStatementBuilder) { final OuterJoinLoadable elementOuterJoinLoadable = (OuterJoinLoadable) getElementEntityReference().getEntityPersister(); //final String tableAlias = getCollectionReferenceAliases().getCollectionTableAlias(); final String tableAlias = getElementEntityReferenceAliases().getTableAlias(); final String fragment = elementOuterJoinLoadable.fromTableFragment( tableAlias ) + elementOuterJoinLoadable.fromJoinFragment( tableAlias, true, true); selectStatementBuilder.appendFromClauseFragment( fragment ); }
@Override public void startingEntityIdentifier(EntityIdentifierDefinition entityIdentifierDefinition) { log.tracef( "%s Starting entity identifier : %s", StringHelper.repeat( ">>", fetchSourceStack.size() ), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName() ); final EntityReference entityReference = (EntityReference) currentSource(); // perform some stack validation if ( ! entityReference.getEntityPersister().equals( entityIdentifierDefinition.getEntityDefinition().getEntityPersister() ) ) { throw new WalkingException( String.format( "Encountered unexpected fetch owner [%s] in stack while processing entity identifier for [%s]", entityReference.getEntityPersister().getEntityName(), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName() ) ); } if ( ExpandingEntityIdentifierDescription.class.isInstance( entityReference.getIdentifierDescription() ) ) { pushToStack( (ExpandingEntityIdentifierDescription) entityReference.getIdentifierDescription() ); } }
if ( entityReference.getEntityPersister().getEntityKeyDefinition() != entityIdentifierDefinition ) { throw new WalkingException( String.format( "Encountered unexpected fetch owner [%s] in stack while processing entity identifier for [%s]", entityReference.getEntityPersister().getEntityName(), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName() String.format( "Encountered unexpected fetch owner [%s] in stack while processing entity identifier for [%s]", entityReference.getEntityPersister().getEntityName(), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName()
final Type identifierType = entityReference.getEntityPersister().getIdentifierType(); final Serializable resolvedId = (Serializable) identifierType.resolve( identifierHydratedForm, if ( resolvedId != null ) { processingState.registerEntityKey( context.getSession().generateEntityKey( resolvedId, entityReference.getEntityPersister() ) );
ResultSetProcessingContext context, EntityKey entityKey) { final Loadable loadable = (Loadable) entityReference.getEntityPersister(); if ( ! loadable.hasSubclasses() ) { return entityReference.getEntityPersister().getEntityName(); "Discriminator: " + discriminatorValue, entityKey.getIdentifier(), entityReference.getEntityPersister().getEntityName() );
private void postLoad( PostLoadEvent postLoadEvent, ResultSetProcessingContextImpl context, List<HydratedEntityRegistration> hydratedEntityRegistrations, List<AfterLoadAction> afterLoadActionList) { // Until this entire method is refactored w/ polymorphism, postLoad was // split off from initializeEntity. It *must* occur after // endCollectionLoad to ensure the collection is in the // persistence context. if ( hydratedEntityRegistrations == null ) { return; } for ( HydratedEntityRegistration registration : hydratedEntityRegistrations ) { TwoPhaseLoad.postLoad( registration.getInstance(), context.getSession(), postLoadEvent ); if ( afterLoadActionList != null ) { for ( AfterLoadAction afterLoadAction : afterLoadActionList ) { afterLoadAction.afterLoad( context.getSession(), registration.getInstance(), (Loadable) registration.getEntityReference().getEntityPersister() ); } } } }
private void checkVersion( ResultSet resultSet, ResultSetProcessingContext context, EntityKey entityKey, Object existing) { final LockMode requestedLockMode = context.resolveLockMode( entityReference ); if ( requestedLockMode != LockMode.NONE ) { final LockMode currentLockMode = context.getSession().getPersistenceContext().getEntry( existing ).getLockMode(); final boolean isVersionCheckNeeded = entityReference.getEntityPersister().isVersioned() && currentLockMode.lessThan( requestedLockMode ); // we don't need to worry about existing version being uninitialized because this block isn't called // by a re-entrant load (re-entrant loads *always* have lock mode NONE) if ( isVersionCheckNeeded ) { //we only check the version when *upgrading* lock modes checkVersion( context.getSession(), resultSet, entityReference.getEntityPersister(), entityReferenceAliases.getColumnAliases(), entityKey, existing ); //we need to upgrade the lock mode to the mode requested context.getSession().getPersistenceContext().getEntry( existing ).setLockMode( requestedLockMode ); } } }
@Override public Object readRow(ResultSet resultSet, ResultSetProcessingContextImpl context) throws SQLException { final ResultSetProcessingContext.EntityReferenceProcessingState processingState = rootReturnReader.getIdentifierResolutionContext( context ); // if the entity reference we are hydrating is a Return, it is possible that its EntityKey is // supplied by the QueryParameter optional entity information if ( context.shouldUseOptionalEntityInformation() && context.getQueryParameters().getOptionalId() != null ) { final EntityKey entityKey = context.getSession().generateEntityKey( context.getQueryParameters().getOptionalId(), processingState.getEntityReference().getEntityPersister() ); processingState.registerIdentifierHydratedForm( entityKey.getIdentifier() ); processingState.registerEntityKey( entityKey ); } return super.readRow( resultSet, context ); }
@Override protected void applyRootReturnSelectFragments(SelectStatementBuilder selectStatementBuilder) { if ( getRootCollectionReturn().allowIndexJoin() && getQueryableCollection().getIndexType().isEntityType() ) { final EntityReference indexEntityReference = getRootCollectionReturn().getIndexGraph().resolveEntityReference(); final EntityReferenceAliases indexEntityReferenceAliases = getAliasResolutionContext().resolveEntityReferenceAliases( indexEntityReference.getQuerySpaceUid() ); selectStatementBuilder.appendSelectClauseFragment( ( (OuterJoinLoadable) indexEntityReference.getEntityPersister() ).selectFragment( indexEntityReferenceAliases.getTableAlias(), indexEntityReferenceAliases.getColumnAliases().getSuffix() ) ); } }
if ( existing != null ) { if ( ! entityReference.getEntityPersister().isInstance( existing ) ) { throw new WrongClassException( "loaded object was of wrong class " + existing.getClass(), entityKey.getIdentifier(), entityReference.getEntityPersister().getEntityName() );
@Override public void foundCircularAssociation(AssociationAttributeDefinition attributeDefinition) { final FetchStrategy fetchStrategy = determineFetchStrategy( attributeDefinition ); final AssociationKey associationKey = attributeDefinition.getAssociationKey(); // go ahead and build the bidirectional fetch if ( attributeDefinition.getAssociationNature() == AssociationAttributeDefinition.AssociationNature.ENTITY ) { final Joinable currentEntityPersister = (Joinable) currentSource().resolveEntityReference().getEntityPersister(); final AssociationKey currentEntityReferenceAssociationKey = new AssociationKey( currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames() ); // if associationKey is equal to currentEntityReferenceAssociationKey // that means that the current EntityPersister has a single primary key attribute // (i.e., derived attribute) which is mapped by attributeDefinition. // This is not a bidirectional association. // TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or // it must be loaded when the ID for the dependent entity is resolved. Is there some other way to // deal with this??? final FetchSource registeredFetchSource = registeredFetchSource( associationKey ); if ( registeredFetchSource != null && ! associationKey.equals( currentEntityReferenceAssociationKey ) ) { currentSource().buildBidirectionalEntityReference( attributeDefinition, fetchStrategy, registeredFetchSource( associationKey ).resolveEntityReference() ); } } else { // Do nothing for collection } }
id, entityInstance, (Loadable) entityReference.getEntityPersister(), concreteEntityPersister == rootEntityPersister ? entityReferenceAliases.getColumnAliases().getSuffixedPropertyAliases() : entityReference.getEntityPersister().getEntityMetamodel().getEntityType(); entityReference.getEntityPersister().getEntityName(), ukName, type.semiResolve( values[index], context.getSession(), entityInstance ),
final EntityReferenceAliases indexEntityReferenceAliases = aliasResolutionContext.generateEntityReferenceAliases( indexEntityReference.getQuerySpaceUid(), indexEntityReference.getEntityPersister() ); readerCollector.add(