db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r538355 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/TransactionImpl.java
Date Tue, 15 May 2007 22:53:16 GMT
Author: arminw
Date: Tue May 15 15:53:15 2007
New Revision: 538355

URL: http://svn.apache.org/viewvc?view=rev&rev=538355
Log:
use PersistenceChecker to detect object state, optimize source

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/TransactionImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/TransactionImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/TransactionImpl.java?view=diff&rev=538355&r1=538354&r2=538355
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/TransactionImpl.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/TransactionImpl.java Tue
May 15 15:53:15 2007
@@ -193,11 +193,11 @@
      */
     public boolean isOpen()
     {
-        return (getStatus() == Status.STATUS_ACTIVE ||
-                getStatus() == Status.STATUS_MARKED_ROLLBACK ||
-                getStatus() == Status.STATUS_PREPARED ||
-                getStatus() == Status.STATUS_PREPARING ||
-                getStatus() == Status.STATUS_COMMITTING);
+        return (txStatus == Status.STATUS_ACTIVE ||
+                txStatus == Status.STATUS_MARKED_ROLLBACK ||
+                txStatus == Status.STATUS_PREPARED ||
+                txStatus == Status.STATUS_PREPARING ||
+                txStatus == Status.STATUS_COMMITTING);
     }
 
     private void checkOpen()
@@ -206,7 +206,7 @@
         {
             throw new TransactionNotInProgressException(
                     "Transaction was not open, call tx.begin() before perform action, current
status is: " +
-                    TxUtil.getStatusString(getStatus()));
+                    TxUtil.getStatusString(txStatus));
         }
     }
 
@@ -239,7 +239,7 @@
         if (log.isDebugEnabled()) log.debug("lock object was called on tx " + this + ", object
is " + obj.toString());
         checkOpen();
         RuntimeObject rtObject = new RuntimeObject(obj, this);
-        lockAndRegister(rtObject, lockMode, isImplicitLocking());
+        lockAndRegister(rtObject, lockMode, implicitLocking);
     }
 
     /**
@@ -248,7 +248,7 @@
      */
     public void lockAndRegister(RuntimeObject rtObject, int lockMode)
     {
-        lockAndRegister(rtObject, lockMode, isImplicitLocking());
+        lockAndRegister(rtObject, lockMode, implicitLocking);
     }
 
     /**
@@ -501,7 +501,7 @@
                 log.error("Unexpected error while unregister transaction from proxy listener",
e);
             }
 
-            LockManager lm = getImplementation().getLockManager();
+            LockManager lm = implementation.getLockManager();
             // this call is important to unlock registered
             // objects and unregistered proxies
             lm.releaseLocks(this);
@@ -692,8 +692,6 @@
      * indicating whether the lock was granted instead of generating an exception.
      * @param  obj          Description of Parameter
      * @param  lockMode     Description of Parameter
-     * @return              Description of the Returned Value
-     * </code>, <code>UPGRADE</code> , and <code>WRITE</code>
.
      * @return true          if the lock has been acquired, otherwise false.
      */
     public boolean tryLock(Object obj, int lockMode)
@@ -1111,7 +1109,7 @@
             }
             ClassDescriptor cld = getBroker().getClassDescriptor(materializedObject.getClass());
             RuntimeObject rt = new RuntimeObject(getBrokerInternal(), materializedObject,
oid, cld, false);
-            lockAndRegister(rt, Transaction.READ, isImplicitLocking());
+            lockAndRegister(rt, Transaction.READ, implicitLocking);
         }
         catch (Throwable t)
         {
@@ -1167,7 +1165,7 @@
     {
         registerToIndirectionHandler(handler);
         // TODO: remove this section when deprecated locking classes are removed
-        if(!(getImplementation().getLockManager() instanceof LockManagerOdmgImpl))
+        if(!(implementation.getLockManager() instanceof LockManagerOdmgImpl))
         {
             unmaterializedLocks.add(rtObj);
         }
@@ -1188,7 +1186,7 @@
     public void releaseUnmaterialzedLocks()
     {
         // TODO: remove this method when deprecated locking classes are removed
-        LockManager lm = getImplementation().getLockManager();
+        LockManager lm = implementation.getLockManager();
         if(!(lm instanceof LockManagerOdmgImpl) && unmaterializedLocks.size() >
0)
         {
             //remove locks for objects which haven't been materialized yet
@@ -1314,7 +1312,7 @@
             else
             {
                 RuntimeObject rt = new RuntimeObject(o, this, false);
-                lockAndRegister(rt, Transaction.READ, isImplicitLocking());
+                lockAndRegister(rt, Transaction.READ, implicitLocking);
             }
         }
         unregisterFromCollectionProxy(colProxy);
@@ -1387,37 +1385,19 @@
      */
     protected boolean isTransient(ClassDescriptor cld, Object obj, Identity oid)
     {
-        // if the Identity is transient we assume a non-persistent object
-        boolean isNew = oid.isTransient();
-        /*
-        detection of transient objects is costly (select of ID in DB to check if object
-        already exists) we do:
-        a. check if the object identity mark the specified object as transient
-        b. lookup from cache
-        c. and if not found, last option select on DB
-        */
-        if(!isNew)
+        boolean isTransient;
+        ObjectEnvelope mod = objectEnvelopeTable.getByIdentity(oid);
+        if(mod != null)
         {
-            ObjectEnvelope mod = objectEnvelopeTable.getByIdentity(oid);
-            if(mod != null)
-            {
-                // already registered object, use current state
-                isNew = mod.needsInsert();
-            }
-            else if(!optimizedTransientObjectDetection || cld.getAutoIncrementFields().length
< 1)
-            {
-                PersistenceBrokerInternal pb = getBrokerInternal();
-                if(cld == null)
-                {
-                    cld = pb.getClassDescriptor(obj.getClass());
-                }
-                // if object was found cache, assume it's old
-                // else make costly check against the DB
-                isNew = pb.serviceObjectCache().lookup(oid) == null
-                        && !pb.serviceBrokerHelper().doesExist(cld, oid, obj);
-            }
+            // already registered object, use current state
+            isTransient = mod.needsInsert();
+        }
+        else
+        {
+            isTransient = !objectEnvelopeTable.getTransaction().getBrokerInternal()
+                    .getPersistenceChecker().isPersistent(obj, cld, oid);
         }
-        return isNew;
+        return isTransient;
     }
 
     /**
@@ -1500,7 +1480,7 @@
             /*
             arminw: Here we use the auto-delete flag defined in metadata
             */
-            result = ord.getCascadingDelete() == ObjectReferenceDescriptor.CASCADE_OBJECT;
+            result = ord.isCascadingDeleteObject();
         }
         else
         {
@@ -1569,7 +1549,7 @@
     public String toString()
     {
         return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
-                .append("tx-status", TxUtil.getStatusString(getStatus()))
+                .append("tx-status", TxUtil.getStatusString(txStatus))
                 .append("unclosed_broker", this.broker != null && !broker.isClosed())
                 .toString();
     }



---------------------------------------------------------------------
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