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, 20 Mar 2002 19:28:26 GMT
baliuka     02/03/20 11:28:26

  Modified:    simplestore/src/java/org/apache/commons/simplestore/persistence
                        Context.java MetaObject.java OIDGenerator.java
                        PersistenceManager.java
                        PersistenceManagerFactory.java Persistent.java
               simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        PersistentProxy.java
               simplestore/src/test/org/apache/commons/simplestore
                        TestSample.java
  Log:
  JAVADOC Documentation
  
  Revision  Changes    Path
  1.3       +33 -3     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Context.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Context.java	17 Mar 2002 13:36:25 -0000	1.2
  +++ Context.java	20 Mar 2002 19:28:26 -0000	1.3
  @@ -56,22 +56,52 @@
   
   import java.util.Set;
   import org.apache.commons.simplestore.cache.Cache;
  -/**
  - *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  +
  +/** This interface used by Persistence implementation to
  + * implement interfaces like OIDGenerator
  + *
  + *
  + *    MetaClassImpl mclass = new MetaClassImpl( MetaClassImpl.class.getClassLoader());
  + *       DBStorage storage = new DBStorage( db );
  + *       ContextImpl context = new ContextImpl(
  + *             mclass,
  + *             new MyOIDGenerator(),// This will be used to generate OID for all objects
  + *             storage,
  + *             SoftRefMemoryCache.getInstance(new java.util.HashMap(),0xFF),
  + *                       storage );
  + *       pm = PersistenceManagerImpl.getPersistenceManager(context);
  + *   
  + * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: Context.java,v 1.2 2002/03/17 13:36:25 baliuka Exp $
  + * @version $Id: Context.java,v 1.3 2002/03/20 19:28:26 baliuka Exp $
    */
   
   public interface Context {
       
  +    /** Returns MataClass implementation
  +     * @param clasz Class for persistent
  +     * @return MetaClass
  +     */    
      public MetaClass getMetaClass( Class clasz );
      
  +   /** Returns Storage implementation
  +    * @return Storage
  +    */   
      public Storage  getStorage();
      
  +   /** Returns TransactionManager implementation
  +    * @return TransactionManager
  +    */   
      public TransactionManager getTransactionManager();
      
  +   /** Returns Cache implementation
  +    * @return Cache
  +    */   
      public Cache getCache();
      
  +   /** Returns OIDGenerator
  +    * @return OIDGenerator
  +    */   
      public OIDGenerator getOIDGenerator();
   
   }
  
  
  
  1.4       +4 -3      jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/MetaObject.java
  
  Index: MetaObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/MetaObject.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MetaObject.java	10 Mar 2002 12:32:30 -0000	1.3
  +++ MetaObject.java	20 Mar 2002 19:28:26 -0000	1.4
  @@ -56,10 +56,11 @@
   
   import java.util.Map;
   
  -/**
  - *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  +/** This interface represents Persistent object State,
  + * used internaly by implementation
  + * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: MetaObject.java,v 1.3 2002/03/10 12:32:30 baliuka Exp $
  + * @version $Id: MetaObject.java,v 1.4 2002/03/20 19:28:26 baliuka Exp $
    */
   
   public interface MetaObject extends Cloneable {
  
  
  
  1.4       +7 -3      jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/OIDGenerator.java
  
  Index: OIDGenerator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/OIDGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- OIDGenerator.java	17 Mar 2002 13:36:25 -0000	1.3
  +++ OIDGenerator.java	20 Mar 2002 19:28:26 -0000	1.4
  @@ -54,13 +54,17 @@
    */
   package org.apache.commons.simplestore.persistence;
   
  -/**
  - *@author     Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
  +/** This interface used to implement OID generator
  + * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
    *      g-froehlich@gmx.de</a>
  - *@version    $Id: OIDGenerator.java,v 1.3 2002/03/17 13:36:25 baliuka Exp $
  + * @version $Id: OIDGenerator.java,v 1.4 2002/03/20 19:28:26 baliuka Exp $
    */
   public interface OIDGenerator {
   
  +    /** Returns next OID for object
  +     * @param clasz Persistent Class
  +     * @return OID
  +     */    
       public Object nextOID(Class clasz);
   
   
  
  
  
  1.2       +62 -3     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/PersistenceManager.java
  
  Index: PersistenceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/PersistenceManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PersistenceManager.java	17 Mar 2002 17:35:48 -0000	1.1
  +++ PersistenceManager.java	20 Mar 2002 19:28:26 -0000	1.2
  @@ -54,23 +54,82 @@
    */
   package org.apache.commons.simplestore.persistence;
   
  -/**
  - *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  +/** This interface is designed for Simplestore user,
  + * use PersistentManagerFactory to setup PersistentManager
  + *
  + * 
  + *       DBPersistenceManagerFactory factory = new DBPersistenceManagerFactory();
  + *       factory.setDriver("org.hsqldb.jdbcDriver");
  + *       factory.setUrl("jdbc:hsqldb:sample");
  + *       factory.setUser("sa");
  + *       factory.setPassword("");
  + *       factory.setMaxConnections(1);
  + *       factory.setMetaResource("org/apache/commons/simplestore/storage.xml");
  + *       pm = factory.getPersistenceManager();
  + *   
  + *
  + *
  + *
  + * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: PersistenceManager.java,v 1.1 2002/03/17 17:35:48 baliuka Exp $
  + * @version $Id: PersistenceManager.java,v 1.2 2002/03/20 19:28:26 baliuka Exp $
    */
   public interface PersistenceManager {
   
  +    /** returns current Transaction, single insatnce per thread
  +     *
  +     *      
  +     * @return Transaction
  +     */    
       public Transaction getTransaction(); 
   
  +    /** returns OID if object is persistent
  +     *
  +     *      Transaction transaction = pm.getTransaction();
  +     *       transaction.begin();
  +     *         MyObject object = (MyObject) pm.createInstance(MyObject.class);
  +     *         Object oid = pm.getOID(object);
  +     *         object.doSomething(oid,object);
  +     *       transaction.commit();
  +     *
  +     * @param pc Persistent Object
  +     * @return OID
  +     */    
       public Object getOID( Object pc );
   
  +    /** Creates OID and implements new Persitent object insatance
  +     * @param aclass Object Type
  +     * @return Persistent
  +     */    
       public Object createInstance( Class aclass ); 
   
  +    /** Finds insatance by OID
  +     * @param clasz Object Type
  +     * @param oid OID
  +     * @throws StorageException Storage Exception or ObjectNotFound Exception
  +     * @return Persistent insatance
  +     */    
       public Object findInstance( Class clasz, Object oid ) throws StorageException; 
   
  +    /** Finds All Persistent insatnces of Class
  +     *    transaction.begin();
  +     *   java.util.Set objects = pm.findAll(MyObject.class);
  +     *    System.out.println("Found " + objects.size() + " objects of type " + MyObject.class);
  +     *   java.util.Iterator i = objects.iterator();
  +     *   while (i.hasNext()) {
  +     *     MyObject object = (MyObject)i.next();
  +     *     object.doSomething();
  +     *  }
  +     *  transaction.commit();
  +     * @param clasz Type
  +     * @throws StorageException Storage specific Exception
  +     * @return Collection persistent objects
  +     */    
       public java.util.Set findAll(Class clasz) throws StorageException; 
   
  +    /** Makes object removed, object becomes invalid after commit
  +     * @param pc Persistent
  +     */    
       public void removeInstance(Object pc);
   
       
  
  
  
  1.2       +19 -1     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/PersistenceManagerFactory.java
  
  Index: PersistenceManagerFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/PersistenceManagerFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PersistenceManagerFactory.java	17 Mar 2002 17:35:48 -0000	1.1
  +++ PersistenceManagerFactory.java	20 Mar 2002 19:28:26 -0000	1.2
  @@ -55,12 +55,30 @@
   package org.apache.commons.simplestore.persistence;
   
   /**
  + * This interface used by Persitence implementation user to
  + * setup PersistenceManager
  + *
  + *    DBPersistenceManagerFactory factory = new DBPersistenceManagerFactory();
  + *       factory.setDriver("org.hsqldb.jdbcDriver");
  + *       factory.setUrl("jdbc:hsqldb:sample");
  + *       factory.setUser("sa");
  + *       factory.setPassword("");
  + *       factory.setMaxConnections(1);
  + *       factory.setMetaResource("org/apache/commons/simplestore/storage.xml");
  + *       pm = factory.getPersistenceManager();
  + *
  + * User can implement this interface to add custom OIDGenerator, Storage,
  + * TransactionManager implementation    
  + *
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: PersistenceManagerFactory.java,v 1.1 2002/03/17 17:35:48 baliuka Exp
$
  + *@version    $Id: PersistenceManagerFactory.java,v 1.2 2002/03/20 19:28:26 baliuka Exp
$
    */
   public interface PersistenceManagerFactory {
   
  +    /** Implementation must return singleton Object
  +     * @return PersitenceManager
  +     */    
       public PersistenceManager getPersistenceManager();
       
   }
  
  
  
  1.4       +10 -1     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Persistent.java
  
  Index: Persistent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Persistent.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Persistent.java	19 Mar 2002 15:23:34 -0000	1.3
  +++ Persistent.java	20 Mar 2002 19:28:26 -0000	1.4
  @@ -55,15 +55,24 @@
   package org.apache.commons.simplestore.persistence;
   
   /**
  + * All persitent objects in SimpleStore implement this interface
  + * this interface
  + * hashCode and equals methods are implemented by Enhancer
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: Persistent.java,v 1.3 2002/03/19 15:23:34 baliuka Exp $
  + *@version    $Id: Persistent.java,v 1.4 2002/03/20 19:28:26 baliuka Exp $
    */
   
   public interface Persistent {
   
  +    /** Returns unique Object identifier
  +     * @return OID
  +     */    
       public Object getOID();
   
  +    /** Returns MetaObject implementation for this object
  +     * @return MetaObject
  +     */    
       public MetaObject getMetaObject();
   
   }
  
  
  
  1.24      +9 -6      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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- PersistentProxy.java	19 Mar 2002 15:23:34 -0000	1.23
  +++ PersistentProxy.java	20 Mar 2002 19:28:26 -0000	1.24
  @@ -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.23 2002/03/19 15:23:34 baliuka Exp $
  + *@version    $Id: PersistentProxy.java,v 1.24 2002/03/20 19:28:26 baliuka Exp $
    */
   public class PersistentProxy
   implements MetaObject,  org.apache.commons.simplestore.tools.Constants ,
  @@ -222,19 +222,19 @@
       public Object handleEquals(Object obj) {
           
           if (obj == null) {
  -            return new Boolean(false);
  +            return Boolean.FALSE;
           }
           
           if (!(obj instanceof Persistent)) {
  -            return new Boolean(false);
  +            return Boolean.FALSE;
           }
           
           Persistent object = (Persistent) obj;
           
           if (m_oid == null) {
  -            return new Boolean(m_oid == m_object.getOID());
  +            return m_oid == m_object.getOID() ?  Boolean.TRUE : Boolean.FALSE;
           } else {
  -            return new Boolean(m_oid.equals(m_object.getOID()));
  +            return m_oid.equals(m_object.getOID()) ?  Boolean.TRUE : Boolean.FALSE;
           }
       }
       public Object afterReturn(Object obj,
  @@ -263,8 +263,11 @@
            if(DEBUG){
              System.out.println("Invoke super:" + method);
            }
  +            
            if( Enhancer.equals(method, HASH_CODE)  ||
  -             Enhancer.equals(method,EQUALS)    ){
  +             Enhancer.equals(method,EQUALS) ||
  +             Enhancer.equals(method,GET_META_OBJECT)||
  +             Enhancer.equals(method,GET_OID)              ){
                return false;
            }else  return true;
       }
  
  
  
  1.18      +3 -44     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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- TestSample.java	20 Mar 2002 17:49:49 -0000	1.17
  +++ TestSample.java	20 Mar 2002 19:28:26 -0000	1.18
  @@ -54,17 +54,12 @@
    */
   package org.apache.commons.simplestore;
   
  -import org.apache.commons.simplestore.jdbc.DriverDataSource;
  +
   import org.apache.commons.simplestore.persistence.Transaction;
   import org.apache.commons.simplestore.persistence.PersistenceManager;
  -import org.apache.commons.simplestore.persistence.impl.DBStorage;
   import org.apache.commons.simplestore.persistence.impl.DBPersistenceManagerFactory;
  -import org.apache.commons.simplestore.persistence.impl.ContextImpl;
  -import org.apache.commons.simplestore.persistence.impl.MetaClassImpl;
  -import org.apache.commons.simplestore.persistence.impl.ConnectionFactory;
  -import org.apache.commons.simplestore.persistence.impl.RandomOIDGenerator;
   import org.apache.commons.simplestore.persistence.ValidationException;
  -import org.apache.commons.simplestore.cache.impl.SoftRefMemoryCache;
  +
   
   import java.util.HashMap;
   import java.util.Map;
  @@ -76,7 +71,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TestSample.java,v 1.17 2002/03/20 17:49:49 baliuka Exp $
  + *@version    $Id: TestSample.java,v 1.18 2002/03/20 19:28:26 baliuka Exp $
    */
   public class TestSample extends TestCase implements org.apache.commons.simplestore.tools.Constants{
       
  @@ -233,43 +228,7 @@
           factory.setMaxConnections(1);
           factory.setMetaResource("org/apache/commons/simplestore/storage.xml");
           pm = factory.getPersistenceManager();
  -        /*
  -        MetaClassImpl.parse("org/apache/commons/simplestore/storage.xml");
           
  -       final DriverDataSource ds = new DriverDataSource();
  -        ds.setDriver("org.hsqldb.jdbcDriver");
  -        ds.setMaxConnections(1);
  -        ds.setUrl("jdbc:hsqldb:sample");
  -        ds.setUser("sa");
  -        ds.setPassword("");
  -        String sql = //"DROP TABLE TEST_PERSISTENT";
  -         "CREATE TABLE TEST_PERSISTENT ( ID bigint not null primary key, parent_object
bigint,Bool_Val smallint," +
  -         " Int_Val integer, Float_Val float, Date_Val date, Str_Val longVarChar, s_1_str_val
 longVarChar )  ";
  -        
  -        java.sql.Connection con = ds.getConnection();
  -        try {
  -            java.sql.Statement stmt = con.createStatement();
  -            try {
  -                stmt.executeUpdate(sql);
  -            } catch (java.sql.SQLException e) {
  -                if(DEBUG)
  -                 System.out.println(e.getMessage());// exists ?
  -            }
  -            stmt.close();
  -        } finally {
  -            con.close();
  -        }
  -       
  -        MetaClassImpl mclass = new MetaClassImpl( MetaClassImpl.class.getClassLoader());
  -        DBStorage storage = new DBStorage( ds );
  -        ContextImpl context = new ContextImpl(
  -              mclass,
  -              new RandomOIDGenerator(),
  -              storage,
  -              SoftRefMemoryCache.getInstance(new java.util.HashMap(),0xFF),
  -                        storage );
  -        pm = PersistenceManagerImpl.getPersistenceManager(context);
  -         */
       }
       
   }
  
  
  

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