From: <one...@us...> - 2003-04-16 04:54:37
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl In directory sc8-pr-cvs1:/tmp/cvs-serv19760/hibernate/impl Modified Files: ScheduledCollectionRemove.java SessionImpl.java Log Message: removed unnecessary collection delete when collection snapshot is empty Index: ScheduledCollectionRemove.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/ScheduledCollectionRemove.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ScheduledCollectionRemove.java 2 Feb 2003 04:19:51 -0000 1.5 --- ScheduledCollectionRemove.java 16 Apr 2003 04:54:32 -0000 1.6 *************** *** 9,21 **** import net.sf.hibernate.engine.SessionImplementor; ! final class ScheduledCollectionRemove extends ScheduledCollectionAction implements SessionImpl.Executable { ! public ScheduledCollectionRemove(CollectionPersister persister, Serializable id, SessionImplementor session) { super(persister, id, session); } public void execute() throws SQLException, HibernateException { persister.softlock(id); ! persister.remove(id, session); } --- 9,24 ---- import net.sf.hibernate.engine.SessionImplementor; ! final class ScheduledCollectionRemove extends ScheduledCollectionAction implements SessionImpl.Executable { ! private boolean emptySnapshot; ! ! public ScheduledCollectionRemove(CollectionPersister persister, Serializable id, boolean emptySnapshot, SessionImplementor session) { super(persister, id, session); + this.emptySnapshot = emptySnapshot; } public void execute() throws SQLException, HibernateException { persister.softlock(id); ! if (!emptySnapshot) persister.remove(id, session); } Index: SessionImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/SessionImpl.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** SessionImpl.java 16 Apr 2003 01:13:27 -0000 1.34 --- SessionImpl.java 16 Apr 2003 04:54:32 -0000 1.35 *************** *** 11,14 **** --- 11,15 ---- import java.io.ObjectStreamException; import java.io.Serializable; + import java.lang.reflect.Array; import java.sql.SQLException; import java.sql.Connection; *************** *** 311,314 **** --- 312,324 ---- return snapshot; } + public boolean snapshotIsEmpty() { + //TODO: implementation here is non-extensible ... + //should use polymorphism + return initialized && snapshot!=null && ( + ( snapshot instanceof Collection && ( (Collection) snapshot ).size()==0 ) || // if snapshot is a collection + ( snapshot instanceof Map && ( (Map) snapshot ).size()==0 ) || // if snapshot is a map + ( snapshot.getClass().isArray() && Array.getLength(snapshot)==0 )// if snapshot is an array + ); + } public void setDirty() { dirty = true; *************** *** 1025,1029 **** private void removeCollection(CollectionPersister role, Serializable id) { ! collectionRemovals.add( new ScheduledCollectionRemove(role, id, this) ); } --- 1035,1039 ---- private void removeCollection(CollectionPersister role, Serializable id) { ! collectionRemovals.add( new ScheduledCollectionRemove(role, id, false, this) ); } *************** *** 2262,2266 **** if ( ce.dorecreate ) collectionCreations.add( new ScheduledCollectionRecreate(coll, ce.currentPersister, ce.currentKey, this) ); ! if ( ce.doremove ) collectionRemovals.add( new ScheduledCollectionRemove(ce.loadedPersister, ce.loadedKey, this) ); if ( ce.doupdate ) collectionUpdates.add( new ScheduledCollectionUpdate(coll, ce.loadedPersister, ce.loadedKey, this) ); --- 2272,2276 ---- if ( ce.dorecreate ) collectionCreations.add( new ScheduledCollectionRecreate(coll, ce.currentPersister, ce.currentKey, this) ); ! if ( ce.doremove ) collectionRemovals.add( new ScheduledCollectionRemove(ce.loadedPersister, ce.loadedKey, ce.snapshotIsEmpty(), this) ); if ( ce.doupdate ) collectionUpdates.add( new ScheduledCollectionUpdate(coll, ce.loadedPersister, ce.loadedKey, this) ); *************** *** 2460,2464 **** if (entry.currentPersister!=null) entry.dorecreate = true; // we will need to create new entries ! if (entry.loadedPersister!=null) { entry.doremove = true; // we will need to remove ye olde entries if (entry.dorecreate) { --- 2470,2474 ---- if (entry.currentPersister!=null) entry.dorecreate = true; // we will need to create new entries ! if ( entry.loadedPersister!=null ) { entry.doremove = true; // we will need to remove ye olde entries if (entry.dorecreate) { |