db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/odmg TransactionImpl.java
Date Tue, 10 Feb 2004 15:28:18 GMT
arminw      2004/02/10 07:28:18

  Modified:    src/java/org/apache/ojb/odmg TransactionImpl.java
  Log:
  add more logging info
  
  Revision  Changes    Path
  1.53      +88 -60    db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- TransactionImpl.java	8 Feb 2004 13:19:46 -0000	1.52
  +++ TransactionImpl.java	10 Feb 2004 15:28:18 -0000	1.53
  @@ -54,6 +54,16 @@
    * <http://www.apache.org/>.
    */
   
  +import javax.transaction.Status;
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.Collection;
  +import java.util.Enumeration;
  +import java.util.Hashtable;
  +import java.util.Iterator;
  +import java.util.Vector;
  +
  +import org.apache.commons.lang.SystemUtils;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.OJBRuntimeException;
  @@ -62,9 +72,9 @@
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
  -import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.accesslayer.MaterializationListener;
  +import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  @@ -86,15 +96,6 @@
   import org.odmg.TransactionAbortedException;
   import org.odmg.TransactionNotInProgressException;
   
  -import javax.transaction.Status;
  -import java.util.ArrayList;
  -import java.util.Collection;
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -import java.util.Iterator;
  -import java.util.Vector;
  -import java.util.Arrays;
  -
   /**
    *
    * Implementation of Transaction for org.odmg.Transaction.
  @@ -316,7 +317,7 @@
           if broker isn't in PB-tx, start tx
           */
           if (log.isDebugEnabled()) log.debug("call beginTransaction() on PB instance");
  -        if(!getBroker().isInTransaction()) broker.beginTransaction();
  +        if (!getBroker().isInTransaction()) broker.beginTransaction();
   
           // Notify objects of impending commits.
           Enumeration enum = objectEnvelopeTable.elements();
  @@ -428,7 +429,7 @@
                   e.printStackTrace();
               }
           }
  -        if(broker != null && !broker.isClosed())
  +        if (broker != null && !broker.isClosed())
           {
               try
               {
  @@ -467,7 +468,7 @@
           }
           catch (Throwable t)
           {
  -            log.error("checkpoint failed",t);
  +            log.error("checkpoint failed", t);
               try
               {
                   doAbort();
  @@ -481,10 +482,10 @@
               {
                   throw (TransactionAbortedException) t;
               }
  -			if (t instanceof LockNotGrantedException)
  -			{
  -				throw (LockNotGrantedException) t;
  -			}
  +            if (t instanceof LockNotGrantedException)
  +            {
  +                throw (LockNotGrantedException) t;
  +            }
               else
               {
                   throw new TransactionAbortedExceptionOJB(t);
  @@ -519,10 +520,10 @@
               {
                   throw (TransactionAbortedException) t;
               }
  -			if (t instanceof LockNotGrantedException)
  -			{
  -				throw (LockNotGrantedException) t;
  -			}
  +            if (t instanceof LockNotGrantedException)
  +            {
  +                throw (LockNotGrantedException) t;
  +            }
               else
               {
                   throw new TransactionAbortedExceptionOJB(t);
  @@ -664,11 +665,11 @@
               throw e;
           }
           catch (PersistenceBrokerSQLException pbse)
  -		{
  -			log.error("Could not prepare for commit: " + pbse.getMessage());
  -			m_txStatus = Status.STATUS_MARKED_ROLLBACK;
  -			throw pbse;
  -		}
  +        {
  +            log.error("Could not prepare for commit: " + pbse.getMessage());
  +            m_txStatus = Status.STATUS_MARKED_ROLLBACK;
  +            throw pbse;
  +        }
           return true;
       }
   
  @@ -682,13 +683,13 @@
           /*
           do nothing if already rolledback
           */
  -        if(m_txStatus == Status.STATUS_ROLLEDBACK)
  +        if (m_txStatus == Status.STATUS_ROLLEDBACK)
           {
               return;
           }
           if (m_txStatus != Status.STATUS_ACTIVE && m_txStatus != Status.STATUS_PREPARED
&&
                   m_txStatus != Status.STATUS_MARKED_ROLLBACK)
  -            throw new IllegalStateException("persist.noTransaction");
  +            throw new IllegalStateException("Illegal state for abort call, state was '"
+ TxUtil.getStatusString(m_txStatus) + "'");
           log.info("Abort transaction was called on tx " + this + ", associated PB was "
+ broker);
           try
           {
  @@ -828,7 +829,7 @@
   
           // no Proxy:
           if (objectToRegister == null)
  -          return;
  +            return;
           ObjectEnvelope envelope = objectEnvelopeTable.getByIdentity(new Identity(objectToRegister,
getBroker()));
           if ((envelope == null) || envelope.needsDelete())
           {
  @@ -867,7 +868,7 @@
           {
               if (!ProxyHelper.isProxy(obj) && (ref != null))
               {
  -            	Object refInstance = ProxyHelper.getRealObject(ref);
  +                Object refInstance = ProxyHelper.getRealObject(ref);
                   ClassDescriptor objCld = this.getBroker().getClassDescriptor(obj.getClass());
                   org.apache.ojb.broker.metadata.FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(objCld);
   
  @@ -875,13 +876,13 @@
                   ValueContainer[] refPkValues;
                   if (refInstance != null)
                   {
  -                  ClassDescriptor refCld = this.getBroker().getClassDescriptor(refInstance.getClass());
  -                  refPkValues = getBroker().serviceBrokerHelper().getKeyValues(refCld,
refInstance, false);
  +                    ClassDescriptor refCld = this.getBroker().getClassDescriptor(refInstance.getClass());
  +                    refPkValues = getBroker().serviceBrokerHelper().getKeyValues(refCld,
refInstance, false);
                   }
                   else
                   {
  -                  refPkValues = new ValueContainer[objFkFields.length];
  -                  Arrays.fill(refPkValues, null);
  +                    refPkValues = new ValueContainer[objFkFields.length];
  +                    Arrays.fill(refPkValues, null);
                   }
   
                   /**
  @@ -970,36 +971,62 @@
                    */
                   if (itemFkFields != null)
                   {
  -                    while (colIterator.hasNext())
  +                    Object item = null;
  +                    try
                       {
  -                        Object item = colIterator.next();
  -                        IndirectionHandler handler = ProxyHelper.getIndirectionHandler(item);
  -                        if (handler != null)
  +                        while (colIterator.hasNext())
                           {
  -                            if (!handler.alreadyMaterialized())
  +                            item = colIterator.next();
  +                            IndirectionHandler handler = ProxyHelper.getIndirectionHandler(item);
  +                            if (handler != null)
                               {
  -                                continue;
  +                                if (!handler.alreadyMaterialized())
  +                                {
  +                                    continue;
  +                                }
  +                                else
  +                                {
  +                                    item = handler.getRealSubject();
  +                                }
                               }
  -                            else
  +                            //if itemCld refers to an interface the foreignKeyFieldDescriptors
  +                            //have to be computed again for each concrete class
  +                            if (itemCld.isInterface())
                               {
  -                                item = handler.getRealSubject();
  +                                ClassDescriptor concreteItemCld = getBroker().getClassDescriptor(item.getClass());
  +                                itemFkFields = cds.getForeignKeyFieldDescriptors(concreteItemCld);
                               }
  +                            // provide all items in collection attributes
  +                            // with foreign key information before locking them!
  +                            for (int j = 0; j < itemFkFields.length; j++)
  +                            {
  +                                FieldDescriptor fld = itemFkFields[j];
  +                                fld.getPersistentField().set(item, objPkValues[j].getValue());
  +                            }
  +                            lock(item, lockMode);
                           }
  -                        //if itemCld refers to an interface the foreignKeyFieldDescriptors
  -                        //have to be computed again for each concrete class
  -                        if (itemCld.isInterface())
  -                        {
  -                            ClassDescriptor concreteItemCld = getBroker().getClassDescriptor(item.getClass());
  -                            itemFkFields = cds.getForeignKeyFieldDescriptors(concreteItemCld);
  -                        }
  -                        // provide all items in collection attributes
  -                        // with foreign key information before locking them!
  -                        for (int j = 0; j < itemFkFields.length; j++)
  -                        {
  -                            FieldDescriptor fld = itemFkFields[j];
  -                            fld.getPersistentField().set(item, objPkValues[j].getValue());
  -                        }
  -                        lock(item, lockMode);
  +                    }
  +                    catch (PersistenceBrokerException e)
  +                    {
  +                        String eol = SystemUtils.LINE_SEPARATOR;
  +                        log.error("Error while set FK in collection references[" +
  +                                eol + "current reference descriptor:" +
  +                                eol + cds.toXML() +
  +                                eol + "current item object: " + item +
  +                                eol + "main object class: " + newTxObject.getClass().getName()
+
  +                                eol + "]", e);
  +                        throw e;
  +                    }
  +                    catch (LockNotGrantedException e)
  +                    {
  +                        String eol = SystemUtils.LINE_SEPARATOR;
  +                        log.error("Lock not granted, while set FK in collection references["
+
  +                                eol + "current reference descriptor:" +
  +                                eol + cds.toXML() +
  +                                eol + "object to lock: " + item +
  +                                eol + "main object class: " + newTxObject.getClass().getName()
+
  +                                eol + "]", e);
  +                        throw e;
                       }
                   }
                   else
  @@ -1036,7 +1063,7 @@
               if (refObj != null)
               {
                   if (ProxyHelper.isProxy(refObj))
  -                {    
  +                {
                       lock(refObj, lockMode);
                   }
                   else if (!registeredForLock.contains(refObj))
  @@ -1194,11 +1221,12 @@
           useWriteLocks = odmgConfig.lockAssociationAsWrites();
           useImplicitLocking = odmgConfig.useImplicitLocking();
       }
  +
       /**
        * @see org.apache.ojb.odmg.TransactionExt#setImplicitLocking(boolean)
        */
       public synchronized void setImplicitLocking(boolean value)
       {
  -    	useImplicitLocking = value;
  +        useImplicitLocking = value;
       }
  -}
  \ No newline at end of file
  +}
  
  
  

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