db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/otm/kit SimpleKit.java
Date Fri, 11 Jul 2003 16:38:32 GMT
olegnitz    2003/07/11 09:38:32

  Modified:    src/java/org/apache/ojb/otm OTMKit.java
               src/java/org/apache/ojb/otm/core BaseConnection.java
                        ConcreteEditingContext.java
               src/java/org/apache/ojb/otm/kit SimpleKit.java
  Log:
  Solved the swizzling problem
  
  Revision  Changes    Path
  1.8       +5 -0      db-ojb/src/java/org/apache/ojb/otm/OTMKit.java
  
  Index: OTMKit.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/OTMKit.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- OTMKit.java	1 Jul 2003 21:04:56 -0000	1.7
  +++ OTMKit.java	11 Jul 2003 16:38:31 -0000	1.8
  @@ -114,4 +114,9 @@
        **/
       public abstract boolean isInsertVerified();
   
  +    /**
  +     * Should OTM perform INSERTs for the given object eagerly or during commit?
  +     **/
  +    public abstract boolean isEagerInsert(Object obj);
  +
   }
  
  
  
  1.18      +27 -28    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- BaseConnection.java	8 Jul 2003 23:56:30 -0000	1.17
  +++ BaseConnection.java	11 Jul 2003 16:38:32 -0000	1.18
  @@ -110,7 +110,7 @@
   		m_configurator = PersistenceBrokerFactory.getConfigurator();
   	}
       
  -    public void close() 
  +    public void close()
       {
           _pb.close();
           _pb = null;
  @@ -185,18 +185,18 @@
               object = _pb.getObjectByIdentity(oid);
               if (object != null)
               {
  -				if (lock != LockType.WRITE_LOCK)
  -				{
  -					copyStrategy = _tx.getKit().getCopyStrategy(oid);
  -					object = copyStrategy.copy(object, _pb);
  -				}
  +                if (lock != LockType.WRITE_LOCK)
  +                {
  +                    copyStrategy = _tx.getKit().getCopyStrategy(oid);
  +                    object = copyStrategy.copy(object, _pb);
  +                }
               }
           }
   
  -	    if (object != null)
  -	    {
  -			_editingContext.insert(oid, object, lock);
  -	    }
  +        if (object != null)
  +        {
  +            _editingContext.insert(oid, object, lock);
  +        }
           return object;
       }
   
  @@ -272,15 +272,15 @@
   
       }
   
  -	/**
  -	 * TODO remove all from editing context.
  -	 * @throws LockingException
  -	 */
  -	public void invalidateAll()
  -		throws LockingException
  -	{
  -		_pb.serviceObjectCache().clear();
  -	}
  +    /**
  +     * TODO remove all from editing context.
  +     * @throws LockingException
  +     */
  +    public void invalidateAll()
  +        throws LockingException
  +    {
  +        _pb.serviceObjectCache().clear();
  +    }
   
       /**
        * @see org.apache.ojb.otm.OTMConnection#lockForWrite(Object)
  @@ -300,7 +300,6 @@
           throws LockingException
       {
           Identity oid = new Identity(object, _pb);
  -		_pb.store(object, ObjectModificationDefaultImpl.INSERT);
           _editingContext.insert(oid, object, LockType.READ_LOCK);
       }
   
  @@ -320,9 +319,9 @@
           return _editingContext;
       }
   
  -	public EnhancedOQLQuery newOQLQuery()
  -	{
  -		OQLQueryImpl query = new OQLQueryImpl(_pb.getPBKey());
  +    public EnhancedOQLQuery newOQLQuery()
  +    {
  +        OQLQueryImpl query = new OQLQueryImpl(_pb.getPBKey());
           try
           {
               m_configurator.configure(query);
  @@ -332,12 +331,12 @@
               throw new ODMGRuntimeException("Error in configuration of OQLQueryImpl instance:
" + e.getMessage());
           }
           return query;
  -	}
  +    }
   
  -	public int getCount(Query query)
  -	{
  -		return _pb.getCount(query);
  -	}
  +    public int getCount(Query query)
  +    {
  +        return _pb.getCount(query);
  +    }
   
       ///////////////////////////////////////
       // Transaction Notifications
  
  
  
  1.18      +94 -67    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ConcreteEditingContext.java	1 Jul 2003 21:04:55 -0000	1.17
  +++ ConcreteEditingContext.java	11 Jul 2003 16:38:32 -0000	1.18
  @@ -87,6 +87,7 @@
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.util.ArrayIterator;
   import org.apache.ojb.otm.EditingContext;
  +import org.apache.ojb.otm.OTMKit;
   import org.apache.ojb.otm.lock.LockManager;
   import org.apache.ojb.otm.lock.LockType;
   import org.apache.ojb.otm.lock.LockingException;
  @@ -146,6 +147,7 @@
           Swizzling swizzlingStrategy;
           IndirectionHandler handler = null;
           Object cachedObject;
  +        OTMKit kit = _tx.getKit();
   
           if (lock == LockType.NO_LOCK)
           {
  @@ -154,7 +156,7 @@
   
           entry = (ContextEntry) _objects.get(oid);
           lockManager = LockManager.getInstance();
  -        swizzlingStrategy = _tx.getKit().getSwizzlingStrategy();
  +        swizzlingStrategy = kit.getSwizzlingStrategy();
   
           if (newObj != null)
           {
  @@ -179,7 +181,7 @@
               {
                   Object origObj;
   
  -                if (_tx.getKit().isInsertVerified())
  +                if (kit.isInsertVerified())
                   {
                       origObj = _pb.getObjectByIdentity(oid);
                   }
  @@ -191,8 +193,15 @@
                   if (origObj == null)
                   {
                       entry.state = State.PERSISTENT_NEW;
  +                    if (kit.isEagerInsert(newObj))
  +                    {
  +                        _pb.store(newObj, entry.state);
  +                        entry.state = State.PERSISTENT_CLEAN;
  +                        origObj = newObj;
  +                    }
                   }
  -                else
  +
  +                if (origObj != null)
                   {
                       _original.put(oid, getFields(origObj));
                   }
  @@ -243,7 +252,7 @@
           // perform automatic read lock for all reachable objects
           // if the inserted object is materialized
           if ((handler == null) && (newObj != null)
  -                && _tx.getKit().isImplicitLockingUsed())
  +                && kit.isImplicitLockingUsed())
           {
               lockReachableObjects(newObj);
           }
  @@ -442,6 +451,28 @@
                   }
               }
   
  +            // Swizzle the context objects and the cache objects
  +            for (int i = 0; i < order.length; i++)
  +            {
  +                Identity oid = order[i];
  +                ContextEntry entry = (ContextEntry) _objects.get(oid);
  +
  +                if (entry.state.needsUpdate())
  +                {
  +                    Object cacheObj = cache.lookup(oid);
  +                    entry.object = swizzlingStrategy.getRealTarget(entry.object);
  +                    if ((cacheObj != null) 
  +                            && !swizzlingStrategy.isSameInstance(entry.object,
cacheObj))
  +                    {
  +                        entry.object = swizzlingStrategy.swizzle(entry.object, cacheObj,
_pb);
  +                        if (entry.object != cacheObj)
  +                        {
  +                            cache.cache(oid, entry.object);
  +                        }
  +                    }
  +                }
  +            }
  +
               // perform database operations
               connMan.setBatchMode(true);
               try
  @@ -451,34 +482,36 @@
                       Identity oid = order[i];
                       ContextEntry entry = (ContextEntry) _objects.get(oid);
                       State state = entry.state;
  -                    Object realTarget;
  +
  +                    if (!state.needsInsert() && !state.needsUpdate()
  +                            && !state.needsDelete())
  +                    {
  +                        continue;
  +                    }
   
                       if (state.needsInsert())
                       {
  -                        realTarget = swizzlingStrategy.getRealTarget(entry.object);
                           if (isInsertVerified)
                           {
                               // PB verifies object existence by default
  -                            _pb.store(realTarget);
  +                            _pb.store(entry.object);
                           }
                           else
                           {
                               // PB migth already created the object by auto-update
                               if (cache.lookup(oid) == null) {
  -                                _pb.store(realTarget, state);
  +                                _pb.store(entry.object, state);
                               }
                           }
   
                       }
                       else if (state.needsUpdate())
                       {
  -                        realTarget = swizzlingStrategy.getRealTarget(entry.object);
  -                        _pb.store(realTarget, state);
  +                        _pb.store(entry.object, state);
                       }
                       else if (state.needsDelete())
                       {
  -                        realTarget = swizzlingStrategy.getRealTarget(entry.object);
  -                        _pb.delete(realTarget);
  +                        _pb.delete(entry.object);
                       }
                       entry.state = state.commit();
                   }
  @@ -552,18 +585,15 @@
           while (iter.hasNext())
           {
               rds = (ObjectReferenceDescriptor) iter.next();
  -			if (rds.getCascadeStore())
  -			{
  -				relObj = rds.getPersistentField().get(object);
  -				if (relObj != null)
  -				{
  -					relOid = new Identity(relObj, _pb);
  -					if (!_order.contains(relOid))
  -					{
  -						insertInternal(relOid, relObj, LockType.READ_LOCK);
  -					}
  -				}
  -			}
  +            relObj = rds.getPersistentField().get(object);
  +            if (relObj != null)
  +            {
  +                relOid = new Identity(relObj, _pb);
  +                if (!_order.contains(relOid))
  +                {
  +                    insertInternal(relOid, relObj, LockType.READ_LOCK);
  +                }
  +            }
           }
   
           // 1:N relations
  @@ -575,49 +605,46 @@
           while (collections.hasNext())
           {
               collectionDescriptor = (CollectionDescriptor) collections.next();
  -			if (collectionDescriptor.getCascadeStore())
  -			{
  -				col = collectionDescriptor.getPersistentField().get(object);
  -				if (col != null)
  -				{
  -					if (col instanceof CollectionProxy)
  -					{
  -						if (!((CollectionProxy) col).isLoaded())
  -						{
  -							continue;
  -						}
  -					}
  -
  -					if (col instanceof ManageableCollection)
  -					{
  -						colIterator = ((ManageableCollection) col).ojbIterator();
  -					}
  -					else if (col instanceof Collection)
  -					{
  -						colIterator = ((Collection) col).iterator();
  -					}
  -					else if (col.getClass().isArray())
  -					{
  -						colIterator = new ArrayIterator(col);
  -					}
  -					else
  -					{
  -						throw new OJBRuntimeException(
  -							col.getClass()
  -								+ " can not be managed by OJB, use Array, Collection or ManageableCollection instead
!");
  -					}
  -
  -					while (colIterator.hasNext())
  -					{
  -						relObj = colIterator.next();
  -						relOid = new Identity(relObj, _pb);
  -						if (!_order.contains(relOid))
  -						{
  -							insertInternal(relOid, relObj, LockType.READ_LOCK);
  -						}
  -					}
  -				}
  -			}
  +            col = collectionDescriptor.getPersistentField().get(object);
  +            if (col != null)
  +            {
  +                if (col instanceof CollectionProxy)
  +                {
  +                    if (!((CollectionProxy) col).isLoaded())
  +                    {
  +                        continue;
  +                    }
  +                }
  +
  +                if (col instanceof ManageableCollection)
  +                {
  +                    colIterator = ((ManageableCollection) col).ojbIterator();
  +                }
  +                else if (col instanceof Collection)
  +                {
  +                    colIterator = ((Collection) col).iterator();
  +                }
  +                else if (col.getClass().isArray())
  +                {
  +                    colIterator = new ArrayIterator(col);
  +                }
  +                else
  +                {
  +                    throw new OJBRuntimeException(
  +                        col.getClass()
  +                            + " can not be managed by OJB, use Array, Collection or ManageableCollection
instead !");
  +                }
  +
  +                while (colIterator.hasNext())
  +                {
  +                    relObj = colIterator.next();
  +                    relOid = new Identity(relObj, _pb);
  +                    if (!_order.contains(relOid))
  +                    {
  +                        insertInternal(relOid, relObj, LockType.READ_LOCK);
  +                    }
  +                }
  +            }
           }
       }
   
  
  
  
  1.11      +11 -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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SimpleKit.java	8 Jul 2003 23:17:44 -0000	1.10
  +++ SimpleKit.java	11 Jul 2003 16:38:32 -0000	1.11
  @@ -99,7 +99,9 @@
           _lockWaitStrategy = new TimeoutStrategy();
           _lockMap = new InMemoryLockMap();
           _noOpCopyStrategy = new NoOpObjectCopyStrategy();
  -        _defaultCopyStrategy = new ReflectiveObjectCopyStrategy();
  +        //_defaultCopyStrategy = new ReflectiveObjectCopyStrategy();
  +        _defaultCopyStrategy = new SerializeObjectCopyStrategy();
  +        //_defaultCopyStrategy = new MetadataObjectCopyStrategy();
           _cloneableCopyStrategy = new CloneableObjectCopyStrategy();
       }
   
  @@ -188,5 +190,13 @@
       public boolean isInsertVerified()
       {
           return false;
  +    }
  +    
  +    /**
  +     * Should OTM perform INSERTs for the given object eagerly or during commit?
  +     **/
  +    public boolean isEagerInsert(Object obj)
  +    {
  +        return true;
       }
   }
  
  
  

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