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.10 diff -u -r1.10 Database.java --- main/org/exolab/castor/jdo/Database.java 10 Jan 2005 21:22:23 -0000 1.10 +++ main/org/exolab/castor/jdo/Database.java 26 Mar 2005 22:25:30 -0000 @@ -47,8 +47,8 @@ package org.exolab.castor.jdo; +import org.exolab.castor.mapping.AccessMode; import org.exolab.castor.persist.PersistenceInfoGroup; -import org.exolab.castor.persist.spi.Complex; /** * An open connection to the database. This object represents an open @@ -112,7 +112,7 @@ * objects are not reflected in the database when the transaction * commits. */ - public static final short ReadOnly = 0; + public static final AccessMode ReadOnly = AccessMode.ReadOnly; /** @@ -127,7 +127,7 @@ * modified. Dirty checking is enabled for all fields marked * as such, and a cached copy is used to populate the object. */ - public static final short Shared = 1; + public static final AccessMode Shared = AccessMode.Shared; /** @@ -144,7 +144,7 @@ * be synchronized with the database and not populated from * the cache. */ - public static final short Exclusive = 2; + public static final AccessMode Exclusive = AccessMode.Exclusive; /** @@ -161,7 +161,7 @@ * be synchronized with the database and not populated from * the cache. Dirty checking is not required. */ - public static final short DbLocked = 3; + public static final AccessMode DbLocked = AccessMode.DbLocked; /** @@ -240,9 +240,9 @@ * @throws PersistenceException An error reported by the * persistence engine */ - public Object load( Class type, Complex identity ) - throws ObjectNotFoundException, LockNotGrantedException, - TransactionNotInProgressException, PersistenceException; +// public Object load( Class type, Complex identity ) +// throws ObjectNotFoundException, LockNotGrantedException, +// TransactionNotInProgressException, PersistenceException; /** *
@@ -264,11 +264,15 @@ * transaction is not in progress * @throws PersistenceException An error reported by the * persistence engine + * @deprecated */ public Object load( Class type, Object identity, short accessMode ) throws TransactionNotInProgressException, ObjectNotFoundException, LockNotGrantedException, PersistenceException; + public Object load(Class type, Object identity, AccessMode mode) + throws TransactionNotInProgressException, ObjectNotFoundException, + LockNotGrantedException, PersistenceException; /** *
@@ -292,9 +296,9 @@ * @throws PersistenceException An error reported by the * persistence engine */ - public Object load( Class type, Complex identity, short accessMode ) - throws ObjectNotFoundException, LockNotGrantedException, - TransactionNotInProgressException, PersistenceException; +// public Object load( Class type, Complex identity, short accessMode ) +// throws ObjectNotFoundException, LockNotGrantedException, +// TransactionNotInProgressException, PersistenceException; /** *
Index: main/org/exolab/castor/jdo/Persistent.java
===================================================================
RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/Persistent.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Persistent.java
--- main/org/exolab/castor/jdo/Persistent.java 3 Mar 2003 07:08:08 -0000 1.1.1.1
+++ main/org/exolab/castor/jdo/Persistent.java 26 Mar 2005 22:25:30 -0000
@@ -90,8 +90,8 @@
* object with the database.
*
* @param accessMode The access mode that was specified for this object
- * either in {@link org.exolab.castor.jdo.OQLQuery#execute( short accessMode )}, or in
- * {@link Database#load( Class type, Object identity, short accessMode )}.
+ * either in {@link org.exolab.castor.jdo.OQLQuery#execute(AccessMode accessMode)}, or in
+ * {@link Database#load(Class type, Object identity, AccessMode accessMode)}.
* The constants are defined in {@link Database}.
* @return the return value is discarded
* @throws Exception An exception occured, the object cannot be loaded
Index: main/org/exolab/castor/jdo/Query.java
===================================================================
RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/Query.java,v
retrieving revision 1.3
diff -u -r1.3 Query.java
--- main/org/exolab/castor/jdo/Query.java 5 Mar 2005 13:41:50 -0000 1.3
+++ main/org/exolab/castor/jdo/Query.java 26 Mar 2005 22:25:31 -0000
@@ -46,6 +46,8 @@
package org.exolab.castor.jdo;
+import org.exolab.castor.mapping.AccessMode;
+
@@ -214,6 +216,7 @@
* transaction is not in progress
* @throws PersistenceException An error reported by the
* persistence engine
+ * @deprecated
*/
public QueryResults execute( short accessMode )
throws QueryException, PersistenceException, TransactionNotInProgressException;
@@ -223,6 +226,12 @@
* This is used for cursor support
*/
public QueryResults execute( short accessMode, boolean scrollable )
+ throws QueryException, PersistenceException, TransactionNotInProgressException;
+
+ public QueryResults execute(AccessMode accessMode)
+ throws QueryException, PersistenceException, TransactionNotInProgressException;
+
+ public QueryResults execute(AccessMode accessMode, boolean scrollable)
throws QueryException, PersistenceException, TransactionNotInProgressException;
/**
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.19
diff -u -r1.19 DatabaseImpl.java
--- main/org/exolab/castor/jdo/engine/DatabaseImpl.java 24 Mar 2005 10:44:57 -0000 1.19
+++ main/org/exolab/castor/jdo/engine/DatabaseImpl.java 26 Mar 2005 22:25:33 -0000
@@ -57,7 +57,6 @@
import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.persist.*;
import org.exolab.castor.persist.spi.CallbackInterceptor;
-import org.exolab.castor.persist.spi.Complex;
import org.exolab.castor.persist.spi.InstanceFactory;
import org.exolab.castor.util.LocalConfiguration;
import org.exolab.castor.util.Messages;
@@ -300,65 +299,44 @@
return ( _scope == null );
}
- public Object load( Class type, Object identity, Object object )
- throws TransactionNotInProgressException, ObjectNotFoundException,
- LockNotGrantedException, PersistenceException {
-
- TransactionContext tx;
- PersistenceInfo info;
-
- tx = getTransaction();
- info = _scope.getPersistenceInfo( type );
+ public Object load(Class type, Object identity)
+ throws ObjectNotFoundException, LockNotGrantedException,
+ TransactionNotInProgressException, PersistenceException {
- return tx.load( info.engine, info.molder, identity, object, null );
+ return load(type, identity, null, null);
}
- public Object load( Class type, Complex identity )
+
+ public Object load(Class type, Object identity, Object object)
throws TransactionNotInProgressException, ObjectNotFoundException,
LockNotGrantedException, PersistenceException {
-
- return load( type, (Object)identity, null );
- }
- public Object load( Class type, Object identity )
- throws ObjectNotFoundException, LockNotGrantedException,
+ return load(type, identity, object, null);
+ }
+
+ public Object load( Class type, Object identity, short accessMode)
+ throws ObjectNotFoundException, LockNotGrantedException,
TransactionNotInProgressException, PersistenceException {
+
+ AccessMode mode = AccessMode.getAccessMode(accessMode);
- return load( type, identity, null );
+ return load(type, identity, null, mode);
}
- public Object load( Class type, Complex identity, short accessMode )
+ public Object load(Class type, Object identity, AccessMode mode)
throws TransactionNotInProgressException, ObjectNotFoundException,
LockNotGrantedException, PersistenceException {
- return load( type, (Object)identity, accessMode );
+ return load(type, identity, null, mode);
}
- public Object load( Class type, Object identity, short accessMode) throws ObjectNotFoundException, LockNotGrantedException, TransactionNotInProgressException, PersistenceException {
- TransactionContext tx;
- PersistenceInfo info;
- AccessMode mode;
-
- switch ( accessMode ) {
- case ReadOnly:
- mode = AccessMode.ReadOnly;
- break;
- case Shared:
- mode = AccessMode.Shared;
- break;
- case Exclusive:
- mode = AccessMode.Exclusive;
- break;
- case DbLocked:
- mode = AccessMode.DbLocked;
- break;
- default:
- throw new IllegalArgumentException( "Value for 'accessMode' is invalid" );
- }
+ private Object load(Class type, Object identity, Object object, AccessMode mode)
+ throws TransactionNotInProgressException, ObjectNotFoundException,
+ LockNotGrantedException, PersistenceException {
- tx = getTransaction();
- info = _scope.getPersistenceInfo( type );
+ TransactionContext tx = getTransaction();
+ PersistenceInfo info = _scope.getPersistenceInfo(type);
- return tx.load( info.engine, info.molder, identity, null, mode );
+ return tx.load(info.engine, info.molder, identity, object, mode);
}
public void create( Object object )
Index: main/org/exolab/castor/jdo/engine/OQLQueryImpl.java
===================================================================
RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/engine/OQLQueryImpl.java,v
retrieving revision 1.13
diff -u -r1.13 OQLQueryImpl.java
--- main/org/exolab/castor/jdo/engine/OQLQueryImpl.java 13 Dec 2004 10:29:19 -0000 1.13
+++ main/org/exolab/castor/jdo/engine/OQLQueryImpl.java 26 Mar 2005 22:25:34 -0000
@@ -416,33 +416,22 @@
public QueryResults execute( short accessMode )
throws QueryException, PersistenceException, TransactionNotInProgressException
{
- return execute(accessMode, false);
+ return execute(AccessMode.getAccessMode(accessMode), false);
}
public QueryResults execute( short accessMode, boolean scrollable )
throws QueryException, PersistenceException, TransactionNotInProgressException
{
- switch ( accessMode ) {
- case Database.ReadOnly:
- return execute( AccessMode.ReadOnly, scrollable );
- case Database.Shared:
- return execute( AccessMode.Shared, scrollable );
- case Database.Exclusive:
- return execute( AccessMode.Exclusive, scrollable );
- case Database.DbLocked:
- return execute( AccessMode.DbLocked, scrollable );
- default:
- throw new IllegalArgumentException( "Value for 'accessMode' is invalid" );
- }
+ return execute(AccessMode.getAccessMode(accessMode), scrollable);
}
- private QueryResults execute( AccessMode accessMode )
+ public QueryResults execute( AccessMode accessMode )
throws QueryException, PersistenceException, TransactionNotInProgressException
{
return execute(accessMode, false);
}
- private QueryResults execute( AccessMode accessMode, boolean scrollable )
+ public QueryResults execute( AccessMode accessMode, boolean scrollable )
throws QueryException, PersistenceException, TransactionNotInProgressException
{
org.exolab.castor.persist.QueryResults results;
Index: main/org/exolab/castor/mapping/AccessMode.java
===================================================================
RCS file: /scm/castor/castor/src/main/org/exolab/castor/mapping/AccessMode.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 AccessMode.java
--- main/org/exolab/castor/mapping/AccessMode.java 3 Mar 2003 07:08:26 -0000 1.1.1.1
+++ main/org/exolab/castor/mapping/AccessMode.java 26 Mar 2005 22:25:35 -0000
@@ -43,9 +43,10 @@
* $Id: AccessMode.java,v 1.1.1.1 2003/03/03 07:08:26 kvisco Exp $
*/
-
package org.exolab.castor.mapping;
+import java.util.HashMap;
+import java.util.Map;
/**
* The access mode for a class. This object is used by class
@@ -67,8 +68,13 @@
* @author Assaf Arkin
* @version $Revision: 1.1.1.1 $ $Date: 2003/03/03 07:08:26 $
*/
-public class AccessMode
-{
+public class AccessMode {
+ //-------------------------------------------------------------------------
+
+ private static final Map IDS = new HashMap(7);
+ private static final Map NAMES = new HashMap(7);
+
+ //-------------------------------------------------------------------------
/**
* Read only access. Objects can be read but are not made
@@ -76,31 +82,30 @@
* persistent storage.
*/
public static final AccessMode ReadOnly
- = new AccessMode( "read-only" );
-
+ = new AccessMode((short) 0, "read-only");
/**
* Shared access. Objects can be read by multiple concurrent
* transactions. Equivalent to optimistic locking.
*/
public static final AccessMode Shared
- = new AccessMode( "shared" );
-
+ = new AccessMode((short) 1, "shared");
/**
* Exclusive access. Objects can be access by a single transaction
* at any given time. Equivalent to pessimistic locking.
*/
public static final AccessMode Exclusive
- = new AccessMode( "exclusive" );
+ = new AccessMode((short) 2, "exclusive");
/**
* DbLocked access. Objects can be access by a single transaction
* at any given time, and a lock is acquired in the database.
*/
public static final AccessMode DbLocked
- = new AccessMode( "db-locked" );
+ = new AccessMode((short) 3, "db-locked");
+ //-------------------------------------------------------------------------
/**
* Returns the access mode from the name. If accessMode
@@ -110,39 +115,114 @@
* @param accessMode The access mode name
* @return The access mode
*/
- public static AccessMode getAccessMode( String accessMode )
- {
- if ( accessMode == null )
- return Shared;
- if ( accessMode.equals( Shared._name ) )
- return Shared;
- if ( accessMode.equals( Exclusive._name ) )
- return Exclusive;
- if ( accessMode.equals( ReadOnly._name ) )
- return ReadOnly;
- if ( accessMode.equals( DbLocked._name ) )
- return DbLocked;
- throw new IllegalArgumentException( "Unrecognized access mode" );
+ public static AccessMode getAccessMode(String accessMode) {
+ AccessMode mode = (AccessMode) NAMES.get(accessMode);
+ if (mode != null) {
+ return mode;
+ } else {
+ throw new IllegalArgumentException("Unrecognized access mode");
+ }
+ }
+
+ public static AccessMode getAccessMode(short accessMode) {
+ AccessMode mode = (AccessMode) IDS.get(new Short(accessMode));
+ if (mode != null) {
+ return mode;
+ } else {
+ throw new IllegalArgumentException("Unrecognized access mode");
+ }
}
+ //-------------------------------------------------------------------------
/**
- * The name of this access mode as it would appear in a
- * mapping file.
+ * The id of this access mode as originally used at Database.load() and
+ * Query.execute().
+ */
+ private short _id;
+
+ /**
+ * The name of this access mode as it would appear in a mapping file.
*/
private String _name;
+ //-------------------------------------------------------------------------
- private AccessMode( String name )
- {
+ private AccessMode(short id, String name) {
+ _id = id;
_name = name;
+
+ IDS.put(new Short(id), this);
+ NAMES.put(name, this);
}
+ public short getId() { return _id; }
+ public String getName() { return _name; }
+
+ //-------------------------------------------------------------------------
- public String toString()
- {
+ /**
+ * Returns the String representation of this kind.
+ *
+ * @return String representation of this kind.
+ */
+ public String toString() {
return _name;
}
+ /**
+ * Clone only returns the one and only instance of this kind.
+ *
+ * @return The original instance.
+ */
+ public Object clone() {
+ return this;
+ }
+
+ /**
+ * Returns if the specified object and this are one and the same instance.
+ *
+ * @param other Object to be compared with this instance.
+ * @return true if other equals this else false.
+ */
+ public boolean equals(final Object other) {
+ return (this == other);
+ }
+
+ /**
+ * Returns the hash code of this object.
+ *
+ * @return Hash code of this object.
+ */
+ public int hashCode() {
+ return (int) _id;
+ }
-} //-- AccessMode
+ /**
+ * Compares {@link #_kind} against {@link #_kind} of the specified
+ * object. So this method is inconsistent with {@link #equals}.
+ *
+ * @param other Object to be compared with this instance.
+ * @return A negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object.
+ */
+ public int compareTo(final Object other) {
+ return compareTo((AccessMode) other);
+ }
+
+ public int compareTo(final AccessMode other) {
+ return _id - other._id;
+ }
+
+ /**
+ * Called during deserialization.
+ *
+ * @return The existing instance of the enum.
So you can use '=='
+ * like 'equals' even if you use a deserialized Enum.
+ */
+ protected Object readResolve() {
+ return NAMES.get(_name);
+ }
+
+ //-------------------------------------------------------------------------
+}
Index: main/org/exolab/castor/persist/TransactionContext.java
===================================================================
RCS file: /scm/castor/castor/src/main/org/exolab/castor/persist/TransactionContext.java,v
retrieving revision 1.16
diff -u -r1.16 TransactionContext.java
--- main/org/exolab/castor/persist/TransactionContext.java 5 Mar 2005 13:41:54 -0000 1.16
+++ main/org/exolab/castor/persist/TransactionContext.java 26 Mar 2005 22:25:42 -0000
@@ -730,10 +730,10 @@
try {
if ( _callback != null ) {
_callback.using( object, _db );
- _callback.loaded( object, toDatabaseAccessMode( accessMode ) );
+ _callback.loaded( object, accessMode.getId() );
} else if ( molder.getCallback() != null ) {
molder.getCallback().using( object, _db );
- molder.getCallback().loaded( object, toDatabaseAccessMode( accessMode ) );
+ molder.getCallback().loaded( object, accessMode.getId() );
}
} catch ( Exception except ) {
release( object );
@@ -2290,23 +2290,6 @@
public boolean isReadOnly( Object object ) {
return (getObjectState(object) == OBJECT_STATE_READ_ONLY);
- }
-
- /**
- * Converts AccessMode constant to Database short constant
- */
- static short toDatabaseAccessMode( AccessMode mode )
- {
- if ( mode == AccessMode.Shared )
- return Database.Shared;
- if ( mode == AccessMode.ReadOnly )
- return Database.ReadOnly;
- if ( mode == AccessMode.DbLocked )
- return Database.DbLocked;
- if ( mode == AccessMode.Exclusive )
- return Database.Exclusive;
- // never happens
- return -1;
}
public Database getDatabase() {
Index: tests/jdo/CacheLeakage.java
===================================================================
RCS file: /scm/castor/castor/src/tests/jdo/CacheLeakage.java,v
retrieving revision 1.3
diff -u -r1.3 CacheLeakage.java
--- tests/jdo/CacheLeakage.java 5 Oct 2004 22:26:41 -0000 1.3
+++ tests/jdo/CacheLeakage.java 26 Mar 2005 22:25:45 -0000
@@ -51,6 +51,7 @@
import java.sql.SQLException;
import java.util.Random;
+import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.PersistenceException;
import org.exolab.castor.jdo.LockNotGrantedException;
@@ -189,16 +190,16 @@
_conn = _category.getJDBCConnection();
_conn.setAutoCommit( false );
- _cacheType = Database.Shared;
+ _cacheType = Database.Shared.getId();
runOnce();
- _cacheType = Database.Exclusive;
+ _cacheType = Database.Exclusive.getId();
runOnce();
- _cacheType = Database.DbLocked;
+ _cacheType = Database.DbLocked.getId();
runOnce();
- _cacheType = Database.ReadOnly;
+ _cacheType = Database.ReadOnly.getId();
runOnce();
assertTrue( "Element leak not detected!", !_errLeak );
Index: tests/jdo/Concurrent.java
===================================================================
RCS file: /scm/castor/castor/src/tests/jdo/Concurrent.java,v
retrieving revision 1.4
diff -u -r1.4 Concurrent.java
--- tests/jdo/Concurrent.java 5 Mar 2005 13:42:01 -0000 1.4
+++ tests/jdo/Concurrent.java 26 Mar 2005 22:25:45 -0000
@@ -50,6 +50,7 @@
import java.sql.Connection;
import java.sql.SQLException;
+import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.OQLQuery;
import org.exolab.castor.jdo.ObjectModifiedException;
@@ -187,7 +188,7 @@
* @param accessMode the access mode that is used in the concurrent
* modification tests
*/
- private void testDirtyChecked( short accessMode )
+ private void testDirtyChecked( AccessMode accessMode )
throws PersistenceException, SQLException {
OQLQuery oql;
@@ -293,7 +294,7 @@
* @param accessMode the access mode that is used in the concurrent
* modification tests
*/
- private void testDirtyIgnored( short accessMode )
+ private void testDirtyIgnored( AccessMode accessMode )
throws PersistenceException, SQLException {
OQLQuery oql;
Index: tests/jdo/Deadlock.java
===================================================================
RCS file: /scm/castor/castor/src/tests/jdo/Deadlock.java,v
retrieving revision 1.4
diff -u -r1.4 Deadlock.java
--- tests/jdo/Deadlock.java 5 Mar 2005 13:42:01 -0000 1.4
+++ tests/jdo/Deadlock.java 26 Mar 2005 22:25:46 -0000
@@ -48,6 +48,8 @@
import java.util.Enumeration;
+
+import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.OQLQuery;
import org.exolab.castor.jdo.PersistenceException;
@@ -98,7 +100,7 @@
/**
* AccessMode used in the tests
*/
- private short _accessMode;
+ private AccessMode _accessMode;
/**
* The java object to be synchronized on
@@ -207,7 +209,7 @@
/**
* Creates threads to test for deadlock detection behaviors.
*/
- public void runOnce( short accessMode )
+ public void runOnce( AccessMode accessMode )
throws PersistenceException, InterruptedException {
stream.println( "Note: this test uses a 2 second delay between threads. CPU and database load might cause the test to not perform synchronously, resulting in erroneous results. Make sure that execution is not hampered by CPU/datebase load." );
Index: tests/jdo/TestPersistent.java
===================================================================
RCS file: /scm/castor/castor/src/tests/jdo/TestPersistent.java,v
retrieving revision 1.3
diff -u -r1.3 TestPersistent.java
--- tests/jdo/TestPersistent.java 5 Mar 2005 13:42:01 -0000 1.3
+++ tests/jdo/TestPersistent.java 26 Mar 2005 22:25:47 -0000
@@ -50,6 +50,8 @@
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
+
+import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.Query;
import org.exolab.castor.jdo.QueryResults;
@@ -280,8 +282,10 @@
Query qry;
QueryResults res;
- if ( _parentId != null )
- _parent = (TestPersistent) _db.load( TestPersistent.class, _parentId, accessMode );
+ if ( _parentId != null ) {
+ AccessMode mode = AccessMode.getAccessMode(accessMode);
+ _parent = (TestPersistent) _db.load( TestPersistent.class, _parentId, mode );
+ }
qry = _db.getOQLQuery( "SELECT p FROM jdo.TestPersistent p WHERE parentId=$1" );
qry.bind( _id );