Java Code Examples for org.hibernate.collection.PersistentCollection#isDirty()
The following examples show how to use
org.hibernate.collection.PersistentCollection#isDirty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectionEntry.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Determine if the collection is "really" dirty, by checking dirtiness * of the collection elements, if necessary */ private void dirty(PersistentCollection collection) throws HibernateException { boolean forceDirty = collection.wasInitialized() && !collection.isDirty() && //optimization getLoadedPersister() != null && getLoadedPersister().isMutable() && //optimization ( collection.isDirectlyAccessible() || getLoadedPersister().getElementType().isMutable() ) && //optimization !collection.equalsSnapshot( getLoadedPersister() ); if ( forceDirty ) { collection.dirty(); } }
Example 2
Source File: CollectionEntry.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void preFlush(PersistentCollection collection) throws HibernateException { 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.debug( "Collection dirty: " + MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() ) ); } setDoupdate(false); setDoremove(false); setDorecreate(false); setReached(false); setProcessed(false); }
Example 3
Source File: OnLockVisitor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
Object processCollection(Object collection, CollectionType type) throws HibernateException { SessionImplementor session = getSession(); CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() ); if ( collection == null ) { //do nothing } else if ( collection instanceof PersistentCollection ) { PersistentCollection persistentCollection = ( PersistentCollection ) collection; if ( persistentCollection.setCurrentSession( session ) ) { if ( isOwnerUnchanged( persistentCollection, persister, extractCollectionKeyFromOwner( persister ) ) ) { // a "detached" collection that originally belonged to the same entity if ( persistentCollection.isDirty() ) { throw new HibernateException( "reassociated object has dirty collection" ); } reattachCollection( persistentCollection, type ); } else { // a "detached" collection that belonged to a different entity throw new HibernateException( "reassociated object has dirty collection reference" ); } } else { // a collection loaded in the current session // can not possibly be the collection belonging // to the entity passed to update() throw new HibernateException( "reassociated object has dirty collection reference" ); } } else { // brand new collection //TODO: or an array!! we can't lock objects with arrays now?? throw new HibernateException( "reassociated object has dirty collection reference (or an array)" ); } return null; }
Example 4
Source File: Collections.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * 1. record the collection role that this collection is referenced by * 2. decide if the collection needs deleting/creating/updating (but * don't actually schedule the action yet) */ private static void prepareCollectionForUpdate( PersistentCollection collection, CollectionEntry entry, EntityMode entityMode, SessionFactoryImplementor factory) throws HibernateException { 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 ) { // it is or was referenced _somewhere_ boolean ownerChanged = loadedPersister != currentPersister || // if either its role changed, !currentPersister .getKeyType().isEqual( // or its key changed entry.getLoadedKey(), entry.getCurrentKey(), entityMode, factory ); if (ownerChanged) { // do a check final boolean orphanDeleteAndRoleChanged = loadedPersister != null && currentPersister != null && loadedPersister.hasOrphanDelete(); if (orphanDeleteAndRoleChanged) { throw new HibernateException( "Don't change the reference to a collection with cascade=\"all-delete-orphan\": " + loadedPersister.getRole() ); } // do the work if ( currentPersister != null ) { entry.setDorecreate(true); // we will need to create new entries } if ( loadedPersister != null ) { entry.setDoremove(true); // we will need to remove ye olde entries if ( entry.isDorecreate() ) { log.trace( "Forcing collection initialization" ); collection.forceInitialization(); // force initialize! } } } else if ( collection.isDirty() ) { // else if it's elements changed entry.setDoupdate(true); } } }