commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bali...@apache.org
Subject cvs commit: jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore TestSample.java
Date Wed, 15 May 2002 16:18:23 GMT
baliuka     02/05/15 09:18:23

  Modified:    simplestore build.xml
               simplestore/src/java/org/apache/commons/simplestore/jdbc
                        DriverDataSource.java
               simplestore/src/java/org/apache/commons/simplestore/persistence
                        InternalTransaction.java
               simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        PersistentProxy.java TransactionImpl.java
               simplestore/src/test/org/apache/commons/simplestore
                        TestSample.java
  Log:
  Fixed rollback on collections
  
  Revision  Changes    Path
  1.27      +2 -2      jakarta-commons-sandbox/simplestore/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/build.xml,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- build.xml	14 May 2002 17:02:50 -0000	1.26
  +++ build.xml	15 May 2002 16:18:23 -0000	1.27
  @@ -1,7 +1,7 @@
   <?xml version="1.0" encoding="UTF-8"?>
   <project basedir="." default="compile" name="simplestore">
   
  -<!--         "simplestore" component of the Jakarta Commons Subproject         $Id:
build.xml,v 1.26 2002/05/14 17:02:50 baliuka Exp $ -->
  +<!--         "simplestore" component of the Jakarta Commons Subproject         $Id:
build.xml,v 1.27 2002/05/15 16:18:23 baliuka Exp $ -->
   
   <!-- ========== Executable Targets ======================================== -->
   
  @@ -185,7 +185,7 @@
     <!-- jvmarg value="-Xrunhprof:cpu=times,file=debug.txt" / -->
     <!-- jvmarg value="-verbose:gc" / --> 
     <!-- jvmarg value="-verbose:class" / --> 
  -     <sysproperty key="DEBUG" value="false"/> 
  +     <sysproperty key="DEBUG" value="true"/> 
         <arg value="${test.entry}"/>
           <classpath>
             <pathelement path="${build.home}/classes"/>
  
  
  
  1.16      +15 -2     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/jdbc/DriverDataSource.java
  
  Index: DriverDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/jdbc/DriverDataSource.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DriverDataSource.java	14 May 2002 17:02:50 -0000	1.15
  +++ DriverDataSource.java	15 May 2002 16:18:23 -0000	1.16
  @@ -78,7 +78,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: DriverDataSource.java,v 1.15 2002/05/14 17:02:50 baliuka Exp $
  + *@version    $Id: DriverDataSource.java,v 1.16 2002/05/15 16:18:23 baliuka Exp $
    *
    */
   public class DriverDataSource implements ConnectionFactory {
  @@ -396,7 +396,7 @@
       throws Throwable{
           try{
               
  -            if( method.getName().equals("close")  ) {
  +            if( method.equals(CLOSE)  ) {
                   close();
                   return null;
                   
  @@ -432,6 +432,19 @@
           );
           
       }
  +    
  +    private static final java.lang.reflect.Method CLOSE;
  +    static{
  +       try{
  +       
  +           CLOSE = java.sql.Connection.class.getMethod("close",new Class[]{});
  +           
  +       }catch( Exception e){
  +        throw new  Error(e.getMessage());
  +       }
  +   
  +   }
  +    
       
   }
   
  
  
  
  1.3       +8 -6      jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/InternalTransaction.java
  
  Index: InternalTransaction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/InternalTransaction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InternalTransaction.java	11 Mar 2002 15:40:53 -0000	1.2
  +++ InternalTransaction.java	15 May 2002 16:18:23 -0000	1.3
  @@ -59,7 +59,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: InternalTransaction.java,v 1.2 2002/03/11 15:40:53 baliuka Exp $
  + *@version    $Id: InternalTransaction.java,v 1.3 2002/05/15 16:18:23 baliuka Exp $
    */
   
   public interface InternalTransaction extends Transaction {
  @@ -70,15 +70,17 @@
   
       public void rollback(Set objects);
   
  -    void add(MetaObject props);
  +    public void add(MetaObject props);
   
  -    java.util.Collection getTransactionalObjects();
  +    public java.util.Collection getTransactionalObjects();
       
  -    void setAttribute(String name, Object value);
  +    public void setAttribute(String name, Object value);
   
  -    Object getAttribute(String name);
  +    public Object getAttribute(String name);
   
  -    void removeAttribute(String name);
  +    public void removeAttribute(String name);
  +    
  +    public void add(Object key, java.util.Collection obj);
   
   }
   
  
  
  
  1.35      +3 -1      jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistentProxy.java
  
  Index: PersistentProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistentProxy.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- PersistentProxy.java	14 May 2002 17:02:51 -0000	1.34
  +++ PersistentProxy.java	15 May 2002 16:18:23 -0000	1.35
  @@ -77,7 +77,7 @@
    *      baliuka@mwm.lt</a>
    *@author     Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
    *      g-froehlich@gmx.de</a>
  - *@version    $Id: PersistentProxy.java,v 1.34 2002/05/14 17:02:51 baliuka Exp $
  + *@version    $Id: PersistentProxy.java,v 1.35 2002/05/15 16:18:23 baliuka Exp $
    */
   public class PersistentProxy
   implements MetaObject,  org.apache.commons.simplestore.tools.Constants ,
  @@ -361,6 +361,7 @@
               java.util.Set set = (java.util.Set)m_context.getCache().get(key);
               
               if( set != null ){
  +                m_context.getTransactionManager().getTransaction().add(key,set);
                   set.remove(m_object);
               }
               
  @@ -370,6 +371,7 @@
               set = (java.util.Set)m_context.getCache().get(key);
               
               if( set != null ){
  +                m_context.getTransactionManager().getTransaction().add(key,set);
                   set.add(m_object);
               }
               
  
  
  
  1.9       +39 -5     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/TransactionImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TransactionImpl.java	12 May 2002 11:40:02 -0000	1.8
  +++ TransactionImpl.java	15 May 2002 16:18:23 -0000	1.9
  @@ -63,6 +63,7 @@
   
   import java.util.HashMap;
   import java.util.HashSet;
  +import java.util.Collection;
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Set;
  @@ -70,7 +71,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TransactionImpl.java,v 1.8 2002/05/12 11:40:02 baliuka Exp $
  + *@version    $Id: TransactionImpl.java,v 1.9 2002/05/15 16:18:23 baliuka Exp $
    */
   
   public class TransactionImpl 
  @@ -83,7 +84,10 @@
       Set objects;
       Map attributes = new HashMap();
       Map storedState = new HashMap();
  +    Map storedCollections = new HashMap();
       boolean complete = true;
  +    Context context;
  +    java.util.List strongRefs = new java.util.ArrayList();
   
       /**
        * Creates new TransactionImpl
  @@ -91,9 +95,12 @@
        *@param  transaction
        *@param  objects
        */
  -    public TransactionImpl(InternalTransaction transaction, Set objects) {
  +    public TransactionImpl( InternalTransaction transaction, 
  +                            Set objects,
  +                            Context context) {
           this.objects = objects;
           this.transaction = transaction;
  +        this.context = context;
   
       }
   
  @@ -106,7 +113,7 @@
               return tr;
           }
   
  -        tr = new TransactionImpl(transaction, new HashSet());
  +        tr = new TransactionImpl(transaction, new HashSet(),context);
           context.getCache().put(threadId, tr);
   
           return tr;
  @@ -135,6 +142,8 @@
           checkState(!complete);
           transaction.commit(objects);
           complete = true;
  +        strongRefs.clear();
  +        storedCollections.clear();
           storedState.clear();
           objects.clear();
       }
  @@ -152,7 +161,7 @@
           doRollback();
       }
       
  -  //TODO: rollback  cached collections
  +  
     private void doRollback() {
           Iterator i = objects.iterator();
           while (i.hasNext()) {
  @@ -160,7 +169,17 @@
               mo.assign((MetaObject) storedState.get(mo.getOID()));
           }
           storedState.clear();
  +         i = storedCollections.keySet().iterator();
  +        while (i.hasNext()) {
  +          Object key = i.next();
  +          Collection cached = (Collection)context.getCache().get(key);
  +          cached.clear();
  +          cached.addAll((Collection)storedCollections.get(key));
  +        } 
  +         
           transaction.rollback(objects);
  +        strongRefs.clear();
  +        storedCollections.clear();
           objects.clear();
           complete = true;
       }
  @@ -170,12 +189,27 @@
           if (objects.add(props)) {
               try {
                   storedState.put(props.getOID(), props.clone());
  -                
  +                strongRefs.add(props.getObject());
               } catch (CloneNotSupportedException cnse) {
                   throw new UnsupportedOperationException(cnse.getMessage());
               }
           }
       }
  +    
  +    public void add(Object key,java.util.Collection obj) {
  +        checkState();
  +         
  +              if(!storedCollections.containsKey(key)){
  +                 java.util.Collection cln = new java.util.HashSet(); 
  +                  cln.addAll(obj);
  +                  strongRefs.add(obj);
  +                  storedCollections.put(key, cln);
  +              
  +              }
  +          
  +        
  +    }
  +    
   
       public void begin(Set objects) {
          throw new java.lang.NoSuchMethodError(); 
  
  
  
  1.26      +59 -34    jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSample.java
  
  Index: TestSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSample.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- TestSample.java	14 May 2002 17:02:51 -0000	1.25
  +++ TestSample.java	15 May 2002 16:18:23 -0000	1.26
  @@ -72,10 +72,12 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TestSample.java,v 1.25 2002/05/14 17:02:51 baliuka Exp $
  + *@version    $Id: TestSample.java,v 1.26 2002/05/15 16:18:23 baliuka Exp $
    */
   public class TestSample extends TestCase implements org.apache.commons.simplestore.tools.Constants{
       
  +   
  +    
       PersistenceManager pm;
       
       public TestSample(String testName) {
  @@ -94,11 +96,6 @@
       public void testCreate() throws java.lang.Exception {
           Transaction transaction = pm.getTransaction(); 
          try{ 
  -           
  -        for (int i = 0; i < 10; i++) {
  -            
  -         
  -            
               transaction.begin();
               TestPersistentClassType object1 = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
               Object oid = pm.getOID(object1);
  @@ -120,25 +117,32 @@
                   
               }
               object3.setDateVal(new java.util.Date());
  -            object3.setIntVal(i);
  -            object3.setFloatVal(i / 2);
  -            object3.setStrVal1("" + i);
  +            object3.setIntVal(8);
  +            object3.setFloatVal(2f);
  +            object3.setStrVal1("Q");
               object3.setBoolVal(true);
               object3.setParent(object2);
               
               assertTrue("Single child", object2.getChildren().size() == 1);
               
  -            Object o1 = object2.getChildren();
  -            Object o2 = object2.getChildren();
  +            java.util.Collection o1 = object2.getChildren();
  +            java.util.Collection o2 = object2.getChildren();
               
                assertTrue("Cached Collection", o1 == o2);
               
  -            transaction.commit();
  +          
               
               assertEquals("Equals " + oid, object2, object1);
               assertTrue(" == " + oid, object2 == object1);
               
  -        }
  +            TestPersistentClassType object4 = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
  +            
  +            object4.setParent(object2);
  +            
  +            assertTrue("Added object to Collection", object2.getChildren().size() == 2);
  +             
  +            transaction.commit();  
  +        
           
          }catch( Exception e){
              e.printStackTrace();
  @@ -148,48 +152,50 @@
       }
       
       public void testRetrieve() throws java.lang.Exception {
  +         Transaction transaction = pm.getTransaction();
  +         transaction.begin();
  +      
           
  -        Transaction transaction = pm.getTransaction();
  -        
  -        transaction.begin();
           java.util.Set objects = pm.findAll(TestPersistentClassType.class);
           
           assertTrue("Cache findAll ", objects == pm.findAll(TestPersistentClassType.class)
);
  +      
  +        java.util.Iterator it = objects.iterator();
  +       
           
  -        java.util.Iterator i = objects.iterator();
  -        
  -        while (i.hasNext()) {
  +        while (it.hasNext()) {
               
  -            TestPersistentClassType object = (TestPersistentClassType) i.next();
  +            TestPersistentClassType object = (TestPersistentClassType) it.next();
               object.toString();
               object.getBoolVal();
               object.getDateVal();
               object.getIntVal();
               object.getFloatVal();
               object.getStrVal1();
  -          
  -            
  +                  
           }
           
  -        transaction.commit();
           
  +       
  +     transaction.commit();   
  +      
       }
       public void testRollback() throws java.lang.Exception {
           
  -        
  +      
           Transaction transaction = pm.getTransaction();
           
           transaction.begin();
           java.util.Set objects = pm.findAll(TestPersistentClassType.class);
           transaction.commit();
           
  -        java.util.Iterator i = objects.iterator();
  +        java.util.Iterator it = objects.iterator();
           
  -        while (i.hasNext()) {
  +        while (it.hasNext()) {
               transaction.begin();
  -            TestPersistentClassType object = (TestPersistentClassType) i.next();
  +            TestPersistentClassType object = (TestPersistentClassType) it.next();
               String val = object.getStrVal();
  -            object.setStrVal( i + "");
  +            object.setStrVal("" + Math.random());
               transaction.rollback();
               transaction.begin();
               assertEquals("After rollback ", val, object.getStrVal());
  @@ -197,12 +203,31 @@
           }
           
           
  -        transaction.begin();
  -        TestPersistentClassType object = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
  -        object.setStrVal("Test roolback on new created " + object);
  -        transaction.rollback();
           
  -        transaction.begin();
  +        
  +            transaction.begin();
  +            TestPersistentClassType child = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
  +            TestPersistentClassType parent = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
  +            transaction.commit();
  +            
  +            java.util.Collection children = parent.getChildren();
  +            
  +            transaction.begin();
  +             
  +            child.setParent(parent);
  +                        
  +            transaction.rollback();
  +           
  +        assertEquals( "Roolback collection ", 0, children.size() );
  +        
  +        
  +        
  +    transaction.begin();
  +    TestPersistentClassType object = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
  +    object.setStrVal("Test roolback on new created " + object);
  +    transaction.rollback();
  +    
  +         transaction.begin();
           try{
               object.getStrVal();
               fail("Exception expected " + object);
  @@ -224,7 +249,7 @@
           assertEquals( object + " Not modified ", 777, object.getIntVal() );
           transaction.commit();
           
  -        
  +       
           
       }
       
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message