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/test/org/apache/ojb OJB.properties
Date Sat, 18 Sep 2004 13:05:55 GMT
arminw      2004/09/18 06:05:55

  Modified:    src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        PersistenceBrokerConfiguration.java
               src/java/org/apache/ojb/broker/util/configuration/impl Tag:
                        OJB_1_0_RELEASE OjbConfiguration.java
               src/java/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        Identity.java
               src/java/org/apache/ojb/odmg/states Tag: OJB_1_0_RELEASE
                        StateNewClean.java StateNewDirty.java
               src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        DatabaseImpl.java ObjectEnvelope.java
                        ObjectEnvelopeTable.java TransactionImpl.java
               src/test/org/apache/ojb Tag: OJB_1_0_RELEASE OJB.properties
  Log:
  adpat classes for use with new locking package
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.4.2.1   +1 -3      db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.java
  
  Index: PersistenceBrokerConfiguration.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- PersistenceBrokerConfiguration.java	9 Apr 2004 13:22:28 -0000	1.4
  +++ PersistenceBrokerConfiguration.java	18 Sep 2004 13:05:55 -0000	1.4.2.1
  @@ -24,8 +24,6 @@
   
   public interface PersistenceBrokerConfiguration
   {
  -    public Class getConnectionFactoryClass();
  -
       public Class getObjectCacheClass();
   
       /**
  
  
  
  No                   revision
  No                   revision
  1.35.2.1  +5 -35     db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java
  
  Index: OjbConfiguration.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java,v
  retrieving revision 1.35
  retrieving revision 1.35.2.1
  diff -u -r1.35 -r1.35.2.1
  --- OjbConfiguration.java	1 Jun 2004 21:42:21 -0000	1.35
  +++ OjbConfiguration.java	18 Sep 2004 13:05:55 -0000	1.35.2.1
  @@ -17,6 +17,9 @@
   
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.locking.LockMapInMemoryImpl;
  +import org.apache.ojb.broker.locking.LockMap;
  +import org.apache.ojb.broker.locking.AbstractLockStrategy;
   import org.apache.ojb.broker.accesslayer.ConnectionFactory;
   import org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl;
   import org.apache.ojb.broker.cache.ObjectCache;
  @@ -36,12 +39,8 @@
   import org.apache.ojb.broker.util.pooling.PoolConfiguration;
   import org.apache.ojb.odmg.OdmgConfiguration;
   import org.apache.ojb.odmg.collections.DListImpl;
  -import org.apache.ojb.odmg.locking.AbstractLockStrategy;
   import org.apache.ojb.odmg.locking.LockManager;
  -import org.apache.ojb.odmg.locking.LockManagerDefaultImpl;
  -import org.apache.ojb.odmg.locking.LockMap;
  -import org.apache.ojb.odmg.locking.LockingConfiguration;
  -import org.apache.ojb.odmg.locking.InMemoryLockMapImpl;
  +import org.apache.ojb.odmg.locking.LockManagerOdmgImpl;
   
   /**
    * This class contains the runtime configuration of the OJB
  @@ -54,7 +53,6 @@
    */
   public class OjbConfiguration extends    ConfigurationAbstractImpl
                                 implements OdmgConfiguration,
  -                                         LockingConfiguration,
                                            PersistenceBrokerConfiguration,
                                            ProxyConfiguration,
                                            PBPoolConfiguration,
  @@ -69,7 +67,6 @@
       private String repositoryFilename;
       private Class objectCacheClass;
       private String[] objectCacheFilter;
  -    private Class connectionFactoryClass;
       private Class persistentFieldClass;
       private Class persistenceBrokerClass;
   
  @@ -94,8 +91,6 @@
       private boolean useImplicitLocking;
       private boolean lockAssociationAsWrites;
       private Class oqlCollectionClass;
  -    private Class lockManagerClass;
  -    private Class lockMapClass;
   
       // Metadata configuration
       private boolean useSerializedRepository;
  @@ -181,26 +176,11 @@
           this.objectCacheFilter = filters;
       }
   
  -    public Class getConnectionFactoryClass()
  -    {
  -        return connectionFactoryClass;
  -    }
  -
  -    public Class getLockManagerClass()
  -    {
  -        return lockManagerClass;
  -    }
  -
       public Class getOqlCollectionClass()
       {
           return oqlCollectionClass;
       }
   
  -    public Class getLockMapClass()
  -    {
  -        return lockMapClass;
  -    }
  -
       public Class getPersistentFieldClass()
       {
           return persistentFieldClass;
  @@ -276,16 +256,6 @@
           objectCacheClass = getClass("ObjectCacheClass", ObjectCacheDefaultImpl.class, ObjectCache.class);
           // load ObjectCache filters
           objectCacheFilter = getStrings("ObjectCacheFilter", "", ",");
  -
  -        // load ConnectionFactory Class
  -        connectionFactoryClass =
  -                getClass("ConnectionFactoryClass", ConnectionFactoryPooledImpl.class, ConnectionFactory.class);
  -
  -        // load LockManager Class
  -        lockManagerClass = getClass("LockManagerClass", LockManagerDefaultImpl.class, LockManager.class);
  -
  -        // load LockMap Class
  -        lockMapClass = getClass("LockMapClass", InMemoryLockMapImpl.class, LockMap.class);
   
           // load PersistentField Class
           persistentFieldClass =
  
  
  
  No                   revision
  No                   revision
  1.36.2.2  +8 -3      db-ojb/src/java/org/apache/ojb/broker/Identity.java
  
  Index: Identity.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/Identity.java,v
  retrieving revision 1.36.2.1
  retrieving revision 1.36.2.2
  diff -u -r1.36.2.1 -r1.36.2.2
  --- Identity.java	27 Jul 2004 00:33:12 -0000	1.36.2.1
  +++ Identity.java	18 Sep 2004 13:05:55 -0000	1.36.2.2
  @@ -329,8 +329,8 @@
        * equal for Identities where Identity.equals() returns true. Therefore
        * all primary key values that return a hashcode depending on its content
        * (this is assumed for String and Number) are taken into account. Additionally
  -     * the hashCode() of the Class this Identity is representing is taken into
  -     * account.
  +     * the hashCode() of the top-level class name of this Identity is representing
  +     * is taken into account.
        */
       public int hashCode()
       {
  @@ -342,7 +342,12 @@
           if(m_hashCode == null)
           {
               HashCodeBuilder hb = new HashCodeBuilder();
  +            /*
  +            the hashcode have to unique across different JVM, so we can't use
               hb.append(getObjectsTopLevelClass().hashCode());
  +            because Class identity is not same in different JVM
  +            */
  +            hb.append(getObjectsTopLevelClass().getName());
   
               for (int i = 0; i < m_pkValues.length; i++)
               {
  
  
  
  No                   revision
  No                   revision
  1.7.2.1   +2 -2      db-ojb/src/java/org/apache/ojb/odmg/states/StateNewClean.java
  
  Index: StateNewClean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateNewClean.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- StateNewClean.java	4 Apr 2004 23:53:40 -0000	1.7
  +++ StateNewClean.java	18 Sep 2004 13:05:55 -0000	1.7.2.1
  @@ -96,7 +96,7 @@
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.refreshObjectImage();
  +        mod.refreshObjectImage(broker);
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -107,7 +107,7 @@
       public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.refreshObjectImage();
  +        mod.refreshObjectImage(broker);
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  
  
  
  1.6.2.1   +3 -3      db-ojb/src/java/org/apache/ojb/odmg/states/StateNewDirty.java
  
  Index: StateNewDirty.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateNewDirty.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- StateNewDirty.java	4 Apr 2004 23:53:40 -0000	1.6
  +++ StateNewDirty.java	18 Sep 2004 13:05:55 -0000	1.6.2.1
  @@ -20,7 +20,7 @@
   import org.apache.ojb.odmg.ObjectEnvelope;
   
   /**
  - * this state represents new objects which have been altered during tx.
  + * This state represents new objects which have been altered during tx.
    */
   public class StateNewDirty extends ModificationState
   {
  @@ -97,7 +97,7 @@
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.refreshObjectImage();
  +        mod.refreshObjectImage(broker);
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -107,7 +107,7 @@
       public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.refreshObjectImage();
  +        mod.refreshObjectImage(broker);
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  
  
  
  No                   revision
  No                   revision
  1.26.2.2  +2 -11     db-ojb/src/java/org/apache/ojb/odmg/DatabaseImpl.java
  
  Index: DatabaseImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/DatabaseImpl.java,v
  retrieving revision 1.26.2.1
  retrieving revision 1.26.2.2
  diff -u -r1.26.2.1 -r1.26.2.2
  --- DatabaseImpl.java	14 Aug 2004 23:42:37 -0000	1.26.2.1
  +++ DatabaseImpl.java	18 Sep 2004 13:05:55 -0000	1.26.2.2
  @@ -366,20 +366,11 @@
   
           try
           {
  -            // check whether object's class is persistence capable
  -            PersistenceBroker broker = ((HasBroker) tx).getBroker();
  -            broker.getClassDescriptor(object.getClass());
               // if a ClassDescriptor was found, OJB knows how to persist the object
               // lock object for write in tx
               tx.lock(object, Transaction.WRITE);
           }
  -        catch (
  -                org
  -                .apache
  -                .ojb
  -                .broker
  -                .metadata
  -                .ClassNotPersistenceCapableException ex)
  +        catch (org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException ex)
           {
               log.error("Persistence object failed: " + object, ex);
               throw new org.odmg.ClassNotPersistenceCapableException(
  
  
  
  1.32.2.3  +39 -101   db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
  
  Index: ObjectEnvelope.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java,v
  retrieving revision 1.32.2.2
  retrieving revision 1.32.2.3
  diff -u -r1.32.2.2 -r1.32.2.3
  --- ObjectEnvelope.java	16 Sep 2004 12:34:45 -0000	1.32.2.2
  +++ ObjectEnvelope.java	18 Sep 2004 13:05:55 -0000	1.32.2.3
  @@ -21,7 +21,6 @@
    *
    */
   
  -import java.io.Serializable;
   import java.lang.reflect.Array;
   import java.util.Collection;
   import java.util.HashMap;
  @@ -30,6 +29,7 @@
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.core.proxy.IndirectionHandler;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  @@ -40,14 +40,14 @@
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.odmg.states.ModificationState;
  -import org.odmg.ODMGRuntimeException;
  +import org.apache.commons.lang.builder.ToStringBuilder;
   
   /**
    * ObjectEnvelope is used during ODMG transactions as a wrapper for a
    * persistent objects declaration
    *
    */
  -public class ObjectEnvelope implements ObjectModification, Serializable
  +public class ObjectEnvelope implements ObjectModification
   {
       static final long serialVersionUID = -829177767933340522L;
       /**
  @@ -60,7 +60,7 @@
       /**
        * myObj holds the object we are wrapping.
        */
  -    private transient Object myObj;
  +    private Object myObj;
   
       /**
        * beforeImage holds a mapping between field
  @@ -68,31 +68,30 @@
        * afterImage holds the mapping at the
        * end of the transaction.
        */
  -    private transient Map beforeImage;
  -    private transient TransactionImpl tx;
  +    private Map beforeImage;
  +    private ObjectEnvelopeTable buffer;
   
       /**
        *
        * Create a wrapper by providing an Object.
        */
  -    public ObjectEnvelope(Identity oid, Object obj, TransactionImpl aTx)
  +    public ObjectEnvelope(ObjectEnvelopeTable buffer, Identity oid, Object obj, PersistenceBroker
broker, boolean isNewObject)
       {
  -        tx = aTx;
  +        this.buffer = buffer;
           this.oid = oid;
           // TODO: do we really need to materialize??
           myObj = ProxyHelper.getRealObject(obj);
  -        refreshObjectImage();
  -        prepareInitialState();
  +        refreshObjectImage(broker);
  +        prepareInitialState(isNewObject);
       }
   
       public void close()
       {
           myObj = null;
           beforeImage = null;
  -        tx = null;
       }
   
  -    public void refreshObjectImage()
  +    public void refreshObjectImage(PersistenceBroker broker)
       {
           try
           {
  @@ -103,14 +102,13 @@
               // see in docs SequenceManagerNativeImpl
               if(beforeImage != null)
               {
  -                oid = new Identity(myObj, tx.getBroker());
  +                oid = broker.serviceIdentity().buildIdentity(myObj);
               }
  -            beforeImage = getMap();
  +            beforeImage = getMap(broker);
           }
           catch(Exception ex)
           {
               beforeImage = null;
  -            oid = null;
               throw new org.odmg.ClassNotPersistenceCapableException(ex.toString());
           }
       }
  @@ -202,10 +200,10 @@
       /**
        * getMap() will return the image of the Object.
        */
  -    private Map getMap() throws PersistenceBrokerException
  +    private Map getMap(PersistenceBroker broker) throws PersistenceBrokerException
       {
           Map fieldValues = new HashMap();
  -        ClassDescriptor mif = tx.getBroker().getClassDescriptor(getObject().getClass());
  +        ClassDescriptor mif = broker.getClassDescriptor(getObject().getClass());
           /**
            * MBAIRD
            * 1. register all fields of object that aren't collections or references
  @@ -341,31 +339,17 @@
        * sets the initial MoificationState of the wrapped object myObj. The initial state
will be StateNewDirty if myObj
        * is not persisten already. The state will be set to StateOldClean if the object is
already persistent.
        */
  -    private void prepareInitialState()
  +    private void prepareInitialState(boolean isNewObject)
       {
           // determine appropriate modification state
           ModificationState initialState = null;
  -        boolean needsInsert;
  -        try
  -        {
  -            // try to lookup the object.
  -            needsInsert = tx.getBroker().serviceObjectCache().lookup(oid) == null
  -                    && !tx.getBroker().serviceBrokerHelper().doesExist(
  -                    tx.getBroker().getClassDescriptor(myObj.getClass()), oid, myObj);
  -        }
  -        catch(PersistenceBrokerException ex)
  -        {
  -            LoggerFactory.getDefaultLogger().error("ObjectEnvelope: ", ex);
  -            throw new ODMGRuntimeException("Unexpected error while check existence of "
  -                    + myObj + ", exception was "+ ex);
  -        }
  -        if(needsInsert)
  +        if(isNewObject)
           {
               // if object is not already persistent it must be marked as new
               // it must be marked as dirty because it must be stored even if it will not
modified during tx
               initialState = org.apache.ojb.odmg.states.StateNewDirty.getInstance();
           }
  -        else if(tx.isDeleted(oid))
  +        else if(isDeleted(oid))
           {
               // if object is already persistent it will be marked as old.
               // it is marked as dirty as it has been deleted during tx and now it is inserted
again,
  @@ -383,6 +367,20 @@
       }
   
       /**
  +     * Checks if the object with the given identity has been deleted
  +     * within the transaction.
  +     * @param id The identity
  +     * @return true if the object has been deleted
  +     * @throws PersistenceBrokerException
  +     */
  +    public boolean isDeleted(Identity id)
  +    {
  +        ObjectEnvelope envelope = buffer.getByIdentity(id);
  +
  +        return (envelope == null ? false : envelope.needsDelete());
  +    }
  +
  +    /**
        * set the Modification state to a new value. Used during state transitions.
        * @param newModificationState org.apache.ojb.server.states.ModificationState
        */
  @@ -392,7 +390,7 @@
           {
               if(LoggerFactory.getDefaultLogger().isDebugEnabled())
               {
  -                LoggerFactory.getDefaultLogger().debug("transition: " + new Identity(this.myObj,
tx.getBroker()) + " ("
  +                LoggerFactory.getDefaultLogger().debug("object state transition for object
" + this.oid + " ("
                           + modificationState + " --> " + newModificationState + ")");
               }
               modificationState = newModificationState;
  @@ -405,28 +403,22 @@
        */
       public String toString()
       {
  -        String obj = null;
  -        if(myObj == null)
  -        {
  -            obj = "null";
  -        }
  -        else
  -        {
  -            obj = new Identity(myObj, tx.getBroker()).toString();
  -        }
  -        return obj + "(" + modificationState + ")";
  +        ToStringBuilder buf = new ToStringBuilder(this);
  +        buf.append("Identity", oid)
  +            .append("ModificationState", modificationState.toString());
  +        return buf.toString();
       }
   
       /**
        * checks whether object and internal clone differ and returns true if so, returns
false else.
        * @return boolean
        */
  -    public boolean hasChanged()
  +    public boolean hasChanged(PersistenceBroker broker)
       {
           Map currentImage = null;
           try
           {
  -            currentImage = getMap();
  +            currentImage = getMap(broker);
           }
           catch(Exception e)
           {
  @@ -436,58 +428,4 @@
   
           return hasChanged.booleanValue();
       }
  -
  -/*
  -arminw: we can't really restore object state with all dependencies and fields
  -without having a deep copy of the clean object. To avoid side-effects disable this
  -feature
  -*/
  -
  -//    public void rollback()
  -//    {
  -//    	if(myObj != null && beforeImage != null)
  -//    	{
  -//			ClassDescriptor mif = tx.getBroker().getClassDescriptor(getObject().getClass());
  -//			/**
  -//			 * Set all the field values back.
  -//			 */
  -//			FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
  -//			for (int i = 0; i < fieldDescs.length; i++)
  -//			{
  -//				 FieldDescriptor fd = fieldDescs[i];
  -//				 PersistentField f = fd.getPersistentField();
  -//
  -//				 Object value = beforeImage.get(fd.getColumnName());
  -//
  -//				 f.set(myObj, value);
  -//			}
  -//
  -//			/**
  -//			 * Set all the Object Reference values back
  -//			 * Don't know exactly what to do when the are identiy objects
  -//			 * (VirtualProxy or proxy classes)
  -//			 */
  -//			Iterator iter = mif.getObjectReferenceDescriptors().iterator();
  -//			while (iter.hasNext())
  -//			{
  -//				ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) iter.next();
  -//			 	Object temp = beforeImage.get(rds);
  -//
  -//			 	if(temp instanceof Identity)
  -//				{
  -//					// TODO what to do now? It was a VirtualProxy instance or a Proxy class.
  -//				}
  -//				else
  -//				{
  -//					rds.getPersistentField().set(myObj, temp);
  -//				}
  -//			}
  -//
  -//			/**
  -//			 * Now set all collections back. But we only stored DirtyMarks.
  -//			 * So what can be rolledback.?
  -//			 */
  -//			// Iterator collections = mif.getCollectionDescriptors().iterator();
  -//    	}
  -//    }
   }
  
  
  
  1.32.2.4  +47 -51    db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java
  
  Index: ObjectEnvelopeTable.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
  retrieving revision 1.32.2.3
  retrieving revision 1.32.2.4
  diff -u -r1.32.2.3 -r1.32.2.4
  --- ObjectEnvelopeTable.java	16 Sep 2004 12:34:45 -0000	1.32.2.3
  +++ ObjectEnvelopeTable.java	18 Sep 2004 13:05:55 -0000	1.32.2.4
  @@ -80,35 +80,21 @@
       private boolean needsCommit = false;
   
       /**
  -     * prepare this instance for reuse
  +     * Creates new ObjectEnvelopeTable
        */
  -    public void refresh()
  +    public ObjectEnvelopeTable(TransactionImpl myTransaction)
       {
  -        /**
  -         * MBAIRD: be nice and remove all references so they can be
  -         * gc'd
  -         */
  -        if (mhtObjectEnvelopes != null)
  -        {
  -            Iterator iter = mvOrderOfIds.iterator();
  -            ObjectEnvelope temp;
  -            while (iter.hasNext())
  -            {
  -                temp = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
  -                temp.close();
  -            }
  -        }
  -        needsCommit = false;
  -        mhtObjectEnvelopes.clear();
  -        mvOrderOfIds.clear();
  +        transaction = myTransaction;
       }
   
       /**
  -     * Creates new ObjectEnvelopeTable
  +     * prepare this instance for reuse
        */
  -    public ObjectEnvelopeTable(TransactionImpl myTransaction)
  +    public void refresh()
       {
  -        transaction = myTransaction;
  +        needsCommit = false;
  +        mhtObjectEnvelopes = new HashMap();
  +        mvOrderOfIds.clear();
       }
   
       /**
  @@ -284,7 +270,7 @@
   					ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
   					if(mod.getModificationState() != StateOldClean.getInstance())
   					{
  -						mod.refreshObjectImage();
  +						mod.refreshObjectImage(transaction.getBroker());
   						mod.setModificationState(StateOldClean.getInstance());
   					}
   			  }
  @@ -311,7 +297,7 @@
   				/**
   				 * second check is, has the object in the envelope changed.
   				 */
  -                if (mod.hasChanged())
  +                if (mod.hasChanged(transaction.getBroker()))
                   {
   					/**
   					 * now, the quickest thing to check is the useImplicitLocking flag. If we are using
  @@ -364,7 +350,7 @@
                   if (log.isDebugEnabled())
                       log.debug("rollback: " + mod);
                   // if the Object has been modified has been modified by transaction, mark
object as dirty
  -                if (mod.hasChanged())
  +                if (mod.hasChanged(transaction.getBroker()))
                   {
                       mod.setModificationState(mod.getModificationState().markDirty());
                   }
  @@ -389,7 +375,7 @@
           }
           else
           {
  -            id = new Identity(pKey, transaction.getBroker());
  +            id = transaction.getBroker().serviceIdentity().buildIdentity(pKey);
           }
           mhtObjectEnvelopes.remove(id);
           mvOrderOfIds.remove(id);
  @@ -423,35 +409,46 @@
        * If no ObjectEnvelope is found, a new one is created and returned.
        * @return the resulting ObjectEnvelope
        */
  -    public ObjectEnvelope get(Object pKey)
  +    public ObjectEnvelope get(Object pKey, boolean isNew)
       {
  -        Identity id = new Identity(pKey, transaction.getBroker());
  -        //Integer keyInteger = new Integer(System.identityHashCode(key));
  -        ObjectEnvelope result = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
  +        PersistenceBroker broker = transaction.getBroker();
  +        Identity oid = broker.serviceIdentity().buildIdentity(pKey);
  +        return get(oid, pKey, isNew);
  +    }
  +
  +    /**
  +     * retrieve an objects ObjectEnvelope state from the hashtable.
  +     * If no ObjectEnvelope is found, a new one is created and returned.
  +     * @return the resulting ObjectEnvelope
  +     */
  +    public ObjectEnvelope get(Identity oid, Object pKey, boolean isNew)
  +    {
  +        PersistenceBroker broker = transaction.getBroker();
  +        ObjectEnvelope result = getByIdentity(oid);
           if (result == null)
           {
  -            result = new ObjectEnvelope(id, pKey, transaction);
  -            mhtObjectEnvelopes.put(id, result);
  -            mvOrderOfIds.add(id);
  +            result = new ObjectEnvelope(this, oid, pKey, broker, isNew);
  +            mhtObjectEnvelopes.put(oid, result);
  +            mvOrderOfIds.add(oid);
               if (log.isDebugEnabled())
                   log.debug("register: " + result);
           }
           return result;
       }
   
  -    /**
  -     * store an objects transactional state into the Hashtable
  -     */
  -    public void put(Object pKey, ObjectEnvelope modification)
  -    {
  -        Identity id = new Identity(pKey, transaction.getBroker());
  -        //Integer keyInt = new Integer(System.identityHashCode(key));
  -        if (log.isDebugEnabled())
  -            log.debug("register: " + modification);
  -        if (!mhtObjectEnvelopes.containsKey(id))
  -            mvOrderOfIds.add(id);
  -        mhtObjectEnvelopes.put(id, modification);
  -    }
  +//    /**
  +//     * Register object.
  +//     */
  +//    public void put(Identity oid, Object pKey)
  +//    {
  +//        Identity id = transaction.getBroker().serviceIdentity().buildIdentity(pKey);
  +//        //Integer keyInt = new Integer(System.identityHashCode(key));
  +//        if (log.isDebugEnabled())
  +//            log.debug("register: " + modification);
  +//        if (!mhtObjectEnvelopes.containsKey(id))
  +//            mvOrderOfIds.add(id);
  +//        mhtObjectEnvelopes.put(id, modification);
  +//    }
   
       /**
        * Returns a String representation of this object
  @@ -472,11 +469,10 @@
       /**
        * retrieve an objects ObjectModification state from the hashtable
        */
  -    public boolean contains(Object pKey)
  +    public boolean contains(Identity oid)
       {
  -        Identity id = new Identity(pKey, transaction.getBroker());
           //Integer keyInteger = new Integer(System.identityHashCode(key));
  -        return mhtObjectEnvelopes.containsKey(id);
  +        return mhtObjectEnvelopes.containsKey(oid);
       }
   
       /**
  @@ -600,7 +596,7 @@
                       // Now we have to retrieve the ObjectEnvelope representing this
                       // Object from the hashtable, remove it from the vector and reorder
                       // the retrieved ObjectEnvelope.
  -                    Identity id = new Identity(colIterator.next(), transaction.getBroker());
  +                    Identity id = transaction.getBroker().serviceIdentity().buildIdentity(colIterator.next());
                       ObjectEnvelope oe = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
                       if (oe != null)
                       {
  @@ -636,7 +632,7 @@
               Object refObj = rds.getPersistentField().get(objectToReorder.getObject());
               if (refObj != null)
               {
  -                Identity id = new Identity(refObj, transaction.getBroker());
  +                Identity id = transaction.getBroker().serviceIdentity().buildIdentity(refObj);
                   ObjectEnvelope oe = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
                   if (oe != null)
                   {
  
  
  
  1.59.2.4  +45 -66    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.59.2.3
  retrieving revision 1.59.2.4
  diff -u -r1.59.2.3 -r1.59.2.4
  --- TransactionImpl.java	16 Sep 2004 12:34:45 -0000	1.59.2.3
  +++ TransactionImpl.java	18 Sep 2004 13:05:55 -0000	1.59.2.4
  @@ -224,10 +224,24 @@
        */
       protected void doLock(Object obj, int lockMode) throws LockNotGrantedException
       {
  -        if (!ProxyHelper.isProxy(obj))
  +        boolean isProxyObject = ProxyHelper.isProxy(obj);
  +        Identity oid = null;
  +        boolean isNewObject = false;
  +
  +        if (!isProxyObject)
           {
  +            PersistenceBroker broker = getBroker();
  +            ClassDescriptor cld = broker.getClassDescriptor(obj.getClass());
  +            isNewObject = broker.serviceBrokerHelper().hasNullPKField(cld, obj);
  +            oid = getBroker().serviceIdentity().buildIdentity(obj);
  +
  +            if(!isNewObject)
  +            {
  +                isNewObject = broker.serviceObjectCache().lookup(oid) == null
  +                            && !broker.serviceBrokerHelper().doesExist(cld, oid,
obj);
  +            }
  +
               if (log.isDebugEnabled()) log.debug("object is not a proxy");
  -            ClassDescriptor cld = this.getBroker().getClassDescriptor(obj.getClass());
               if (!cld.isAcceptLocks())
               {
                   if (log.isDebugEnabled())
  @@ -240,25 +254,30 @@
                       log.debug("proceeding with lock on class: " + cld.getClassNameOfObject()
+ " object " + obj.toString());
               }
           }
  +        else
  +        {
  +            IndirectionHandler handler = ProxyHelper.getIndirectionHandler(obj);
  +            oid = handler.getIdentity();
  +        }
   
           LockManager lm = LockManagerFactory.getLockManager();
           if (lockMode == Transaction.READ)
           {
  -            if (!lm.readLock(this, obj))
  +            if (!lm.readLock(this,oid, obj))
               {
                   throw new LockNotGrantedException("Can not lock for READ: " + obj);
               }
           }
           else if (lockMode == Transaction.WRITE)
           {
  -            if (!lm.writeLock(this, obj))
  +            if (!lm.writeLock(this, oid, obj))
               {
                   throw new LockNotGrantedException("Can not lock for WRITE: " + obj);
               }
           }
           else if (lockMode == Transaction.UPGRADE)
           {
  -            if (!lm.upgradeLock(this, obj))
  +            if (!lm.upgradeLock(this, oid, obj))
               {
                   throw new LockNotGrantedException("Can not lock for UPGRADE: " + obj);
               }
  @@ -266,7 +285,7 @@
           try
           {
               if (log.isDebugEnabled()) log.debug("registering lock on object at " + System.currentTimeMillis());
  -            register(obj, lockMode);
  +            register(oid, obj, lockMode, isNewObject);
           }
           catch (Throwable t)
           {
  @@ -490,7 +509,7 @@
        */
       public void markDelete(Object anObject)
       {
  -        ObjectEnvelope otw = objectEnvelopeTable.get(anObject);
  +        ObjectEnvelope otw = objectEnvelopeTable.get(anObject, false);
           otw.setModificationState(otw.getModificationState().markDelete());
       }
   
  @@ -499,7 +518,7 @@
        */
       public void markDirty(Object anObject)
       {
  -        ObjectEnvelope otw = objectEnvelopeTable.get(anObject);
  +        ObjectEnvelope otw = objectEnvelopeTable.get(anObject, false);
           otw.refreshObjectIfNeeded(anObject);
           otw.setModificationState(otw.getModificationState().markDirty());
       }
  @@ -724,24 +743,10 @@
       }
   
       /**
  -     * Checks if the object with the given identity has been deleted
  -     * within the transaction.
  -     * @param id The identity
  -     * @return true if the object has been deleted
  -     * @throws PersistenceBrokerException
  -     */
  -    public boolean isDeleted(Identity id)
  -    {
  -        ObjectEnvelope envelope = objectEnvelopeTable.getByIdentity(id);
  -
  -        return (envelope == null ? false : envelope.needsDelete());
  -    }
  -
  -    /**
        * registers the object with this transaction recursively with all associations.
        * OJB implicitely acquires read locks on registered objects.
        */
  -    private synchronized void register(Object newTxObject, int lockMode)
  +    private synchronized void register(Identity oid, Object newTxObject, int lockMode,
boolean isNewObject)
               throws LockNotGrantedException, PersistenceBrokerException
       {
           Object objectToRegister = newTxObject;
  @@ -786,15 +791,24 @@
           if (objectToRegister != null)
           {
               ClassDescriptor cld = this.getBroker().getClassDescriptor(objectToRegister.getClass());
  -            Identity oid = getBroker().serviceIdentity().buildIdentity(cld, objectToRegister);
  +            if(oid == null)
  +            {
  +                oid = getBroker().serviceIdentity().buildIdentity(cld, objectToRegister);
  +            }
               ObjectEnvelope envelope = objectEnvelopeTable.getByIdentity(oid);
               // if we found an envelope, object is already registered and we do nothing!
               if ((envelope == null) || envelope.needsDelete())
               {
                   // 1. register associated objects
                   doLockReferences(cld, objectToRegister, lockMode);
  +                // if the object was deleted and reinsert again in same tx
  +                if(envelope != null)
  +                {
  +                    envelope.refreshObjectIfNeeded(objectToRegister);
  +                    envelope.setModificationState(org.apache.ojb.odmg.states.StateOldDirty.getInstance());
  +                }
                   // 2. register object itself
  -                objectEnvelopeTable.put(objectToRegister, new ObjectEnvelope(oid, objectToRegister,
this));
  +                objectEnvelopeTable.get(oid, objectToRegister, isNewObject);
                   doLockCollections(cld, objectToRegister, lockMode);
               }
               else
  @@ -838,42 +852,6 @@
           }
       }
   
  -    private void assertFkAssignment(Object obj, Object ref, ObjectReferenceDescriptor rds)
  -    {
  -        try
  -        {
  -            if (!ProxyHelper.isProxy(obj) && (ref != null))
  -            {
  -                Class refClass = ProxyHelper.getRealClass(ref);
  -                ClassDescriptor objCld = this.getBroker().getClassDescriptor(obj.getClass());
  -                FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(objCld);
  -
  -                ValueContainer[] refPkValues;
  -                ClassDescriptor refCld = this.getBroker().getClassDescriptor(refClass);
  -                refPkValues = getBroker().serviceBrokerHelper().getKeyValues(refCld, ref,
false);
  -
  -                /*
  -                 * MBAIRD:
  -                 * objFkFields could end up being null in case of non-mapped indirection
table
  -                 * of m:n relationship
  -                 */
  -                if (objFkFields != null)
  -                {
  -                    FieldDescriptor fld = null;
  -                    for (int i = 0; i < objFkFields.length; i++)
  -                    {
  -                        fld = objFkFields[i];
  -                        fld.getPersistentField().set(obj, (refPkValues[i] != null ? refPkValues[i].getValue()
: null));
  -                    }
  -                }
  -            }
  -        }
  -        catch (Throwable t)
  -        {
  -            throw new PersistenceBrokerException(t);
  -        }
  -    }
  -
       private void lockCollections(ClassDescriptor cld, Object newTxObject, int lockMode)
               throws PersistenceBrokerException
       {
  @@ -1057,11 +1035,12 @@
        */
       public void afterMaterialization(IndirectionHandler handler, Object materializedObject)
       {
  -        if (log.isDebugEnabled())
  -            log.debug("deferred registration: " + new Identity(materializedObject, getBroker()).toString());
           try
           {
  -            register(materializedObject, READ);
  +            Identity oid = handler.getIdentity();
  +            if (log.isDebugEnabled())
  +            log.debug("deferred registration: " + oid);
  +            register(oid, materializedObject, READ, false);
           }
           catch (Throwable t)
           {
  @@ -1221,7 +1200,7 @@
               if (useImplicitLocking && this.isOpen())
               {
                   int lock = useWriteLocks ? Transaction.WRITE : Transaction.READ;
  -                this.register(o, lock);
  +                this.register(null, o, lock, false);
               }
           }
       }
  
  
  
  No                   revision
  No                   revision
  1.75.2.1  +11 -7     db-ojb/src/test/org/apache/ojb/OJB.properties
  
  Index: OJB.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
  retrieving revision 1.75
  retrieving revision 1.75.2.1
  diff -u -r1.75 -r1.75.2.1
  --- OJB.properties	27 Jun 2004 23:36:23 -0000	1.75
  +++ OJB.properties	18 Sep 2004 13:05:55 -0000	1.75.2.1
  @@ -253,24 +253,28 @@
   #----------------------------------------------------------------------------------------
   # Locking
   #----------------------------------------------------------------------------------------
  -# The LockManagerClass entry tells OJB which concrete LockManager
  +# The OdmgLockManagerClass entry tells OJB odmg-api which concrete LockManager
   # implementation is to be used.
  -LockManagerClass=org.apache.ojb.odmg.locking.LockManagerDefaultImpl
  +OdmgLockManagerClass=org.apache.ojb.odmg.locking.LockManagerOdmgImpl
  +#
  +#
  +# The 'LockManagerClass' specify the internal used LockManager implementation.
  +LockManagerClass=org.apache.ojb.broker.locking.LockManagerDefaultImpl
   #
   # The LockMapClass entry tells OJB which concrete LockMap
   # implementation is to be used.
   # If OJB is running on multiple concurrent clients it is recommended
  -# to use the RemoteLockMapImpl. It guarantees to provide
  +# to use the LockMapRemoteImpl. It guarantees to provide
   # Lockmanagement across multiple JVMs.
   # This Implemenation relies on a Servlet based Lockserver. To use it you have to
   # deploy the ojb-lockserver.war into a Servlet engine.
   # and you have to set the Property LockServletUrl to point to this servlet.
   # (see LockServletUrl section below).
   # If OJB is running in a single JVM (e.g. in a desktop app, or in a servlet
  -# engine) it is save to use the InMemoryLockMapImpl. Using it will result
  +# engine) it is save to use the LockMapInMemoryImpl. Using it will result
   # in a large performance gain.
  -#LockMapClass=org.apache.ojb.odmg.locking.RemoteLockMapImpl
  -LockMapClass=org.apache.ojb.odmg.locking.InMemoryLockMapImpl
  +#LockMapClass=org.apache.ojb.broker.locking.LockMapRemoteImpl
  +LockMapClass=org.apache.ojb.broker.locking.LockMapInMemoryImpl
   #
   # The LockTimeout entry defines the maximum time in milliseconds
   # that a lock may be hold. Defaults to 60000 = 1 minute
  
  
  

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