private boolean isInverse(CollectionEntry collectionEntry) { return collectionEntry.getLoadedCollectionDescriptor().isInverse(); }
/** * After a collection was initialized or evicted, we don't * need to batch fetch it anymore, remove it from the queue * if necessary */ public void removeBatchLoadableCollection(CollectionEntry ce) { LinkedHashMap<CollectionEntry, PersistentCollection> map = batchLoadableCollections.get( ce.getLoadedCollectionDescriptor().getNavigableRole().getFullPath() ); if ( map != null ) { map.remove( ce ); } }
/** * Is this the "inverse" end of a bidirectional one-to-many, or * of a collection with no orphan delete? */ @SuppressWarnings({"JavaDoc"}) protected boolean isInverseOneToManyOrNoOrphanDelete() { final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); return ce != null && ce.getLoadedCollectionDescriptor().isInverse() && ( ce.getLoadedCollectionDescriptor().isOneToMany() || !ce.getLoadedCollectionDescriptor().hasOrphanDelete() ); }
@Override public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection) { final CollectionEntry ce = getCollectionEntry( collection ); if ( ce.getLoadedCollectionDescriptor() == null ) { return null; } Object loadedOwner = null; // TODO: an alternative is to check if the owner has changed; if it hasn't then // return collection.getOwner() final Object entityId = getLoadedCollectionOwnerIdOrNull( ce ); if ( entityId != null ) { loadedOwner = getCollectionOwner( entityId, ce.getLoadedCollectionDescriptor() ); } return loadedOwner; }
/** * Is this the "inverse" end of a bidirectional association with * no orphan delete enabled? */ @SuppressWarnings({"JavaDoc"}) protected boolean isInverseCollectionNoOrphanDelete() { final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); return ce != null && ce.getLoadedCollectionDescriptor().isInverse() && !ce.getLoadedCollectionDescriptor().hasOrphanDelete(); }
/** * If a CollectionEntry represents a batch loadable collection, add * it to the queue. */ public void addBatchLoadableCollection(PersistentCollection collection, CollectionEntry ce) { final PersistentCollectionDescriptor collectionDescriptor = ce.getLoadedCollectionDescriptor(); LinkedHashMap<CollectionEntry, PersistentCollection> map = batchLoadableCollections.get( collectionDescriptor.getNavigableRole().getFullPath() ); if ( map == null ) { map = new LinkedHashMap<>( 16 ); batchLoadableCollections.put( collectionDescriptor.getNavigableRole().getFullPath(), map ); } map.put( ce, collection ); }
protected static PersistentCollectionDescriptor getLoadedCollectionDescriptor(PersistentCollection collection, EventSource source ) { CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection ); return ( ce == null ? null : ce.getLoadedCollectionDescriptor() ); }
/** * Get the ID for the entity that owned this persistent collection when it was loaded * * @param ce The collection entry * @return the owner ID if available from the collection's loaded key; otherwise, returns null */ private Object getLoadedCollectionOwnerIdOrNull(CollectionEntry ce) { if ( ce == null || ce.getLoadedKey() == null || ce.getLoadedCollectionDescriptor() == null ) { return null; } final Object loadedKey = ce.getLoadedKey(); // todo (6.0) : need to account for non-PK Fks (aka, "property-ref") return loadedKey; }
private String resolveReferencingPropertyName(CollectionEntry collectionEntry) { final String ownerEntityName = collectionEntry.getLoadedCollectionDescriptor() .getContainer() .getNavigableName(); return collectionEntry.getNavigableRole().getFullPath().substring( ownerEntityName.length() + 1 ); }
public boolean isSnapshotEmpty(PersistentCollection collection) { //TODO: does this really need to be here? // does the collection already have // it's own up-to-date snapshot? return collection.wasInitialized() && ( getLoadedCollectionDescriptor() == null || getLoadedCollectionDescriptor().getMutabilityPlan().isMutable() ) && collection.isSnapshotEmpty( getSnapshot() ); }
/** * Is this the "inverse" end of a bidirectional association? */ @SuppressWarnings({"JavaDoc"}) protected boolean isInverseCollection() { final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); return ce != null && ce.getLoadedCollectionDescriptor().isInverse(); }
public void postInitialize(PersistentCollection collection) throws HibernateException { snapshot = getLoadedCollectionDescriptor().getMutabilityPlan().isMutable() ? collection.getSnapshot( getLoadedCollectionDescriptor() ) : null; collection.setSnapshot(loadedKey, role, snapshot); if ( getLoadedCollectionDescriptor().getBatchSize() > 1 ) { ( (AbstractPersistentCollection) collection ).getSession() .getPersistenceContext() .getBatchFetchQueue() .removeBatchLoadableCollection( this ); } }
private boolean isOneToMany(CollectionEntry collectionEntry) { return collectionEntry.getLoadedCollectionDescriptor() .getElementDescriptor() .getClassification() .equals( CollectionElement.ElementClassification.ONE_TO_MANY ); }
private void evictCollection(PersistentCollection collection) { CollectionEntry ce = (CollectionEntry) getSession().getPersistenceContext().getCollectionEntries().remove(collection); if ( LOG.isDebugEnabled() ) { LOG.debugf( "Evicting collection: %s", MessageHelper.collectionInfoString( ce.getLoadedCollectionDescriptor(), collection, ce.getLoadedKey(), getSession() ) ); } if (ce.getLoadedCollectionDescriptor() != null && ce.getLoadedCollectionDescriptor().getBatchSize() > 1) { getSession().getPersistenceContext().getBatchFetchQueue().removeBatchLoadableCollection(ce); } if ( ce.getLoadedCollectionDescriptor() != null && ce.getLoadedKey() != null ) { //TODO: is this 100% correct? getSession().getPersistenceContext().getCollectionsByKey().remove( new CollectionKey( ce.getLoadedCollectionDescriptor(), ce.getLoadedKey() ) ); } }
@Override public void onPostRecreateCollection(PostCollectionRecreateEvent event) { final CollectionEntry collectionEntry = getCollectionEntry( event ); if ( !collectionEntry.getLoadedCollectionDescriptor().isInverse() ) { onCollectionAction( event, event.getCollection(), null, collectionEntry ); } else { onCollectionActionInversed( event, event.getCollection(), null, collectionEntry ); } } }
private static void processNeverReferencedCollection(PersistentCollection coll, SessionImplementor session) throws HibernateException { final PersistenceContext persistenceContext = session.getPersistenceContext(); final CollectionEntry entry = persistenceContext.getCollectionEntry( coll ); if ( LOG.isDebugEnabled() ) { LOG.debugf( "Found collection with unloaded owner: %s", MessageHelper.collectionInfoString( entry.getLoadedCollectionDescriptor(), coll, entry.getLoadedKey(), session ) ); } entry.setCurrentDescriptor( entry.getLoadedCollectionDescriptor() ); entry.setCurrentKey( entry.getLoadedKey() ); prepareCollectionForUpdate( coll, entry); }
@Override public void onPreUpdateCollection(PreCollectionUpdateEvent event) { final CollectionEntry collectionEntry = getCollectionEntry( event ); if ( !collectionEntry.getLoadedCollectionDescriptor().isInverse() ) { onCollectionAction( event, event.getCollection(), collectionEntry.getSnapshot(), collectionEntry ); } else { onCollectionActionInversed( event, event.getCollection(), collectionEntry.getSnapshot(), collectionEntry ); } } }
@Override public Boolean doWork() { final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); final PersistentCollectionDescriptor collectionDescriptor = entry.getLoadedCollectionDescriptor(); if ( collectionDescriptor.isExtraLazy() ) { if ( hasQueuedOperations() ) { session.flush(); } return collectionDescriptor.indexExists( entry.getLoadedKey(), index, session ); } else { read(); } return null; } }
@Override public Boolean doWork() { final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); final PersistentCollectionDescriptor collectionDescriptor = entry.getLoadedCollectionDescriptor(); if ( collectionDescriptor.isExtraLazy() ) { if ( hasQueuedOperations() ) { session.flush(); } return collectionDescriptor.elementExists( entry.getLoadedKey(), element, session ); } else { read(); } return null; } }
@Override public void onPreRemoveCollection(PreCollectionRemoveEvent event) { final CollectionEntry collectionEntry = getCollectionEntry( event ); if ( collectionEntry != null ) { if ( !collectionEntry.getLoadedCollectionDescriptor().isInverse() ) { Serializable oldColl = collectionEntry.getSnapshot(); if ( !event.getCollection().wasInitialized() && shouldGenerateRevision( event ) ) { // In case of uninitialized collection we need a fresh snapshot to properly calculate audit data. oldColl = initializeCollection( event ); } onCollectionAction( event, null, oldColl, collectionEntry ); } else { // HHH-7510 - Avoid LazyInitializationException when global_with_modified_flag = true if ( getAuditService().getOptions().isGlobalWithModifiedFlagEnabled() ) { initializeCollection( event ); } } } } }