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 ObjectEnvelope.java ObjectEnvelopeTable.java
Date Tue, 16 Nov 2004 17:45:35 GMT
arminw      2004/11/16 09:45:35

  Modified:    src/java/org/apache/ojb/odmg/states Tag: OJB_1_0_RELEASE
                        ModificationState.java StateNewClean.java
                        StateNewDelete.java StateNewDirty.java
                        StateOldClean.java StateOldDelete.java
                        StateOldDirty.java
               src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        ObjectEnvelope.java ObjectEnvelopeTable.java
  Log:
  first part of refactored state handling
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.12.2.1  +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.12.2.1
  diff -u -r1.12 -r1.12.2.1
  --- ModificationState.java	4 Apr 2004 23:53:40 -0000	1.12
  +++ ModificationState.java	16 Nov 2004 17:45:35 -0000	1.12.2.1
  @@ -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.7.2.2   +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.7.2.1
  retrieving revision 1.7.2.2
  diff -u -r1.7.2.1 -r1.7.2.2
  --- StateNewClean.java	18 Sep 2004 13:05:55 -0000	1.7.2.1
  +++ StateNewClean.java	16 Nov 2004 17:45:35 -0000	1.7.2.2
  @@ -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.5.2.1   +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.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- StateNewDelete.java	5 Apr 2004 12:16:24 -0000	1.5
  +++ StateNewDelete.java	16 Nov 2004 17:45:35 -0000	1.5.2.1
  @@ -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.6.2.2   +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.6.2.1
  retrieving revision 1.6.2.2
  diff -u -r1.6.2.1 -r1.6.2.2
  --- StateNewDirty.java	18 Sep 2004 13:05:55 -0000	1.6.2.1
  +++ StateNewDirty.java	16 Nov 2004 17:45:35 -0000	1.6.2.2
  @@ -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.5.2.1   +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.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- StateOldClean.java	5 Apr 2004 12:16:24 -0000	1.5
  +++ StateOldClean.java	16 Nov 2004 17:45:35 -0000	1.5.2.1
  @@ -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.5.2.1   +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.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- StateOldDelete.java	5 Apr 2004 12:16:24 -0000	1.5
  +++ StateOldDelete.java	16 Nov 2004 17:45:35 -0000	1.5.2.1
  @@ -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.7.2.1   +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.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- StateOldDirty.java	4 Apr 2004 23:53:40 -0000	1.7
  +++ StateOldDirty.java	16 Nov 2004 17:45:35 -0000	1.7.2.1
  @@ -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
  
  
  
  No                   revision
  No                   revision
  1.32.2.4  +133 -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.32.2.3
  retrieving revision 1.32.2.4
  diff -u -r1.32.2.3 -r1.32.2.4
  --- ObjectEnvelope.java	18 Sep 2004 13:05:55 -0000	1.32.2.3
  +++ ObjectEnvelope.java	16 Nov 2004 17:45:35 -0000	1.32.2.4
  @@ -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;
  @@ -38,9 +40,12 @@
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.util.ObjectModification;
  +import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
   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 +80,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 +296,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 +306,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 +364,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 +445,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(), ObjectModificationDefaultImpl.UPDATE);
  +    }
  +
  +    public void doInsert()
  +    {
  +        getBroker().store(getObject(), ObjectModificationDefaultImpl.INSERT);
  +    }
  +
  +    public void doDelete()
  +    {
  +        getBroker().delete(getObject());
  +    }
  +
  +    public void doEvictFromCache()
  +    {
  +        getBroker().removeFromCache(getIdentity());
  +    }
  +}
  \ No newline at end of file
  
  
  
  1.32.2.7  +27 -20    db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java
  
  Index: ObjectEnvelopeTable.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
  retrieving revision 1.32.2.6
  retrieving revision 1.32.2.7
  diff -u -r1.32.2.6 -r1.32.2.7
  --- ObjectEnvelopeTable.java	3 Nov 2004 19:11:47 -0000	1.32.2.6
  +++ ObjectEnvelopeTable.java	16 Nov 2004 17:45:35 -0000	1.32.2.7
  @@ -89,6 +89,11 @@
           transaction = myTransaction;
       }
   
  +    TransactionImpl getTransaction()
  +    {
  +        return transaction;
  +    }
  +
       /**
        * prepare this instance for reuse
        */
  @@ -133,6 +138,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();
   
  @@ -193,13 +201,27 @@
                       List referenceDescriptors = broker.getClassDescriptor(mod.getObject().getClass()).getObjectReferenceDescriptors();
                       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);
        */
  @@ -340,7 +362,7 @@
   					ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
   					if(mod.getModificationState() != StateOldClean.getInstance())
   					{
  -						mod.refreshObjectImage(transaction.getBroker());
  +						mod.refreshObjectImage();
   						mod.setModificationState(StateOldClean.getInstance());
   					}
   			  }
  @@ -424,7 +446,7 @@
                   {
                       mod.setModificationState(mod.getModificationState().markDirty());
                   }
  -                mod.getModificationState().rollback(mod, broker);
  +                mod.getModificationState().rollback(mod);
               }
           }
           finally
  @@ -493,11 +515,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())
  @@ -506,20 +527,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
        */
  @@ -727,4 +734,4 @@
           return config;
       }
   
  -}
  +}
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message