Index: doc/release-notes.xml =================================================================== RCS file: /scm/castor/castor/src/doc/release-notes.xml,v retrieving revision 1.119 diff -u -r1.119 release-notes.xml --- doc/release-notes.xml 10 Nov 2005 10:41:04 -0000 1.119 +++ doc/release-notes.xml 10 Nov 2005 15:51:05 -0000 @@ -65,11 +65,24 @@ -

Added helper method to close database

+

Improved Database.getIdentity(Object)

-

Added org.castor.jdo.util.JDOUtils.closeDatabase() method to close - an open database instance without throwing exceptions. Any active - transaction will be silently rolled back.

+

The new implementation of the Database.getIdentity(Object) does not rely on the + object being loaded in the same transaction anymore. It is even not required to + have an active transaction. The identity will now be determined by calling the + getters of the fields defined as identities in the mapping. If a mapping for the + objects class could not be found a ClassNotPersistenceCapableException will be + thrown. Null is only returned if the objects identity is null.

+ +

Note:Care should be take if you previously used the null return of + Database.getIdentity(Object) to determine if the object has been loaded in + the current transaction before.

+ +

Added helper method to close database

+ +

Added org.castor.jdo.util.JDOUtils.closeDatabase() method to close an open + database instance without throwing exceptions. Any active transaction will be + silently rolled back.

Bugs

@@ -87,9 +100,30 @@ + + + Improved Database.getIdentity(Object) to be able to resolve identity without + relying on the object been loaded from the database in the same transaction. + + + Ralf Joachim + ralf.joachim@syscon-world.de + + + Ralf Joachim + ralf.joachim@syscon-world.de + + + Henk van Voorthujsen + voorth@xs4all.nl + + Enh. + JDO + 20051110 + - Added org.castor.jdo.util.JDOUtils.closeDatabase() helper method. + Added org.castor.jdo.util.JDOUtils.closeDatabase() helper method. Ralf Joachim @@ -109,7 +143,7 @@ - Refactored org.exolab.castor.jdo.Utils into org.castor.jdo.util.JDOUtils. + Refactored org.exolab.castor.jdo.Utils into org.castor.jdo.util.JDOUtils. Ralf Joachim Index: etc/CHANGELOG =================================================================== RCS file: /scm/castor/castor/src/etc/CHANGELOG,v retrieving revision 1.278 diff -u -r1.278 CHANGELOG --- etc/CHANGELOG 10 Nov 2005 10:41:04 -0000 1.278 +++ etc/CHANGELOG 10 Nov 2005 15:51:28 -0000 @@ -7,6 +7,12 @@ Added non-trivial sample for usage of binding file +JDO: Fixed bug CASTOR-1239 using contribution from Ralf Joachim[ralf.joachim@syscon-world.de] + Improved Database.getIdentity(Object) to be able to resolve identity without + relying on the object been loaded from the database in the same transaction. + Details: http://jira.codehaus.org/browse/CASTOR-1239 + (Ralf - 20051110) + JDO: Fixed bug CASTOR-1260 using contribution from Ralf Joachim[ralf.joachim@syscon-world.de] Added org.castor.jdo.util.JDOUtils.closeDatabase() helper method. Details: http://jira.codehaus.org/browse/CASTOR-1260 Index: main/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 --- main/org/castor/persist/TransactionContext.java 5 Sep 2005 20:38:30 -0000 1.6 +++ main/org/castor/persist/TransactionContext.java 10 Nov 2005 15:51:39 -0000 @@ -1960,25 +1960,6 @@ } /** - * Returns the object's identity. If the identity was determined when the - * object was created, or if the object was retrieved, that identity is - * returned. If the identity has been modified, this will not be reflected - * until the transaction commits. Null is returned if the identity is null, - * the object does not have any identity, or the object is not persistent. - * - * @param object - * The object - * @return The object's identity, or null - */ - public Object getIdentity(final Object object) { - OID oid = _tracker.getOIDForObject(object); - if (oid != null) { - return oid.getIdentity(); - } - return null; - } - - /** * Returns the status of this transaction. */ public int getStatus() { Index: main/org/exolab/castor/jdo/Database.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/Database.java,v retrieving revision 1.12 diff -u -r1.12 Database.java --- main/org/exolab/castor/jdo/Database.java 27 Apr 2005 09:35:15 -0000 1.12 +++ main/org/exolab/castor/jdo/Database.java 10 Nov 2005 15:51:43 -0000 @@ -548,17 +548,21 @@ /** - * Returns the object's identity. If the identity was determined when - * the object was created, or if the object was retrieved, that identity - * is returned. If the identity has been modified, this will not be - * reflected until the transaction commits. Null is returned if the - * identity is null, the object does not have any identity, or the - * object is not persistent. - * - * @param object The object - * @return The object's identity, or null + * Returns the object's identity. The identity will be determined by calling the + * getters of the fields defined as identities in the mapping. If a mapping for + * the objects class could not be found a ClassNotPersistenceCapableException + * will be thrown. Null is only returned if the objects identity is null. It is + * not required to have an active transaction when using this method. + *

+ * Note: Prior to 0.9.9.1 release of castor the identity could only be + * determined if the object took part in the transaction. If this was not the case, + * the previous implementation also returned null. + * + * @param object The object. + * @return The object's identity, or null. + * @throws ClassNotPersistenceCapableException The class is not persistent capable. */ - public Object getIdentity( Object object ); + public Object getIdentity(Object object) throws ClassNotPersistenceCapableException; /** Index: main/org/exolab/castor/jdo/engine/DatabaseImpl.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/engine/DatabaseImpl.java,v retrieving revision 1.28 diff -u -r1.28 DatabaseImpl.java --- main/org/exolab/castor/jdo/engine/DatabaseImpl.java 13 Oct 2005 08:52:14 -0000 1.28 +++ main/org/exolab/castor/jdo/engine/DatabaseImpl.java 10 Nov 2005 15:51:46 -0000 @@ -403,13 +403,16 @@ return false; } - public Object getIdentity(Object object) - { - if ( _scope == null ) + /* (non-Javadoc) + * @see org.exolab.castor.jdo.Database#getIdentity(java.lang.Object) + */ + public Object getIdentity(final Object object) throws ClassNotPersistenceCapableException { + if ( _scope == null ) { throw new IllegalStateException( Messages.message( "jdo.dbClosed" ) ); - if ( _ctx != null && _ctx.isOpen() ) - return _ctx.getIdentity( object ); - return null; + } + + PersistenceInfo info = _scope.getPersistenceInfo(object.getClass()); + return info.molder.getActualIdentity(_classLoader, object); }