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 Mon, 11 Mar 2002 15:40:53 GMT
baliuka     02/03/11 07:40:53

  Modified:    simplestore/src/java/org/apache/commons/simplestore/persistence
                        InternalTransaction.java
               simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        AbstractStorage.java DBStorage.java
                        TransactionImpl.java
               simplestore/src/test/org/apache/commons/simplestore
                        TestSample.java
  Log:
  Some refactoring for Collection type support
  
  Revision  Changes    Path
  1.2       +3 -1      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InternalTransaction.java	11 Feb 2002 20:23:30 -0000	1.1
  +++ InternalTransaction.java	11 Mar 2002 15:40:53 -0000	1.2
  @@ -59,7 +59,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: InternalTransaction.java,v 1.1 2002/02/11 20:23:30 froehlich Exp $
  + *@version    $Id: InternalTransaction.java,v 1.2 2002/03/11 15:40:53 baliuka Exp $
    */
   
   public interface InternalTransaction extends Transaction {
  @@ -72,6 +72,8 @@
   
       void add(MetaObject props);
   
  +    java.util.Collection getTransactionalObjects();
  +    
       void setAttribute(String name, Object value);
   
       Object getAttribute(String name);
  
  
  
  1.6       +12 -31    jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/AbstractStorage.java
  
  Index: AbstractStorage.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/AbstractStorage.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractStorage.java	11 Mar 2002 09:53:07 -0000	1.5
  +++ AbstractStorage.java	11 Mar 2002 15:40:53 -0000	1.6
  @@ -68,7 +68,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: AbstractStorage.java,v 1.5 2002/03/11 09:53:07 baliuka Exp $
  + *@version    $Id: AbstractStorage.java,v 1.6 2002/03/11 15:40:53 baliuka Exp $
    */
   
   public abstract class AbstractStorage
  @@ -98,8 +98,7 @@
           try {
               internalBegin();
           } catch (Throwable t) {
  -            // TODO
  -            t.printStackTrace();
  +              t.printStackTrace();
               throw new RuntimeException(t.getClass() + ":" + t.getMessage());
           }
       }
  @@ -109,33 +108,19 @@
       }
       
       public void commit() {
  -        try {
  -           // getTransaction().commit();
  -          //  internalCommit();
              throw new java.lang.NoSuchMethodError(); 
  -        } catch (Throwable t) {
  -            // TODO
  -            t.printStackTrace();
  -            throw new RuntimeException(t.getClass() + ":" + t.getMessage());
  -        }
  -    }
  +       }
       
       public void begin() {
  -        try {
  -        //    getTransaction().begin();
  -        //    internalBegin();
              throw new java.lang.NoSuchMethodError(); 
  -        } catch (Throwable t) {
  -            // TODO
  -            throw new RuntimeException(t.getClass() + ":" + t.getMessage());
  -        }
  +      
       }
       
       public void rollback(Set objects) {
           try {
  -            //TODO implement roolback
  +      
               internalRollback();
  -          //  objects.clear();
  +      
           } catch (Throwable t) {
               throw new RuntimeException(t.getClass() + ":" + t.getMessage());
           }
  @@ -143,14 +128,7 @@
       
       public void rollback() {
           
  -        try {
  -          //  getTransaction().rollback();
  -         //   internalRollback();
               throw new java.lang.NoSuchMethodError();
  -        } catch (Throwable t) {
  -            // TODO
  -            throw new RuntimeException(t.getClass() + ":" + t.getMessage());
  -        }
           
       }
       
  @@ -178,11 +156,10 @@
                   }
                   throw new java.lang.IllegalStateException(pp.toString());
               }
  -           // objects.clear();
  +      
               internalCommit();
           } catch (Throwable t) {
  -            // TODO
  -            t.printStackTrace();
  +          t.printStackTrace();
               throw new RuntimeException(t.getMessage() + " "  + pp);
           }
           
  @@ -200,6 +177,10 @@
       protected abstract void internalBegin() throws StorageException;
       
       public abstract java.util.Collection retrieve(Class clasz, int index, Object value)throws
StorageException; 
  +    
  +    public java.util.Collection getTransactionalObjects() {
  +        throw new java.lang.NoSuchMethodError();
  +    }
       
   }
   
  
  
  
  1.9       +10 -1     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/DBStorage.java
  
  Index: DBStorage.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/DBStorage.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DBStorage.java	11 Mar 2002 10:37:22 -0000	1.8
  +++ DBStorage.java	11 Mar 2002 15:40:53 -0000	1.9
  @@ -85,7 +85,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: DBStorage.java,v 1.8 2002/03/11 10:37:22 baliuka Exp $
  + *@version    $Id: DBStorage.java,v 1.9 2002/03/11 15:40:53 baliuka Exp $
    */
   public class DBStorage extends AbstractStorage implements org.apache.commons.simplestore.tools.Constants
{
       
  @@ -429,6 +429,15 @@
           final String sql = "SELECT "+ mClass.getOIDName() + " AS " + INTERNAL_OID +
                                 ", * FROM " + mClass.getName() +
           " WHERE " + mClass.getPropertyName(index) + "=?";
  +        
  +        java.util.Collection tObjects = getTransaction().getTransactionalObjects();
  +        for( java.util.Iterator i = tObjects.iterator(); i.hasNext(); ){
  +          MetaObject mo = (MetaObject)i.next();
  +          if( mo.getPersistentClass().equals(clasz) && mo.getProperty(index).equals(value)
){
  +              objects.add( mo.getObject() );
  +          }
  +        }
  +        
            
           excecute( sql, new Object[]{value}, new QueryHandler(objects, clasz));
           
  
  
  
  1.4       +17 -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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TransactionImpl.java	10 Mar 2002 12:32:30 -0000	1.3
  +++ TransactionImpl.java	11 Mar 2002 15:40:53 -0000	1.4
  @@ -68,7 +68,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TransactionImpl.java,v 1.3 2002/03/10 12:32:30 baliuka Exp $
  + *@version    $Id: TransactionImpl.java,v 1.4 2002/03/11 15:40:53 baliuka Exp $
    */
   
   public class TransactionImpl 
  @@ -147,6 +147,9 @@
       public void rollback() {
           checkState();
           checkState(!complete);
  +        doRollback();
  +    }
  +  private void doRollback() {
           Iterator i = objects.iterator();
           while (i.hasNext()) {
               MetaObject mo = (MetaObject) i.next();
  @@ -173,18 +176,15 @@
       }
   
       public void begin(Set objects) {
  -       // transaction.begin(objects);
          throw new java.lang.NoSuchMethodError(); 
       }
   
       public void rollback(Set objects) {
           throw new java.lang.NoSuchMethodError();
  -       // transaction.rollback(objects);
       }
   
       public void commit(Set objects) {
  -       // transaction.commit(objects);
  -        throw new java.lang.NoSuchMethodError();
  +            throw new java.lang.NoSuchMethodError();
       }
   
       public void removeAttribute(String name) {
  @@ -201,6 +201,18 @@
           int id = getCurrentThreadId();
           if (threadId != id) {
               throw new IllegalStateException("Accessed Transaction " + threadId + " in "
+ id);
  +        }
  +    }
  +    
  +    public java.util.Collection getTransactionalObjects() {
  +        return java.util.Collections.unmodifiableCollection(objects);
  +    }
  +    protected void finalize()throws Throwable{
  +        try{
  +          checkState(complete);
  +        }catch(Throwable t){
  +           t.printStackTrace();//FATAL
  +           doRollback();
           }
       }
   }
  
  
  
  1.13      +1 -3      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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestSample.java	11 Mar 2002 09:53:08 -0000	1.12
  +++ TestSample.java	11 Mar 2002 15:40:53 -0000	1.13
  @@ -73,7 +73,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TestSample.java,v 1.12 2002/03/11 09:53:08 baliuka Exp $
  + *@version    $Id: TestSample.java,v 1.13 2002/03/11 15:40:53 baliuka Exp $
    */
   public class TestSample extends TestCase implements org.apache.commons.simplestore.tools.Constants{
       
  @@ -124,9 +124,7 @@
               object3.setStrVal1("" + i);
               object3.setBoolVal(true);
               object3.setParent(object2);
  -            transaction.commit();
               
  -            transaction.begin();
               assertTrue("Single child", object2.getChildren().size() == 1);
               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