avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: avalon-excalibur/store/src/java/org/apache/excalibur/store/impl JispKey.java JispStringKey.java AbstractJispFilesystemStore.java
Date Mon, 14 Jul 2003 13:58:19 GMT
cziegeler    2003/07/14 06:58:19

  Modified:    store/src/java/org/apache/excalibur/store/impl
                        JispStringKey.java AbstractJispFilesystemStore.java
  Added:       store/lib jisp-2.5.1.jar
               lib      jisp-2.5.1.jar
               store/src/java/org/apache/excalibur/store/impl JispKey.java
  Removed:     store/lib Jisp2.0.1.jar
               lib      jisp-2.0.1.jar
  Log:
  Updating to latest jisp (which jar is used?) and start rewriting some parts of the store
  
  Revision  Changes    Path
  1.1                  avalon-excalibur/store/lib/jisp-2.5.1.jar
  
  	<<Binary file>>
  
  
  1.1                  avalon-excalibur/lib/jisp-2.5.1.jar
  
  	<<Binary file>>
  
  
  1.8       +6 -3      avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/JispStringKey.java
  
  Index: JispStringKey.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/JispStringKey.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JispStringKey.java	22 Mar 2003 12:46:55 -0000	1.7
  +++ JispStringKey.java	14 Jul 2003 13:58:19 -0000	1.8
  @@ -63,15 +63,18 @@
    * @author <a href="mailto:g-froehlich@gmx.de">Gerhard Froehlich</a>
    * @version CVS $Id$
    */
  -final public class JispStringKey extends KeyObject {
  +public final class JispStringKey extends KeyObject {
       final static long serialVersionUID = -6894793231339165076L;
  +
       private String m_Key;
   
  +    static private final String INIT = new String("");
  +    
       /**
        *  Constructor for the JispStringKey object
        */
       public JispStringKey() {
  -        m_Key = new String("");
  +        m_Key = INIT;
       }
   
       /**
  
  
  
  1.8       +55 -36    avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractJispFilesystemStore.java
  
  Index: AbstractJispFilesystemStore.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractJispFilesystemStore.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractJispFilesystemStore.java	5 Apr 2003 19:39:38 -0000	1.7
  +++ AbstractJispFilesystemStore.java	14 Jul 2003 13:58:19 -0000	1.8
  @@ -52,19 +52,20 @@
   import java.io.File;
   import java.io.IOException;
   import java.io.Serializable;
  +import java.util.Collections;
   import java.util.Enumeration;
   
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.thread.ThreadSafe;
  -import org.apache.excalibur.store.Store;
  -
   import com.coyotegulch.jisp.BTreeIndex;
  -import com.coyotegulch.jisp.BTreeObjectIterator;
  +import com.coyotegulch.jisp.BTreeIterator;
   import com.coyotegulch.jisp.IndexedObjectDatabase;
   import com.coyotegulch.jisp.KeyNotFound;
   import com.coyotegulch.jisp.KeyObject;
   
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.excalibur.store.Store;
  +
   /**
    * This store is based on the Jisp library
    * (http://www.coyotegulch.com/jisp/index.html). This store uses B-Tree indexes
  @@ -102,7 +103,8 @@
        * Sets the repository's location
        */
       public void setDirectory(final File directory)
  -    throws IOException {
  +    throws IOException 
  +    {
           this.m_directoryFile = directory;
   
           /* Save directory path prefix */
  @@ -110,9 +112,11 @@
           this.m_directoryPath += File.separator;
   
           /* Does directory exist? */
  -        if (!this.m_directoryFile.exists()) {
  +        if (!this.m_directoryFile.exists()) 
  +        {
               /* Create it anew */
  -            if (!this.m_directoryFile.mkdir()) {
  +            if (!this.m_directoryFile.mkdir()) 
  +            {
                   throw new IOException(
                   "Error creating store directory '" + this.m_directoryPath + "': ");
               }
  @@ -209,26 +213,42 @@
        * Frees some values of the data file.<br>
        * TODO: implementation
        */
  -    public synchronized void free() {
  -       //TODO: implementation
  +    public synchronized void free() 
  +    {
       }
   
       /**
        * Clear the Store of all elements
        */
       public synchronized void clear() {
  -        BTreeObjectEnumeration enum = new BTreeObjectEnumeration(m_Database.createIterator(m_Index),this);
  -
  -        if (getLogger().isDebugEnabled()) {
  +        
  +        if (getLogger().isDebugEnabled()) 
  +        {
               this.getLogger().debug("clear(): Clearing the database ");
           }
  -        
  -        while(enum.hasMoreElements()) {
  -            Object tmp = enum.nextElement();
  -            if (getLogger().isDebugEnabled()) {
  -                this.getLogger().debug("clear(): Removing key: " + tmp.toString());
  -            }
  -            this.remove(tmp);
  +
  +        try 
  +        {
  +            final BTreeIterator iter = new BTreeIterator(m_Index);
  +            Object tmp;
  +            do 
  +            {
  +                tmp = iter.getKey();
  +                if ( tmp != null ) 
  +                {
  +                    if (getLogger().isDebugEnabled()) 
  +                    {
  +                        this.getLogger().debug("clear(): Removing key: " + tmp.toString());
  +                    }
  +                    iter.moveNext();
  +                    this.remove( tmp );
  +                }
  +            } 
  +            while (tmp != null);
  +        } 
  +        catch (Exception ignore) 
  +        {
  +            getLogger().error("store(..): Exception", ignore);
           }
       }
   
  @@ -284,19 +304,16 @@
        * @return  Enumeration Object with all existing keys
        */
       public Enumeration keys() {
  -        BTreeObjectEnumeration enum = new BTreeObjectEnumeration(m_Database.createIterator(m_Index),this);
  -        return enum;
  +        try {
  +            BTreeObjectEnumeration enum = new BTreeObjectEnumeration(new BTreeIterator(m_Index),
this);
  +            return enum;
  +        } catch (Exception ignore) {
  +            return Collections.enumeration(Collections.EMPTY_LIST);
  +        }
       }
   
       public int size() {
  -        int cnt = 0;
  -
  -        BTreeObjectEnumeration enum = new BTreeObjectEnumeration(m_Database.createIterator(m_Index),this);
  -
  -        while(enum.hasMoreElements()) {
  -            cnt++;
  -        }
  -        return cnt;
  +        return m_Index.count();
       }
   
       /**
  @@ -305,7 +322,8 @@
        * @param key the key object
        * @return the wrapped key object
        */
  -    private KeyObject wrapKeyObject(Object key) {
  +    private KeyObject wrapKeyObject(Object key) 
  +    {
           // TODO: Implementation of Integer and Long keys
           String skey = String.valueOf(key);
           return new JispStringKey(key.toString());
  @@ -333,11 +351,12 @@
           }
       }
   
  -    class BTreeObjectEnumeration implements Enumeration {
  -        private BTreeObjectIterator m_Iterator;
  +    class BTreeObjectEnumeration implements Enumeration 
  +    {
  +        private BTreeIterator m_Iterator;
           private AbstractJispFilesystemStore m_Store;
   
  -        public BTreeObjectEnumeration(BTreeObjectIterator iterator, AbstractJispFilesystemStore
store) {
  +        public BTreeObjectEnumeration(BTreeIterator iterator, AbstractJispFilesystemStore
store) {
               m_Iterator = iterator;
               m_Store = store;
           }
  
  
  
  1.1                  avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/JispKey.java
  
  Index: JispKey.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
   
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
   
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 "Jakarta", "Avalon", "Excalibur" 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 (INCLU-
   DING, 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.excalibur.store.impl;
  
  import java.io.IOException;
  import java.io.ObjectInput;
  import java.io.ObjectOutput;
  
  import com.coyotegulch.jisp.KeyObject;
  
  /**
   * Wrapper class for Keys to be compatible with the
   * Jisp KeyObject.
   * This will hopefully soon replace the JispStringKey implementation
   * IT'S NOT FINISHED YET, PLEASE DON'T USE IT !!!!
   * 
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: JispKey.java,v 1.1 2003/07/14 13:58:19 cziegeler Exp $
   */
  public final class JispKey extends KeyObject 
  {
  // TODO
      //final static long serialVersionUID = -6894793231339165076L;
  
      protected Object m_Key;
  
      protected int    m_KeyHashCode;
      
      static protected final String INIT = new String("");
      static protected final int    INIT_HASH_CODE = INIT.hashCode();
      /**
       *  Constructor for the JispStringKey object
       */
      public JispKey() {
          m_Key = INIT;
          m_KeyHashCode = INIT_HASH_CODE;
      }
  
      /**
       *  Constructor for the JispStringKey object
       *
       * @param keyValue the Value of the Key as String
       */
      public JispKey(Object keyValue) 
      {
          m_Key = keyValue;
          m_KeyHashCode = m_Key.hashCode();
      }
  
      /**
       * Compares two String Keys
       *
       * @param key the KeyObject to be compared
       * @return 0 if equal, 1 if greater, -1 if less
       */
  
      public int compareTo(KeyObject key) 
      {
          if (key instanceof JispKey) 
          {
              final JispKey other = (JispKey)key;
              if ( other.m_KeyHashCode == m_KeyHashCode ) 
              {
                  if ( m_Key.equals(other.m_Key) ) 
                  {
                      return KEY_EQUAL;
                  }
                  // we have the same hashcode, but different keys
                  if ( m_Key.hashCode() < other.m_Key.hashCode() ) 
                  {
                      return KEY_LESS;
                  }
                  return KEY_MORE;
              } 
              else 
              {
                  if ( m_KeyHashCode < other.m_KeyHashCode ) 
                  {
                      return KEY_LESS;
                  }
                  return KEY_MORE;
              }
          } 
          else 
          {
              return KEY_ERROR;
          }
      }
  
      /**
       *  Composes a null Kewy
       *
       * @return a null Key
       */
      public KeyObject makeNullKey() 
      {
          return new JispKey();
      }
  
      /**
       * The object implements the writeExternal method to save its contents
       * by calling the methods of DataOutput for its primitive values or
       * calling the writeObject method of ObjectOutput for objects, strings,
       * and arrays.
       *
       * @param out the stream to write the object to
       * @exception IOException
       */
      public void writeExternal(ObjectOutput out)
      throws IOException 
      {
          out.writeObject(m_Key);
      }
  
      /**
       * The object implements the readExternal method to restore its contents
       * by calling the methods of DataInput for primitive types and readObject
       * for objects, strings and arrays. The readExternal method must read the
       * values in the same sequence and with the same types as were written by writeExternal.
       *
       * @param in the stream to read data from in order to restore the object
       * @exception IOException
       * @exception ClassNotFoundException
       */
  
      public void readExternal(ObjectInput in)
      throws IOException, ClassNotFoundException 
      {
          m_Key = in.readObject();
      }
  
  }
  
  
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message