db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r428990 [3/5] - in /db/ojb/trunk/proposals/otm: ./ java/ java/org/ java/org/apache/ java/org/apache/ojb/ java/org/apache/ojb/otm/ java/org/apache/ojb/otm/copy/ java/org/apache/ojb/otm/core/ java/org/apache/ojb/otm/kit/ java/org/apache/ojb/o...
Date Sat, 05 Aug 2006 12:18:15 GMT
Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/kit/SimpleKit.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/kit/SimpleKit.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/kit/SimpleKit.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/kit/SimpleKit.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,166 @@
+package org.apache.ojb.otm.kit;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.otm.OTMKit;
+import org.apache.ojb.otm.copy.*;
+import org.apache.ojb.otm.lock.map.InMemoryLockMap;
+import org.apache.ojb.otm.lock.map.LockMap;
+import org.apache.ojb.otm.lock.wait.LockWaitStrategy;
+import org.apache.ojb.otm.lock.wait.TimeoutStrategy;
+import org.apache.ojb.otm.swizzle.CopySwizzling;
+import org.apache.ojb.otm.swizzle.Swizzling;
+import org.apache.ojb.otm.transaction.LocalTransactionFactory;
+import org.apache.ojb.otm.transaction.TransactionFactory;
+
+import java.io.Serializable;
+
+/**
+ * A base implementation of an OTMKit using local transactions, an
+ * in-memory lock map, and metadata based object copying for
+ * object swizzling in transactional contexts.
+ *
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ */
+public class SimpleKit extends OTMKit
+{
+
+    private static SimpleKit _instance;
+
+    protected TransactionFactory _txFactory;
+    protected Swizzling _swizzlingStrategy;
+    protected LockWaitStrategy _lockWaitStrategy;
+    protected LockMap _lockMap;
+    protected ObjectCopyStrategy _noOpCopyStrategy;
+    protected ObjectCopyStrategy _defaultCopyStrategy;
+    protected ObjectCopyStrategy _cloneableCopyStrategy;
+
+    /**
+     * Constructor for SimpleKit.
+     */
+    protected SimpleKit()
+    {
+        super();
+        _txFactory = new LocalTransactionFactory();
+        _swizzlingStrategy = new CopySwizzling();
+        _lockWaitStrategy = new TimeoutStrategy();
+        _lockMap = new InMemoryLockMap();
+        _noOpCopyStrategy = new NoOpObjectCopyStrategy();
+        //_defaultCopyStrategy = new ReflectiveObjectCopyStrategy();
+        //_defaultCopyStrategy = new SerializeObjectCopyStrategy();
+        _defaultCopyStrategy = new MetadataObjectCopyStrategy();
+        _cloneableCopyStrategy = new CloneableObjectCopyStrategy();
+    }
+
+    /**
+     * Obtain the single instance of SimpleKit
+     */
+    public static SimpleKit getInstance()
+    {
+        if (_instance == null)
+        {
+            _instance = new SimpleKit();
+        }
+        return _instance;
+    }
+
+    ///////////////////////////////////////
+    // OTMKit Protocol
+    ///////////////////////////////////////
+
+    /**
+     * @see org.apache.ojb.otm.OTMKit#getTransactionFactory()
+     */
+    protected TransactionFactory getTransactionFactory()
+    {
+        return _txFactory;
+    }
+
+    /**
+     * @see org.apache.ojb.otm.OTMKit#getSwizzlingStrategy()
+     */
+    public Swizzling getSwizzlingStrategy()
+    {
+        return _swizzlingStrategy;
+    }
+
+
+    /**
+    * @see org.apache.ojb.otm.OTMKit#getLockWaitStrategy()
+    */
+    public LockWaitStrategy getLockWaitStrategy()
+    {
+        return _lockWaitStrategy;
+    }
+
+    /**
+     * @see org.apache.ojb.otm.OTMKit#getLockMap()
+     */
+    public LockMap getLockMap()
+    {
+        return _lockMap;
+    }
+
+    /**
+     * @see org.apache.ojb.otm.OTMKit#getCopyStrategy(Identity)
+     */
+    public ObjectCopyStrategy getCopyStrategy(Identity oid)
+    {
+        Class clazz = oid.getClass();
+
+        if (OjbCloneable.class.isAssignableFrom(clazz))
+        {
+            return _cloneableCopyStrategy;
+        }
+        else if (Serializable.class.isAssignableFrom(clazz))
+        {
+            return _defaultCopyStrategy;
+        }
+        else
+        {
+            return _noOpCopyStrategy;
+        }
+    }
+
+    /**
+     * Should OTM implicitely lock all objects that are reachable
+     * from the explicitely locked object? The updates to the locked
+     * objects are automatically stored to the database at the end
+     * of transaction.
+     **/
+    public boolean isImplicitLockingUsed()
+    {
+        return true;
+    }
+
+
+    /**
+     * Should OTM verify each inserted object for presence in the database?
+     **/
+    public boolean isInsertVerified()
+    {
+        return false;
+    }
+    
+    /**
+     * Should OTM perform INSERTs for the given object eagerly or during commit?
+     **/
+    public boolean isEagerInsert(Object obj)
+    {
+        return false;
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/IsolationFactory.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/IsolationFactory.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/IsolationFactory.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/IsolationFactory.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,102 @@
+package org.apache.ojb.otm.lock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.broker.locking.IsolationLevels;
+import org.apache.ojb.otm.lock.isolation.ReadCommittedIsolation;
+import org.apache.ojb.otm.lock.isolation.ReadUncommittedIsolation;
+import org.apache.ojb.otm.lock.isolation.RepeatableReadIsolation;
+import org.apache.ojb.otm.lock.isolation.SerializableIsolation;
+import org.apache.ojb.otm.lock.isolation.TransactionIsolation;
+
+/**
+ *
+ * <javadoc>
+ *
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ *
+ */
+public class IsolationFactory
+{
+
+    private static final TransactionIsolation READ_UNCOMMITTED_ISOLATION
+        = new ReadUncommittedIsolation();
+    private static final TransactionIsolation READ_COMMITTED_ISOLATION
+        = new ReadCommittedIsolation();
+    private static final TransactionIsolation REPEATABLE_READ_ISOLATION
+        = new RepeatableReadIsolation();
+    private static final TransactionIsolation SERIALIZABLE_ISOLATION
+        = new SerializableIsolation();
+
+
+    /**
+     *
+     * Fetches the isolation level of given class from its ClassDescriptor.
+     *
+     */
+    public static TransactionIsolation getIsolationLevel (PersistenceBroker pb,
+                                                          ObjectLock lock)
+    {
+        /*
+        arminw: use real object class instead of top-level class
+        to match isolation level of given class
+        */
+        // Class clazz = lock.getTargetIdentity().getObjectsTopLevelClass();
+        Class clazz = lock.getTargetIdentity().getObjectsRealClass();
+        ClassDescriptor classDescriptor = pb.getClassDescriptor(clazz);
+        IsolationLevels isolationLevel = classDescriptor.getIsolationLevel();
+
+        TransactionIsolation isolation;
+        switch (isolationLevel.getValue()) {
+
+            case IsolationLevels.IL_READ_UNCOMMITTED:
+                isolation = READ_UNCOMMITTED_ISOLATION;
+                break;
+
+            case IsolationLevels.IL_READ_COMMITTED:
+                isolation = READ_COMMITTED_ISOLATION;
+                break;
+
+            case IsolationLevels.IL_REPEATABLE_READ:
+                isolation = REPEATABLE_READ_ISOLATION;
+                break;
+
+            case IsolationLevels.IL_SERIALIZABLE:
+                isolation = SERIALIZABLE_ISOLATION;
+                break;
+            /*
+            TODO: fix this!!
+            */
+            case IsolationLevels.IL_NO_LOCKING:
+                // new added isolation level
+                isolation = READ_UNCOMMITTED_ISOLATION;
+                break;
+            case IsolationLevels.IL_OPTIMISTIC:
+                // new added isolation level
+                isolation = READ_UNCOMMITTED_ISOLATION;
+                break;
+
+            default:
+                throw new UnknownIsolationException(
+                    "Isolation level " + isolationLevel + " is not supported");
+        }
+
+        return isolation;
+    }
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockListener.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockListener.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockListener.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockListener.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,32 @@
+package org.apache.ojb.otm.lock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.otm.core.Transaction;
+
+/**
+ *
+ * Protocol to notify when a lock is released by a transaction. This is used by wait strategies to
+ * implementation deadlock prevention/detection/recovery algorithms.
+ * 
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ * 
+ */
+public interface LockListener
+{
+    public void lockReleased (Transaction tx, Identity oid);
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockManager.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockManager.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockManager.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockManager.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,90 @@
+package org.apache.ojb.otm.lock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.isolation.TransactionIsolation;
+import org.apache.ojb.otm.lock.map.LockMap;
+
+/**
+ *
+ * Manages locks on objects across transactions.
+ *
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ *
+ */
+public class LockManager
+{
+    private static LockManager _Instance = new LockManager();
+
+    public static LockManager getInstance ()
+    {
+        return _Instance;
+    }
+
+    private LockManager()
+    {
+
+    }
+
+    public void ensureLock(Identity oid, Transaction tx, int lock,
+                           PersistenceBroker pb)
+        throws LockingException
+    {
+        LockMap lockMap = tx.getKit().getLockMap();
+        ObjectLock objectLock = lockMap.getLock(oid);
+        TransactionIsolation isolation;
+
+        isolation = IsolationFactory.getIsolationLevel(pb, objectLock);
+
+        if (lock == LockType.READ_LOCK)
+        {
+            isolation.readLock(tx, objectLock);
+        }
+        else if (lock == LockType.WRITE_LOCK)
+        {
+            isolation.writeLock(tx, objectLock);
+        }
+    }
+
+    public int getLockHeld(Identity oid, Transaction tx)
+    {
+        LockMap lockMap = tx.getKit().getLockMap();
+        ObjectLock lock = lockMap.getLock(oid);
+
+        int lockHeld = LockType.NO_LOCK;
+        if (tx.equals(lock.getWriter()))
+        {
+            lockHeld = LockType.WRITE_LOCK;
+        }
+        else if (lock.isReader(tx))
+        {
+            lockHeld = LockType.READ_LOCK;
+        }
+
+        return lockHeld;
+    }
+
+    public void releaseLock(Identity oid, Transaction tx)
+    {
+        LockMap lockMap = tx.getKit().getLockMap();
+
+        ObjectLock objectLock = lockMap.getLock(oid);
+        objectLock.releaseLock(tx);
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockType.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockType.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockType.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockType.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,22 @@
+package org.apache.ojb.otm.lock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public final class LockType
+{
+    public static final int NO_LOCK = 0;
+    public static final int READ_LOCK = 1;
+    public static final int WRITE_LOCK = 2;
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockingException.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockingException.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockingException.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/LockingException.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,58 @@
+package org.apache.ojb.otm.lock;
+
+import org.apache.commons.lang.exception.NestableException;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class LockingException extends NestableException
+{
+
+	/**
+	 * Constructor for LockingException.
+	 */
+	public LockingException()
+	{
+		super();
+	}
+
+	/**
+	 * Constructor for LockingException.
+	 * @param arg0
+	 */
+	public LockingException(String message)
+	{
+		super(message);
+	}
+
+	/**
+	 * Constructor for LockingException.
+	 * @param arg0
+	 */
+	public LockingException(Throwable exception)
+	{
+		super(exception);
+	}
+
+	/**
+	 * Constructor for LockingException.
+	 * @param arg0
+	 * @param arg1
+	 */
+	public LockingException(String message, Throwable exception)
+	{
+		super(message, exception);
+	}
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/ObjectLock.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/ObjectLock.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/ObjectLock.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/ObjectLock.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,241 @@
+package org.apache.ojb.otm.lock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.otm.OTMKit;
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.wait.LockWaitStrategy;
+
+/**
+ *
+ * Represents the locks held for an object. The basic assertion is that at any given point
+ * in time, there can be multiple readers, but just one writer.
+ *
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ *
+ */
+public class ObjectLock
+{
+    //////////////////////////////////
+    // IVars
+    //////////////////////////////////
+
+    private Identity _oid;
+    private LockEntry _writer;
+    private HashMap _readers = new HashMap();
+
+
+    ////////////////////////////////////////
+    // Constructor
+    ////////////////////////////////////////
+
+    public ObjectLock(Identity oid)
+    {
+        _oid = oid;
+    }
+
+    ////////////////////////////////////////
+    // Operations
+    ////////////////////////////////////////
+
+    public Identity getTargetIdentity()
+    {
+        return _oid;
+    }
+
+    public Transaction getWriter()
+    {
+        return (_writer == null)? null: _writer.getTx();
+    }
+
+    public boolean isReader(Transaction tx)
+    {
+        return _readers.containsKey(tx);
+    }
+
+    public boolean doesReaderExists()
+    {
+        return (_readers.size() > 0);
+    }
+
+    public Collection getReaders()
+    {
+        return Collections.unmodifiableCollection(_readers.keySet());
+    }
+
+    public void readLock(Transaction tx)
+    {
+        if (!isReader(tx))
+        {
+            new LockEntry(tx);
+        }
+    }
+
+    public void writeLock(Transaction tx)
+        throws LockingException
+    {
+        if (getWriter() != tx)
+        {
+            LockEntry lock = (LockEntry) _readers.get(tx);
+
+            if (lock == null)
+            {
+                lock = new LockEntry(tx);
+            }
+            lock.writeLock();
+        }
+    }
+
+    public void releaseLock(Transaction tx)
+    {
+        LockEntry lock = (LockEntry)_readers.get(tx);
+
+        if (lock != null)
+        {
+            lock.release();
+        }
+    }
+
+    public void waitForTx(Transaction tx)
+        throws LockingException
+    {
+        OTMKit kit = tx.getKit();
+        LockWaitStrategy waitStrategy = kit.getLockWaitStrategy();
+        waitStrategy.waitForLock(this, tx);
+    }
+
+    public boolean isFree()
+    {
+        return ((_writer == null) && _readers.isEmpty());
+    }
+
+    /////////////////////////////////////////
+    // Inner classes
+    /////////////////////////////////////////
+
+    private class LockEntry
+    {
+        public Transaction _tx;
+        public ArrayList _listeners;
+
+        public LockEntry(Transaction tx)
+        {
+            _tx = tx;
+            _listeners = null;
+            _readers.put(_tx, LockEntry.this);
+        }
+
+        /**
+         *
+         * Returns the LockListeners for this entry.
+         *
+         * @return      ArrayList of LockListeners
+         *
+         */
+        public ArrayList getListeners()
+        {
+            return _listeners;
+        }
+
+        /**
+         *
+         * Returns the transaction held by this LockEntry.
+         *
+         * @return      Transaction
+         *
+         */
+        public Transaction getTx()
+        {
+            return _tx;
+        }
+
+        /**
+         *
+         *  Add a listener to the list of LockListeners. LockListener is notified, when this
+         *  LockEntry is released.
+         *
+         *  @param listener         the LockListener
+         *
+         */
+        public void addListener(LockListener listener)
+        {
+            if (listener != null)
+            {
+                if (_listeners == null)
+                {
+                    _listeners = new ArrayList();
+                }
+
+                _listeners.add(listener);
+            }
+        }
+
+        /**
+         *
+         *  Make this lock a writer. If a writer is already present, the call will block until
+         *  the lock is released by the writer.
+         *
+         */
+        public void writeLock() throws LockingException
+        {
+            while (true)
+            {
+                if (_writer != null && _writer._tx != _tx)
+                {
+                    waitForTx(_tx);
+                }
+
+                synchronized (ObjectLock.this)
+                {
+                    if (_writer == null || _writer._tx == _tx)
+                    {
+                        _writer = this;
+                        return;
+                    }
+                }
+            }
+        }
+
+        public void release()
+        {
+            synchronized (ObjectLock.this)
+            {
+                if (_writer == this)
+                {
+                    _writer = null;
+                }
+            }
+
+            _readers.remove(_tx);
+
+            if (_listeners != null)
+            {
+                for (Iterator iterator = _listeners.iterator(); iterator.hasNext();)
+                {
+                  LockListener listener = (LockListener) iterator.next();
+                  listener.lockReleased(_tx, _oid);
+                }
+            }
+        }
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/UnknownIsolationException.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/UnknownIsolationException.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/UnknownIsolationException.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/UnknownIsolationException.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,58 @@
+package org.apache.ojb.otm.lock;
+
+import org.apache.ojb.otm.core.OTMGenericException;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class UnknownIsolationException extends OTMGenericException
+{
+
+	/**
+	 * Constructor for UnknownIsolationException.
+	 */
+	public UnknownIsolationException()
+	{
+		super();
+	}
+
+	/**
+	 * Constructor for UnknownIsolationException.
+	 * @param msg
+	 */
+	public UnknownIsolationException(String msg)
+	{
+		super(msg);
+	}
+
+	/**
+	 * Constructor for UnknownIsolationException.
+	 * @param cause
+	 */
+	public UnknownIsolationException(Throwable cause)
+	{
+		super(cause);
+	}
+
+	/**
+	 * Constructor for UnknownIsolationException.
+	 * @param msg
+	 * @param cause
+	 */
+	public UnknownIsolationException(String msg, Throwable cause)
+	{
+		super(msg, cause);
+	}
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/AbstractIsolation.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/AbstractIsolation.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/AbstractIsolation.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/AbstractIsolation.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,28 @@
+package org.apache.ojb.otm.lock.isolation;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ * <javadoc>
+ * 
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ * 
+ */
+public abstract class AbstractIsolation implements TransactionIsolation
+{
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/ReadCommittedIsolation.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/ReadCommittedIsolation.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/ReadCommittedIsolation.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/ReadCommittedIsolation.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,66 @@
+package org.apache.ojb.otm.lock.isolation;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/**
+ *
+ * READ_COMMITTED IsolationStrategy.
+ *
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ * @author Thomas Mahler & David Dixon-Peugh
+ *
+ */
+public class ReadCommittedIsolation extends AbstractIsolation
+{
+
+    /**
+     * @see org.apache.ojb.otm.lock.TransactionIsolation#readLock(Transaction, ObjectLocks)
+     */
+    public void readLock(Transaction tx, ObjectLock lock)
+        throws LockingException
+    {
+        Transaction writer = lock.getWriter();
+        if (writer == null)
+        {
+            lock.readLock(tx);
+            if (lock.getWriter() != null)
+            {
+                lock.releaseLock(tx);
+                readLock(tx, lock);
+            }
+        }
+        else if (tx != writer)
+        {
+            lock.waitForTx(writer);
+            readLock(tx, lock);
+        }
+        // else if tx is the writer, it can also read.
+    }
+
+    /**
+     * @see org.apache.ojb.otm.lock.TransactionIsolation#writeLock(Transaction, ObjectLocks)
+     */
+    public void writeLock(Transaction tx, ObjectLock lock)
+        throws LockingException
+    {
+        lock.writeLock(tx);
+    }
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/ReadUncommittedIsolation.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/ReadUncommittedIsolation.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/ReadUncommittedIsolation.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/ReadUncommittedIsolation.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,44 @@
+package org.apache.ojb.otm.lock.isolation;
+
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class ReadUncommittedIsolation extends AbstractIsolation
+{
+
+    /**
+     * @see org.apache.ojb.otm.lock.TransactionIsolation#lockForRead(Transaction, ObjectLocks)
+     */
+    public void readLock(Transaction tx, ObjectLock lock)
+    {
+        // Read locks are always granted
+        lock.readLock(tx);
+    }
+
+    /**
+     * @see org.apache.ojb.otm.lock.TransactionIsolation#lockForWrite(Transaction, ObjectLocks)
+     */
+    public void writeLock(Transaction tx, ObjectLock lock)
+        throws LockingException
+    {
+        // WriteLock will wait for an existing write lock to be released before it locks
+        // it for this transaction
+        lock.writeLock(tx);
+    }
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/RepeatableReadIsolation.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/RepeatableReadIsolation.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/RepeatableReadIsolation.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/RepeatableReadIsolation.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,82 @@
+package org.apache.ojb.otm.lock.isolation;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class RepeatableReadIsolation extends AbstractIsolation
+{
+
+    /**
+     * @see org.apache.ojb.otm.lock.isolation.TransactionIsolation#readLock(Transaction, ObjectLock)
+     */
+    public void readLock(Transaction tx, ObjectLock lock)
+        throws LockingException
+    {
+        Transaction writer = lock.getWriter();
+        if (writer == null)
+        {
+            lock.readLock(tx);
+            if (lock.getWriter() != null)
+            {
+                lock.releaseLock(tx);
+                readLock(tx, lock);
+            }
+        }
+        else if (tx != writer)
+        {
+            lock.waitForTx(writer);
+            readLock(tx, lock);
+        }
+        // else if tx is the writer, it can also read.
+    }
+
+    /**
+     * @see org.apache.ojb.otm.lock.isolation.TransactionIsolation#writeLock(Transaction, ObjectLock)
+     */
+    public void writeLock(Transaction tx, ObjectLock lock)
+        throws LockingException
+    {
+        Collection readers = lock.getReaders();
+        
+        if (!readers.isEmpty())
+        {
+            for (Iterator it = readers.iterator(); it.hasNext(); )
+            {
+                Transaction reader = (Transaction) it.next();
+
+                if (reader != tx)
+                {
+                    lock.waitForTx(reader);
+                    writeLock(tx, lock);
+                    return;
+                }
+            }
+        }
+        
+        lock.writeLock(tx);
+        readers = lock.getReaders();
+        if (readers.size() > 1)
+        {
+            lock.releaseLock(tx);
+            writeLock(tx, lock);
+        }
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/SerializableIsolation.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/SerializableIsolation.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/SerializableIsolation.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/SerializableIsolation.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,80 @@
+package org.apache.ojb.otm.lock.isolation;
+
+import java.util.Collection;
+
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class SerializableIsolation extends AbstractIsolation
+{
+
+    /**
+     * @see org.apache.ojb.otm.lock.isolation.TransactionIsolation#readLock(Transaction, ObjectLock)
+     */
+    public void readLock (Transaction tx, ObjectLock lock)
+        throws LockingException
+    {
+        Collection readers = lock.getReaders();
+        if (readers.isEmpty())
+        {
+            lock.readLock(tx);
+            readers = lock.getReaders();
+            if (readers.size() > 1)
+            {
+                lock.releaseLock(tx);
+                readLock(tx, lock);
+            }
+        }
+        else
+        {
+            Transaction reader = (Transaction) readers.iterator().next();
+
+            if (reader != tx) {
+                lock.waitForTx(reader);
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.ojb.otm.lock.isolation.TransactionIsolation#writeLock(Transaction, ObjectLock)
+     */
+    public void writeLock (Transaction tx, ObjectLock lock)
+        throws LockingException
+    {
+        Collection readers = lock.getReaders();
+        if (readers.isEmpty())
+        {
+            readLock(tx, lock);
+            writeLock(tx, lock);
+        }
+        else
+        {
+            Transaction reader = (Transaction) readers.iterator().next();
+            if (reader == tx)
+            {
+                lock.writeLock(tx);
+            }
+            else
+            {
+                lock.waitForTx(reader);
+                writeLock(tx, lock);
+            }
+        }
+    }
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/TransactionIsolation.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/TransactionIsolation.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/TransactionIsolation.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/isolation/TransactionIsolation.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,37 @@
+package org.apache.ojb.otm.lock.isolation;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/**
+ *
+ * <javadoc>
+ * 
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ * 
+ */
+public interface TransactionIsolation
+{
+    
+    public void readLock (Transaction tx, ObjectLock locks)
+        throws LockingException;
+    
+    public void writeLock (Transaction tx, ObjectLock locks)
+        throws LockingException;
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/map/InMemoryLockMap.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/map/InMemoryLockMap.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/map/InMemoryLockMap.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/map/InMemoryLockMap.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,84 @@
+package org.apache.ojb.otm.lock.map;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/**
+ *
+ * <javadoc>
+ *
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ *
+ */
+public class InMemoryLockMap implements LockMap
+{
+
+    private HashMap _locks;
+
+    public InMemoryLockMap ()
+    {
+        _locks = new HashMap();
+    }
+
+
+    /**
+     *
+     * @see org.apache.ojb.otm.lock.map.LockMap#getLock(Identity)
+     *
+     */
+    public ObjectLock getLock(Identity oid)
+    {
+        ObjectLock lock;
+
+        synchronized (_locks)
+        {
+            lock = (ObjectLock) _locks.get(oid);
+            if (lock == null)
+            {
+                lock = new ObjectLock(oid);
+                _locks.put(oid, lock);
+            }
+        }
+        return lock;
+    }
+
+    public void gc()
+    {
+        synchronized (_locks)
+        {
+            for (Iterator it = _locks.entrySet().iterator(); it.hasNext(); )
+            {
+                Map.Entry entry = (Map.Entry) it.next();
+                ObjectLock lock = (ObjectLock) entry.getValue();
+                if (lock.isFree())
+                {
+                    it.remove();
+                }
+            }
+        }
+    }
+
+    public String toString()
+    {
+        return _locks.toString();
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/map/LockMap.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/map/LockMap.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/map/LockMap.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/map/LockMap.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,40 @@
+package org.apache.ojb.otm.lock.map;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/**
+ *
+ * <javadoc>
+ *
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ *
+ */
+public interface LockMap
+{
+    
+    public ObjectLock getLock(Identity oid);
+
+    /**
+     * This is "garbage collection" - remove free locks from 
+     * the map. This method is called at the end of each transaction.
+     * Maybe that would be better to call it by timer?
+     */
+    public void gc();
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/ConcurrentModificationException.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/ConcurrentModificationException.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/ConcurrentModificationException.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/ConcurrentModificationException.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,59 @@
+package org.apache.ojb.otm.lock.wait;
+
+/* Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.otm.lock.LockingException;
+
+public class ConcurrentModificationException extends LockingException
+{
+
+	/**
+	 * Constructor for ConcurrentModificationException.
+	 */
+	public ConcurrentModificationException()
+	{
+		super();
+	}
+
+	/**
+	 * Constructor for ConcurrentModificationException.
+	 * @param message
+	 */
+	public ConcurrentModificationException(String message)
+	{
+		super(message);
+	}
+
+	/**
+	 * Constructor for ConcurrentModificationException.
+	 * @param exception
+	 */
+	public ConcurrentModificationException(Throwable exception)
+	{
+		super(exception);
+	}
+
+	/**
+	 * Constructor for ConcurrentModificationException.
+	 * @param message
+	 * @param exception
+	 */
+	public ConcurrentModificationException(String message, Throwable exception)
+	{
+		super(message, exception);
+	}
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/DeadlockException.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/DeadlockException.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/DeadlockException.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/DeadlockException.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,66 @@
+package org.apache.ojb.otm.lock.wait;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.otm.lock.LockingException;
+
+/**
+ *
+ * <javadoc>
+ * 
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ * 
+ */
+public class DeadlockException extends LockingException
+{
+
+	/**
+	 * Constructor for DeadlockException.
+	 */
+	public DeadlockException()
+	{
+		super();
+	}
+
+	/**
+	 * Constructor for DeadlockException.
+	 * @param message
+	 */
+	public DeadlockException(String message)
+	{
+		super(message);
+	}
+
+	/**
+	 * Constructor for DeadlockException.
+	 * @param exception
+	 */
+	public DeadlockException(Throwable exception)
+	{
+		super(exception);
+	}
+
+	/**
+	 * Constructor for DeadlockException.
+	 * @param message
+	 * @param exception
+	 */
+	public DeadlockException(String message, Throwable exception)
+	{
+		super(message, exception);
+	}
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/LockWaitStrategy.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/LockWaitStrategy.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/LockWaitStrategy.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/LockWaitStrategy.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,39 @@
+package org.apache.ojb.otm.lock.wait;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/**
+ *
+ * LockWaitStrategy is responsible for waiting for a particular lock to be released. Typically, the
+ * LockWaitStrategy implements deadlock prevention/detection/recovery mechanisms.
+ *
+ * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
+ *
+ */
+public interface LockWaitStrategy
+{
+    
+    /**
+     * @param lock The lock that the tx is waiting for
+     * @param tx The waiting tx
+     */
+    public void waitForLock(ObjectLock lock, Transaction tx)
+            throws LockingException;
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/NoWaitStrategy.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/NoWaitStrategy.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/NoWaitStrategy.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/NoWaitStrategy.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,35 @@
+package org.apache.ojb.otm.lock.wait;
+
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class NoWaitStrategy implements LockWaitStrategy
+{
+
+    /**
+    * @see org.apache.ojb.otm.lock.wait.LockWaitStrategy#waitForLock(ObjectLock, Transaction)
+    */
+    public void waitForLock(ObjectLock lock, Transaction tx)
+        throws LockingException
+    {
+        throw new ConcurrentModificationException(
+            "Object [id: " + lock.getTargetIdentity() 
+            + "] locked by Transaction " + lock.getWriter());
+    }
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/TimeoutStrategy.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/TimeoutStrategy.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/TimeoutStrategy.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/lock/wait/TimeoutStrategy.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,134 @@
+package org.apache.ojb.otm.lock.wait;
+
+import java.util.HashMap;
+import org.apache.ojb.otm.core.Transaction;
+import org.apache.ojb.otm.lock.LockingException;
+import org.apache.ojb.otm.lock.ObjectLock;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class TimeoutStrategy implements LockWaitStrategy
+{
+
+    /**
+     * Maps tx to the lock that tx waits for.
+     * Is used for deadlock detection
+     */
+    private static HashMap _waitsFor = new HashMap();
+
+    private long _timeout;
+
+    /**
+     * @param timeout the number of milliseconds to wait before throwing exception
+     */
+    public TimeoutStrategy(long timeout)
+    {
+        if (timeout <= 0)
+        {
+            throw new IllegalArgumentException("Illegal timeout value: " + timeout);
+        }
+        _timeout = timeout;
+    }
+
+    /**
+     * The default timeout is 30 seconds
+     */
+    public TimeoutStrategy() 
+    {
+        this(30000);
+    }
+
+    /**
+    * @see org.apache.ojb.otm.lock.wait.LockWaitStrategy#waitForLock(ObjectLock, Transaction)
+    */
+    public void waitForLock(ObjectLock lock, Transaction tx)
+        throws LockingException
+    {
+        Transaction writerTx;
+        ObjectLock writerWaitsForLock;
+
+        // test for deadlock
+        writerTx = lock.getWriter();
+        while (writerTx != null)
+        {
+            writerWaitsForLock = (ObjectLock) _waitsFor.get(writerTx);
+            if (writerWaitsForLock == null)
+            {
+                break;
+            }
+            writerTx = writerWaitsForLock.getWriter();
+            if (writerTx == null)
+            {
+                break;
+            }
+            if (writerTx == tx)
+            {
+                StringBuffer sb = new StringBuffer();
+
+                // deadlock detected.
+                // Now we traverse the cycle once more to provide more info
+                writerTx = lock.getWriter();
+                sb.append(lock.getTargetIdentity());
+                while (writerTx != tx)
+                {
+                    writerWaitsForLock = (ObjectLock) _waitsFor.get(writerTx);
+                    sb.append(" -> ");
+                    sb.append(writerWaitsForLock.getTargetIdentity());
+                    writerTx = writerWaitsForLock.getWriter();
+                }
+                throw new DeadlockException(sb.toString());
+            }
+        }
+
+        // No deadlock detected, then wait the given timeout
+        _waitsFor.put(tx, lock);
+        try
+        {
+            long now = System.currentTimeMillis();
+            long deadline = System.currentTimeMillis() + _timeout;
+
+            do
+            {
+                if (lock.getWriter() == null)
+                {
+                    return;
+                }
+
+                try
+                {
+                    long toSleep = Math.min(deadline - now, 1000);
+                    Thread.sleep(toSleep);
+                    now += toSleep;
+                } catch (InterruptedException ex) {
+                    now = System.currentTimeMillis();
+                }
+            }
+            while (now < deadline);
+
+            writerTx = lock.getWriter();
+
+            if (writerTx != null)
+            {
+                throw new ConcurrentModificationException(
+                        "Object [id: " + lock.getTargetIdentity()
+                        + "] locked by Transaction " + writerTx);
+            }
+        }
+        finally
+        {
+            _waitsFor.remove(tx);
+        }
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/Hollow.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/Hollow.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/Hollow.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/Hollow.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,72 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * this state represents persistent objects outside of transaction
+ * (no ODMG equivalent).
+ */
+public class Hollow extends State
+{
+
+    Hollow()
+    {
+    }
+
+    /**
+     * return a String representation
+     */
+    public String toString()
+    {
+        return "Hollow";
+    }
+
+    //-------------- State transitions --------------------
+
+    /**
+     * Describes the state transition when object is gotten from the cache
+     * or is loaded from database (once per transaction).
+     */
+    public State getObject()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_CLEAN;
+    }
+
+    /**
+     * Describes the state transition when user modifies object
+     */
+    public State markDirty()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_DIRTY;
+    }
+
+    /**
+     * Describes the state transition on deletePersistent()
+     */
+    public State deletePersistent()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_DELETED;
+    }
+
+    public State rollback()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/IllegalObjectStateException.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/IllegalObjectStateException.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/IllegalObjectStateException.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/IllegalObjectStateException.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,64 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.otm.core.OTMGenericException;
+
+/**
+ *
+ * Exception on illegal object state.
+ *
+ */
+public class IllegalObjectStateException extends OTMGenericException
+{
+
+	/**
+	 * Constructor for IllegalObjectStateException.
+	 */
+	public IllegalObjectStateException()
+	{
+		super();
+	}
+
+	/**
+	 * Constructor for IllegalObjectStateException.
+	 * @param msg
+	 */
+	public IllegalObjectStateException(String msg)
+	{
+		super(msg);
+	}
+
+	/**
+	 * Constructor for IllegalObjectStateException.
+	 * @param cause
+	 */
+	public IllegalObjectStateException(Throwable cause)
+	{
+		super(cause);
+	}
+
+	/**
+	 * Constructor for IllegalObjectStateException.
+	 * @param msg
+	 * @param cause
+	 */
+	public IllegalObjectStateException(String msg, Throwable cause)
+	{
+		super(msg, cause);
+	}
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentClean.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentClean.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentClean.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentClean.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,78 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * this state represents old Objects (i.e. already persistent but not changed during tx)
+ * --> no need to do anything for commit or rollback (ODMG StateOldClean).
+ */
+public class PersistentClean extends State
+{
+
+    PersistentClean()
+    {
+    }
+
+    /**
+     * return a String representation
+     */
+    public String toString()
+    {
+        return "Persistent-clean";
+    }
+
+    //-------------- State transitions --------------------
+
+    /**
+     * Describes the state transition when user modifies object
+     */
+    public State markDirty()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_DIRTY;
+    }
+    
+    /**
+     * Describes the state transition on deletePersistent()
+     */
+    public State deletePersistent()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_DELETED;
+    }
+    
+    /**
+     * Describes the state transition on commit()
+     */
+    public State commit()
+            throws IllegalObjectStateException
+    {
+        return State.HOLLOW;
+    }
+
+    /**
+     * Describes the state transition on rollback()
+     */
+    public State rollback()
+            throws IllegalObjectStateException
+    {
+        return State.HOLLOW;
+    }
+
+
+    //-------------- State semantics --------------------
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentDeleted.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentDeleted.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentDeleted.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentDeleted.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,91 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * this state represents old objects which have been marked for deletion
+ * during tx (ODMG StateOldDelete).
+ */
+public class PersistentDeleted extends State
+{
+    
+    PersistentDeleted()
+    {
+    }
+
+    /**
+     * return a String representation
+     */
+    public String toString()
+    {
+        return "Persistent-deleted";
+    }
+
+    //-------------- State transitions --------------------
+
+    /**
+     * Describes the state transition on makePersistent()
+     */
+    public State makePersistent()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_DIRTY;
+    }
+
+    /**
+     * Describes the state transition on deletePersistent()
+     */
+    public State deletePersistent()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+
+    /**
+     * Describes the state transition on commit()
+     */
+    public State commit()
+            throws IllegalObjectStateException
+    {
+        return State.TRANSIENT;
+    }
+
+    /**
+     * Describes the state transition on rollback()
+     */
+    public State rollback()
+            throws IllegalObjectStateException
+    {
+        return State.HOLLOW;
+    }
+
+
+    //-------------- State semantics --------------------
+
+    /**
+     * returns true is this state requires DELETE
+     * @return boolean
+     */
+    public boolean needsDelete()
+    {
+        return true;
+    }
+
+    public boolean isDeleted()
+    {
+        return true;
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentDirty.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentDirty.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentDirty.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentDirty.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,100 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * this state represents persistent objects which have been altered 
+ * during tx (ODMG StateOldDirty).
+ */
+public class PersistentDirty extends State
+{
+
+    PersistentDirty()
+    {
+    }
+
+    /**
+     * return a String representation
+     */
+    public String toString()
+    {
+        return "Persistent-dirty";
+    }
+
+    //-------------- State transitions --------------------
+
+    /**
+     * Describes the state transition when user modifies object
+     */
+    public State markDirty()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+
+    /**
+     * Describes the state transition on makePersistent()
+     */
+    public State makePersistent()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+
+    /**
+     * Describes the state transition on deletePersistent()
+     */
+    public State deletePersistent()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_DELETED;
+    }
+
+    /**
+     * Describes the state transition on commit()
+     */
+    public State commit()
+            throws IllegalObjectStateException
+    {
+        return State.HOLLOW;
+    }
+
+    /**
+     * Describes the state transition on rollback()
+     */
+    public State rollback()
+            throws IllegalObjectStateException
+    {
+        return State.HOLLOW;
+    }
+
+    public State refresh()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_CLEAN;
+    }
+
+    //-------------- State semantics --------------------
+
+    /**
+     * returns true is this state requires UPDATE
+     */
+    public boolean needsUpdate()
+    {
+        return true;
+    }
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentNew.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentNew.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentNew.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentNew.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,95 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * this state represents new objects which must be created during tx
+ * (ODMG StateNewDirty).
+ */
+public class PersistentNew extends State
+{
+
+    PersistentNew()
+    {
+    }
+
+    /**
+     * return a String representation
+     */
+    public String toString()
+    {
+        return "Persistent-new";
+    }
+
+    //-------------- State transitions --------------------
+
+    /**
+     * Describes the state transition when user modifies object
+     */
+    public State markDirty()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+
+    /**
+     * Describes the state transition on makePersistent()
+     */
+    public State makePersistent()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+
+    /**
+     * Describes the state transition on deletePersistent()
+     */
+    public State deletePersistent()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_NEW_DELETED;
+    }
+
+    /**
+     * Describes the state transition on commit()
+     */
+    public State commit()
+            throws IllegalObjectStateException
+    {
+        return State.HOLLOW;
+    }
+
+    /**
+     * Describes the state transition on rollback()
+     */
+    public State rollback()
+            throws IllegalObjectStateException
+    {
+        return State.TRANSIENT;
+    }
+
+
+    //-------------- State semantics --------------------
+
+    /**
+     * object is new, thus we need an INSERT to store it
+     */
+    public boolean needsInsert()
+    {
+        return true;
+    }
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentNewDeleted.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentNewDeleted.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentNewDeleted.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/PersistentNewDeleted.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,79 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * this state represents new objects which have been mrked for deletion during tx
+ * (ODMG StateNewDelete).
+ */
+public class PersistentNewDeleted extends State
+{
+
+    PersistentNewDeleted()
+    {
+    }
+
+    /**
+     * return a String representation
+     */
+    public String toString()
+    {
+        return "Persistent-new-deleted";
+    }
+
+    //-------------- State transitions --------------------
+
+    /**
+     * Describes the state transition on makePersistent()
+     */
+    public State makePersistent()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_NEW;
+    }
+
+    /**
+     * Describes the state transition on deletePersistent()
+     */
+    public State deletePersistent()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+
+    /**
+     * Describes the state transition on commit()
+     */
+    public State commit()
+            throws IllegalObjectStateException
+    {
+        return State.TRANSIENT;
+    }
+
+    /**
+     * Describes the state transition on rollback()
+     */
+    public State rollback()
+            throws IllegalObjectStateException
+    {
+        return State.TRANSIENT;
+    }
+
+    public boolean isDeleted()
+    {
+        return true;
+    }
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/State.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/State.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/State.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/State.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,140 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.util.ObjectModification;
+
+/**
+ * Represents the state of object.
+ */
+public abstract class State implements ObjectModification
+{
+    public static final State TRANSIENT = new Transient();
+
+    public static final State PERSISTENT_CLEAN = new PersistentClean();
+
+    public static final State PERSISTENT_DIRTY = new PersistentDirty();
+
+    public static final State PERSISTENT_NEW = new PersistentNew();
+
+    public static final State PERSISTENT_DELETED = new PersistentDeleted();
+
+    public static final State PERSISTENT_NEW_DELETED = new PersistentNewDeleted();
+
+    public static final State HOLLOW = new Hollow();
+
+    //-------------- State transitions --------------------
+
+    /**
+     * Describes the state transition when object is gotten from the cache
+     * or is loaded from database (once per transaction).
+     */
+    public State getObject()
+            throws IllegalObjectStateException
+    {
+        throw new IllegalObjectStateException(this + " during getObject");
+    }
+
+    /**
+     * Describes the state transition when user modifies object
+     */
+    public State markDirty()
+            throws IllegalObjectStateException
+    {
+        throw new IllegalObjectStateException(this + " during markDirty()");
+    }
+
+    /**
+     * Describes the state transition on makePersistent()
+     */
+    public State makePersistent()
+            throws IllegalObjectStateException
+    {
+        throw new IllegalObjectStateException(this + " during makePersistent()");
+    }
+
+    /**
+     * Describes the state transition on deletePersistent()
+     */
+    public State deletePersistent()
+            throws IllegalObjectStateException
+    {
+        throw new IllegalObjectStateException(this + " during deletePersistent()");
+    }
+
+    /**
+     * Describes the state transition on commit()
+     */
+    public State commit()
+            throws IllegalObjectStateException
+    {
+        throw new IllegalObjectStateException(this + " during commit()");
+    }
+
+    /**
+     * Describes the state transition on rollback()
+     */
+    public State rollback()
+            throws IllegalObjectStateException
+    {
+        throw new IllegalObjectStateException(this + " during rollback()");
+    }
+
+    /**
+     * Describes the state transition on refresh()
+     */
+    public State refresh()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+
+
+    //-------------- State semantics --------------------
+
+    /**
+     * returns true is this state requires INSERT
+     */
+    public boolean needsInsert()
+    {
+        return false;
+    }
+
+    /**
+     * returns true is this state requires UPDATE
+     */
+    public boolean needsUpdate()
+    {
+        return false;
+    }
+
+    /**
+     * returns true is this state requires DELETE
+     */
+    public boolean needsDelete()
+    {
+        return false;
+    }
+
+    /**
+     * returns true is this state means that the object has been deleted
+     */
+    public boolean isDeleted()
+    {
+        return false;
+    }
+
+}

Added: db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/Transient.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/Transient.java?rev=428990&view=auto
==============================================================================
--- db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/Transient.java (added)
+++ db/ojb/trunk/proposals/otm/java/org/apache/ojb/otm/states/Transient.java Sat Aug  5 05:18:12 2006
@@ -0,0 +1,53 @@
+package org.apache.ojb.otm.states;
+
+/* Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * this state represents new objects not made persistent yet
+ * (ODMG StateNewClean) and already deleted objects.
+ */
+public class Transient extends State
+{
+
+    Transient()
+    {
+    }
+
+    /**
+     * return a String representation
+     */
+    public String toString()
+    {
+        return "Transient";
+    }
+
+    //-------------- State transitions --------------------
+
+    /**
+     * Describes the state transition on makePersistent()
+     */
+    public State makePersistent()
+            throws IllegalObjectStateException
+    {
+        return State.PERSISTENT_NEW;
+    }
+
+    public State rollback()
+            throws IllegalObjectStateException
+    {
+        return this;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message