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 Sun, 24 Mar 2002 06:27:36 GMT
baliuka     02/03/23 22:27:36

  Modified:    simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        DBStorage.java
               simplestore/src/test/org/apache/commons/simplestore
                        TestSample.java
  Added:       simplestore/lib jdbm.jar
               simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        DBPersistenceManagerFactory.java
                        JDBMPersistenceManagerFactory.java
  Log:
  Added JDBM storage
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/simplestore/lib/jdbm.jar
  
  	<<Binary file>>
  
  
  1.16      +13 -7     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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DBStorage.java	23 Mar 2002 14:54:53 -0000	1.15
  +++ DBStorage.java	24 Mar 2002 06:27:35 -0000	1.16
  @@ -65,7 +65,6 @@
   import org.apache.commons.simplestore.persistence.IllegalTransactionStateException;
   
   import java.lang.reflect.Method;
  -import java.lang.reflect.Proxy;
   import java.sql.Connection;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
  @@ -78,15 +77,14 @@
   import java.util.List;
   import java.util.Map;
   import java.util.Properties;
  -import java.util.ResourceBundle;
   import java.util.Set;
   
   
  -// TODO Synchronization
  +
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: DBStorage.java,v 1.15 2002/03/23 14:54:53 baliuka Exp $
  + *@version    $Id: DBStorage.java,v 1.16 2002/03/24 06:27:35 baliuka Exp $
    */
   public class DBStorage extends AbstractStorage implements org.apache.commons.simplestore.tools.Constants
{
       
  @@ -406,9 +404,17 @@
           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) && mo.getProperty(index).equals(value)
){
  -              objects.add( mo.getObject() );
  -          }
  +           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))  ){
  +                    objects.add( mo.getObject() );
  +                    continue;
  +                 }
  +           } 
  +                
           }
           
            
  
  
  
  1.1                  jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/DBPersistenceManagerFactory.java
  
  Index: DBPersistenceManagerFactory.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache Cocoon" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.simplestore.persistence.impl;
  
  import org.apache.commons.simplestore.persistence.PersistenceManagerFactory;
  import org.apache.commons.simplestore.persistence.PersistenceManager;
  import org.apache.commons.simplestore.persistence.impl.PersistenceManagerImpl;
  import org.apache.commons.simplestore.persistence.SimplestoreException;
  import org.apache.commons.simplestore.jdbc.DriverDataSource;
  import org.apache.commons.simplestore.persistence.Transaction;
  import org.apache.commons.simplestore.persistence.impl.DBStorage;
  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;
  
  
  /**
   * This PersistenceManagerFactory implementation used
   *to setup Persitence manager for DB storage, random idgenerator,
   * soft reference cache and XML metadata
   *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
   *      baliuka@mwm.lt</a>
   *@version    $Id: DBPersistenceManagerFactory.java,v 1.1 2002/03/24 06:27:35 baliuka Exp
$
   */
  public class DBPersistenceManagerFactory implements PersistenceManagerFactory{
      
     static private PersistenceManager pm;
      
      /** Holds value of property user. */
      private String user = "";
      
      /** Holds value of property password. */
      private String password = "";
      
      /** Holds value of property driver. */
      private String driver;
      
      /** Holds value of property maxConnections. */
      private int maxConnections = 1;
      
      /** Holds value of property url. */
      private String url;
      
      /** Holds value of property loader. */
      private ClassLoader loader;
      
      /** Holds value of property metaResource. */
      private String metaResource;
      
      /** Holds value of property maxStrongRef. */
      private int maxStrongRef = 0xFF;
      
      /** Creates a new instance of DBPersistenceManagerFactory */
      public DBPersistenceManagerFactory() {
      }
      
      public PersistenceManager getPersistenceManager() {
          try{
          if( pm == null ){
            
           if( loader == null ){
               loader = PersistenceManager.class.getClassLoader();
           }
           
         MetaClassImpl.parse(loader.getResourceAsStream( metaResource),loader);
          
         final DriverDataSource ds = new DriverDataSource();
          ds.setDriver(driver);
          ds.setMaxConnections(maxConnections);
          ds.setUrl(url);
          ds.setUser(user);
          ds.setPassword(password);
         
          MetaClassImpl mclass = new MetaClassImpl( MetaClassImpl.class.getClassLoader());
          DBStorage storage = new DBStorage( ds );
          ContextImpl context = new ContextImpl(
                mclass, new DefaultTypeConverter(),
                new RandomOIDGenerator(),
                storage,
                SoftRefMemoryCache.getInstance(new java.util.HashMap(),maxStrongRef),
                          storage );
          pm = PersistenceManagerImpl.getPersistenceManager(context);
          
          }
          return pm;
          }catch( Exception e) {
            throw new SimplestoreException(e.getClass()+":"+e.getMessage());
          }
      }
      
      /** Getter for property user.
       * @return Value of property user.
       */
      public String getUser() {
          return this.user;
      }
      
      /** Setter for property user.
       * @param user New value of property user.
       */
      public void setUser(String user) {
          this.user = user;
      }
      
      /** Getter for property password.
       * @return Value of property password.
       */
      public String getPassword() {
          return this.password;
      }
      
      /** Setter for property password.
       * @param password New value of property password.
       */
      public void setPassword(String password) {
          this.password = password;
      }
      
      /** Getter for property driver.
       * @return Value of property driver.
       */
      public String getDriver() {
          return this.driver;
      }
      
      /** Setter for property driver.
       * @param driver New value of property driver.
       */
      public void setDriver(String driver) {
          this.driver = driver;
      }
      
      /** Getter for property maxConnections.
       * @return Value of property maxConnections.
       */
      public int getMaxConnections() {
          return this.maxConnections;
      }
      
      /** Setter for property maxConnections.
       * @param maxConnections New value of property maxConnections.
       */
      public void setMaxConnections(int maxConnections) {
          this.maxConnections = maxConnections;
      }
      
      /** Getter for property url.
       * @return Value of property url.
       */
      public String getUrl() {
          return this.url;
      }
      
      /** Setter for property url.
       * @param url New value of property url.
       */
      public void setUrl(String url) {
          this.url = url;
      }
      
      /** Getter for property loader.
       * @return Value of property loader.
       */
      public ClassLoader getLoader() {
          return this.loader;
      }
      
      /** Setter for property loader.
       * @param loader New value of property loader.
       */
      public void setLoader(ClassLoader loader) {
          this.loader = loader;
      }
      
      /** Getter for property metaResource.
       * @return Value of property metaResource.
       */
      public String getMetaResource() {
          return this.metaResource;
      }
      
      /** Setter for property metaResource.
       * @param metaResource New value of property metaResource.
       */
      public void setMetaResource(String metaResource) {
          this.metaResource = metaResource;
      }
      
      /** Getter for property maxStrongRef.
       * @return Value of property maxStrongRef.
       */
      public int getMaxStrongRef() {
          return this.maxStrongRef;
      }
      
      /** Setter for property maxStrongRef.
       * @param maxStrongRef New value of property maxStrongRef.
       */
      public void setMaxStrongRef(int maxStrongRef) {
          this.maxStrongRef = maxStrongRef;
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/JDBMPersistenceManagerFactory.java
  
  Index: JDBMPersistenceManagerFactory.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache Cocoon" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.simplestore.persistence.impl;
  
  import org.apache.commons.simplestore.persistence.PersistenceManagerFactory;
  import org.apache.commons.simplestore.persistence.PersistenceManager;
  import org.apache.commons.simplestore.persistence.impl.PersistenceManagerImpl;
  import org.apache.commons.simplestore.persistence.SimplestoreException;
  import org.apache.commons.simplestore.jdbc.DriverDataSource;
  import org.apache.commons.simplestore.persistence.Transaction;
  import org.apache.commons.simplestore.persistence.impl.JDBMStorage;
  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 jdbm.helper.MRU;
  import jdbm.helper.ObjectCache;
  import jdbm.helper.LongComparator;
  import jdbm.recman.RecordManager;
  
  
  
  /**
   * This PersistenceManagerFactory implementation used
   *to setup Persitence manager for DB storage, random idgenerator,
   * soft reference cache and XML metadata
   *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
   *      baliuka@mwm.lt</a>
   *@version    $Id: JDBMPersistenceManagerFactory.java,v 1.1 2002/03/24 06:27:35 baliuka
Exp $
   */
  public class JDBMPersistenceManagerFactory implements PersistenceManagerFactory{
      
      static private PersistenceManager pm;
      
      
      /** Holds value of property loader. */
      private ClassLoader loader;
      
      /** Holds value of property metaResource. */
      private String metaResource;
      
      /** Holds value of property maxStrongRef. */
      private int maxStrongRef = 0xFF;
      
      /** Holds value of property file. */
      private String file;
      
      /** Creates a new instance of DBPersistenceManagerFactory */
      public JDBMPersistenceManagerFactory() {
      }
      
      public PersistenceManager getPersistenceManager() {
          try{
              if( pm == null ){
                  
                  if( loader == null ){
                      loader = PersistenceManager.class.getClassLoader();
                  }
                  
                  MetaClassImpl.parse(loader.getResourceAsStream( metaResource),loader);
                  
                  MetaClassImpl mclass = new MetaClassImpl( MetaClassImpl.class.getClassLoader());
                  RecordManager recman = new RecordManager( file );
                  ObjectCache cache = new ObjectCache( recman, new MRU( 100 ) );
                  JDBMStorage storage = new JDBMStorage(recman ,cache,new LongComparator());
                  ContextImpl context = new ContextImpl(
                  mclass, new DefaultTypeConverter(),
                  new RandomOIDGenerator(),
                  storage,
                  SoftRefMemoryCache.getInstance(new java.util.HashMap(),maxStrongRef),
                  storage );
                  pm = PersistenceManagerImpl.getPersistenceManager(context);
                  
              }
              return pm;
          }catch( Exception e) {
              throw new SimplestoreException(e.getClass()+":"+e.getMessage());
          }
      }
      
      
      /** Setter for property user.
       * @param user New value of property user.
       */
      
      /** Getter for property loader.
       * @return Value of property loader.
       */
      public ClassLoader getLoader() {
          return this.loader;
      }
      
      /** Setter for property loader.
       * @param loader New value of property loader.
       */
      public void setLoader(ClassLoader loader) {
          this.loader = loader;
      }
      
      /** Getter for property metaResource.
       * @return Value of property metaResource.
       */
      public String getMetaResource() {
          return this.metaResource;
      }
      
      /** Setter for property metaResource.
       * @param metaResource New value of property metaResource.
       */
      public void setMetaResource(String metaResource) {
          this.metaResource = metaResource;
      }
      
      /** Getter for property maxStrongRef.
       * @return Value of property maxStrongRef.
       */
      public int getMaxStrongRef() {
          return this.maxStrongRef;
      }
      
      /** Setter for property maxStrongRef.
       * @param maxStrongRef New value of property maxStrongRef.
       */
      public void setMaxStrongRef(int maxStrongRef) {
          this.maxStrongRef = maxStrongRef;
      }
      
      /** Getter for property file.
       * @return Value of property file.
       */
      public String getFile() {
          return this.file;
      }
      
      /** Setter for property file.
       * @param file New value of property file.
       */
      public void setFile(String file) {
          this.file = file;
      }
      
  }
  
  
  
  1.19      +9 -1      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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TestSample.java	20 Mar 2002 19:28:26 -0000	1.18
  +++ TestSample.java	24 Mar 2002 06:27:35 -0000	1.19
  @@ -58,6 +58,7 @@
   import org.apache.commons.simplestore.persistence.Transaction;
   import org.apache.commons.simplestore.persistence.PersistenceManager;
   import org.apache.commons.simplestore.persistence.impl.DBPersistenceManagerFactory;
  +import org.apache.commons.simplestore.persistence.impl.JDBMPersistenceManagerFactory;
   import org.apache.commons.simplestore.persistence.ValidationException;
   
   
  @@ -71,7 +72,7 @@
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: TestSample.java,v 1.18 2002/03/20 19:28:26 baliuka Exp $
  + *@version    $Id: TestSample.java,v 1.19 2002/03/24 06:27:35 baliuka Exp $
    */
   public class TestSample extends TestCase implements org.apache.commons.simplestore.tools.Constants{
       
  @@ -220,6 +221,7 @@
       
       protected void setUp() throws java.lang.Exception {
           super.setUp();
  +       if(false){ 
           DBPersistenceManagerFactory factory = new DBPersistenceManagerFactory();
           factory.setDriver("org.hsqldb.jdbcDriver");
           factory.setUrl("jdbc:hsqldb:sample");
  @@ -228,6 +230,12 @@
           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();
  +       }
           
       }
       
  
  
  

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