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 J2EETransactionImpl.java ObjectEnvelope.java ObjectEnvelopeTable.java TransactionAbortedExceptionOJB.java TransactionImpl.java
Date Sun, 28 Nov 2004 03:17:33 GMT
arminw      2004/11/27 19:17:33

  Modified:    src/java/org/apache/ojb/odmg/states ModificationState.java
                        StateNewClean.java StateNewDelete.java
                        StateNewDirty.java StateOldClean.java
                        StateOldDelete.java StateOldDirty.java
               src/java/org/apache/ojb/odmg J2EETransactionImpl.java
                        ObjectEnvelope.java ObjectEnvelopeTable.java
                        TransactionAbortedExceptionOJB.java
                        TransactionImpl.java
  Log:
  merge with 1.0.x branch
  
  Revision  Changes    Path
  1.13      +5 -23     db-ojb/src/java/org/apache/ojb/odmg/states/ModificationState.java
  
  Index: ModificationState.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/ModificationState.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ModificationState.java	4 Apr 2004 23:53:40 -0000	1.12
  +++ ModificationState.java	28 Nov 2004 03:17:33 -0000	1.13
  @@ -15,13 +15,11 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.PersistenceBroker;
  +import java.io.Serializable;
  +
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.odmg.ObjectEnvelope;
   
  -import java.io.Serializable;
  -
   /**
    * Describes an objects transactional state regarding commiting and rollbacking
    */
  @@ -60,19 +58,19 @@
       /**
        *
        */
  -    public abstract void checkpoint(ObjectEnvelope mod, PersistenceBroker broker)
  +    public abstract void checkpoint(ObjectEnvelope mod)
               throws PersistenceBrokerException;
   
       /**
        *
        */
  -    public abstract void commit(ObjectEnvelope mod, PersistenceBroker broker)
  +    public abstract void commit(ObjectEnvelope mod)
               throws PersistenceBrokerException;
   
       /**
        *
        */
  -    public abstract void rollback(ObjectEnvelope mod, PersistenceBroker broker);
  +    public abstract void rollback(ObjectEnvelope mod);
   
       /**
        * return a String representation
  @@ -109,21 +107,5 @@
       public boolean needsDelete()
       {
           return false;
  -    }
  -
  -    /**
  -     * remove Object from the ObjectCache
  -     */
  -    protected void removeFromCache(Object objectOrIdentity, PersistenceBroker broker)
  -    {
  -        try
  -        {
  -            broker.removeFromCache(objectOrIdentity);
  -        }
  -        catch (PersistenceBrokerException e)
  -        {
  -            LoggerFactory.getDefaultLogger().error("[" + this.getClass().getName() + "]" +
  -                    " Can't remove object from cache. obj was " + objectOrIdentity + ",  used PB " + broker, e);
  -        }
       }
   }
  
  
  
  1.9       +8 -10     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StateNewClean.java	20 Sep 2004 14:30:58 -0000	1.8
  +++ StateNewClean.java	28 Nov 2004 03:17:33 -0000	1.9
  @@ -15,8 +15,6 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
   import org.apache.ojb.odmg.ObjectEnvelope;
   
   /**
  @@ -92,11 +90,11 @@
       /**
        * checkpoint the transaction
        */
  -    public void checkpoint(ObjectEnvelope mod, PersistenceBroker broker)
  +    public void checkpoint(ObjectEnvelope mod)
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
  -        broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.refreshObjectImage(broker);
  +        mod.doInsert();
  +        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -104,18 +102,18 @@
       /**
        * commit the associated transaction
        */
  -    public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws org.apache.ojb.broker.PersistenceBrokerException
  +    public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException
       {
  -        broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.refreshObjectImage(broker);
  +        mod.doInsert();
  +        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
       /**
        * rollback the transaction
        */
  -    public void rollback(ObjectEnvelope mod, PersistenceBroker broker)
  +    public void rollback(ObjectEnvelope mod)
       {
  -        this.removeFromCache(mod.getObject(), broker);
  +        mod.doEvictFromCache();
       }
   }
  
  
  
  1.6       +113 -1    db-ojb/src/java/org/apache/ojb/odmg/states/StateNewDelete.java
  
  Index: StateNewDelete.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateNewDelete.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StateNewDelete.java	5 Apr 2004 12:16:24 -0000	1.5
  +++ StateNewDelete.java	28 Nov 2004 03:17:33 -0000	1.6
  @@ -1 +1,113 @@
  -package org.apache.ojb.odmg.states;

/* Copyright 2002-2004 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.apache.ojb.broker.PersistenceBroker;

import org.apache.ojb.odmg.ObjectEnvelope;

/**
 * this state represents new objects which have been mrked for deletion during tx.
 */
public class StateNewDelete extends ModificationState
{
    private static StateNewDelete _instance = new StateNewDelete();

    /**
     * return resulting state after marking clean
     */
    public ModificationState markClean()
    {
        return StateNewClean.getInstance();
    }

    /**
     * return resulting state after marking delete
     */
    public ModificationState markDelete()
    {
        return this;
    }

    /**
     * return resulting state after marking dirty
     */
    public ModificationState markDirty()
    {
        return StateNewDirty.getInstance();
    }

    /**
     * return resulting state after marking new
     */
    public ModificationState markNew()
    {
        return this;
    }

    /**
     * return resulting state after marking old
     */
    public ModificationState markOld()
    {
        return StateOldDelete.getInstance();
    }

    /**
     * returns true is this state requires DELETE
     * @return boolean
     */
    public boolean needsDelete()
    {
        return true;
    }

    /**
     * private constructor: use singleton instance
     */
    private StateNewDelete()
    {
    }

    /**
     * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
     */
    public static StateNewDelete getInstance()
    {
        return _instance;
    }

    /**
     * rollback the ObjectModification
     */
    public void checkpoint(ObjectEnvelope mod, PersistenceBroker broker)
    {
    }

    /**
     * commit ObjectModification
     */
    public void commit(ObjectEnvelope mod, PersistenceBroker broker)
    {
        this.removeFromCache(mod.getObject(), broker);
    }

    /**
     *
     */
    public void rollback(ObjectEnvelope mod, PersistenceBroker broker)
    {
        this.removeFromCache(mod.getObject(), broker);
    }
}
  +package org.apache.ojb.odmg.states;
  +
  +/* Copyright 2002-2004 The Apache Software Foundation
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +
  +import org.apache.ojb.odmg.ObjectEnvelope;
  +
  +/**
  + * this state represents new objects which have been mrked for deletion during tx.
  + */
  +public class StateNewDelete extends ModificationState
  +{
  +    private static StateNewDelete _instance = new StateNewDelete();
  +
  +    /**
  +     * return resulting state after marking clean
  +     */
  +    public ModificationState markClean()
  +    {
  +        return StateNewClean.getInstance();
  +    }
  +
  +    /**
  +     * return resulting state after marking delete
  +     */
  +    public ModificationState markDelete()
  +    {
  +        return this;
  +    }
  +
  +    /**
  +     * return resulting state after marking dirty
  +     */
  +    public ModificationState markDirty()
  +    {
  +        return StateNewDirty.getInstance();
  +    }
  +
  +    /**
  +     * return resulting state after marking new
  +     */
  +    public ModificationState markNew()
  +    {
  +        return this;
  +    }
  +
  +    /**
  +     * return resulting state after marking old
  +     */
  +    public ModificationState markOld()
  +    {
  +        return StateOldDelete.getInstance();
  +    }
  +
  +    /**
  +     * returns true is this state requires DELETE
  +     * @return boolean
  +     */
  +    public boolean needsDelete()
  +    {
  +        return true;
  +    }
  +
  +    /**
  +     * private constructor: use singleton instance
  +     */
  +    private StateNewDelete()
  +    {
  +    }
  +
  +    /**
  +     * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
  +     */
  +    public static StateNewDelete getInstance()
  +    {
  +        return _instance;
  +    }
  +
  +    /**
  +     * rollback the ObjectModification
  +     */
  +    public void checkpoint(ObjectEnvelope mod)
  +    {
  +    }
  +
  +    /**
  +     * commit ObjectModification
  +     */
  +    public void commit(ObjectEnvelope mod)
  +    {
  +        mod.doEvictFromCache();
  +    }
  +
  +    /**
  +     *
  +     */
  +    public void rollback(ObjectEnvelope mod)
  +    {
  +        mod.doEvictFromCache();
  +    }
  +}
  
  
  
  1.8       +8 -10     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StateNewDirty.java	20 Sep 2004 14:30:58 -0000	1.7
  +++ StateNewDirty.java	28 Nov 2004 03:17:33 -0000	1.8
  @@ -15,8 +15,6 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
   import org.apache.ojb.odmg.ObjectEnvelope;
   
   /**
  @@ -93,21 +91,21 @@
       /**
        * checkpoint the ObjectModification
        */
  -    public void checkpoint(ObjectEnvelope mod, PersistenceBroker broker)
  +    public void checkpoint(ObjectEnvelope mod)
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
  -        broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.refreshObjectImage(broker);
  +        mod.doInsert();
  +        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
       /**
        * commit the associated transaction
        */
  -    public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws org.apache.ojb.broker.PersistenceBrokerException
  +    public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException
       {
  -        broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.refreshObjectImage(broker);
  +        mod.doInsert();
  +        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -115,9 +113,9 @@
        * rollback
        *
        */
  -    public void rollback(ObjectEnvelope mod, PersistenceBroker broker)
  +    public void rollback(ObjectEnvelope mod)
       {
  -        this.removeFromCache(mod.getObject(), broker);
  +        mod.doEvictFromCache();
       }
   
   }
  
  
  
  1.6       +107 -1    db-ojb/src/java/org/apache/ojb/odmg/states/StateOldClean.java
  
  Index: StateOldClean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateOldClean.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StateOldClean.java	5 Apr 2004 12:16:24 -0000	1.5
  +++ StateOldClean.java	28 Nov 2004 03:17:33 -0000	1.6
  @@ -1 +1,107 @@
  -package org.apache.ojb.odmg.states;

/* Copyright 2002-2004 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.apache.ojb.broker.PersistenceBroker;

import org.apache.ojb.odmg.ObjectEnvelope;

/**
 * this state represents old Objects (i.e. already persistent but not changed during tx)
 * --> no need to do anything for commit or rollback
 */
public class StateOldClean extends ModificationState
{
    private static StateOldClean _instance = new StateOldClean();

    /**
     * private constructor: use singleton instance
     */
    private StateOldClean()
    {

    }

    /**
     * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
     */
    public static StateOldClean getInstance()
    {
        return _instance;
    }

    /**
     * return resulting state after marking clean
     */
    public ModificationState markClean()
    {
        return this;
    }

    /**
     * return resulting state after marking delete
     */
    public ModificationState markDelete()
    {
        return StateOldDelete.getInstance();
    }

    /**
     * return resulting state after marking dirty
     */
    public ModificationState markDirty()
    {
        return StateOldDirty.getInstance();
    }

    /**
     * return resulting state after marking new
     */
    public ModificationState markNew()
    {
        return this;
    }

    /**
     * return resulting state after marking old
     */
    public ModificationState markOld()
    {
        return this;
    }

    /**
     * rollback the ObjectModification
     */
    public void checkpoint(ObjectEnvelope mod, PersistenceBroker broker)
    {

    }

    /**
     * commit the associated transaction
     */
    public void commit(ObjectEnvelope mod, PersistenceBroker broker)
    {

    }

    /**
     *
     */
    public void rollback(ObjectEnvelope mod, PersistenceBroker broker)
    {

    }
}
  +package org.apache.ojb.odmg.states;
  +
  +/* Copyright 2002-2004 The Apache Software Foundation
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +
  +import org.apache.ojb.odmg.ObjectEnvelope;
  +
  +/**
  + * this state represents old Objects (i.e. already persistent but not changed during tx)
  + * --> no need to do anything for commit or rollback
  + */
  +public class StateOldClean extends ModificationState
  +{
  +    private static StateOldClean _instance = new StateOldClean();
  +
  +    /**
  +     * private constructor: use singleton instance
  +     */
  +    private StateOldClean()
  +    {
  +
  +    }
  +
  +    /**
  +     * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
  +     */
  +    public static StateOldClean getInstance()
  +    {
  +        return _instance;
  +    }
  +
  +    /**
  +     * return resulting state after marking clean
  +     */
  +    public ModificationState markClean()
  +    {
  +        return this;
  +    }
  +
  +    /**
  +     * return resulting state after marking delete
  +     */
  +    public ModificationState markDelete()
  +    {
  +        return StateOldDelete.getInstance();
  +    }
  +
  +    /**
  +     * return resulting state after marking dirty
  +     */
  +    public ModificationState markDirty()
  +    {
  +        return StateOldDirty.getInstance();
  +    }
  +
  +    /**
  +     * return resulting state after marking new
  +     */
  +    public ModificationState markNew()
  +    {
  +        return this;
  +    }
  +
  +    /**
  +     * return resulting state after marking old
  +     */
  +    public ModificationState markOld()
  +    {
  +        return this;
  +    }
  +
  +    /**
  +     * rollback the ObjectModification
  +     */
  +    public void checkpoint(ObjectEnvelope mod)
  +    {
  +
  +    }
  +
  +    /**
  +     * commit the associated transaction
  +     */
  +    public void commit(ObjectEnvelope mod)
  +    {
  +
  +    }
  +
  +    /**
  +     *
  +     */
  +    public void rollback(ObjectEnvelope mod)
  +    {
  +
  +    }
  +}
  
  
  
  1.6       +116 -1    db-ojb/src/java/org/apache/ojb/odmg/states/StateOldDelete.java
  
  Index: StateOldDelete.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateOldDelete.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StateOldDelete.java	5 Apr 2004 12:16:24 -0000	1.5
  +++ StateOldDelete.java	28 Nov 2004 03:17:33 -0000	1.6
  @@ -1 +1,116 @@
  -package org.apache.ojb.odmg.states;

/* Copyright 2002-2004 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerException;

import org.apache.ojb.odmg.ObjectEnvelope;

/**
 * this state represents old objects which have been marked for deletion during tx.
 */
public class StateOldDelete extends ModificationState
{
    private static StateOldDelete _instance = new StateOldDelete();

    /**
     * private constructor: use singleton instance
     */
    private StateOldDelete()
    {
    }

    /**
     * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
     */
    public static StateOldDelete getInstance()
    {
        return _instance;
    }

    /**
     * return resulting state after marking clean
     */
    public ModificationState markClean()
    {
        return StateOldClean.getInstance();
    }

    /**
     * return resulting state after marking delete
     */
    public ModificationState markDelete()
    {
        return this;
    }

    /**
     * return resulting state after marking dirty
     */
    public ModificationState markDirty()
    {
        return this;
    }

    /**
     * return resulting state after marking new
     */
    public ModificationState markNew()
    {
        return StateNewDelete.getInstance();
    }

    /**
     * return resulting state after marking old
     */
    public ModificationState markOld()
    {
        return this;
    }

    /**
     * returns true is this state requires DELETE
     * @return boolean
     */
    public boolean needsDelete()
    {
        return true;
    }

    /**
     * rollback the transaction
     */
    public void checkpoint(ObjectEnvelope mod, PersistenceBroker broker)
            throws org.apache.ojb.broker.PersistenceBrokerException
    {
        broker.delete(mod.getObject());
    }

    /**
     * commit the associated transaction
     */
    public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws PersistenceBrokerException
    {
        broker.delete(mod.getObject());
        this.removeFromCache(mod.getObject(), broker);
    }

    /**
     *
     */
    public void rollback(ObjectEnvelope mod, PersistenceBroker broker)
    {
        this.removeFromCache(mod.getObject(), broker);
    }
}
  +package org.apache.ojb.odmg.states;
  +
  +/* Copyright 2002-2004 The Apache Software Foundation
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.odmg.ObjectEnvelope;
  +
  +/**
  + * this state represents old objects which have been marked for deletion during tx.
  + */
  +public class StateOldDelete extends ModificationState
  +{
  +    private static StateOldDelete _instance = new StateOldDelete();
  +
  +    /**
  +     * private constructor: use singleton instance
  +     */
  +    private StateOldDelete()
  +    {
  +    }
  +
  +    /**
  +     * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
  +     */
  +    public static StateOldDelete getInstance()
  +    {
  +        return _instance;
  +    }
  +
  +    /**
  +     * return resulting state after marking clean
  +     */
  +    public ModificationState markClean()
  +    {
  +        return StateOldClean.getInstance();
  +    }
  +
  +    /**
  +     * return resulting state after marking delete
  +     */
  +    public ModificationState markDelete()
  +    {
  +        return this;
  +    }
  +
  +    /**
  +     * return resulting state after marking dirty
  +     */
  +    public ModificationState markDirty()
  +    {
  +        return this;
  +    }
  +
  +    /**
  +     * return resulting state after marking new
  +     */
  +    public ModificationState markNew()
  +    {
  +        return StateNewDelete.getInstance();
  +    }
  +
  +    /**
  +     * return resulting state after marking old
  +     */
  +    public ModificationState markOld()
  +    {
  +        return this;
  +    }
  +
  +    /**
  +     * returns true is this state requires DELETE
  +     * @return boolean
  +     */
  +    public boolean needsDelete()
  +    {
  +        return true;
  +    }
  +
  +    /**
  +     * rollback the transaction
  +     */
  +    public void checkpoint(ObjectEnvelope mod)
  +            throws org.apache.ojb.broker.PersistenceBrokerException
  +    {
  +        mod.doDelete();
  +    }
  +
  +    /**
  +     * commit the associated transaction
  +     */
  +    public void commit(ObjectEnvelope mod) throws PersistenceBrokerException
  +    {
  +        mod.doDelete();
  +    }
  +
  +    /**
  +     *
  +     */
  +    public void rollback(ObjectEnvelope mod)
  +    {
  +        mod.doEvictFromCache();
  +    }
  +}
  
  
  
  1.8       +6 -8      db-ojb/src/java/org/apache/ojb/odmg/states/StateOldDirty.java
  
  Index: StateOldDirty.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateOldDirty.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StateOldDirty.java	4 Apr 2004 23:53:40 -0000	1.7
  +++ StateOldDirty.java	28 Nov 2004 03:17:33 -0000	1.8
  @@ -15,8 +15,6 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
   import org.apache.ojb.odmg.ObjectEnvelope;
   
   /**
  @@ -85,27 +83,27 @@
       /**
        * checkpoint the transaction
        */
  -    public void checkpoint(ObjectEnvelope mod, PersistenceBroker broker)
  +    public void checkpoint(ObjectEnvelope mod)
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
  -        broker.store(mod.getObject(), ObjectModificationDefaultImpl.UPDATE);
  +        mod.doUpdate();
       }
   
   
       /**
        * commit the associated transaction
        */
  -    public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws org.apache.ojb.broker.PersistenceBrokerException
  +    public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException
       {
  -        broker.store(mod.getObject(), ObjectModificationDefaultImpl.UPDATE);
  +        mod.doUpdate();
       }
   
       /**
        * rollback transaction.
        */
  -    public void rollback(ObjectEnvelope mod, PersistenceBroker broker)
  +    public void rollback(ObjectEnvelope mod)
       {
  -        this.removeFromCache(mod.getObject(), broker);
  +        mod.doEvictFromCache();
   /*
   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
  
  
  
  1.28      +14 -6     db-ojb/src/java/org/apache/ojb/odmg/J2EETransactionImpl.java
  
  Index: J2EETransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/J2EETransactionImpl.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- J2EETransactionImpl.java	14 Nov 2004 09:37:20 -0000	1.27
  +++ J2EETransactionImpl.java	28 Nov 2004 03:17:33 -0000	1.28
  @@ -26,6 +26,7 @@
   import org.apache.ojb.odmg.locking.LockManager;
   import org.odmg.LockNotGrantedException;
   import org.odmg.TransactionAbortedException;
  +import org.odmg.ODMGRuntimeException;
   
   /**
    * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
  @@ -145,7 +146,7 @@
                       || status == Status.STATUS_NO_TRANSACTION)
               {
                   log.error("Synchronization#beforeCompletion: Can't prepare for commit, because tx status was "
  -                        + TxUtil.getStatusString(status) + ". Do internal cleanup.");
  +                        + TxUtil.getStatusString(status) + ". Do internal cleanup only.");
               }
               else
               {
  @@ -159,6 +160,7 @@
           }
           catch(Exception e)
           {
  +            log.error("Synchronization#beforeCompletion: Error while prepare for commit", e);
               if(e instanceof LockNotGrantedException)
               {
                   throw (LockNotGrantedException) e;
  @@ -167,10 +169,14 @@
               {
                   throw (TransactionAbortedException) e;
               }
  +            else if(e instanceof ODMGRuntimeException)
  +            {
  +                throw (ODMGRuntimeException) e;
  +            }
               else
               {
  -                new OJBRuntimeException("Method beforeCompletion() fails, status of JTA-tx was "
  -                        + TxUtil.getStatusString(status), e);
  +                throw new ODMGRuntimeException("Method beforeCompletion() fails, status of JTA-tx was "
  +                        + TxUtil.getStatusString(status) + ", message: " + e.getMessage());
               }
   
           }
  @@ -215,7 +221,7 @@
       {
           try
           {
  -            // prepareForCommit was done before
  +            // prepare for commit was done before on 'beforeCompleation' call
               if(log.isDebugEnabled()) log.debug("Commit transaction " + this + ", commit on broker " + broker);
               if(hasBroker())
               {
  @@ -223,11 +229,13 @@
                   doClose();
               }
               setStatus(Status.STATUS_COMMITTED);
  +            // Now, we notify everything the commit is done.
  +            performTransactionAwareAfterCommit();
           }
           catch(Exception ex)
           {
               // We should not reach this block
  -            log.error("Error while commit used PB-Instance and close resources", ex);
  +            log.error("Unexpected error while do commit on used PB-Instance and close resources", ex);
               abort();
           }
       }
  
  
  
  1.36      +132 -18   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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- ObjectEnvelope.java	20 Sep 2004 14:30:58 -0000	1.35
  +++ ObjectEnvelope.java	28 Nov 2004 03:17:33 -0000	1.36
  @@ -21,15 +21,17 @@
    *
    */
   
  -import java.lang.reflect.Array;
  +import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
   
  +import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.core.proxy.IndirectionHandler;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  @@ -40,7 +42,9 @@
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.odmg.states.ModificationState;
  -import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.ojb.odmg.states.StateNewDirty;
  +import org.apache.ojb.odmg.states.StateOldClean;
  +import org.apache.ojb.odmg.states.StateOldDirty;
   
   /**
    * ObjectEnvelope is used during ODMG transactions as a wrapper for a
  @@ -75,24 +79,40 @@
        *
        * Create a wrapper by providing an Object.
        */
  -    public ObjectEnvelope(ObjectEnvelopeTable buffer, Identity oid, Object obj, PersistenceBroker broker, boolean isNewObject)
  +    public ObjectEnvelope(ObjectEnvelopeTable buffer, Identity oid, Object obj, boolean isNewObject)
       {
           this.buffer = buffer;
           this.oid = oid;
           // TODO: do we really need to materialize??
           myObj = ProxyHelper.getRealObject(obj);
  -        refreshObjectImage(broker);
  +        refreshObjectImage();
           prepareInitialState(isNewObject);
       }
   
  +    PersistenceBroker getBroker()
  +    {
  +        return buffer.getTransaction().getBroker();
  +    }
  +
  +    TransactionImpl getTx()
  +    {
  +        return buffer.getTransaction();
  +    }
  +
  +    ObjectEnvelopeTable getEnvelopeTable()
  +    {
  +        return buffer;
  +    }
  +
       public void close()
       {
           myObj = null;
           beforeImage = null;
       }
   
  -    public void refreshObjectImage(PersistenceBroker broker)
  +    public void refreshObjectImage()
       {
  +        PersistenceBroker broker = getBroker();
           try
           {
               hasChanged = null;
  @@ -275,7 +295,7 @@
               Object collectionOrArray = collectionDescriptor.getPersistentField().get(myObj);
               if(collectionOrArray != null)
               {
  -                int referencesId = 0;
  +                Collection referencesId = null;
                   // no special treatment for CollectionProxies required,
                   // their size() method does not materialize the elements.
                   /**
  @@ -285,18 +305,14 @@
                    */
                   if(collectionOrArray instanceof Collection)
                   {
  -                    referencesId = ((Collection) collectionOrArray).size();
  +                    referencesId = new ArrayList((Collection) collectionOrArray);
                   }
                   else if(collectionOrArray.getClass().isArray())
                   {
  -                    referencesId = Array.getLength(collectionOrArray);
  -                }
  -                else
  -                {
  -                    referencesId = collectionOrArray.hashCode();
  +                    referencesId = Arrays.asList((Object[]) collectionOrArray);
                   }
   
  -                fieldValues.put(collectionDescriptor, new Integer(referencesId));
  +                fieldValues.put(collectionDescriptor, referencesId);
               }
           }
           return fieldValues;
  @@ -347,20 +363,20 @@
           {
               // 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();
  +            initialState = StateNewDirty.getInstance();
           }
           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,
               // possibly with new field values.
  -            initialState = org.apache.ojb.odmg.states.StateOldDirty.getInstance();
  +            initialState = StateOldDirty.getInstance();
           }
           else
           {
               // if object is already persistent it will be marked as old.
               // it is marked as clean as it has not been modified during tx already
  -            initialState = org.apache.ojb.odmg.states.StateOldClean.getInstance();
  +            initialState = StateOldClean.getInstance();
           }
           // remember it:
           modificationState = initialState;
  @@ -428,4 +444,102 @@
   
           return hasChanged.booleanValue();
       }
  -}
  +
  +    /**
  +     * Mark new or deleted collection elements
  +     * @param broker
  +     */
  +    void markCollectionElements(PersistenceBroker broker)
  +    {
  +        Map currentImage = getMap(broker);
  +
  +        Iterator iter = currentImage.entrySet().iterator();
  +        while (iter.hasNext())
  +        {
  +            Map.Entry entry = (Map.Entry) iter.next();
  +            if (entry.getKey() instanceof CollectionDescriptor)
  +            {
  +                CollectionDescriptor cds = (CollectionDescriptor) entry.getKey();
  +
  +                Collection oldCol = (Collection) beforeImage.get(entry.getKey());
  +                Collection newCol = (Collection) entry.getValue();
  +
  +                if (!cds.isMtoNRelation())
  +                {
  +                    markDelete(oldCol, newCol);
  +                }
  +
  +                // requires fix in InvocationHandler
  +                markNew(oldCol, newCol);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Mark object for delete if it's not available in the new Collection.
  +     * @param oldCol
  +     * @param newCol
  +     */
  +    private void markDelete(Collection oldCol, Collection newCol)
  +    {
  +        if (oldCol == null)
  +        {
  +            return;
  +        }
  +
  +        Iterator oldIter = oldCol.iterator();
  +        while (oldIter.hasNext())
  +        {
  +            Object oldObj = oldIter.next();
  +            if ((newCol != null) && (!newCol.contains(oldObj)))
  +            {
  +                ObjectEnvelope mod = buffer.get(oldObj, false);
  +                mod.setModificationState(mod.getModificationState().markDelete());
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Mark object for insert if it's not available in the old Collection.
  +     * @param oldCol
  +     * @param newCol
  +     */
  +    private void markNew(Collection oldCol, Collection newCol)
  +    {
  +        if (newCol == null)
  +        {
  +            return;
  +        }
  +
  +        Iterator newIter = newCol.iterator();
  +        while (newIter.hasNext())
  +        {
  +            Object newObj = newIter.next();
  +            if ((oldCol != null) && (!oldCol.contains(newObj)))
  +            {
  +                ObjectEnvelope mod = buffer.get(newObj, true);
  +                mod.setModificationState(mod.getModificationState().markNew());
  +            }
  +        }
  +    }
  +
  +    public void doUpdate()
  +    {
  +        getBroker().store(getObject(), org.apache.ojb.broker.OJB.UPDATE);
  +    }
  +
  +    public void doInsert()
  +    {
  +        getBroker().store(getObject(), org.apache.ojb.broker.OJB.INSERT);
  +    }
  +
  +    public void doDelete()
  +    {
  +        getBroker().delete(getObject());
  +    }
  +
  +    public void doEvictFromCache()
  +    {
  +        getBroker().removeFromCache(getIdentity());
  +    }
  +}
  \ No newline at end of file
  
  
  
  1.40      +114 -174  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.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- ObjectEnvelopeTable.java	20 Nov 2004 09:57:20 -0000	1.39
  +++ ObjectEnvelopeTable.java	28 Nov 2004 03:17:33 -0000	1.40
  @@ -32,6 +32,8 @@
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
  +import org.apache.ojb.broker.core.proxy.CollectionProxy;
  +import org.apache.ojb.broker.core.proxy.IndirectionHandler;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  @@ -43,6 +45,7 @@
   import org.odmg.LockNotGrantedException;
   import org.odmg.Transaction;
   import org.odmg.TransactionAbortedException;
  +import org.odmg.ODMGRuntimeException;
   
   /**
    * manages all ObjectEnvelopes included by a transaction.
  @@ -85,6 +88,11 @@
           transaction = myTransaction;
       }
   
  +    TransactionImpl getTransaction()
  +    {
  +        return transaction;
  +    }
  +
       /**
        * prepare this instance for reuse
        */
  @@ -129,6 +137,9 @@
               // 0. turn on the batch mode
               connMan.setBatchMode(true);
   
  +            // 0.5 mark objects no longer available in collection for delete
  +            checkAllEnvelopes(broker);
  +
               // 1. upgrade implicit locks.
               upgradeImplicitLocksAndCheckIfCommitIsNeeded();
   
  @@ -145,21 +156,26 @@
               setCleanState();
   
           }
  -        catch (Throwable t)
  +        catch (Exception e)
           {
  -            // we do that in TransactionImpl#abort()
  -            //            broker.abortTransaction();
               connMan.clearBatch();
  -            log.error("Commit on object level failed for tx " + transaction, t);
  -            if (t instanceof OptimisticLockException)
  +            if(e instanceof OptimisticLockException)
               {
  +                log.warn("Optimistic lock exception while write objects", e);
                   // PB OptimisticLockException should be clearly signalled to the user
  -                Object sourceObject = ((OptimisticLockException) t).getSourceObject();
  -                throw new LockNotGrantedException("(" + sourceObject + ")" + t.getMessage());
  +                Object sourceObject = ((OptimisticLockException) e).getSourceObject();
  +                throw new LockNotGrantedException("Optimistic lock exception occur, source object was (" + sourceObject + ")," +
  +                        " message was (" + e.getMessage() + ")");
  +            }
  +            else if(!(e instanceof RuntimeException))
  +            {
  +                log.warn("Error while write objects for tx " + transaction, e);
  +                throw new ODMGRuntimeException("Unexpected error while write objects: " + e.getMessage());
               }
               else
               {
  -                throw new TransactionAbortedExceptionOJB(t);
  +                log.warn("Error while write objects for tx " + transaction, e);
  +                throw (RuntimeException) e;
               }
           }
           finally
  @@ -187,18 +203,33 @@
                   if(ProxyHelper.isMaterialized(mod.getObject()))
                   {
                       List referenceDescriptors = broker.getClassDescriptor(mod.getObject().getClass()).getObjectReferenceDescriptors();
  -                    assignReferenceFKs(broker, mod.getObject(), referenceDescriptors);
  +                    assignSingleReferenceFKs(broker, mod.getObject(), referenceDescriptors);
                   }
  -                mod.getModificationState().commit(mod, broker);
  +                mod.getModificationState().commit(mod);
  +                assignCollectionFKs(broker, broker.getClassDescriptor(mod.getObject().getClass()), mod.getObject());
               }
           }
       }
   
       /**
  +     * Mark objects no longer available in collection for delete and new objects for insert.
  +     * @param broker the PB to persist all objects
  +     */
  +    private void checkAllEnvelopes(PersistenceBroker broker)
  +    {
  +        Iterator iter = ((List) mvOrderOfIds.clone()).iterator();
  +        while (iter.hasNext())
  +        {
  +            ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
  +            mod.markCollectionElements(broker);
  +        }
  +    }
  +
  +    /**
        * 	assigns all foreign key attributes of the Object obj.
        *  used during store(obj, boolean);
        */
  -    private void assignReferenceFKs(PersistenceBroker broker, Object obj, List referenceDescriptors) throws PersistenceBrokerException
  +    private void assignSingleReferenceFKs(PersistenceBroker broker, Object obj, List referenceDescriptors) throws PersistenceBrokerException
       {
           try
           {
  @@ -208,7 +239,7 @@
               {
                   ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
                   Object ref = rds.getPersistentField().get(obj);
  -                assertFkAssignment(broker, obj, ref, rds);
  +                singleFkAssignment(broker, obj, ref, rds);
               }
           }
           catch (Throwable t)
  @@ -217,7 +248,7 @@
           }
       }
   
  -    private void assertFkAssignment(PersistenceBroker broker, Object obj, Object ref, ObjectReferenceDescriptor rds)
  +    private void singleFkAssignment(PersistenceBroker broker, Object obj, Object ref, ObjectReferenceDescriptor rds)
       {
           try
           {
  @@ -253,6 +284,73 @@
           }
       }
   
  +    private void assignCollectionFKs(PersistenceBroker broker, ClassDescriptor cld, Object mainObject)
  +            throws PersistenceBrokerException
  +    {
  +        Iterator i = cld.getCollectionDescriptors().iterator();
  +        while (i.hasNext())
  +        {
  +            CollectionDescriptor cds = (CollectionDescriptor) i.next();
  +            Object col = cds.getPersistentField().get(mainObject);
  +            if (col != null)
  +            {
  +                CollectionProxy proxy = ProxyHelper.getCollectionProxy(col);
  +                // if we found an unmaterialized proxy we skip FK assignment
  +                if (proxy != null && !proxy.isLoaded())
  +                {
  +                    continue;
  +                }
  +                // get PK values of the main object
  +                // BRJ: do not convertToSql
  +                ValueContainer[] objPkValues = broker.serviceBrokerHelper().getKeyValues(cld, mainObject, false);
  +                // get foreign key info for collection elements
  +                ClassDescriptor itemCld = broker.getClassDescriptor(cds.getItemClass());
  +                FieldDescriptor[] itemFkFields = cds.getForeignKeyFieldDescriptors(itemCld);
  +
  +                // get Iterator for Collection or Array
  +                Iterator colIterator = BrokerHelper.getCollectionIterator(col);
  +                Object item = null;
  +                while (colIterator.hasNext())
  +                {
  +                    item = colIterator.next();
  +                    IndirectionHandler handler = ProxyHelper.getIndirectionHandler(item);
  +                    if (handler != null)
  +                    {
  +                        if (!handler.alreadyMaterialized())
  +                        {
  +                            continue;
  +                        }
  +                        else
  +                        {
  +                            // @todo consider registering to hear when this is
  +                            // derefernced instead of just loading here -bmc
  +                            item = handler.getRealSubject();
  +                        }
  +                    }
  +                    // assign FK in referenced objects for all 1:n references
  +                    if(!cds.isMtoNRelation())
  +                    {
  +                        //if itemCld refers to an interface the foreignKeyFieldDescriptors
  +                        //have to be computed again for each concrete class
  +                        if (itemCld.isInterface())
  +                        {
  +                            ClassDescriptor concreteItemCld = broker.getClassDescriptor(item.getClass());
  +                            itemFkFields = cds.getForeignKeyFieldDescriptors(concreteItemCld);
  +                        }
  +                        // provide all items in collection attributes
  +                        // with foreign key information
  +                        for (int j = 0; j < itemFkFields.length; j++)
  +                        {
  +                            FieldDescriptor fld = itemFkFields[j];
  +                            fld.getPersistentField().set(item, objPkValues[j].getValue());
  +                        }
  +                    }
  +                }
  +            }
  +        }
  +    }
  +
  +
   	/**
   	 *
   	 */
  @@ -268,7 +366,7 @@
   					ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
   					if(mod.getModificationState() != StateOldClean.getInstance())
   					{
  -						mod.refreshObjectImage(transaction.getBroker());
  +						mod.refreshObjectImage();
   						mod.setModificationState(StateOldClean.getInstance());
   					}
   			  }
  @@ -339,7 +437,6 @@
       {
           try
           {
  -            PersistenceBroker broker = transaction.getBroker();
               Iterator iter = mvOrderOfIds.iterator();
               while (iter.hasNext())
               {
  @@ -351,7 +448,7 @@
                   {
                       mod.setModificationState(mod.getModificationState().markDirty());
                   }
  -                mod.getModificationState().rollback(mod, broker);
  +                mod.getModificationState().rollback(mod);
               }
           }
           finally
  @@ -420,11 +517,10 @@
        */
       public ObjectEnvelope get(Identity oid, Object pKey, boolean isNew)
       {
  -        PersistenceBroker broker = transaction.getBroker();
           ObjectEnvelope result = getByIdentity(oid);
           if (result == null)
           {
  -            result = new ObjectEnvelope(this, oid, pKey, broker, isNew);
  +            result = new ObjectEnvelope(this, oid, pKey, isNew);
               mhtObjectEnvelopes.put(oid, result);
               mvOrderOfIds.add(oid);
               if (log.isDebugEnabled())
  @@ -433,20 +529,6 @@
           return result;
       }
   
  -//    /**
  -//     * 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
        */
  @@ -487,148 +569,6 @@
               for (int i = 0; i < newOrder.length; i++)
               {
                   mvOrderOfIds.add(newOrder[i]);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * put an object and all its dependent objects in the new vector. If the object
  -     * in question is going to be DELETEd, first the objects referenced in collections
  -     * are put in the vector, then the object in question and then the references.
  -     * Otherwise the order is reversed.
  -     */
  -    private void reorderObject(
  -        Map htNewHashtable,
  -        List newVector,
  -        ObjectEnvelope objectToReorder,
  -        Identity id,
  -        Map htOldVectorPosition)
  -        throws IllegalAccessException
  -    {
  -        PersistenceBroker broker = transaction.getBroker();
  -        if (objectToReorder != null)
  -        {
  -            ClassDescriptor cld = broker.getClassDescriptor(objectToReorder.getObject().getClass());
  -            if (objectToReorder.needsDelete())
  -            {
  -                reorderCollection(
  -                    htNewHashtable,
  -                    newVector,
  -                    objectToReorder,
  -                    cld,
  -                    htOldVectorPosition);
  -                newVector.add(id);
  -                htNewHashtable.put(id, objectToReorder);
  -                reorderReference(
  -                    htNewHashtable,
  -                    newVector,
  -                    objectToReorder,
  -                    cld,
  -                    htOldVectorPosition);
  -            }
  -            else
  -            {
  -                reorderReference(
  -                    htNewHashtable,
  -                    newVector,
  -                    objectToReorder,
  -                    cld,
  -                    htOldVectorPosition);
  -                newVector.add(id);
  -                htNewHashtable.put(id, objectToReorder);
  -                reorderCollection(
  -                    htNewHashtable,
  -                    newVector,
  -                    objectToReorder,
  -                    cld,
  -                    htOldVectorPosition);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Resolves all objects referenced in collections of objectToReorder. The referenced
  -     * objects are removed from the list of modified objects in this class and passed
  -     * to reorderObject, where dependencies of the object are resolved (i.e. if the referenced
  -     * object contains again collections or references) and it is finally put into the new order
  -     * vector.
  -     */
  -    private void reorderCollection(
  -        Map htNewHashtable,
  -        List newVector,
  -        ObjectEnvelope objectToReorder,
  -        ClassDescriptor cld,
  -        Map htOldVectorPosition)
  -        throws IllegalAccessException
  -    {
  -        Iterator i;
  -        i = cld.getCollectionDescriptors().iterator();
  -        while (i.hasNext())
  -        {
  -            CollectionDescriptor cds = (CollectionDescriptor) i.next();
  -            Object col = cds.getPersistentField().get(objectToReorder.getObject());
  -            if (col != null)
  -            {
  -                Iterator colIterator;
  -                if (ProxyHelper.isCollectionProxy(col) && !ProxyHelper.getCollectionProxy(col).isLoaded())
  -                {
  -                    colIterator = Collections.EMPTY_LIST.iterator();
  -                }
  -                else
  -                {
  -                    colIterator = BrokerHelper.getCollectionIterator(col);
  -                }
  -                while (colIterator.hasNext())
  -                {
  -                    // The collection now contains all the objects in the collection.
  -                    // 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 = transaction.getBroker().serviceIdentity().buildIdentity(colIterator.next());
  -                    ObjectEnvelope oe = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
  -                    if (oe != null)
  -                    {
  -                        mvOrderOfIds.set(((Integer) htOldVectorPosition.get(id)).intValue(), null);
  -                        // mvOrderOfIds.set(mvOrderOfIds.indexOf(id), null);
  -                        mhtObjectEnvelopes.remove(id);
  -                        reorderObject(htNewHashtable, newVector, oe, id, htOldVectorPosition);
  -                    }
  -                }
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Resolves all objects referenced in references of objectToReorder. The referenced
  -     * objects are removed from the list of modified objects in this class and passed
  -     * to reorderObject, where dependencies of the object are resolved (i.e. if the referenced
  -     * object contains again collections or references) and it is finally put into the new order
  -     * vector.
  -     */
  -    private void reorderReference(
  -        Map htNewHashtable,
  -        List newVector,
  -        ObjectEnvelope objectToReorder,
  -        ClassDescriptor cld,
  -        Map htOldVectorPosition)
  -        throws IllegalAccessException
  -    {
  -        Iterator i = cld.getObjectReferenceDescriptors().iterator();
  -        while (i.hasNext())
  -        {
  -            ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
  -            Object refObj = rds.getPersistentField().get(objectToReorder.getObject());
  -            if (refObj != null)
  -            {
  -                Identity id = transaction.getBroker().serviceIdentity().buildIdentity(refObj);
  -                ObjectEnvelope oe = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
  -                if (oe != null)
  -                {
  -                    mhtObjectEnvelopes.remove(id);
  -                    mvOrderOfIds.set(((Integer) htOldVectorPosition.get(id)).intValue(), null);
  -                    // mvOrderOfIds.set(mvOrderOfIds.indexOf(id), null);
  -                    reorderObject(htNewHashtable, newVector, oe, id, htOldVectorPosition);
  -                }
               }
           }
       }
  
  
  
  1.5       +34 -27    db-ojb/src/java/org/apache/ojb/odmg/TransactionAbortedExceptionOJB.java
  
  Index: TransactionAbortedExceptionOJB.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionAbortedExceptionOJB.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TransactionAbortedExceptionOJB.java	4 Apr 2004 23:53:38 -0000	1.4
  +++ TransactionAbortedExceptionOJB.java	28 Nov 2004 03:17:33 -0000	1.5
  @@ -18,11 +18,11 @@
   import org.odmg.TransactionAbortedException;
   
   /**
  - * This specialised exception allows us to capture the cause of an 
  + * This specialised exception allows us to capture the cause of an
    * ODMG TransactionAbortedException. This, in turn,
  - * gives the "catcher" of the exception the ability to take different 
  + * gives the "catcher" of the exception the ability to take different
    * courses of action dependent upon why the transaction was aborted. <p>
  - * This exception has been created as a subclass of 
  + * This exception has been created as a subclass of
    * org.odmg.TransactionAbortedException so that we don't
    * <ul>
    * <li>Modify the ODMG exception - as it is defined by the ODMG spec
  @@ -33,32 +33,39 @@
    */
   public class TransactionAbortedExceptionOJB extends TransactionAbortedException
   {
  -  /**
  -   * The cause of a TransactionAbortedException
  -   */
  -  private Throwable cause;
  +    /**
  +     * The cause of a TransactionAbortedException
  +     */
  +    private Throwable cause;
   
  -  public TransactionAbortedExceptionOJB()
  -  {
  -    super();
  -  }
  +    public TransactionAbortedExceptionOJB()
  +    {
  +        super();
  +    }
   
  -  public TransactionAbortedExceptionOJB(String msg)
  -  {
  -    super(msg);
  -  }
  +    public TransactionAbortedExceptionOJB(String msg)
  +    {
  +        super(msg);
  +    }
   
  -  public TransactionAbortedExceptionOJB(Throwable cause)
  -  {
  -    this.cause = cause;
  -  }
  +    public TransactionAbortedExceptionOJB(String msg, Throwable th)
  +    {
  +        super(msg);
  +        this.cause = th;
  +    }
   
  -  /**
  -   * Returns the cause of the exception. May be null.
  -   * @return
  -   */
  -  public Throwable getCause()
  -  {
  -    return cause;
  -  }
  +    public TransactionAbortedExceptionOJB(Throwable cause)
  +    {
  +        this.cause = cause;
  +    }
  +
  +    /**
  +     * Returns the cause of the exception. May be null.
  +     *
  +     * @return
  +     */
  +    public Throwable getCause()
  +    {
  +        return cause;
  +    }
   }
  
  
  
  1.67      +45 -88    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.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- TransactionImpl.java	14 Nov 2004 09:37:20 -0000	1.66
  +++ TransactionImpl.java	28 Nov 2004 03:17:33 -0000	1.67
  @@ -15,20 +15,18 @@
    * limitations under the License.
    */
   
  +import javax.transaction.Status;
   import java.util.ArrayList;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Iterator;
   
  -import javax.transaction.Status;
  -
   import org.apache.commons.lang.SystemUtils;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PBFactoryException;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
  -import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.core.proxy.CollectionProxy;
   import org.apache.ojb.broker.core.proxy.CollectionProxyListener;
   import org.apache.ojb.broker.core.proxy.IndirectionHandler;
  @@ -36,7 +34,6 @@
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  -import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.GUID;
  @@ -889,99 +886,59 @@
           }
           if (implicitLocking)
           {
  -            lockCollections(cld, objectToRegister, assLockMode);
  -        }
  -    }
  -
  -    private void lockCollections(ClassDescriptor cld, Object newTxObject, int lockMode)
  -            throws PersistenceBrokerException
  -    {
  -        Iterator i;
  -        i = cld.getCollectionDescriptors().iterator();
  -        while (i.hasNext())
  -        {
  -            CollectionDescriptor cds = (CollectionDescriptor) i.next();
  -            Object col = cds.getPersistentField().get(newTxObject);
  -            if (col != null)
  +            Iterator i = cld.getCollectionDescriptors().iterator();
  +            while (i.hasNext())
               {
  -                CollectionProxy proxy = ProxyHelper.getCollectionProxy(col);
  -                if (proxy != null)
  +                CollectionDescriptor cds = (CollectionDescriptor) i.next();
  +                Object col = cds.getPersistentField().get(objectToRegister);
  +                if (col != null)
                   {
  -                    if (!proxy.isLoaded())
  +                    CollectionProxy proxy = ProxyHelper.getCollectionProxy(col);
  +                    if (proxy != null)
                       {
  -                        if (log.isDebugEnabled()) log.debug("adding self as listener to collection proxy");
  -                        proxy.addListener(this);
  -                        continue;
  -                    }
  -                }
  -                Iterator colIterator = BrokerHelper.getCollectionIterator(col);
  -                // get foreign info for collection elements
  -                ClassDescriptor itemCld = this.getBroker().getClassDescriptor(cds.getItemClass());
  -                // BRJ: do not convertToSql
  -                ValueContainer[] objPkValues = this.getBroker().serviceBrokerHelper().getKeyValues(cld, newTxObject, false);
  -                FieldDescriptor[] itemFkFields = cds.getForeignKeyFieldDescriptors(itemCld);
  -
  -                Object item = null;
  -                try
  -                {
  -                    while (colIterator.hasNext())
  -                    {
  -                        item = colIterator.next();
  -                        IndirectionHandler handler = ProxyHelper.getIndirectionHandler(item);
  -                        if (handler != null)
  +                        if (!proxy.isLoaded())
                           {
  -                            if (!handler.alreadyMaterialized())
  -                            {
  -                                continue;
  -                            }
  -                            else
  -                            {
  -                                // @todo consider registering to hear when this is
  -                                // derefernced instead of just loading here -bmc
  -                                item = handler.getRealSubject();
  -                            }
  +                            if (log.isDebugEnabled()) log.debug("adding self as listener to collection proxy");
  +                            proxy.addListener(this);
  +                            continue;
                           }
  -                        if(!cds.isMtoNRelation())
  +                    }
  +                    Iterator colIterator = BrokerHelper.getCollectionIterator(col);
  +                    Object item = null;
  +                    try
  +                    {
  +                        while (colIterator.hasNext())
                           {
  -                            //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++)
  +                            item = colIterator.next();
  +                            IndirectionHandler handler = ProxyHelper.getIndirectionHandler(item);
  +                            if (handler != null)
                               {
  -                                FieldDescriptor fld = itemFkFields[j];
  -                                fld.getPersistentField().set(item, objPkValues[j].getValue());
  +                                if (!handler.alreadyMaterialized())
  +                                {
  +                                    handler.addListener(this);
  +                                    continue;
  +                                }
  +                                else
  +                                {
  +                                    // @todo consider registering to hear when this is
  +                                    // derefernced instead of just loading here -bmc
  +                                    item = handler.getRealSubject();
  +                                }
                               }
  +                            doLock(item, assLockMode);
                           }
  -                        doLock(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;
  +                    catch (LockNotGrantedException e)
  +                    {
  +                        String eol = SystemUtils.LINE_SEPARATOR;
  +                        log.error("Lock not granted, while lock collection references[" +
  +                                eol + "current reference descriptor:" +
  +                                eol + cds.toXML() +
  +                                eol + "object to lock: " + item +
  +                                eol + "main object class: " + objectToRegister.getClass().getName() +
  +                                eol + "]", e);
  +                        throw e;
  +                    }
                   }
               }
           }
  
  
  

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