Index: org/castor/persist/TransactionContext.java =================================================================== RCS file: /scm/castor/castor/src/main/org/castor/persist/TransactionContext.java,v retrieving revision 1.6 diff -u -r1.6 TransactionContext.java --- org/castor/persist/TransactionContext.java 5 Sep 2005 20:38:30 -0000 1.6 +++ org/castor/persist/TransactionContext.java 19 Sep 2005 21:07:39 -0000 @@ -506,56 +506,6 @@ * same object within the transaction will return the same object instance * (except for read-only access). *
- * This method is similar to {@link #fetch}except that it will load the - * object only once within a transaction and always return the same - * instance. - *
- * If the object is loaded for read-only then no lock is acquired and - * updates to the object are not reflected at commit time. If the object is - * loaded for read-write then a read lock is acquired (unless timeout or - * deadlock detected) and the object is stored at commit time. The object is - * then considered persistent and may be deleted or upgraded to write lock. - * If the object is loaded for exclusive access then a write lock is - * acquired and the object is synchronized with the persistent copy. - *
- * Attempting to load the object twice in the same transaction, once with - * exclusive lock and once with read-write lock will result in an exception. - * - * @param engine - * The persistence engine - * @param molder - * The class persistence molder - * @param identity - * The object's identity - * @param objectToBeLoaded - * The object to fetch (single instance per transaction) - * @param suggestedAccessMode - * The access mode (see {@link AccessMode}) the values in - * persistent storage - * @throws LockNotGrantedException - * Timeout or deadlock occured attempting to acquire lock on - * object - * @throws ObjectNotFoundException - * The object was not found in persistent storage - * @throws PersistenceException - * An error reported by the persistence engine - * @return object being loaded - */ - public synchronized Object load(final LockEngine engine, - final ClassMolder molder, - final Object identity, - ProposedObject proposedObject, - final AccessMode suggestedAccessMode) - throws ObjectNotFoundException, LockNotGrantedException, PersistenceException { - return load(engine, molder, identity, proposedObject, - suggestedAccessMode, null); - } - - /** - * Load an object for use within the transaction. Multiple access to the - * same object within the transaction will return the same object instance - * (except for read-only access). - *
* This method work the same as * {@link #load(LockEngine,ClassMolder,Object,Object,AccessMode)}, except a * QueryResults can be specified. @@ -754,8 +704,15 @@ objectInTransaction = proposedExpanded.getObject(); } else { + if (oid.getName().equals(newoid.getName())) { // rehash the object entry, because oid might have changed! _tracker.trackOIDChange(objectInTransaction, engine, oid, newoid); + } else { + _tracker.untrackObject(objectInTransaction); + objectInTransaction = proposedObject.getObject(); + _tracker.trackObject(engine, proposedObject.getActualClassMolder(), + newoid, objectInTransaction); + } } } catch (ClassCastException except) { @@ -849,6 +806,56 @@ } /** + * Load an object for use within the transaction. Multiple access to the + * same object within the transaction will return the same object instance + * (except for read-only access). + *
+ * This method is similar to {@link #fetch}except that it will load the + * object only once within a transaction and always return the same + * instance. + *
+ * If the object is loaded for read-only then no lock is acquired and + * updates to the object are not reflected at commit time. If the object is + * loaded for read-write then a read lock is acquired (unless timeout or + * deadlock detected) and the object is stored at commit time. The object is + * then considered persistent and may be deleted or upgraded to write lock. + * If the object is loaded for exclusive access then a write lock is + * acquired and the object is synchronized with the persistent copy. + *
+ * Attempting to load the object twice in the same transaction, once with + * exclusive lock and once with read-write lock will result in an exception. + * + * @param engine + * The persistence engine + * @param molder + * The class persistence molder + * @param identity + * The object's identity + * @param objectToBeLoaded + * The object to fetch (single instance per transaction) + * @param suggestedAccessMode + * The access mode (see {@link AccessMode}) the values in + * persistent storage + * @throws LockNotGrantedException + * Timeout or deadlock occured attempting to acquire lock on + * object + * @throws ObjectNotFoundException + * The object was not found in persistent storage + * @throws PersistenceException + * An error reported by the persistence engine + * @return object being loaded + */ + public synchronized Object load(final LockEngine engine, + final ClassMolder molder, + final Object identity, + ProposedObject proposedObject, + final AccessMode suggestedAccessMode) + throws ObjectNotFoundException, LockNotGrantedException, PersistenceException { + return load(engine, molder, identity, proposedObject, + suggestedAccessMode, null); + } + + /** * Walk a data object tree starting from the specified object, and mark all * object to be created. *
Index: org/exolab/castor/persist/LockEngine.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/persist/LockEngine.java,v retrieving revision 1.24 diff -u -r1.24 LockEngine.java --- org/exolab/castor/persist/LockEngine.java 5 Sep 2005 20:38:30 -0000 1.24 +++ org/exolab/castor/persist/LockEngine.java 19 Sep 2005 21:07:42 -0000 @@ -365,6 +365,24 @@ lockedOid = lock.getOID(); + if (!oid.getName().equals(lockedOid.getName())) { + molder = lockedOid.getMolder(); + typeInfo = (TypeInfo) _typeInfo.get(lockedOid.getName()); + proposedObject.setProposedClass(lockedOid.getMolder().getJavaClass(tx.getClassLoader())); + proposedObject.setActualClass(lockedOid.getMolder().getJavaClass(tx.getClassLoader())); + Object newObject; + try { + newObject = molder.newInstance(tx.getClassLoader()); + } catch (InstantiationException e) { + throw new PersistenceException ("Problem creating instance of " + molder.getName()); + } catch (IllegalAccessException e) { + throw new PersistenceException ("Problem creating instance of " + molder.getName()); + } catch (ClassNotFoundException e) { + throw new PersistenceException ("Problem creating instance of " + molder.getName()); + } + molder.setIdentity(tx, newObject, lockedOid.getIdentity()); + proposedObject.setObject(newObject); + } Object stamp = typeInfo.molder.load(tx, lockedOid, lock, proposedObject, suggestedAccessMode, results); // if object has been expanded, return early @@ -1242,8 +1260,11 @@ if (oid.getName().equals(cacheOid.getName())) { entry.setOID(oid); locks.put(oid, entry); + } else if (oid.equals(cacheOid)) { + //entry.setOID(cacheOid); + locks.put(cacheOid, entry); } else { - entry = null; + entry = null; } } } Index: org/exolab/castor/persist/OID.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/persist/OID.java,v retrieving revision 1.5 diff -u -r1.5 OID.java --- org/exolab/castor/persist/OID.java 27 Jul 2005 11:54:21 -0000 1.5 +++ org/exolab/castor/persist/OID.java 19 Sep 2005 21:07:43 -0000 @@ -261,7 +261,7 @@ * * @return The object's type's full name */ - String getName() { + public String getName() { return _name; }