db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/otm/kit SimpleKit.java
Date Fri, 25 Jul 2003 00:22:00 GMT
mattbaird    2003/07/24 17:22:00

  Modified:    src/java/org/apache/ojb/otm/transaction
                        LocalTransactionFactory.java
               src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
                        BaseConnection.java
               src/java/org/apache/ojb/otm/copy
                        MetadataObjectCopyStrategy.java
               src/java/org/apache/ojb/otm/util IdentityHashMap.java
               src/java/org/apache/ojb/otm/swizzle CopySwizzling.java
               src/java/org/apache/ojb/otm/kit SimpleKit.java
  Log:
  using contains on arraylist is slow for large changes, switch to hashmap
  
  Revision  Changes    Path
  1.5       +3 -5      db-ojb/src/java/org/apache/ojb/otm/transaction/LocalTransactionFactory.java
  
  Index: LocalTransactionFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/transaction/LocalTransactionFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LocalTransactionFactory.java	16 Jun 2003 16:17:57 -0000	1.4
  +++ LocalTransactionFactory.java	25 Jul 2003 00:22:00 -0000	1.5
  @@ -102,15 +102,13 @@
   
   
       /**
  -     * @see org.apache.ojb.otm.transaction.TransactionFactory#acquireConnection(OTMKit,
PBKey)
  +     * @see org.apache.ojb.otm.transaction.TransactionFactory#acquireConnection(PBKey)
        */
       public OTMConnection acquireConnection (PBKey pbKey)
       {
           OTMConnection newConnection = new LocalConnection(pbKey);
  -
  -            // Ensure the transaction is established for this connection.
  -        Transaction tx = getTransactionForConnection(newConnection);
  -
  +        // Ensure the transaction is established for this connection.
  +        getTransactionForConnection(newConnection);
           return newConnection;
       }
   
  
  
  
  1.22      +17 -17    db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java
  
  Index: ConcreteEditingContext.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ConcreteEditingContext.java	24 Jul 2003 21:55:03 -0000	1.21
  +++ ConcreteEditingContext.java	25 Jul 2003 00:22:00 -0000	1.22
  @@ -118,7 +118,7 @@
       private HashSet _withoutBidirAssc;
   
       private HashMap _objects;
  -    private ArrayList _order;
  +    private HashMap _order;
       private Transaction _tx;
       private PersistenceBroker _pb;
       private HashMap _original;
  @@ -135,7 +135,7 @@
           _tx = tx;
           _pb = pb;
           _objects = new HashMap();
  -        _order = new ArrayList();
  +        _order = new HashMap();
           _original = new HashMap();
           _checkpointed = _original;
           pbkey = _pb.getPBKey();
  @@ -158,7 +158,7 @@
       //////////////////////////////////////////
   
       /**
  -     * @see org.apache.ojb.otm.EditingContext#insert(Object, int)
  +     * @see org.apache.ojb.otm.EditingContext#insert(Identity, Object, int)
        */
       public void insert(Identity oid, Object obj, int lock)
               throws LockingException
  @@ -174,7 +174,6 @@
           LockManager lockManager;
           Swizzling swizzlingStrategy;
           IndirectionHandler handler = null;
  -        Object cachedObject;
           OTMKit kit = _tx.getKit();
   
           if (lock == LockType.NO_LOCK)
  @@ -283,8 +282,9 @@
               }
           }
   
  -        if (!_order.contains(oid)) {
  -            _order.add(oid);
  +        if (_order.get(oid)==null)
  +        {
  +            _order.put(oid,oid);
           }
   
           // perform automatic read lock for all reachable objects
  @@ -311,7 +311,8 @@
       {
           ContextEntry entry;
   
  -        if (_order.contains(oid)) {
  +        if (_order.get(oid)!=null)
  +        {
               _order.remove(oid);
           }
           entry = insertInternal(oid, object, LockType.WRITE_LOCK, true, false);
  @@ -411,7 +412,7 @@
       {
           checkpointInternal();
           _checkpointed = new HashMap();
  -        for (Iterator iterator = _order.iterator(); iterator.hasNext();)
  +        for (Iterator iterator = _order.keySet().iterator(); iterator.hasNext();)
           {
               Identity oid = (Identity) iterator.next();
               ContextEntry entry = (ContextEntry) _objects.get(oid);
  @@ -435,7 +436,7 @@
           boolean saveBatchMode = connMan.isBatchMode();
           Swizzling swizzlingStrategy = _tx.getKit().getSwizzlingStrategy();
           LockManager lockManager = LockManager.getInstance();
  -        Identity[] lockOrder = (Identity[]) _order.toArray(new Identity[_order.size()]);
  +        Identity[] lockOrder = (Identity[]) _order.keySet().toArray(new Identity[_order.size()]);
           ObjectCache cache = _pb.serviceObjectCache();
           boolean isInsertVerified = _tx.getKit().isInsertVerified();
   
  @@ -468,7 +469,6 @@
                       Identity oid = lockOrder[i];
                       ContextEntry entry = (ContextEntry) _objects.get(oid);
                       State state = entry.state;
  -                    IndirectionHandler handler;
   
                       if (entry.object == null) // invalidated
                       {
  @@ -531,7 +531,7 @@
               }
               while (countNewObjects > 0);
   
  -            Identity[] order = (Identity[]) _order.toArray(new Identity[_order.size()]);
  +            Identity[] order = (Identity[]) _order.keySet().toArray(new Identity[_order.size()]);
   
               // Swizzle the context objects and the cache objects
               for (int i = 0; i < order.length; i++)
  @@ -636,7 +636,7 @@
        */
       public void rollback()
       {
  -        for (Iterator iterator = _order.iterator(); iterator.hasNext();)
  +        for (Iterator iterator = _order.keySet().iterator(); iterator.hasNext();)
           {
               Identity oid = (Identity) iterator.next();
               ContextEntry entry = (ContextEntry) _objects.get(oid);
  @@ -680,8 +680,8 @@
   
           // N:1 relations
           Iterator iter = mif.getObjectReferenceDescriptors().iterator();
  -        ObjectReferenceDescriptor rds = null;
  -        Object relObj = null;
  +        ObjectReferenceDescriptor rds;
  +        Object relObj;
           Identity relOid;
   
           while (iter.hasNext())
  @@ -695,7 +695,7 @@
               if (relObj != null)
               {
                   relOid = new Identity(relObj, _pb);
  -                if (!_order.contains(relOid))
  +                if (_order.get(relOid)==null)
                   {
                       insertInternal(relOid, relObj, LockType.READ_LOCK, false,
                                      rds.getOtmDependent());
  @@ -738,7 +738,7 @@
                   {
                       relObj = colIterator.next();
                       relOid = new Identity(relObj, _pb);
  -                    if (!_order.contains(relOid))
  +                    if (_order.get(relOid) == null)
                       {
                           insertInternal(relOid, relObj, LockType.READ_LOCK, false,
                                          collectionDescriptor.getOtmDependent());
  @@ -1116,7 +1116,7 @@
   
           entry.state = State.PERSISTENT_NEW;
           _objects.put(oid, entry);
  -        _order.add(oid);
  +        _order.put(oid,oid);
       }
   
       /**
  
  
  
  1.20      +14 -20    db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java
  
  Index: BaseConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- BaseConnection.java	11 Jul 2003 19:01:24 -0000	1.19
  +++ BaseConnection.java	25 Jul 2003 00:22:00 -0000	1.20
  @@ -54,35 +54,31 @@
    * <http://www.apache.org/>.
    */
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
  -import java.util.Iterator;
  -import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.PBKey;
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
  -import org.apache.ojb.broker.VirtualProxy;
  -import org.apache.ojb.broker.util.configuration.ConfigurationException;
  -import org.apache.ojb.broker.util.configuration.Configurator;
  +import org.apache.ojb.broker.*;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.accesslayer.OJBIterator;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.util.configuration.ConfigurationException;
  +import org.apache.ojb.broker.util.configuration.Configurator;
  +import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
  +import org.apache.ojb.odmg.oql.OQLQueryImpl;
   import org.apache.ojb.otm.EditingContext;
   import org.apache.ojb.otm.OTMConnection;
   import org.apache.ojb.otm.copy.ObjectCopyStrategy;
  -import org.apache.ojb.otm.lock.LockManager;
   import org.apache.ojb.otm.lock.LockType;
   import org.apache.ojb.otm.lock.LockingException;
  -import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
  -import org.apache.ojb.odmg.oql.OQLQueryImpl;
   import org.odmg.ODMGRuntimeException;
   
  +//#ifdef JDK13
  +import java.lang.reflect.Proxy;
  +//#else
  +/*
  +import com.develop.java.lang.reflect.Proxy;
  +*/
  +//#endif
  +import java.util.Iterator;
  +
   /**
    *
    * <javadoc>
  @@ -261,8 +257,6 @@
       public void invalidate(Identity oid)
               throws LockingException
       {
  -        LockManager lockManager = LockManager.getInstance();
  -
           // lock for write and mark as invalidated in the editing context
           _editingContext.insert(oid, null, LockType.WRITE_LOCK);
   
  
  
  
  1.8       +6 -6      db-ojb/src/java/org/apache/ojb/otm/copy/MetadataObjectCopyStrategy.java
  
  Index: MetadataObjectCopyStrategy.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/copy/MetadataObjectCopyStrategy.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MetadataObjectCopyStrategy.java	16 Jul 2003 00:04:37 -0000	1.7
  +++ MetadataObjectCopyStrategy.java	25 Jul 2003 00:22:00 -0000	1.8
  @@ -142,10 +142,10 @@
               }
           }
   
  -        Object retval;
  +        final Object retval;
           try
           {
  -            Constructor con = cld.getZeroArgumentConstructor();
  +            final Constructor con = cld.getZeroArgumentConstructor();
               retval = ConstructorHelper.instantiate(con);
               objMap.put(toCopy,retval);
           }
  @@ -184,7 +184,7 @@
                * recursively copy the referenced objects
                * register in the objMap first
                */
  -            Object object = f.get(toCopy);
  +            final Object object = f.get(toCopy);
               /**
                * if this is a proxy, just copy the proxy, don't materialize it, and stop
recursing
                */
  @@ -194,7 +194,7 @@
               }
               else
               {
  -                Object clone = clone(object, objMap, broker);
  +                final Object clone = clone(object, objMap, broker);
                   objMap.put(object, clone);
                   f.set(retval, clone);
               }
  @@ -227,7 +227,7 @@
                   {
                       final Collection newCollection = (Collection) collection.getClass().newInstance();
                       final Iterator tempIter = ((Collection) collection).iterator();
  -                    Object obj = null;
  +                    Object obj;
                       while (tempIter.hasNext())
                       {
                           obj = tempIter.next();
  @@ -240,7 +240,7 @@
                           }
                           else
                           {
  -                            Object clone = clone(obj, objMap, broker);
  +                            final Object clone = clone(obj, objMap, broker);
                               objMap.put(obj, clone);
                               newCollection.add(clone);
                           }
  
  
  
  1.2       +13 -13    db-ojb/src/java/org/apache/ojb/otm/util/IdentityHashMap.java
  
  Index: IdentityHashMap.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/util/IdentityHashMap.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IdentityHashMap.java	8 Jul 2003 16:01:58 -0000	1.1
  +++ IdentityHashMap.java	25 Jul 2003 00:22:00 -0000	1.2
  @@ -63,18 +63,18 @@
    * Date: Jul 8, 2003
    * Time: 8:37:00 AM
    */
  -public final class IdentityHashMap extends HashMap
  +final class IdentityHashMap extends HashMap
   {
   	private static final class IdentityKey
   	{
  -		private Object m_key;
  +		private final Object m_key;
   
  -		public IdentityKey(Object key)
  +		public IdentityKey(final Object key)
   		{
   			m_key = key;
   		}
   
  -		public boolean equals(Object o)
  +		public boolean equals(final Object o)
   		{
   			return (o == m_key);
   		}
  @@ -90,7 +90,7 @@
   	 * @param initialCapacity
   	 * @param loadFactor
   	 */
  -	public IdentityHashMap(int initialCapacity, float loadFactor)
  +	public IdentityHashMap(final int initialCapacity, final float loadFactor)
   	{
   		super(initialCapacity, loadFactor);
   	}
  @@ -99,7 +99,7 @@
   	 * Constructor for IdentityHashMap.
   	 * @param initialCapacity
   	 */
  -	public IdentityHashMap(int initialCapacity)
  +	public IdentityHashMap(final int initialCapacity)
   	{
   		super(initialCapacity);
   	}
  @@ -116,7 +116,7 @@
   	 * Constructor for IdentityHashMap.
   	 * @param t
   	 */
  -	public IdentityHashMap(Map t)
  +	public IdentityHashMap(final Map t)
   	{
   		super(t);
   	}
  @@ -124,7 +124,7 @@
   	/**
   	 * @see java.util.Map#get(java.lang.Object)
   	 */
  -	public Object get(Object key)
  +	public Object get(final Object key)
   	{
   		return super.get(new IdentityKey(key));
   	}
  @@ -132,7 +132,7 @@
   	/**
   	 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
   	 */
  -	public Object put(Object key, Object value)
  +	public Object put(final Object key, final Object value)
   	{
   		return super.put(new IdentityKey(key), value);
   	}
  @@ -140,9 +140,9 @@
   	/**
   	 * adds an object to the Map. new IdentityKey(obj) is used as key
   	 */
  -	public Object add(Object value)
  +	public Object add(final Object value)
   	{
  -		Object key = new IdentityKey(value);
  +		final Object key = new IdentityKey(value);
   		if (!super.containsKey(key))
   		{
   			return super.put(key, value);
  @@ -156,7 +156,7 @@
   	/**
   	 * @see java.util.Map#remove(java.lang.Object)
   	 */
  -	public Object remove(Object key)
  +	public Object remove(final Object key)
   	{
   		return super.remove(new IdentityKey(key));
   	}
  @@ -164,7 +164,7 @@
   	/**
   	 * @see java.util.Map#containsKey(java.lang.Object)
   	 */
  -	public boolean containsKey(Object key)
  +	public boolean containsKey(final Object key)
   	{
   		return super.containsKey(new IdentityKey(key));
   	}
  
  
  
  1.5       +1 -1      db-ojb/src/java/org/apache/ojb/otm/swizzle/CopySwizzling.java
  
  Index: CopySwizzling.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/swizzle/CopySwizzling.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CopySwizzling.java	13 Jul 2003 14:07:16 -0000	1.4
  +++ CopySwizzling.java	25 Jul 2003 00:22:00 -0000	1.5
  @@ -23,7 +23,7 @@
   {
   
       /**
  -     * @see org.apache.ojb.otm.swizzle.Swizzling#swizzle(Object, Object, PersistenceBroker)
  +     * @see org.apache.ojb.otm.swizzle.Swizzling#swizzle(Object, Object, PersistenceBroker,
ObjectCache)
        */
       public Object swizzle(Object newObj, Object oldObj, PersistenceBroker pb,
                             ObjectCache cache)
  
  
  
  1.14      +1 -1      db-ojb/src/java/org/apache/ojb/otm/kit/SimpleKit.java
  
  Index: SimpleKit.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/kit/SimpleKit.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SimpleKit.java	13 Jul 2003 14:07:16 -0000	1.13
  +++ SimpleKit.java	25 Jul 2003 00:22:00 -0000	1.14
  @@ -136,7 +136,7 @@
   
   
       /**
  -    * @see org.apache.ojb.otm.OTMKit#getLockFactory()
  +    * @see org.apache.ojb.otm.OTMKit#getLockWaitStrategy()
       */
       public LockWaitStrategy getLockWaitStrategy()
       {
  
  
  

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