CollectionEntry entry, SessionFactoryImplementor factory) { if ( entry.isProcessed() ) { throw new AssertionFailure( "collection was processed twice by flush()" ); entry.setProcessed( true ); final CollectionPersister loadedPersister = entry.getLoadedPersister(); final CollectionPersister currentPersister = entry.getCurrentPersister(); if ( loadedPersister != null || currentPersister != null ) { && !currentPersister.getKeyType().isEqual( entry.getLoadedKey(), entry.getCurrentKey(), factory ) && !( entry.getLoadedKey() instanceof DelayedPostInsertIdentifier ); entry.setDorecreate( true ); entry.setDoremove( true ); if ( entry.isDorecreate() ) { LOG.trace( "Forcing collection initialization" ); collection.forceInitialization(); entry.setDoupdate( true );
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() && ( getLoadedPersister()==null || getLoadedPersister().isMutable() ) && collection.isSnapshotEmpty( getSnapshot() ); }
/** * Add a collection to the cache, creating a new collection entry for it * * @param collection The collection for which we are adding an entry. * @param persister The collection persister */ private void addCollection(PersistentCollection collection, CollectionPersister persister) { final CollectionEntry ce = new CollectionEntry( persister, collection ); collectionEntries.put( collection, ce ); }
@Override public CollectionEntry addInitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id) throws HibernateException { final CollectionEntry ce = new CollectionEntry( collection, persister, id, flushing ); ce.postInitialize( collection ); addCollection( collection, ce, id ); return ce; }
/** * 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 Serializable getLoadedCollectionOwnerIdOrNull(CollectionEntry ce) { if ( ce == null || ce.getLoadedKey() == null || ce.getLoadedPersister() == null ) { return null; } // TODO: an alternative is to check if the owner has changed; if it hasn't then // get the ID from collection.getOwner() return ce.getLoadedPersister().getCollectionType().getIdOfOwnerOrNull( ce.getLoadedKey(), session ); }
/** * Called after execution of an action */ public void afterAction(PersistentCollection collection) { loadedKey = getCurrentKey(); setLoadedPersister( getCurrentPersister() ); boolean resnapshot = collection.wasInitialized() && ( isDoremove() || isDorecreate() || isDoupdate() ); if ( resnapshot ) { snapshot = loadedPersister==null || !loadedPersister.isMutable() ? null : collection.getSnapshot(loadedPersister); //re-snapshot } collection.postAction(); }
if ( !ce.isReached() && !ce.isIgnore() ) { Collections.processUnreachableCollection( me.getKey(), session ); if ( ce.isDorecreate() ) { session.getInterceptor().onCollectionRecreate( coll, ce.getCurrentKey() ); actionQueue.addAction( new CollectionRecreateAction( coll, ce.getCurrentPersister(), ce.getCurrentKey(), session if ( ce.isDoremove() ) { session.getInterceptor().onCollectionRemove( coll, ce.getLoadedKey() ); actionQueue.addAction( new CollectionRemoveAction( coll, ce.getLoadedPersister(), ce.getLoadedKey(), ce.isSnapshotEmpty(coll), session if ( ce.isDoupdate() ) { session.getInterceptor().onCollectionUpdate( coll, ce.getLoadedKey() ); actionQueue.addAction( new CollectionUpdateAction( coll, ce.getLoadedPersister(), ce.getLoadedKey(),
public void preFlush(PersistentCollection collection) throws HibernateException { if ( loadedKey == null && collection.getKey() != null ) { loadedKey = collection.getKey(); } boolean nonMutableChange = collection.isDirty() && getLoadedPersister() != null && !getLoadedPersister().isMutable(); if ( nonMutableChange ) { throw new HibernateException( "changed an immutable collection instance: " + MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() ) ); } dirty( collection ); if ( LOG.isDebugEnabled() && collection.isDirty() && getLoadedPersister() != null ) { LOG.debugf( "Collection dirty: %s", MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() ) ); } setReached( false ); setProcessed( false ); setDoupdate( false ); setDoremove( false ); setDorecreate( false ); }
ce.setCurrentPersister( persister ); ce.setCurrentKey( type.getKeyOfOwner( entity, session ) ); MessageHelper.collectionInfoString( persister, collection, ce.getCurrentKey(), session ) ); ce.setReached( true ); ce.setProcessed( true ); if ( ce.isReached() ) { ce.setReached( true ); persister, collection, ce.getCurrentKey(), session ), MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), session persister, collection, ce.getCurrentKey(), session ),
PersistentCollection collection, CollectionEntry entry) { if ( entry.isProcessed() ) { throw new AssertionFailure( "collection was processed twice by flush()" ); entry.setProcessed( true ); final PersistentCollectionDescriptor loadedDescriptor = entry.getLoadedCollectionDescriptor(); final PersistentCollectionDescriptor currentDescriptor = entry.getCurrentDescriptor(); if ( loadedDescriptor != null || currentDescriptor != null ) { && !currentDescriptor.getKeyJavaTypeDescriptor().areEqual( entry.getLoadedKey(), entry.getCurrentKey() ) && !( entry.getLoadedKey() instanceof DelayedPostInsertIdentifier ); entry.setDorecreate( true ); entry.setDoremove( true ); if ( entry.isDorecreate() ) { LOG.trace( "Forcing collection initialization" ); collection.forceInitialization(); entry.setDoupdate( true );
if ( !ce.isReached() && !ce.isIgnore() ) { Collections.processUnreachableCollection( me.getKey(), session ); if ( ce.isDorecreate() ) { session.getInterceptor().onCollectionRecreate( coll, ce.getCurrentKey() ); actionQueue.addAction( new CollectionRecreateAction( coll, ce.getCurrentDescriptor(), ce.getCurrentKey(), session if ( ce.isDoremove() ) { session.getInterceptor().onCollectionRemove( coll, ce.getLoadedKey() ); actionQueue.addAction( new CollectionRemoveAction( coll, ce.getLoadedCollectionDescriptor(), ce.getLoadedKey(), ce.isSnapshotEmpty(coll), session if ( ce.isDoupdate() ) { session.getInterceptor().onCollectionUpdate( coll, ce.getLoadedKey() ); actionQueue.addAction( new CollectionUpdateAction( coll, ce.getLoadedCollectionDescriptor(), ce.getLoadedKey(),
public void preFlush(PersistentCollection collection) throws HibernateException { if ( loadedKey == null && collection.getKey() != null ) { loadedKey = collection.getKey(); } boolean nonMutableChange = collection.isDirty() && getLoadedCollectionDescriptor() != null && !getLoadedCollectionDescriptor().getMutabilityPlan().isMutable(); if ( nonMutableChange ) { throw new HibernateException( "changed an immutable collection instance: " + MessageHelper.collectionInfoString( getLoadedCollectionDescriptor().getNavigableRole().getFullPath(), getLoadedKey() ) ); } dirty( collection ); if ( LOG.isDebugEnabled() && collection.isDirty() && getLoadedCollectionDescriptor() != null ) { LOG.debugf( "Collection dirty: %s", MessageHelper.collectionInfoString( getLoadedCollectionDescriptor().getNavigableRole().getFullPath(), getLoadedKey() ) ); } setReached( false ); setProcessed( false ); setDoupdate( false ); setDoremove( false ); setDorecreate( false ); }
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.getLoadedPersister(), coll, entry.getLoadedKey(), session ) ); } entry.setCurrentPersister( entry.getLoadedPersister() ); entry.setCurrentKey( entry.getLoadedKey() ); prepareCollectionForUpdate( coll, entry, session.getFactory() ); }
ce.setCurrentDescriptor( collectionAttribute.getCollectionDescriptor() ); ce.setCurrentKey( collectionAttribute.getCollectionDescriptor().getKeyOfOwner( entity, session ) ); MessageHelper.collectionInfoString( collectionAttribute.getCollectionDescriptor(), collection, ce.getCurrentKey(), session ) ); ce.setReached( true ); ce.setProcessed( true ); if ( ce.isReached() ) { ce.setReached( true ); collectionAttribute.getCollectionDescriptor(), collection, ce.getCurrentKey(), session ), MessageHelper.collectionInfoString( ce.getLoadedCollectionDescriptor(), collection, ce.getLoadedKey(), session collectionAttribute.getCollectionDescriptor(), collection, ce.getCurrentKey(), session ),
/** * 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.getLoadedPersister().getRole() ); if ( map != null ) { map.remove( ce ); } }
CollectionEntry collectionEntry = me.getValue(); PersistentCollection persistentCollection = me.getKey(); collectionEntry.postFlush(persistentCollection); if ( collectionEntry.getLoadedPersister() == null ) { collectionEntry.getLoadedPersister(), collectionEntry.getLoadedKey() ); persistenceContext.getCollectionsByKey().put(collectionKey, persistentCollection);
@Override public void execute() throws HibernateException { // this QueuedOperationCollectionAction has to be executed before any other // CollectionAction involving the same collection. getPersister().processQueuedOps( getCollection(), getKey(), getSession() ); // TODO: It would be nice if this could be done safely by CollectionPersister#processQueuedOps; // Can't change the SPI to do this though. ((AbstractPersistentCollection) getCollection() ).clearOperationQueue(); // The other CollectionAction types call CollectionEntry#afterAction, which // clears the dirty flag. We don't want to call CollectionEntry#afterAction unless // there is no other CollectionAction that will be executed on the same collection. final CollectionEntry ce = getSession().getPersistenceContext().getCollectionEntry( getCollection() ); if ( !ce.isDoremove() && !ce.isDoupdate() && !ce.isDorecreate() ) { ce.afterAction( getCollection() ); } } }
private void cascadeOrphans(JPABase base, PersistentCollection persistentCollection, boolean willBeSaved) { String dbName = JPA.getDBName(this.getClass()); SessionImpl session = ((SessionImpl) JPA.em(dbName).getDelegate()); PersistenceContext pc = session.getPersistenceContext(); CollectionEntry ce = pc.getCollectionEntry(persistentCollection); if (ce != null) { CollectionPersister cp = ce.getLoadedPersister(); if (cp != null) { Type ct = cp.getElementType(); if (ct instanceof EntityType) { EntityEntry entry = pc.getEntry(base); String entityName = entry.getEntityName(); entityName = ((EntityType) ct).getAssociatedEntityName(session.getFactory()); if (ce.getSnapshot() != null) { Collection orphans = ce.getOrphans(entityName, persistentCollection); for (Object o : orphans) { saveAndCascadeIfJPABase(o, willBeSaved); } } } } } }
String propertyName = collectionEntry.getRole().substring(collectionEntry.getLoadedPersister().getOwnerEntityPersister().getEntityName().length()+1); Object change = getChange(collectionEntry.getLoadedPersister().getOwnerEntityPersister(), event.getSession(), event.getAffectedOwnerEntityName(), event.getAffectedOwnerIdOrNull(), owner); if (change == null || !(change instanceof Change)) return; Serializable oldColl = collectionEntry.getSnapshot();
/** * Called after execution of an action */ public void afterAction(PersistentCollection collection) { loadedKey = getCurrentKey(); setLoadedDescriptor( getCurrentDescriptor() ); boolean resnapshot = collection.wasInitialized() && ( isDoremove() || isDorecreate() || isDoupdate() ); if ( resnapshot ) { snapshot = loadedCollectionDescriptor == null || !loadedCollectionDescriptor.getMutabilityPlan().isMutable() ? null //re-snapshot : collection.getSnapshot( loadedCollectionDescriptor ); } collection.postAction(); }