/** * @deprecated (since 5.2) Use * {@link #getMetamodel()}} -> {@link Metamodel#findCollectionDescriptor(String)} instead */ @Deprecated default PersistentCollectionDescriptor getCollectionPersister(String role) throws MappingException { final PersistentCollectionDescriptor<?,?,?> collectionDescriptor = getMetamodel().findCollectionDescriptor( role ); if ( collectionDescriptor == null ) { throw new MappingException( "Could not locate CollectionPersister for given role [" + role + "]" ); } return collectionDescriptor; }
@Override public CollectionStatisticsImpl getCollectionStatistics(String role) { if ( sessionFactory == null ) { return null; } return collectionStatsMap.computeIfAbsent( role, s -> new CollectionStatisticsImpl( sessionFactory.getMetamodel().findCollectionDescriptor( role ) ) ); }
@Override public CollectionDataAccess getCollectionDataAccess(NavigableRole collectionRole) { final PersistentCollectionDescriptor collectionDescriptor = sessionFactory.getMetamodel() .findCollectionDescriptor( collectionRole.getFullPath() ); final CollectionDataAccess access = collectionDataAccessMap.get( collectionDescriptor ); if ( access == null ) { // todo (6.0) : is it an error here if the entity is not configured for caching (no map hit)? } return access; }
@Override public void evictCollectionData(String role) { final PersistentCollectionDescriptor collectionDescriptor = sessionFactory.getMetamodel().findCollectionDescriptor( role ); evictCollectionData( collectionDescriptor ); }
void afterDeserialize(SessionFactoryImplementor factory) { loadedCollectionDescriptor = ( factory == null ? null : factory.getMetamodel().findCollectionDescriptor( role.getFullPath() ) ); }
/** * Reconnect to session after deserialization... * * @param session The session being deserialized */ public void afterDeserialize(SharedSessionContractImplementor session) { if ( this.session != null || this.collectionDescriptor != null ) { throw new IllegalStateException( "already attached to a session." ); } // IMPL NOTE: non-flushed changes code calls this method with session == null... // guard against NullPointerException if ( session != null ) { this.session = session; this.collectionDescriptor = session.getFactory().getMetamodel().findCollectionDescriptor( collectionRole ); } }
@Override public boolean containsCollection(String role, Serializable ownerIdentifier) { final PersistentCollectionDescriptor collectionDescriptor = sessionFactory.getMetamodel().findCollectionDescriptor( role ); final CollectionDataAccess cacheAccess = collectionDescriptor.getCacheAccess(); if ( cacheAccess == null ) { return false; } final Object key = cacheAccess.generateCacheKey( ownerIdentifier, collectionDescriptor, sessionFactory, null ); return cacheAccess.contains( key ); }
/** * For initialized detached collections */ public CollectionEntry(PersistentCollection collection, SessionFactoryImplementor factory) throws MappingException { // detached collections that get found + reattached // during flush shouldn't be ignored ignore = false; loadedKey = collection.getKey(); setLoadedDescriptor( factory.getMetamodel().findCollectionDescriptor( collection.getRole() ) ); snapshot = collection.getStoredSnapshot(); }
@Override public Object getIndexInOwner(String entity, String property, Object childEntity, Map mergeMap) { final EntityTypeDescriptor entityDescriptor = session.getFactory().getMetamodel().findEntityDescriptor( entity ); final PersistentCollectionDescriptor collectionDescriptor = session.getFactory().getMetamodel().findCollectionDescriptor( entity + '.' + property );
@Override public void evictCollectionData(String role, Serializable ownerIdentifier) { final PersistentCollectionDescriptor collectionDescriptor = sessionFactory.getMetamodel().findCollectionDescriptor( role ); final CollectionDataAccess cacheAccess = collectionDescriptor.getCacheAccess(); if ( cacheAccess == null ) { return; } if ( LOG.isDebugEnabled() ) { LOG.debugf( "Evicting second-level cache: %s", MessageHelper.collectionInfoString( collectionDescriptor, ownerIdentifier, sessionFactory ) ); } final Object key = cacheAccess.generateCacheKey( ownerIdentifier, collectionDescriptor, sessionFactory, null ); cacheAccess.evict( key ); }
final String collectionRole = entityName + '.' + propertyName; final EntityTypeDescriptor entityDescriptor = session.getFactory().getMetamodel().findEntityDescriptor( entityName ); final PersistentCollectionDescriptor collectionDescriptor = session.getFactory().getMetamodel().findCollectionDescriptor( collectionRole );
final PersistentCollectionDescriptor descriptor = eventSource.getFactory() .getMetamodel() .findCollectionDescriptor( attribute.getNavigableName() );
/** * Reattach a detached (disassociated) initialized or uninitialized * collection wrapper, using a snapshot carried with the collection * wrapper */ protected void reattachCollection(PersistentCollection collection, NavigableRole role) throws HibernateException { if ( collection.wasInitialized() ) { PersistentCollectionDescriptor collectionDescriptor = getSession().getFactory().getMetamodel() .findCollectionDescriptor( role.getFullPath() ); getSession().getPersistenceContext() .addInitializedDetachedCollection( collectionDescriptor, collection ); } else { if ( !isCollectionSnapshotValid(collection) ) { throw new HibernateException( "could not reassociate uninitialized transient collection" ); } PersistentCollectionDescriptor collectionDescriptor = getSession().getFactory().getMetamodel() .findCollectionDescriptor( collection.getRole() ); getSession().getPersistenceContext() .addUninitializedDetachedCollection( collectionDescriptor, collection ); } }
session.getFactory().getMetamodel().findCollectionDescriptor( getRole() ), this );
@Override public final boolean setCurrentSession(SharedSessionContractImplementor session) throws HibernateException { if ( session == this.session ) { assert collectionDescriptor != null; return false; } else if ( this.session != null ) { assert collectionDescriptor != null; final String msg = generateUnexpectedSessionStateMessage( session ); if ( isConnectedToSession() ) { throw new HibernateException( "Illegal attempt to associate a collection with two open sessions. " + msg ); } else { LOG.logUnexpectedSessionInCollectionNotConnected( msg ); this.collectionDescriptor = session.getFactory().getMetamodel().findCollectionDescriptor( getRole() ); } } if ( hasQueuedOperations() ) { LOG.queuedOperationWhenAttachToSession( MessageHelper.collectionInfoString( getRole(), getKey() ) ); } this.session = session; return true; }
@Override public Object processCollection(Object collection, PluralPersistentAttribute collectionAttribute) throws HibernateException { if ( collection == PersistentCollectionDescriptor.UNFETCHED_COLLECTION ) { return null; } final EventSource session = getSession(); final PersistentCollectionDescriptor descriptor = session.getFactory() .getMetamodel() .findCollectionDescriptor( collectionAttribute.getNavigableName() ); if ( isUpdate ) { removeCollection( descriptor, extractCollectionKeyFromOwner( descriptor ), session ); } if ( collection != null && collection instanceof PersistentCollection ) { final PersistentCollection wrapper = (PersistentCollection) collection; wrapper.setCurrentSession( session ); if ( wrapper.wasInitialized() ) { session.getPersistenceContext().addNewCollection( descriptor, wrapper ); } else { reattachCollection( wrapper, descriptor.getNavigableRole() ); } } else { // otherwise a null or brand new collection // this will also (inefficiently) handle arrays, which // have no snapshot, so we can't do any better //processArrayOrNewCollection(collection, type); } return null; }
final PersistentCollectionDescriptor descriptor = session.getFactory() .getMetamodel() .findCollectionDescriptor( collectionAttribute.getNavigableName() );
final PersistentCollectionDescriptor descriptor = session.getFactory() .getMetamodel() .findCollectionDescriptor( collectionAttribute.getNavigableName() ); if ( isOwnerUnchanged( persistentCollection, descriptor, extractCollectionKeyFromOwner( descriptor ) ) ) {