commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From froehl...@apache.org
Subject cvs commit: jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl TransactionImpl.java PersistentProxy.java PersistenceManager.java DBStorage.java AbstractStorage.java
Date Mon, 11 Feb 2002 20:30:10 GMT
froehlich    02/02/11 12:30:10

  Modified:    simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        TransactionImpl.java PersistentProxy.java
                        PersistenceManager.java DBStorage.java
                        AbstractStorage.java
  Log:
  fixed imports and formating
  
  Revision  Changes    Path
  1.2       +13 -15    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TransactionImpl.java	11 Feb 2002 20:23:38 -0000	1.1
  +++ TransactionImpl.java	11 Feb 2002 20:30:09 -0000	1.2
  @@ -60,15 +60,15 @@
   import org.apache.commons.simplestore.persistence.MetaObject;
   
   import java.util.HashMap;
  -import java.util.Set;
  -import java.util.Map;
   import java.util.HashSet;
   import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Set;
   
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TransactionImpl.java,v 1.1 2002/02/11 20:23:38 froehlich Exp $
  + *@version    $Id: TransactionImpl.java,v 1.2 2002/02/11 20:30:09 froehlich Exp $
    */
   
   public class TransactionImpl implements InternalTransaction {
  @@ -78,7 +78,7 @@
       int threadId = getCurrentThreadId();
       InternalTransaction transaction;
       Set objects;
  -    Map attributes  = new HashMap();
  +    Map attributes = new HashMap();
       Map storedState = new HashMap();
       boolean complete = true;
   
  @@ -106,7 +106,6 @@
           instances.put(threadId, tr);
   
           return tr;
  -
       }
   
       private static int getCurrentThreadId() {
  @@ -146,9 +145,9 @@
           checkState();
           checkState(!complete);
           Iterator i = objects.iterator();
  -        while(i.hasNext()){
  -          MetaObject mo = (MetaObject)i.next();   
  -          mo.assign( (MetaObject)storedState.get( mo.getOID() ) );// NPE ?
  +        while (i.hasNext()) {
  +            MetaObject mo = (MetaObject) i.next();
  +            mo.assign((MetaObject) storedState.get(mo.getOID()));// NPE ?
           }
           storedState.clear();
           transaction.rollback(objects);
  @@ -157,14 +156,13 @@
   
       public void add(MetaObject props) {
           checkState();
  -        if(objects.add(props)){
  -         try{   
  -          storedState.put(props.getOID(),props.clone());
  -         }catch( CloneNotSupportedException cnse ){
  -           throw new UnsupportedOperationException(cnse.getMessage());
  -         } 
  +        if (objects.add(props)) {
  +            try {
  +                storedState.put(props.getOID(), props.clone());
  +            } catch (CloneNotSupportedException cnse) {
  +                throw new UnsupportedOperationException(cnse.getMessage());
  +            }
           }
  -
       }
   
       public void begin(Set objects) {
  
  
  
  1.2       +96 -98    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PersistentProxy.java	11 Feb 2002 20:23:38 -0000	1.1
  +++ PersistentProxy.java	11 Feb 2002 20:30:09 -0000	1.2
  @@ -53,37 +53,37 @@
    * <http://www.apache.org/>.
    */
   package org.apache.commons.simplestore.persistence.impl;
  +import java.io.Serializable;
   
  +import org.apache.commons.simplestore.persistence.MetaClass;
   import org.apache.commons.simplestore.persistence.MetaObject;
   import org.apache.commons.simplestore.persistence.Persistent;
   import org.apache.commons.simplestore.persistence.TransactionManager;
  -import org.apache.commons.simplestore.persistence.MetaClass;
   
   import java.lang.reflect.InvocationHandler;
   import java.lang.reflect.Method;
   import java.lang.reflect.Proxy;
  -import java.io.Serializable;
  -import java.util.Map;
  -import java.util.Hashtable;
   import java.util.HashMap;
  +import java.util.Hashtable;
  +import java.util.Map;
   
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: PersistentProxy.java,v 1.1 2002/02/11 20:23:38 froehlich Exp $
  + *@version    $Id: PersistentProxy.java,v 1.2 2002/02/11 20:30:09 froehlich Exp $
    */
  -public class PersistentProxy 
  -implements MetaObject, InvocationHandler,Cloneable, Serializable {
  -    
  +public class PersistentProxy
  +         implements MetaObject, InvocationHandler, Cloneable, Serializable {
  +
       private static Method HASH_CODE;
       private static Method EQUALS;
       private static Method TO_STRING;
       private static Method GET_OID;
       private static Method GET_META_OBJECT;
       private static Map defaults = new Hashtable();
  -    
  +
       Map map = new HashMap();
  -    
  +
       Object oid = null;
       Persistent object;
       Class pClass;
  @@ -91,8 +91,8 @@
       boolean dirty = false;
       boolean deleted = false;
       boolean newCreated;
  -    
  -    
  +
  +
       /**
        * Creates new ValueProxy
        *
  @@ -102,22 +102,22 @@
        *@param  transactionManager
        */
       public PersistentProxy(Class pClass, Object oid, boolean newCreated, TransactionManager
transactionManager) {
  -        
  +
           this.oid = oid;
           this.newCreated = newCreated;
           this.transactionManager = transactionManager;
           this.pClass = pClass;
  -        
  +
       }
  -    
  -    // TODO : "next" interceptor as parameter 
  +
  +    // TODO : "next" interceptor as parameter
       public static Persistent getPersitent(Class persistent, Object oid, boolean newCreated,
TransactionManager transactionManager) {
           PersistentProxy handler = new PersistentProxy(persistent, oid, newCreated, transactionManager);
           Persistent p = (Persistent) Proxy.newProxyInstance(
  -        Thread.currentThread().getContextClassLoader(), new Class[]{persistent, Persistent.class},
handler);
  +                Thread.currentThread().getContextClassLoader(), new Class[]{persistent,
Persistent.class}, handler);
           handler.object = p;
           if (newCreated) {
  -            
  +
               MetaObject mo = p.getMetaObject();
               transactionManager.getTransaction().add(mo);
           }
  @@ -125,7 +125,7 @@
       }
       // TODO must be converter interface
       public static Object convertNumber(Number number, Class cls) {
  -        
  +
           if (cls.equals(Byte.class)) {
               return new Byte(number.byteValue());
           } else if (cls.equals(Short.class)) {
  @@ -145,11 +145,11 @@
           } else {
               throw new UnsupportedOperationException("Number class = " + number.getClass().getName()
+ " Target Class " + cls.getName());
           }
  -        
  +
       }
       // TODO must be converter interface
       public static Object convertPrimityve(Number number, Class cls) {
  -        
  +
           if (cls.equals(Byte.TYPE)) {
               return new Byte(number.byteValue());
           } else if (cls.equals(Short.TYPE)) {
  @@ -169,7 +169,7 @@
           } else {
               throw new UnsupportedOperationException("Number class = " + number.getClass().getName()
+ " Target Class " + cls.getName());
           }
  -        
  +
       }
       // TODO must be converter interface
       public static Object convert(Object object, Class cls) {
  @@ -182,32 +182,32 @@
                       return convertPrimityve((Number) object, cls);
                   }
               }
  -            
  +
               if (object == null) {
                   return null;
               }
  -            
  +
               if (cls.isAssignableFrom(object.getClass())) {
                   return object;
               }
  -            
  +
               // if( object instanceof String ){ ?????
               //     return org.apache.commons.beanutils.ConvertUtils.convert((String)object,cls);
               // }
  -            
  -            
  +
  +
               if (cls.isAssignableFrom(Number.class) && object instanceof Number)
{
                   return convertNumber((Number) object, cls);
               }
  -            
  +
               if (cls.equals(Boolean.class) && object instanceof Number) {
                   return new Boolean(((Number) object).intValue() != 0);
               }
  -            
  +
               if (cls.equals(Character.TYPE)) {
                   return new Character(object.toString().charAt(0));
               }
  -            
  +
               throw new UnsupportedOperationException(cls.getName() + ":" + object);
           } catch (Throwable t) {
               // TODO
  @@ -215,125 +215,128 @@
               throw new RuntimeException(t.getClass().getName() + ":" + t.getMessage());
           }
       }
  -    
  +
       public void setProperty(String name, Object value) {
  -        
  +
           Object old = map.put(name, value);
           if (old == null || !old.equals(value)) {
               dirty = true;
               transactionManager.getTransaction().add(this);
           }
       }
  -    
  +
       public void setDirty(boolean dirty) {
           this.dirty = dirty;
           this.newCreated = false;
       }
  -    
  -    
  +
  +
       public boolean isDeleted() {
           return deleted;
       }
  -    
  +
       public boolean isNew() {
           return newCreated;
       }
  -    
  +
       public MetaObject getMetaObject() {
           return this;
       }
  -    
  +
       public Map getProperties() {
           return map;
       }
  -    
  +
       public Object getProperty(String name) {
           return map.get(name);
       }
  -    
  +
       public boolean isLoaded() {
           return true;
       }
  -    
  +
       public Class getPersistentClass() {
           return pClass;
       }
  -    
  +
       public Object getOID() {
           return oid;
       }
  -    
  +
       public boolean isDirty() {
           return dirty;
       }
  -    
  +
       public Persistent getObject() {
           return object;
       }
  -    
  +
  +    public MetaClass getMetaClass() {
  +        throw new UnsupportedOperationException("Not implemented");
  +    }
  +
       public Object handleEquals(Object obj) {
  -        
  +
           if (obj == null) {
               return new Boolean(false);
           }
  -        
  +
           if (!(obj instanceof Persistent)) {
               return new Boolean(false);
           }
  -        
  +
           Persistent object = (Persistent) obj;
  -        
  +
           if (oid == null) {
  -            
  +
               return new Boolean(oid == object.getOID());
           } else {
  -            
  +
               return new Boolean(oid.equals(object.getOID()));
           }
  -        
  +
       }
  -    
  +
       public Object invoke(Object obj, Method method, Object[] obj2) throws Throwable {
  -        
  +
           synchronized (this) {
  -            
  +
               if (GET_META_OBJECT.equals(method)) {
                   return this;
               } else if (TO_STRING.equals(method)) {
  -                
  +
                   return oid + "";
               } else if (GET_OID.equals(method)) {
  -                
  +
                   return oid;
               } else if (HASH_CODE.equals(method)) {
  -                
  +
                   if (oid == null) {
                       return new Integer(0);
                   }
                   return new Integer(oid.hashCode());
               } else if (EQUALS.equals(method)) {
  -                
  +
                   return handleEquals(obj2[0]);
  -                
               } else {
  -                
  +
                   return handleProperty(obj, method, obj2);
               }
  -            
  +
           }
       }
  -    
  -    
  +
  +
       public Object handleProperty(Object obj, Method method, Object[] obj2) throws Throwable
{
  -        
  +
           String name = method.getName();
  -        
  +
           if (name.startsWith("set")) {
  -            
  +
               setProperty(name.substring(3), obj2[0]);
               return null;
           } else if (name.startsWith("get") || name.startsWith("is")) {
  -            
  +
               if (method.getName().startsWith("get")) {
                   name = method.getName().substring(3);
               } else {
  @@ -345,24 +348,42 @@
               }
               return value;
           }
  -        
  +
           throw new IllegalStateException("pure method " + method.getName());
  -        
       }
  -    
  +
       public void remove() {
           deleted = true;
       }
  -    
  +
  +    public Object clone() throws CloneNotSupportedException {
  +        PersistentProxy cln = (PersistentProxy) super.clone();
  +        cln.dirty = false;
  +        map = (Map) ((HashMap) map).clone();
  +        return cln;
  +    }
  +
  +    public void assign(MetaObject mo) {
  +
  +        map.clear();
  +        map.putAll(mo.getProperties());
  +        oid = mo.getOID();
  +        object = mo.getObject();
  +        pClass = mo.getPersistentClass();
  +        dirty = mo.isDirty();
  +        deleted = mo.isDeleted();
  +        newCreated = mo.isNew();
  +    }
  +
       static {
           try {
               GET_OID = Persistent.class.getMethod("getOID", null);
               GET_META_OBJECT = Persistent.class.getMethod("getMetaObject", null);
  -            
  +
               HASH_CODE = Object.class.getMethod("hashCode", null);
               TO_STRING = Object.class.getMethod("toString", null);
               EQUALS = Object.class.getMethod("equals", new Class[]{Object.class});
  -            
  +
               defaults.put(byte.class, new Byte((byte) 0));
               defaults.put(short.class, new Short((short) 0));
               defaults.put(int.class, new Integer(0));
  @@ -371,34 +392,11 @@
               defaults.put(double.class, new Double(0));
               defaults.put(char.class, new Character('\u0000'));
               defaults.put(boolean.class, new Boolean(false));
  -            
  +
           } catch (Exception e) {
               e.printStackTrace();
               throw new Error(e.getMessage());
           }
  -    }
  -    
  -    public Object clone()throws CloneNotSupportedException{
  -        PersistentProxy cln = (PersistentProxy)super.clone();
  -        cln.dirty = false;
  -        map = (Map)((HashMap)map).clone();
  -        return cln;
  -    }
  -    
  -    public void assign(MetaObject mo) {
  -        
  -        map.clear();
  -        map.putAll(mo.getProperties());
  -        oid = mo.getOID();
  -        object = mo.getObject();
  -        pClass = mo.getPersistentClass();
  -        dirty = mo.isDirty();
  -        deleted = mo.isDeleted();
  -        newCreated = mo.isNew();
  -    }
  -    
  -    public MetaClass getMetaClass() {
  -        throw new UnsupportedOperationException("Not implemented");
       }
   }
   
  
  
  
  1.2       +8 -10     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistenceManager.java
  
  Index: PersistenceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistenceManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PersistenceManager.java	11 Feb 2002 20:23:38 -0000	1.1
  +++ PersistenceManager.java	11 Feb 2002 20:30:09 -0000	1.2
  @@ -56,23 +56,22 @@
   
   import org.apache.commons.simplestore.cache.Cache;
   import org.apache.commons.simplestore.cache.impl.SoftRefMemoryCache;
  -
  -import org.apache.commons.simplestore.persistence.TransactionManager;
  +import org.apache.commons.simplestore.persistence.MetaObject;
  +import org.apache.commons.simplestore.persistence.Persistent;
   import org.apache.commons.simplestore.persistence.Storage;
  -import org.apache.commons.simplestore.persistence.Transaction;
   import org.apache.commons.simplestore.persistence.StorageException;
  -import org.apache.commons.simplestore.persistence.Persistent;
  -import org.apache.commons.simplestore.persistence.MetaObject;
  +import org.apache.commons.simplestore.persistence.Transaction;
  +import org.apache.commons.simplestore.persistence.TransactionManager;
   
  -import java.util.HashMap;
  +import java.math.BigInteger;
   import java.security.SecureRandom;
  +import java.util.HashMap;
   import java.util.Set;
  -import java.math.BigInteger;
   
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: PersistenceManager.java,v 1.1 2002/02/11 20:23:38 froehlich Exp $
  + *@version    $Id: PersistenceManager.java,v 1.2 2002/02/11 20:30:09 froehlich Exp $
    */
   
   public class PersistenceManager {
  @@ -83,7 +82,7 @@
   
       private Storage storage;
       private TransactionManager transactionManager;
  -    private Cache cache = SoftRefMemoryCache.getInstance(new HashMap(),  0xFF);
  +    private Cache cache = SoftRefMemoryCache.getInstance(new HashMap(), 0xFF);
   
       /**
        * Creates new PersiatenceManager
  @@ -113,7 +112,6 @@
       public Object getOID(Object pc) {
   
           return ((Persistent) pc).getOID();
  -
       }
   
       public Object createInstance(Class aclass) {
  
  
  
  1.2       +21 -22    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DBStorage.java	11 Feb 2002 20:23:38 -0000	1.1
  +++ DBStorage.java	11 Feb 2002 20:30:09 -0000	1.2
  @@ -55,37 +55,37 @@
   package org.apache.commons.simplestore.persistence.impl;
   
   import org.apache.commons.simplestore.cache.Cache;
  +import org.apache.commons.simplestore.persistence.InternalTransaction;
  +import org.apache.commons.simplestore.persistence.MetaObject;
   import org.apache.commons.simplestore.persistence.ObjectNotFound;
   import org.apache.commons.simplestore.persistence.Persistent;
  -import org.apache.commons.simplestore.persistence.MetaObject;
   import org.apache.commons.simplestore.persistence.StorageException;
  -import org.apache.commons.simplestore.persistence.InternalTransaction;
   
  -import java.lang.reflect.Proxy;
   import java.lang.reflect.Method;
  -import java.util.Properties;
  -import java.util.Date;
  -import java.util.HashSet;
  -import java.sql.Date;
  +import java.lang.reflect.Proxy;
   import java.sql.Connection;
  +import java.sql.Date;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
  -import java.sql.Types;
   import java.sql.ResultSetMetaData;
   import java.sql.SQLException;
  -import java.util.ResourceBundle;
  +import java.sql.Types;
  +import java.util.ArrayList;
  +import java.util.Date;
   import java.util.Enumeration;
  +import java.util.HashSet;
  +import java.util.List;
   import java.util.Map;
  +import java.util.Properties;
  +import java.util.ResourceBundle;
   import java.util.Set;
  -import java.util.List;
  -import java.util.ArrayList;
   import javax.sql.DataSource;
   
   // TODO Synchronization
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: DBStorage.java,v 1.1 2002/02/11 20:23:38 froehlich Exp $
  + *@version    $Id: DBStorage.java,v 1.2 2002/02/11 20:30:09 froehlich Exp $
    */
   public class DBStorage extends AbstractStorage {
   
  @@ -196,7 +196,7 @@
                           }
                       }
                   }
  -                if ( statement.execute() ) {
  +                if (statement.execute()) {
                       rs = statement.getResultSet();
                   } else {
                       return statement.getUpdateCount();
  @@ -310,7 +310,7 @@
   
               };
   
  -        if ( excecute(connection, sql, new Object[]{id}, rsh) == 0 ) {
  +        if (excecute(connection, sql, new Object[]{id}, rsh) == 0) {
               throw new ObjectNotFound(pc.getOID().toString(), null);
           }
   
  @@ -376,10 +376,9 @@
   
           final String sql = "UPDATE " + name + " SET " + names;
   
  -       if(  excecute(connection, sql, values.toArray(), null ) == 0 ){
  -           throw new ObjectNotFound(properties.getOID().toString(), null);
  -       }   
  -
  +        if (excecute(connection, sql, values.toArray(), null) == 0) {
  +            throw new ObjectNotFound(properties.getOID().toString(), null);
  +        }
       }
   
       // TODO : mot very meanigful here
  @@ -425,7 +424,7 @@
                   params += ",?";
               }
           }
  -       //TODO : ID !!!
  +        //TODO : ID !!!
           final String sql = "INSERT INTO " + toSQLName(clasz.getName()) + "(ID" + names
+ ")VALUES(?" + params + ")";
   
           excecute(connection, sql, values.toArray(), null);
  @@ -440,9 +439,9 @@
           // TODO : ID must be in some mapping
           final String sql = "DELETE FROM " + name + " WHERE ID=?";
   
  -       if( excecute(connection, sql, new Object[]{id}, null) == 0 ){
  -           throw new ObjectNotFound(obj.getOID().toString(), null);
  -       }
  +        if (excecute(connection, sql, new Object[]{id}, null) == 0) {
  +            throw new ObjectNotFound(obj.getOID().toString(), null);
  +        }
       }
   
       protected void internalCommit() throws StorageException {
  
  
  
  1.2       +7 -8      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractStorage.java	11 Feb 2002 20:23:38 -0000	1.1
  +++ AbstractStorage.java	11 Feb 2002 20:30:09 -0000	1.2
  @@ -54,25 +54,25 @@
    */
   package org.apache.commons.simplestore.persistence.impl;
   
  -import org.apache.commons.simplestore.persistence.Storage;
   import org.apache.commons.simplestore.persistence.InternalTransaction;
  -import org.apache.commons.simplestore.persistence.TransactionManager;
   import org.apache.commons.simplestore.persistence.MetaObject;
  +import org.apache.commons.simplestore.persistence.Storage;
   import org.apache.commons.simplestore.persistence.StorageException;
  +import org.apache.commons.simplestore.persistence.TransactionManager;
   
  -import java.util.Map;
   import java.util.HashMap;
  -import java.util.Set;
   import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Set;
   
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: AbstractStorage.java,v 1.1 2002/02/11 20:23:38 froehlich Exp $
  + *@version    $Id: AbstractStorage.java,v 1.2 2002/02/11 20:30:09 froehlich Exp $
    */
   
  -public abstract class AbstractStorage 
  -implements Storage, InternalTransaction, TransactionManager {
  +public abstract class AbstractStorage
  +         implements Storage, InternalTransaction, TransactionManager {
   
       Map attributes = new HashMap();
   
  @@ -80,7 +80,6 @@
   
           attributes.put(name, value);
       }
  -
   
   
       public InternalTransaction getTransaction() {
  
  
  

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