You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by fr...@apache.org on 2002/02/12 12:38:42 UTC

cvs commit: jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl RandomOIDGenerator.java PersistenceManager.java

froehlich    02/02/12 03:38:42

  Modified:    simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        PersistenceManager.java
  Added:       simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        RandomOIDGenerator.java
  Log:
  added OID generator interface and
  random based impl.
  
  Revision  Changes    Path
  1.3       +4 -40     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PersistenceManager.java	11 Feb 2002 20:30:09 -0000	1.2
  +++ PersistenceManager.java	12 Feb 2002 11:38:42 -0000	1.3
  @@ -64,22 +64,19 @@
   import org.apache.commons.simplestore.persistence.TransactionManager;
   
   import java.math.BigInteger;
  -import java.security.SecureRandom;
   import java.util.HashMap;
   import java.util.Set;
   
   /**
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - *@version    $Id: PersistenceManager.java,v 1.2 2002/02/11 20:30:09 froehlich Exp $
  + *@version    $Id: PersistenceManager.java,v 1.3 2002/02/12 11:38:42 froehlich Exp $
    */
   
   public class PersistenceManager {
  -
  +    
       private static PersistenceManager pm;
  -
  -    private static SecureRandom seeder = new SecureRandom();
  -
  +    private RandomOIDGenerator mRandomOIDGenerator = new RandomOIDGenerator();
       private Storage storage;
       private TransactionManager transactionManager;
       private Cache cache = SoftRefMemoryCache.getInstance(new HashMap(), 0xFF);
  @@ -93,7 +90,6 @@
       protected PersistenceManager(Storage storage, TransactionManager transactionManager) {
           this.storage = storage;
           this.transactionManager = transactionManager;
  -
       }
   
       public static PersistenceManager getPersistenceManager(Storage storage, TransactionManager transactions) {
  @@ -105,36 +101,29 @@
       }
   
       public Transaction getTransaction() {
  -
           return transactionManager.getTransaction();
       }
   
       public Object getOID(Object pc) {
  -
           return ((Persistent) pc).getOID();
       }
   
       public Object createInstance(Class aclass) {
  -
  -        Object id = generateOID(aclass);
  +        Object id = mRandomOIDGenerator.getIntOID();
           Persistent p = PersistentProxy.getPersitent(aclass, id, true, transactionManager);
           cache.put(id, p);
  -
           return p;
       }
   
       public Object findInstance(Class clasz, Object oid) throws StorageException {
  -
           return storage.retrieveObject(clasz, oid);
       }
   
       public Set findAll(Class clasz) throws StorageException {
  -
           return storage.retrieveAll(clasz);
       }
   
       public void removeInstance(Object pc) {
  -
           MetaObject p = ((Persistent) pc).getMetaObject();
           if (p != null) {
               p.remove();
  @@ -142,32 +131,7 @@
       }
   
       public void registerClass(Class clasz) throws StorageException {
  -
           storage.registerClass(clasz);
  -
  -    }
  -
  -    private synchronized Object generateOID(Class aclass) {
  -
  -        //TODO ADD interface OIDGenerator
  -
  -        byte[] bytes = new byte[8];
  -        int value = seeder.nextInt();
  -        int i = 0;
  -
  -        bytes[i++] = (byte) ((value >>> 24) & 0xFF);
  -        bytes[i++] = (byte) ((value >>> 16) & 0xFF);
  -        bytes[i++] = (byte) ((value >>> 8) & 0xFF);
  -        bytes[i++] = (byte) (value & 0xFF);
  -
  -        value = (int) System.currentTimeMillis() & 0xFFFFFFFF;
  -
  -        bytes[i++] = (byte) ((value >>> 24) & 0xFF);
  -        bytes[i++] = (byte) ((value >>> 16) & 0xFF);
  -        bytes[i++] = (byte) ((value >>> 8) & 0xFF);
  -        bytes[i++] = (byte) (value & 0xFF);
  -
  -        return new Long(new BigInteger(bytes).longValue());
       }
   }
   
  
  
  
  1.1                  jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/RandomOIDGenerator.java
  
  Index: RandomOIDGenerator.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.OIDGenerator;
  
  import java.security.SecureRandom;
  
  /**
   *@author     Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
   *      g-froehlich@gmx.de</a>
   *@version    $Id: RandomOIDGenerator.java,v 1.1 2002/02/12 11:38:42 froehlich Exp $
   */
  public class RandomOIDGenerator implements OIDGenerator {
      
      SecureRandom mSecureRandom = null;
  
      public RandomOIDGenerator() {
          mSecureRandom = new SecureRandom();
      }
      
      public Long getLongOID() {
          return new Long(mSecureRandom.nextLong());
      }
      
      public Integer getIntOID() {
          return new Integer(mSecureRandom.nextInt());
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>