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 Thu, 09 May 2002 17:02:40 GMT
baliuka     02/05/09 10:02:39

  Modified:    simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        AbstractStorage.java KeyPair.java
                        PersistentProxy.java TransactionImpl.java
               simplestore/src/test/org/apache/commons/simplestore
                        TestSample.java
  Log:
  Minor changes
  
  Revision  Changes    Path
  1.12      +8 -3      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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AbstractStorage.java	8 May 2002 18:04:48 -0000	1.11
  +++ AbstractStorage.java	9 May 2002 17:02:39 -0000	1.12
  @@ -71,7 +71,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: AbstractStorage.java,v 1.11 2002/05/08 18:04:48 baliuka Exp $
  + *@version    $Id: AbstractStorage.java,v 1.12 2002/05/09 17:02:39 baliuka Exp $
    */
   
   public abstract class AbstractStorage
  @@ -182,16 +182,18 @@
      
       public  java.util.Collection retrieve(Class clasz, int index, Object value)throws StorageException{
       
  -        
  +       
           Object key = new KeyPair(clasz,new KeyPair(new Integer(index),value));
           
           java.util.Set objects = null;
  +        
           java.util.Set cachedObjects = (java.util.Set)context.getCache().get(key);
           
           if( cachedObjects != null ){
              objects = cachedObjects;
  -        }else{
  +         }else{
              objects =  new java.util.HashSet();
  +           context.getCache().put(key,objects); 
           }
           
           
  @@ -214,6 +216,9 @@
         if( cachedObjects != null ){
              return cachedObjects;
           }
  +        
  +        
  +         
             
           
           
  
  
  
  1.2       +10 -3     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/KeyPair.java
  
  Index: KeyPair.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/KeyPair.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- KeyPair.java	8 May 2002 18:46:21 -0000	1.1
  +++ KeyPair.java	9 May 2002 17:02:39 -0000	1.2
  @@ -58,7 +58,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: KeyPair.java,v 1.1 2002/05/08 18:46:21 baliuka Exp $
  + *@version    $Id: KeyPair.java,v 1.2 2002/05/09 17:02:39 baliuka Exp $
    */
   public class KeyPair {
      Object left;
  @@ -77,16 +77,23 @@
           
           return retValue;
       }
  -    
  +    public String toString(){
  +      return    "( left=" + left + " right=" + right + ")";              
  +    }
       public boolean equals(Object obj) {
          if ( obj != null ){
          
              if( obj instanceof KeyPair ){
              
                KeyPair  object = (KeyPair)obj;
  -             return  
  +             
  +            return
                  ( left == null ? object.left == null : left.equals(object.left) )&&
                  ( right == null ? object.right == null : right.equals(object.right) );
  +             
  +               
  +               
  +            
                  
              }else{
              
  
  
  
  1.31      +55 -38    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.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- PersistentProxy.java	8 May 2002 18:16:34 -0000	1.30
  +++ PersistentProxy.java	9 May 2002 17:02:39 -0000	1.31
  @@ -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.30 2002/05/08 18:16:34 baliuka Exp $
  + *@version    $Id: PersistentProxy.java,v 1.31 2002/05/09 17:02:39 baliuka Exp $
    */
   public class PersistentProxy
   implements MetaObject,  org.apache.commons.simplestore.tools.Constants ,
  @@ -305,77 +305,94 @@
           ";clean="      + isClean();
           
       }
  -    
  -    public Object handleProperty(Object obj, Method method, Object[] obj2) throws Throwable
{
  -        
  -        if( isClean() || isDeleted() )
  -            throw new IllegalStateException("Object properties invalidated");
  +   
  +    public Object readProperty( Method method ) throws Throwable {
           
           int index = m_metaClass.getPropertyIndex( method );
           
  -        if ( method.getReturnType() == Void.TYPE && obj2.length == 1 ) {
  +        if( method.getReturnType().isAssignableFrom(java.util.Collection.class )){
  +                return  m_context.getStorage().
  +                retrieve( m_metaClass.getReference(index),
  +                m_metaClass.getReferenceField(index),m_oid );
  +                
  +            }
  +            Object value =  getProperty(index);;
  +            if( value != null && m_metaClass.isReference( method ) ){
  +                      System.out.println("Referenced:" + m_metaClass.getReferenceField(index));
  +                return m_context.getStorage().
  +                retrieveObject( method.getReturnType(),value );
  +            }
               
  +            return  m_context.getTypeConverter().toAppType(value,method.getReturnType());
  +    
  +    }
  +    
  +     public void writeProperty( Method method, Object param) throws Throwable {
  +         
  +         int index = m_metaClass.getPropertyIndex( method );
               
               Validator validator = m_metaClass.getValidator(index);
               
  -            if( validator != null && !validator.isValid(obj2[0]) ){
  -                throw new ValidationException(obj,method,obj2[0],validator.toString());
  +            if( validator != null && !validator.isValid(param) ){
  +                throw new ValidationException(m_object,method,param,validator.toString());
               }
               
               Object oldValue  =  getProperty(index);
               
  -            if(  oldValue == null && obj2[0] == null   ){
  -                return null;
  -            }else if( ( oldValue != null ) && oldValue.equals(obj2[0]) ){
  -                return null;
  +            if(  oldValue == null && param == null   ){
  +                return ;
  +            }else if( ( oldValue != null ) && oldValue.equals(param) ){
  +                return ;
               }
  +          
  +            //Dirty :
               
  -            
  -           Object newValue = obj2[0];
  +           Object newValue = param;
             
               if( m_metaClass.isReference(method) ){
  -              if( obj2[0] != null ){
  -                newValue = ((Persistent)obj2[0]).getOID();
  +              if( param != null ){
  +                newValue = ((Persistent)param).getOID();
                 }
  -                           
                   setProperty(index, newValue );
               }else{
  -                setProperty(index, obj2[0]);
  +                setProperty(index, param);
                   
               }
               
               
               Object key = new KeyPair(m_clazz,new KeyPair(new Integer(index),oldValue));
               java.util.Set set = (java.util.Set)m_context.getCache().get(key);
  -            if( set != null )set.remove(m_object);
  +            
  +            if( set != null ){
  +                set.remove(m_object);
  +            }
               
               key = new KeyPair(m_clazz,
               new KeyPair(new Integer(index),newValue));
               
               set = (java.util.Set)m_context.getCache().get(key);
               
  -            if( set != null )set.add(m_object);
  -            
  -           
  +            if( set != null ){
  +                set.add(m_object);
  +            }
               
               setState(true,DIRTY);
  -            return null;
  -            
  -        } else if( obj2.length == 0  ){
  +       
  +    }
  +   
  +    
  +    public Object handleProperty(Object obj, Method method, Object[] params) throws Throwable
{
  +        
  +        if( isClean() || isDeleted() )
  +            throw new IllegalStateException("Object properties invalidated");
  +        
               
  -            if( method.getReturnType().isAssignableFrom(java.util.Collection.class )){
  -                return java.util.Collections.unmodifiableCollection( m_context.getStorage().
  -                retrieve( m_metaClass.getReference(index),
  -                m_metaClass.getReferenceField(index),m_oid ));
  -                
  -            }
  -            Object value =  getProperty(index);;
  -            if( value != null && m_metaClass.isReference( method ) ){
  -                return m_context.getStorage().
  -                retrieveObject( method.getReturnType(),value );
  -            }
  +        if ( method.getReturnType() == Void.TYPE && params.length == 1 ) {
  +            writeProperty( method, params[0] );
  +            return null;
  +        } else if( params.length == 0  ){
               
  -            return  m_context.getTypeConverter().toAppType(value,method.getReturnType());
  +            return readProperty(method);
           }
           throw new java.lang.NoSuchMethodError("pure method invoked: " + method);
       }
  
  
  
  1.7       +3 -1      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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TransactionImpl.java	16 Mar 2002 18:55:45 -0000	1.6
  +++ TransactionImpl.java	9 May 2002 17:02:39 -0000	1.7
  @@ -69,7 +69,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TransactionImpl.java,v 1.6 2002/03/16 18:55:45 baliuka Exp $
  + *@version    $Id: TransactionImpl.java,v 1.7 2002/05/09 17:02:39 baliuka Exp $
    */
   
   public class TransactionImpl 
  @@ -150,6 +150,8 @@
           checkState(!complete);
           doRollback();
       }
  +    
  +  //TODO: rollback  cached collections
     private void doRollback() {
           Iterator i = objects.iterator();
           while (i.hasNext()) {
  
  
  
  1.23      +19 -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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- TestSample.java	20 Apr 2002 10:30:18 -0000	1.22
  +++ TestSample.java	9 May 2002 17:02:39 -0000	1.23
  @@ -72,7 +72,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TestSample.java,v 1.22 2002/04/20 10:30:18 baliuka Exp $
  + *@version    $Id: TestSample.java,v 1.23 2002/05/09 17:02:39 baliuka Exp $
    */
   public class TestSample extends TestCase implements org.apache.commons.simplestore.tools.Constants{
       
  @@ -92,9 +92,12 @@
       }
       
       public void testCreate() throws java.lang.Exception {
  +        Transaction transaction = pm.getTransaction(); 
  +       try{ 
  +           
           for (int i = 0; i < 10; i++) {
               
  -            Transaction transaction = pm.getTransaction();
  +         
               
               transaction.begin();
               TestPersistentClassType object1 = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
  @@ -125,6 +128,12 @@
               object3.setParent(object2);
               
               assertTrue("Single child", object2.getChildren().size() == 1);
  +            
  +            Object o1 = object2.getChildren();
  +            Object o2 = object2.getChildren();
  +            
  +             assertTrue("Cached Collection", o1 == o2);
  +            
               transaction.commit();
               
               assertEquals("Equals " + oid, object2, object1);
  @@ -132,6 +141,11 @@
               
           }
           
  +       }catch( Exception e){
  +           e.printStackTrace();
  +          transaction.commit();
  +          throw (Exception)e.fillInStackTrace();
  +       }
       }
       
       public void testRetrieve() throws java.lang.Exception {
  @@ -141,6 +155,8 @@
           transaction.begin();
           java.util.Set objects = pm.findAll(TestPersistentClassType.class);
           
  +        assertTrue("Cache findAll ", objects == pm.findAll(TestPersistentClassType.class)
);
  +        
          if( DEBUG )
           System.out.println("retrieved " + objects.size());
           java.util.Iterator i = objects.iterator();
  @@ -154,7 +170,7 @@
               object.getIntVal();
               object.getFloatVal();
               object.getStrVal1();
  -            object.getParent();
  +          
               
           }
           
  
  
  

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