You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2004/02/02 17:54:58 UTC

cvs commit: avalon-excalibur/store/src/java/org/apache/excalibur/store/impl AbstractJispFilesystemStore.java

leosutic    2004/02/02 08:54:58

  Modified:    store/src/java/org/apache/excalibur/store/impl
                        AbstractJispFilesystemStore.java
  Log:
  Applied patches for bug 25482
  
  Revision  Changes    Path
  1.4       +98 -118   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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractJispFilesystemStore.java	13 Dec 2003 04:18:41 -0000	1.3
  +++ AbstractJispFilesystemStore.java	2 Feb 2004 16:54:58 -0000	1.4
  @@ -1,51 +1,51 @@
   /*
   
  - ============================================================================
  -                   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/>.
  - 
  +============================================================================
  +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;
   
  @@ -76,26 +76,26 @@
    * @version CVS $Id$
    */
   public abstract class AbstractJispFilesystemStore
  -extends AbstractReadWriteStore
  -implements Store, ThreadSafe {
  -
  +    extends AbstractReadWriteStore
  +    implements Store, ThreadSafe {
  +    
       /** The directory repository */
       protected File m_directoryFile;
  -
  +    
       /** The database  */   
       protected IndexedObjectDatabase m_Database;
       
       /** And the index */
       protected BTreeIndex m_Index;
  -
  +    
       /**
        * Sets the repository's location
        */
       public void setDirectory(final File directory)
  -    throws IOException 
  +        throws IOException 
       {
           this.m_directoryFile = directory;
  -
  +        
           /* Does directory exist? */
           if (!this.m_directoryFile.exists()) 
           {
  @@ -103,25 +103,25 @@
               if (!this.m_directoryFile.mkdirs()) 
               {
                   throw new IOException(
  -                "Error creating store directory '" + this.m_directoryFile.getAbsolutePath() + "'. ");
  +                    "Error creating store directory '" + this.m_directoryFile.getAbsolutePath() + "'. ");
               }
           }
  -
  +        
           /* Is given file actually a directory? */
           if (!this.m_directoryFile.isDirectory()) 
           {
               throw new IOException("'" + this.m_directoryFile.getAbsolutePath() + "' is not a directory");
           }
  -
  +        
           /* Is directory readable and writable? */
           if (!(this.m_directoryFile.canRead() && this.m_directoryFile.canWrite())) 
           {
               throw new IOException(
                   "Directory '" + this.m_directoryFile.getAbsolutePath() + "' is not readable/writable"
  -            );
  +                );
           }
       }
  -   
  +    
       /**
        * Returns a Object from the store associated with the Key Object
        *
  @@ -131,7 +131,7 @@
       protected Object doGet(Object key) 
       {
           Object value = null;
  -
  +        
           try 
           {
               value = m_Database.read(this.wrapKeyObject(key), m_Index);
  @@ -154,7 +154,7 @@
           
           return value;
       }
  -
  +    
       /**
        *  Store the given object in the indexed data file.
        *
  @@ -163,17 +163,17 @@
        * @exception  IOException
        */
       protected void doStore(Object key, Object value)
  -    throws IOException 
  +        throws IOException 
       {
  -
  +        
           if (getLogger().isDebugEnabled()) 
           {
               getLogger().debug("store(): Store file with key: "
  -                              + key.toString());
  +                + key.toString());
               getLogger().debug("store(): Store file with value: "
  -                              + value.toString());
  +                + value.toString());
           }
  -
  +        
           if (value instanceof Serializable) 
           {
               try 
  @@ -192,7 +192,7 @@
               throw new IOException("Object not Serializable");
           }
       }
  -
  +    
       /**
        * Frees some values of the data file.<br>
        * TODO: implementation
  @@ -201,13 +201,13 @@
       {
           // if we ever implement this, we should implement doFree()
       }
  -
  +    
       /* (non-Javadoc)
        * @see org.apache.excalibur.store.impl.AbstractReadWriteStore#doFree()
        */
       protected void doFree() {
       }
  -
  +    
       /**
        * Clear the Store of all elements
        */
  @@ -218,53 +218,33 @@
           {
               getLogger().debug("clear(): Clearing the database ");
           }
  -
  +        
           try 
           {
               
               //empty the cache before clearing
               m_Index.emptyPageCache();
               final BTreeIterator iter = new BTreeIterator(m_Index);
  -            Object tmp;
  -//            do 
  -//            {
  -//                tmp = iter.getKey();
  -//                if ( tmp != null ) 
  -//                {
  -//                    if (getLogger().isDebugEnabled()) 
  -//                    {
  -//                        getLogger().debug("clear(): Removing key: " + tmp.toString());
  -//                    }
  -//                    iter.moveNext();
  -//                    this.doRemove( tmp );
  -//                }
  -//            } 
  -//            //while (tmp != null);
  -//          while(iter.moveNext());
  -
  -            while(iter.isValid()) 
  -            {
  -                tmp = iter.getKey();
  -                if( tmp != null )  
  -                {
  -                    if (getLogger().isDebugEnabled()) 
  -                    {
  -                        getLogger().debug("clear(): Removing key: " + tmp.toString());
  -                    }
  -                    this.doRemove(tmp);
  +            Object key;
  +            KeyObject[] keyArray = new KeyObject[1];
  +            while(iter.isValid()) {
  +                key = iter.getKey();
  +                if (key != null) {
  +                    //This key should not be wrapped in a JipsKey because it comes from the iterator.
  +                    keyArray[0] = (KeyObject) key;
  +                    m_Database.remove( keyArray );
                   }
  -                if( !iter.moveNext() )
  -                {
  +                if (!iter.moveNext()){
                       break;
                   }
  -            }
  +            } 
           } 
           catch (Exception ignore) 
           {
               getLogger().error("store(..): Exception", ignore);
           }
       }
  -
  +    
       /**
        * Removes a value from the data file with the given key.
        *
  @@ -276,11 +256,11 @@
           {
               getLogger().debug("remove(..) Remove item");
           }
  -
  +        
           try 
           {
               KeyObject[] keyArray = new KeyObject[1];
  -            keyArray[0] = (KeyObject)key;
  +            keyArray[0] = wrapKeyObject(key);
               m_Database.remove(keyArray);
           } 
           catch (KeyNotFound ignore) 
  @@ -291,7 +271,7 @@
               getLogger().error("remove(..): Exception", e);
           }
       }
  -
  +    
       /**
        *  Test if the the index file contains the given key
        *
  @@ -301,7 +281,7 @@
       protected boolean doContainsKey(Object key) 
       {
           long res = -1;
  -
  +        
           try 
           {
               res = m_Index.findKey(this.wrapKeyObject(key));
  @@ -317,7 +297,7 @@
           {
               getLogger().error("containsKey(..): Exception", e);
           }
  -
  +        
           if (res > 0) 
           {
               return true;
  @@ -327,7 +307,7 @@
               return false;
           }
       }
  -
  +    
       /**
        * Returns a Enumeration of all Keys in the indexed file.<br>
        *
  @@ -344,12 +324,12 @@
               return Collections.enumeration(Collections.EMPTY_LIST);
           }
       }
  -
  +    
       protected int doGetSize() 
       {
           return m_Index.count();
       }
  -
  +    
       /**
        * This method wraps around the key Object a Jisp KeyObject.
        *
  @@ -360,7 +340,7 @@
       {
           return new JispKey( key );
       }
  -
  +    
       /**
        * Return the Null JispKey
        */
  @@ -374,12 +354,12 @@
           private Object m_Next;
           private BTreeIterator m_Iterator;
           private AbstractJispFilesystemStore m_Store;
  -
  +        
           public BTreeObjectEnumeration(BTreeIterator iterator, AbstractJispFilesystemStore store) 
           {
               m_Iterator = iterator;
               m_Store = store;
  -
  +            
               // Obtain first element. If any.
               try
               {
  @@ -391,22 +371,22 @@
                   m_Next = null;
               }
           }
  -
  +        
           public boolean hasMoreElements() 
           {
               return (m_Next != null);
           }
  -
  +        
           public Object nextElement() throws NoSuchElementException
           {
               if (m_Next == null)
               {
                   throw new NoSuchElementException();
               }
  -
  +            
               // Save current element
               Object tmp = m_Next;
  -
  +            
               // Advance to the next element
               try
               {
  @@ -430,10 +410,10 @@
                   m_Store.getLogger().error("store(..): Exception", cnfe);
                   m_Next = null;
               }
  -
  +            
               // Return the real key
               return ((JispKey) tmp).getKey();
           }
       }
  -
  +    
   }
  
  
  

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