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 Sat, 13 Apr 2002 13:28:10 GMT
baliuka     02/04/13 06:28:09

  Modified:    simplestore/src/java/org/apache/commons/simplestore/jdbc
                        DriverDataSource.java
               simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        PersistentProxy.java
               simplestore/src/test/org/apache/commons/simplestore
                        TestSample.java
  Log:
  
  
  Revision  Changes    Path
  1.10      +27 -11    jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/jdbc/DriverDataSource.java
  
  Index: DriverDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/jdbc/DriverDataSource.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DriverDataSource.java	19 Mar 2002 12:48:08 -0000	1.9
  +++ DriverDataSource.java	13 Apr 2002 13:28:09 -0000	1.10
  @@ -78,7 +78,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: DriverDataSource.java,v 1.9 2002/03/19 12:48:08 baliuka Exp $
  + *@version    $Id: DriverDataSource.java,v 1.10 2002/04/13 13:28:09 baliuka Exp $
    *
    */
   public class DriverDataSource implements ConnectionFactory {
  @@ -213,14 +213,17 @@
           synchronized (this) {
               
               if (connection == null) {
  -                connection = new ConnectionWrapper[maxConnections];
  +                connection = 
  +                new ConnectionWrapper[ 
  +                    maxConnections < 1 ? 1 : maxConnections 
  +                    ];
               }
               
               int i = 0;
               while ( true ) { //  must loop and wait not used connection
  -                if (connection[i] != null) {           // if we will return used connection,
it is very possible
  -                    if (!connection[i].isUsed()) {    //  we will break transaction demarcation
  -                        counter = i;                  // it is not a problem for "readonly"
data
  +                if (connection[i] != null) {           
  +                    if (!connection[i].isUsed()) {    
  +                        counter = i;                  
                           
                           if (connection[ i ].isClosed()) { // expired ?
                               try {
  @@ -230,6 +233,7 @@
                               } catch (Exception ignore) {
                                   
                               }
  +                            
                               connection[ i ] = newConnection();
                           }
                           
  @@ -242,7 +246,9 @@
                   i = ( i + 1 ) % maxConnections;
                   try{
                       
  -                    if( i == 0  ) wait();
  +                    if( i == 0  ) {
  +                        wait( 1000 );
  +                    }
                       
                   }catch( java.lang.InterruptedException ie ){
                       
  @@ -289,7 +295,7 @@
   class ConnectionProxy  implements InvocationHandler {
       
       
  -    boolean used = true;
  +    private Thread used;
       private Connection connection;
       private ConnectionFactory ds;
       
  @@ -302,7 +308,7 @@
         throws Throwable{
          
            if( method.getName().equals("close")  ) {
  -           used = false;
  +           used = null;
               synchronized( ds ){ 
                  ds.notifyAll();
                }  
  @@ -312,11 +318,21 @@
                connection.close();
                return null;     
            }else if (method.getName().equals("isUsed")){
  -            return new Boolean(used);
  +             
  +             return ( used == null || !used.isAlive() || 
  +                       used == Thread.currentThread()  
  +                       
  +                   ) ? Boolean.FALSE : Boolean.TRUE ;
  +             
  +             
            }else if (method.getName().equals("setUsed")){
  -            used = ((Boolean) args[0] ).booleanValue();
  +            if( ((Boolean) args[0] ).booleanValue()){
  +              used = Thread.currentThread();
  +            }else{
  +              used = null;
  +            }
               return null;
  -         }else    return method.invoke(connection,args) ;
  +         }else  return method.invoke(connection,args) ;
       }
      public static  ConnectionWrapper create(Connection connection, ConnectionFactory ds){
          return (ConnectionWrapper)
  
  
  
  1.26      +2 -2      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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- PersistentProxy.java	3 Apr 2002 18:17:08 -0000	1.25
  +++ PersistentProxy.java	13 Apr 2002 13:28:09 -0000	1.26
  @@ -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.25 2002/04/03 18:17:08 baliuka Exp $
  + *@version    $Id: PersistentProxy.java,v 1.26 2002/04/13 13:28:09 baliuka Exp $
    */
   public class PersistentProxy
   implements MetaObject,  org.apache.commons.simplestore.tools.Constants ,
  @@ -343,7 +343,7 @@
                    retrieveObject( method.getReturnType(),value );
               }
               
  -            return  value;
  +            return  m_context.getTypeConverter().toAppType(value,method.getReturnType());
           }
           throw new java.lang.NoSuchMethodError("pure method invoked: " + method);
       }
  
  
  
  1.21      +38 -37    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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TestSample.java	24 Mar 2002 09:24:31 -0000	1.20
  +++ TestSample.java	13 Apr 2002 13:28:09 -0000	1.21
  @@ -72,7 +72,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TestSample.java,v 1.20 2002/03/24 09:24:31 baliuka Exp $
  + *@version    $Id: TestSample.java,v 1.21 2002/04/13 13:28:09 baliuka Exp $
    */
   public class TestSample extends TestCase implements org.apache.commons.simplestore.tools.Constants{
       
  @@ -101,22 +101,22 @@
               Object oid = pm.getOID(object1);
               object1.doSomething(object1.toString());
               transaction.commit();
  -           
  +            
               transaction.begin();
               TestPersistentClassType object2 = (TestPersistentClassType) pm.findInstance(TestPersistentClassType.class,
oid);
               transaction.commit();
               
               transaction.begin();
               TestPersistentClassType object3 = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
  -             try{
  -                 
  -              object3.setNuls();
  -              fail("ValidationException expected");
  -              
  -             }catch(ValidationException ve){
  -              if(DEBUG)
  -                  ve.printStackTrace();
  -             }
  +            try{
  +                
  +                object3.setNuls();
  +                fail("ValidationException expected");
  +                
  +            }catch(ValidationException ve){
  +                if(DEBUG)
  +                    ve.printStackTrace();
  +            }
               object3.setDateVal(new java.util.Date());
               object3.setIntVal(i);
               object3.setFloatVal(i / 2);
  @@ -140,20 +140,21 @@
           
           transaction.begin();
           java.util.Set objects = pm.findAll(TestPersistentClassType.class);
  -        if( DEBUG )
  -         System.out.println("retrieved " + objects.size());
  +        
  +       if( DEBUG )
  +        System.out.println("retrieved " + objects.size());
           java.util.Iterator i = objects.iterator();
           
           while (i.hasNext()) {
               
               TestPersistentClassType object = (TestPersistentClassType) i.next();
  -             object.toString();
  -             object.getBoolVal();
  -             object.getDateVal();
  -             object.getIntVal();
  -             object.getFloatVal();
  -             object.getStrVal1();
  -             object.getParent();
  +            object.toString();
  +            object.getBoolVal();
  +            object.getDateVal();
  +            object.getIntVal();
  +            object.getFloatVal();
  +            object.getStrVal1();
  +            object.getParent();
               
           }
           
  @@ -186,8 +187,8 @@
           transaction.begin();
           TestPersistentClassType object = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
           object.setStrVal("Test roolback on new created " + object);
  -       if( DEBUG ) 
  -        System.out.println(object.getStrVal());
  +        if( DEBUG )
  +            System.out.println(object.getStrVal());
           transaction.rollback();
           
           transaction.begin();
  @@ -222,21 +223,21 @@
       protected void setUp() throws java.lang.Exception {
           super.setUp();
           long time = System.currentTimeMillis();
  -       if(false){ 
  -        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();
  -       }else{
  -        JDBMPersistenceManagerFactory factory = new JDBMPersistenceManagerFactory();
  -        factory.setFile("sample");
  -        factory.setMetaResource("org/apache/commons/simplestore/storage.xml");
  -        pm = factory.getPersistenceManager();
  -       }
  +        if(true){
  +            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();
  +        }else{
  +            JDBMPersistenceManagerFactory factory = new JDBMPersistenceManagerFactory();
  +            factory.setFile("sample");
  +            factory.setMetaResource("org/apache/commons/simplestore/storage.xml");
  +            pm = factory.getPersistenceManager();
  +        }
           System.out.println("Setup: " + ( System.currentTimeMillis()/1000f - time/1000f
)  );
       }
       
  
  
  

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