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/java/org/apache/commons/simplestore/persistence/impl AbstractStorage.java DBStorage.java
Date Sun, 14 Apr 2002 13:42:45 GMT
baliuka     02/04/14 06:42:45

  Modified:    simplestore/docs developers-guide.html users-guide.html
               simplestore/src/java/org/apache/commons/simplestore/persistence
                        PersistenceManager.java Spi.java Storage.java
                        TypeConverter.java
               simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        AbstractStorage.java DBStorage.java
  Log:
  
  
  Revision  Changes    Path
  1.4       +150 -5    jakarta-commons-sandbox/simplestore/docs/developers-guide.html
  
  Index: developers-guide.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/docs/developers-guide.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- developers-guide.html	3 Apr 2002 18:17:08 -0000	1.3
  +++ developers-guide.html	14 Apr 2002 13:42:45 -0000	1.4
  @@ -5,10 +5,10 @@
       <TITLE>SimpleStore Developers Guide</TITLE>
     <style>
   
  -   h3{color:navy};
  -   pre{color:navy};
  -   code{color:navy};
  -   
  +   h3{color:navy}
  +   pre{color:navy}
  +   code{color:navy}
  +   span{color:red}
     </style>
     </HEAD>
     <BODY link='navy' alink='navy' vlink='navy'>
  @@ -134,6 +134,38 @@
   Implementation must use <code>Cache</code> for reachability management and
Identity. Single persistent
   object instance must be loaded with the same OID. OID object and persistent's class is
unique pair.
   Use storege implementations as examples or base classes for custom storage implementations.
  +
  +<pre>
  +<b>public</b> java.util.Collection retrieve(Class clasz, int index, Object
value)
  +                                                        throws StorageException{
  +        
  +        <b>final</b> Set objects = new HashSet();
  +        <b>final</b> MetaClass mClass =  context.getMetaClass(clasz);
  +        <b>final</b> String sql = <span>"SELECT "</span>+ mClass.getOIDName()
+ <span>" AS "</span> + INTERNAL_OID +
  +                              <span>", * FROM "</span> + mClass.getName() +
  +        <span>" WHERE "</span> + mClass.getPropertyName(index) + <span>"=?"</span>;
  +        <span style="color:green">//find uncommited objects first</span>
  +        java.util.Collection tObjects = context.getTransactionManager().getTransaction().getTransactionalObjects();
  +        <b>for</b>( java.util.Iterator i = tObjects.iterator(); i.hasNext();
){
  +          MetaObject mo = (MetaObject)i.next();
  +           <b>if</b>( mo.getPersistentClass().equals(clasz) ){
  +           <b>if</b>( (value == <b>null</b>) && (mo.getProperty(index)
== <b>null</b>) ){  
  +                    objects.add( mo.getObject() );
  +                    <b>continue</b>;
  +                  }
  +                 if( value != <b>null</b> && value.equals(mo.getProperty(index))
 ){
  +                    objects.add( mo.getObject() );
  +                    <b>continue</b>;
  +                 }
  +           } 
  +        }
  +       <span style="color:green">//execute SQL statement</span>
  +        excecute( sql, <b>new</b> Object[]{value}, new QueryHandler(objects,
clasz));
  +        
  +        <b>return</b> objects;
  +    }
  + </pre>   
  +
   </p>
   <a name='cache'><h3>Cache</h3></a>
   <p>
  @@ -156,6 +188,119 @@
    distributed objects, Object to XML mapping.
   SimpleStore use <a href='http://jakarta.apache.org/bcel'>BCEL</a>
    to enhance classes and implement Persistent interface.
  +
  + Generated code for <code>java.util.Vector</code>:
  + 
  +<pre>
  +<b>public boolean</b> removeElement(Object arg1)
  +Code(max_stack = 8, max_locals = 8, code_length = 112)
  +<hr>
  +0:    iconst_1
  +1:    anewarray         &lt;java.lang.Object&gt; (16)
  +4:    dup
  +5:    iconst_0
  +6:    aload_1
  +7:    aastore
  +8:    astore_2
  +9:    aload_0
  +10:   getfield          org.apache.java.util.Vector$$EnhancedBySimplestore$$.h Lorg/apache/commons/simplestore/tools/MethodInterceptor;
(14)
  +13:   aload_0
  +14:   getstatic         org.apache.java.util.Vector$$EnhancedBySimplestore$$.METHOD_23
Ljava/lang/reflect/Method; (240)
  +17:   aload_2
  +18:   invokeinterface   org.apache.commons.simplestore.tools.MethodInterceptor.<b>beforeInvoke</b>
(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object; (49) 
  4       0
  +23:   astore_3
  +24:   aconst_null
  +25:   astore            %4
  +27:   iconst_0
  +28:   istore            %5
  +30:   aconst_null
  +31:   astore            %6
  +33:   aload_0
  +34:   getfield          org.apache.java.util.Vector$$EnhancedBySimplestore$$.h Lorg/apache/commons/simplestore/tools/MethodInterceptor;
(14)
  +37:   aload_0
  +38:   getstatic         org.apache.java.util.Vector$$EnhancedBySimplestore$$.METHOD_23
Ljava/lang/reflect/Method; (240)
  +41:   aload_2
  +42:   aload_3
  +43:   invokeinterface   org.apache.commons.simplestore.tools.MethodInterceptor.<b>invokeSuper</b>
(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;Ljava/lang/Object;)Z (57)
   5       0
  +48:   ifeq              <b>#73</b>
  +51:   iconst_1
  +52:   istore            %5
  +54:   new               &lt;java.lang.Boolean> (63)
  +57:   dup
  +58:   aload_0
  +59:   aload_1
  +60:   invokespecial     java.util.Vector.<b>removeElement</b> (Ljava/lang/Object;)Z
(243)
  +63:   invokespecial     java.lang.Boolean.&lt;init&gt; (Z)V (70)
  +66:   astore            %4
  +68:   goto              <b>#73</b>
  +71:   astore            %6
  +73:   aload_0
  +74:   getfield          org.apache.java.util.Vector$$EnhancedBySimplestore$$.h Lorg/apache/commons/simplestore/tools/MethodInterceptor;
(14)
  +77:   aload_0
  +78:   getstatic         org.apache.java.util.Vector$$EnhancedBySimplestore$$.METHOD_23
Ljava/lang/reflect/Method; (240)
  +81:   aload_2
  +82:   aload_3
  +83:   iload             %5
  +85:   aload             %4
  +87:   aload             %6
  +89:   invokeinterface   org.apache.commons.simplestore.tools.MethodInterceptor.<b>afterReturn</b>
(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;Ljava/lang/Object;ZLjava/lang/Object;Ljava/lang/Throwable;)Ljava/lang/Object;
(53)   8       0
  +94:   astore            %7
  +96:   aload             %7
  +98:   ifnonnull         <b>#103</b>
  +101:  iconst_0
  +102:  ireturn
  +103:  aload             %7
  +105:  checkcast         &lt;java.lang.Boolean&gt; (63)
  +108:  invokevirtual     java.lang.Boolean.<b>booleanValue</b> ()Z (74)
  +111:  ireturn
  +<hr>
  +Exception handler(s) = 
  +From    To      Handler Type
  +54      68      71      java.lang.Throwable(76)
  +</pre>
  +
  + Decompiled code:
  +<pre>
  +
  +<b> package </b> org.apache.java.util;
  +
  +<b> public class </b> Vector$$EnhancedBySimplestore$$ <b> extends </b>java.util.Vector{
  +
  + <b>org.apache.commons.simplestore.tools.MethodInterceptor</b> h;
  + //...
  + <b>static java.lang.reflect.Method </b> METHOD_23 =
  +                Vector.class.getMethod(<span style='color:red'>"removeElement"</span>,
  +                                           new Class[]{Object.class}
  +                                   ); 
  + //...
  +
  + <b>public boolean</b> removeElement(Object arg1){
  +
  +   Object args[] = { arg1 };
  +   Object retValFromBefore = h.<b>beforeInvoke</b>(this,METHOD_23,args);
  +   boolean invokedSuper = false;
  +   Throwable t = null;
  +   Object retValFromSuper = null;
  +
  +   if( h.<b>invokeSuper</b>(this,METHOD_23,args,retValFromBefore) ){
  +     invokedSuper = true;
  +   try{
  +
  +      retValFromSuper = new Boolean( <b>super</b>.removeElement(arg1) );
  +
  +    }catch(Throwable tl){
  +        t = tl
  +    }
  +
  +   }
  +
  +  return ((Boolean) h.<b>afterReturn</b>(this, METHOD_23, args,
  +                       retValFromBefore, invokedSuper, retValFromSuper,t )
  +            ).booleanValue();
  +
  +}
  +</pre>
  + This code will not compile it doe's not handle <code>Throwable</code>.
   </p>
   
   <a name='persistent'><h3>Persistent</h3></a>
  @@ -176,7 +321,7 @@
    <code>Persistent</code> returns this implementation.
   This interface is used by Storage implementation too.
    <pre>
  -public interface MetaObject extends Cloneable {
  +<b>public interface</b> MetaObject <b>extends</b> Cloneable {
   
       public Object <b>getOID</b>();
   
  
  
  
  1.8       +3 -3      jakarta-commons-sandbox/simplestore/docs/users-guide.html
  
  Index: users-guide.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/docs/users-guide.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- users-guide.html	3 Apr 2002 18:17:08 -0000	1.7
  +++ users-guide.html	14 Apr 2002 13:42:45 -0000	1.8
  @@ -3,9 +3,9 @@
   
   <title>SimpleStore Usere Guide</title>
     <style>
  -   h3{color:navy};
  -   pre{color:navy};
  -   code{color:navy};
  +   h3{color:navy}
  +   pre{color:navy}
  +   code{color:navy}
      
     </style>
   </head>
  
  
  
  1.4       +11 -1     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PersistenceManager.java	23 Mar 2002 14:54:52 -0000	1.3
  +++ PersistenceManager.java	14 Apr 2002 13:42:45 -0000	1.4
  @@ -72,7 +72,7 @@
    *
    * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: PersistenceManager.java,v 1.3 2002/03/23 14:54:52 baliuka Exp $
  + * @version $Id: PersistenceManager.java,v 1.4 2002/04/14 13:42:45 baliuka Exp $
    */
   public interface PersistenceManager {
   
  @@ -134,8 +134,18 @@
        */    
       public void removeInstance(Object pc);
   
  +    /** returns state of persistent object
  +     * @param pc Persistent
  +     * @return true if object is new and uncommited
  +     */    
       public boolean isNew(Object pc);
       
  +    /** returns state of persistent object,
  +     * deleted objects are not removed from cache,
  +     * Persistence manager can return deleted object if it exists in cache
  +     * @param pc Persistent
  +     * @return true if object deleted
  +     */    
       public boolean isDeleted(Object pc);
   }
   
  
  
  
  1.2       +5 -1      jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Spi.java
  
  Index: Spi.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Spi.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Spi.java	1 Apr 2002 17:19:33 -0000	1.1
  +++ Spi.java	14 Apr 2002 13:42:45 -0000	1.2
  @@ -55,12 +55,16 @@
   package org.apache.commons.simplestore.persistence;
   
   /**
  + * This All service provider interfaces extend Spi
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: Spi.java,v 1.1 2002/04/01 17:19:33 baliuka Exp $
  + *@version    $Id: Spi.java,v 1.2 2002/04/14 13:42:45 baliuka Exp $
    */
   public interface Spi {
       
  +    /** Sets persitence context
  +     * @param context Configured context object
  +     */    
      public void setContext(Context context);
      
   }
  
  
  
  1.7       +25 -6     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Storage.java
  
  Index: Storage.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Storage.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Storage.java	1 Apr 2002 17:08:09 -0000	1.6
  +++ Storage.java	14 Apr 2002 13:42:45 -0000	1.7
  @@ -63,21 +63,40 @@
    *
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: Storage.java,v 1.6 2002/04/01 17:08:09 baliuka Exp $
  + *@version    $Id: Storage.java,v 1.7 2002/04/14 13:42:45 baliuka Exp $
    */
   
   public interface Storage extends Spi{
   
  -    public void storeObject(MetaObject properties) throws StorageException;
  -
  -    public Object retrieveObject(Class clasz, Object id) throws StorageException;
  +    /** Used by factory to set context object
  +     * @param context Context */    
   
       public void setContext(Context context );
   
  +    /**
  +     * retrieves all objects of clasz type
  +     * @param clasz type
  +     * @throws StorageException on storage error
  +     * @return  set of persistent objects
  +     */    
       public Set retrieveAll(Class clasz) throws StorageException;
  -
  -    public void close() throws StorageException;
       
  +    /**
  +     * retrieve object by OID
  +     * @param clasz type
  +     * @param id OID
  +     * @throws StorageException on storage error
  +     * @return  Persistent object
  +     */    
  +    public Object retrieveObject(Class clasz, Object id) throws StorageException;
  +  
  +    /** retrieve object by property
  +     * @param clasz type
  +     * @param index property index
  +     * @param value property value
  +     * @throws StorageException on storage error
  +     * @return set of persistent objects
  +     */    
       public java.util.Collection retrieve(Class clasz, int index, Object value)throws StorageException;
       
   }
  
  
  
  1.6       +12 -1     jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/TypeConverter.java
  
  Index: TypeConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/TypeConverter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TypeConverter.java	1 Apr 2002 17:08:09 -0000	1.5
  +++ TypeConverter.java	14 Apr 2002 13:42:45 -0000	1.6
  @@ -59,12 +59,23 @@
    *
    *@author     Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
    *     g-froehlich@gmx.de</a>
  - *@version    $Id: TypeConverter.java,v 1.5 2002/04/01 17:08:09 baliuka Exp $
  + *@version    $Id: TypeConverter.java,v 1.6 2002/04/14 13:42:45 baliuka Exp $
    */
   
   public interface TypeConverter extends Spi{
            
  +    /** Conversts value from storage to app type
  +     * @param object value
  +     * @param clazz type
  +     * @return transformed object
  +     */    
        public Object toAppType(Object object , Class clazz);
  +     
  +    /** Conversts value to storage  type
  +     * @param object value
  +     * @param clazz type
  +     * @return transformed object
  +     */    
        
        public Object toStorageType(Object object , Class clazz);
        
  
  
  
  1.9       +3 -2      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AbstractStorage.java	14 Mar 2002 19:42:22 -0000	1.8
  +++ AbstractStorage.java	14 Apr 2002 13:42:45 -0000	1.9
  @@ -69,7 +69,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: AbstractStorage.java,v 1.8 2002/03/14 19:42:22 baliuka Exp $
  + *@version    $Id: AbstractStorage.java,v 1.9 2002/04/14 13:42:45 baliuka Exp $
    */
   
   public abstract class AbstractStorage
  @@ -165,7 +165,8 @@
           }
           
       }
  -    
  +
  +    public abstract void storeObject(MetaObject properties) throws StorageException;  
       
       protected abstract void createObject(MetaObject properties) throws StorageException;
       
  
  
  
  1.17      +53 -48    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DBStorage.java	24 Mar 2002 06:27:35 -0000	1.16
  +++ DBStorage.java	14 Apr 2002 13:42:45 -0000	1.17
  @@ -84,12 +84,12 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: DBStorage.java,v 1.16 2002/03/24 06:27:35 baliuka Exp $
  + *@version    $Id: DBStorage.java,v 1.17 2002/04/14 13:42:45 baliuka Exp $
    */
   public class DBStorage extends AbstractStorage implements org.apache.commons.simplestore.tools.Constants
{
       
       private final static String CONNECTION = "org.apache.commons.simplestore.jdbc.DBStorage.connection";
  -     private final static String INTERNAL_OID = "INTERNAL_OID";
  +    private final static String INTERNAL_OID = "INTERNAL_OID";
       //TODO : must be in MetaClass
       private static Properties procedures = new Properties();
       private ConnectionFactory ds;
  @@ -104,7 +104,7 @@
           this.ds = ds;
       }
       
  -
  +    
       public  Object toSQLType(Object object) {
           return context.getTypeConverter().toStorageType(object,null);
       }
  @@ -132,9 +132,9 @@
                           }
                       }
                   }
  -                if (statement.execute()) {
  +                if (statement.execute()) { // SELECT
                       rs = statement.getResultSet();
  -                } else {
  +                } else { // UPDATE
                       return statement.getUpdateCount();
                   }
                   
  @@ -165,7 +165,7 @@
                   }
               }
           } catch (SQLException se) {
  -            throw new StorageException(sql, se);
  +            throw new StorageException(sql, se.fillInStackTrace());
           }
           return result;
       }
  @@ -177,6 +177,7 @@
       
       public Object retrieveObject( final Class clasz, Object id ) throws StorageException
{
           
  +        //try cahce first
           Persistent result = (Persistent) context.getCache().get(id);
           
           if (result != null) {
  @@ -197,15 +198,16 @@
                   
                   try {
                       if ( name.equalsIgnoreCase(mClass.getOIDName())) {
  +                        //OID is known
                           return;
                       }
                       
                       int propIndex =  mClass.getPropertyIndex( name );
  -                       props[ propIndex ] = value;
  +                    props[ propIndex ] = value;
                       
                   } catch (Throwable t) {
                       t.printStackTrace();
  -                    throw new StorageException(t.getMessage(), t);
  +                    throw new StorageException(t.getMessage(), t.fillInStackTrace());
                   }
               }
               
  @@ -225,14 +227,16 @@
           final MetaClass mClass =  context.getMetaClass(clasz);
           final String sql = "SELECT "+ mClass.getOIDName() + " AS " + INTERNAL_OID + ",
* FROM " + mClass.getName();
           final Set objects = new HashSet();
  -      java.util.Collection tObjects = context.getTransactionManager().getTransaction().getTransactionalObjects();
  +        
  +        //find uncommited objects first
  +        java.util.Collection tObjects = context.getTransactionManager().getTransaction().getTransactionalObjects();
           for( java.util.Iterator i = tObjects.iterator(); i.hasNext(); ){
  -          MetaObject mo = (MetaObject)i.next();
  -          if( mo.getPersistentClass().equals(clasz) ){
  -              objects.add( mo.getObject() );
  -          }
  +            MetaObject mo = (MetaObject)i.next();
  +            if( mo.getPersistentClass().equals(clasz) ){
  +                objects.add( mo.getObject() );
  +            }
           }
  -    
  +        
           
           excecute( sql, null, new QueryHandler(objects, clasz));
           
  @@ -276,7 +280,7 @@
           values.add(properties.getOID());
           
           final String sql = "UPDATE " + name + " SET " + names;
  -            excecute( sql, values.toArray(), null);
  +        excecute( sql, values.toArray(), null);
           
       }
       
  @@ -289,9 +293,7 @@
                   connection.close();
               }
           } catch (Exception e) {
  -            
  -            e.printStackTrace();
  -            // TODO
  +            throw new StorageException(e.getMessage(), e.fillInStackTrace());
           }
       }
       
  @@ -331,6 +333,10 @@
           
       }
       
  +   /**
  +    * this method doe's not removes object from cache  
  +    */
  +    
       protected void removeObject(MetaObject obj) throws StorageException {
           
           final MetaClass mClass =  context.getMetaClass(obj.getPersistentClass());
  @@ -353,7 +359,7 @@
                   connection.close();
               }
           } catch (SQLException se) {
  -            throw new StorageException(se.getMessage(), se);
  +            throw new StorageException(se.getMessage(), se.fillInStackTrace());
           }
       }
       
  @@ -367,61 +373,60 @@
               }
           } catch (SQLException se) {
               
  -            throw new StorageException(se.getMessage(), se);
  +            throw new StorageException(se.getMessage(), se.fillInStackTrace());
           }
       }
       
       protected void internalBegin() throws StorageException {
  -        try {
  -            Connection connection = ds.getConnection();
  -            context.getTransactionManager().getTransaction().setAttribute(CONNECTION, connection);
  -            
  -        } catch (SQLException se) {
  -            throw new StorageException(se.getMessage(), se);
  -        }
  +        // do nothing
       }
       
       private Connection getConnection() {
  -        
  -        Connection connection = (Connection) context.getTransactionManager().getTransaction().getAttribute(CONNECTION);
  -        
  -        if (connection == null) {
  -              throw new IllegalTransactionStateException("Transaction not Started");
  +        try{
  +            Connection connection = (Connection) context.getTransactionManager().getTransaction().getAttribute(CONNECTION);
  +            
  +            if (connection == null) {
  +                // open new connection
  +                connection = ds.getConnection();
  +                context.getTransactionManager().getTransaction().setAttribute(CONNECTION,
connection);
  +            }
  +            return connection;
  +            
  +        } catch (SQLException se) {
  +            throw new StorageException(se.getMessage(), se.fillInStackTrace());
           }
  -        
  -        return connection;
       }
       
       public java.util.Collection retrieve(Class clasz, int index, Object value)
  -                                                        throws StorageException{
  +    throws StorageException{
           
           final Set objects = new HashSet();
           final MetaClass mClass =  context.getMetaClass(clasz);
           final String sql = "SELECT "+ mClass.getOIDName() + " AS " + INTERNAL_OID +
  -                              ", * FROM " + mClass.getName() +
  +        ", * FROM " + mClass.getName() +
           " WHERE " + mClass.getPropertyName(index) + "=?";
  -        
  +        //find uncommited objects first
           java.util.Collection tObjects = context.getTransactionManager().getTransaction().getTransactionalObjects();
           for( java.util.Iterator i = tObjects.iterator(); i.hasNext(); ){
  -          MetaObject mo = (MetaObject)i.next();
  -           if( mo.getPersistentClass().equals(clasz) ){
  -           if( (value == null) && (mo.getProperty(index) == null) ){  
  +            MetaObject mo = (MetaObject)i.next();
  +            if( mo.getPersistentClass().equals(clasz) ){
  +                if( (value == null) && (mo.getProperty(index) == null) ){
                       objects.add( mo.getObject() );
                       continue;
  -                  }
  -                 if( value != null && value.equals(mo.getProperty(index))  ){
  +                }
  +                if( value != null && value.equals(mo.getProperty(index))  ){
                       objects.add( mo.getObject() );
                       continue;
  -                 }
  -           } 
  -                
  +                }
  +            }
  +            
           }
           
  -         
  +        
           excecute( sql, new Object[]{value}, new QueryHandler(objects, clasz));
           
           return objects;
  -       
  +        
           
       }
       
  @@ -441,7 +446,7 @@
               try {
                   name = name.toUpperCase();
                   if (index == 1) {
  -                    
  +                    //try to find in cache first
                       Persistent p = (Persistent) context.getCache().get(value);
                       if ( p != null ) {
                           props = null;
  
  
  

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