ehatcher    2005/01/18 06:11:09

  Modified:    contributions/db/src/java/org/apache/lucene/store/db
                        DbLock.java DbOutputStream.java File.java
                        DbDirectory.java Block.java DbInputStream.java
  Added:       contributions/db/src/java/com/sleepycat/db
                        DbHandleExtractor.java
  Log:
  Update of DBDirectory from Andi.
  
  Revision  Changes    Path
  1.2       +13 -53    
jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbLock.java
  
  Index: DbLock.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbLock.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DbLock.java       14 Jan 2004 00:29:45 -0000      1.1
  +++ DbLock.java       18 Jan 2005 14:11:09 -0000      1.2
  @@ -1,59 +1,19 @@
   package org.apache.lucene.store.db;
   
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  +/**
  + * Copyright 2002-2004 The Apache Software Foundation
    *
  - * Copyright (c) 2004 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" and "Apache Software Foundation" and
  - *    "Apache Lucene" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Lucene", 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 the Open Source
  - * Applications Foundation on behalf of the Apache Software Foundation.
  - * For more information on the Open Source Applications Foundation, please 
see
  - * <http://www.osafoundation.org>.
  - * For more information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
    */
   
   import org.apache.lucene.store.Lock;
  
  
  
  1.4       +15 -55    
jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbOutputStream.java
  
  Index: DbOutputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbOutputStream.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DbOutputStream.java       5 Aug 2004 14:30:46 -0000       1.3
  +++ DbOutputStream.java       18 Jan 2005 14:11:09 -0000      1.4
  @@ -1,67 +1,27 @@
   package org.apache.lucene.store.db;
   
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  +/**
  + * Copyright 2002-2004 The Apache Software Foundation
    *
  - * Copyright (c) 2004 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" and "Apache Software Foundation" and
  - *    "Apache Lucene" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Lucene", 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 the Open Source
  - * Applications Foundation on behalf of the Apache Software Foundation.
  - * For more information on the Open Source Applications Foundation, please 
see
  - * <http://www.osafoundation.org>.
  - * For more information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
    */
   
   import java.io.IOException;
   
   import org.apache.lucene.store.OutputStream;
   
  -import com.sleepycat.db.Db;
  -import com.sleepycat.db.DbTxn;
  +import com.sleepycat.db.internal.Db;
  +import com.sleepycat.db.internal.DbTxn;
   
   /**
    * @author Andi Vajda
  
  
  
  1.3       +45 -90    
jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/File.java
  
  Index: File.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/File.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- File.java 1 Jun 2004 09:27:03 -0000       1.2
  +++ File.java 18 Jan 2005 14:11:09 -0000      1.3
  @@ -1,59 +1,19 @@
   package org.apache.lucene.store.db;
   
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2004 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" and "Apache Software Foundation" and
  - *    "Apache Lucene" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Lucene", 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.
  - * ====================================================================
  +/**
  + * Copyright 2002-2004 The Apache Software Foundation
    *
  - * This software consists of voluntary contributions made by the Open Source
  - * Applications Foundation on behalf of the Apache Software Foundation.
  - * For more information on the Open Source Applications Foundation, please 
see
  - * <http://www.osafoundation.org>.
  - * For more information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
    */
   
   import java.io.IOException;
  @@ -63,11 +23,12 @@
   import java.io.DataInputStream;
   import java.util.Random;
   
  -import com.sleepycat.db.Dbt;
  -import com.sleepycat.db.Dbc;
  -import com.sleepycat.db.Db;
  -import com.sleepycat.db.DbTxn;
  -import com.sleepycat.db.DbException;
  +import com.sleepycat.db.DatabaseEntry;
  +import com.sleepycat.db.internal.DbConstants;
  +import com.sleepycat.db.internal.Dbc;
  +import com.sleepycat.db.internal.Db;
  +import com.sleepycat.db.internal.DbTxn;
  +import com.sleepycat.db.DatabaseException;
   
   /**
    * @author Andi Vajda
  @@ -77,7 +38,7 @@
   
       static protected Random random = new Random();
   
  -    protected Dbt key, data;
  +    protected DatabaseEntry key, data;
       protected long length, timeModified;
       protected String name;
       protected byte[] uuid;
  @@ -87,9 +48,8 @@
       {
           setName(name);
   
  -        data = new Dbt(new byte[32]);
  -        data.setUserBufferLength(data.getSize());
  -        data.setFlags(Db.DB_DBT_USERMEM);
  +        data = new DatabaseEntry(new byte[32]);
  +        data.setUserBuffer(data.getSize(), true);
       }
   
       protected File(Db files, Db blocks, DbTxn txn, int flags,
  @@ -104,13 +64,11 @@
                   throw new IOException("File does not exist: " + name);
               else
               {
  -                Dbt key = new Dbt(new byte[24]);
  -                Dbt data = new Dbt(null);
  +                DatabaseEntry key = new DatabaseEntry(new byte[24]);
  +                DatabaseEntry data = new DatabaseEntry(null);
   
  -                key.setFlags(Db.DB_DBT_USERMEM);
  -                key.setUserBufferLength(24);
  -                data.setPartialLength(0);
  -                data.setFlags(Db.DB_DBT_USERMEM | Db.DB_DBT_PARTIAL);
  +                key.setUserBuffer(24, true);
  +                data.setPartial(true);
   
                   uuid = new byte[16];
   
  @@ -124,8 +82,8 @@
                                             (uuid[8] & (byte) 0x3f));
                           System.arraycopy(uuid, 0, key.getData(), 0, 16);
                       } while (blocks.get(txn, key, data,
  -                                        flags) != Db.DB_NOTFOUND);
  -                } catch (DbException e) {
  +                                        flags) != DbConstants.DB_NOTFOUND);
  +                } catch (DatabaseException e) {
                       throw new IOException(e.getMessage());
                   }
               }
  @@ -148,9 +106,8 @@
           out.writeUTF(name);
           out.close();
   
  -        key = new Dbt(buffer.toByteArray());
  -        key.setUserBufferLength(key.getSize());
  -        key.setFlags(Db.DB_DBT_USERMEM);
  +        key = new DatabaseEntry(buffer.toByteArray());
  +        key.setUserBuffer(key.getSize(), true);
   
           this.name = name;
       }
  @@ -178,9 +135,9 @@
           throws IOException
       {
           try {
  -            if (files.get(txn, key, data, flags) == Db.DB_NOTFOUND)
  +            if (files.get(txn, key, data, flags) == DbConstants.DB_NOTFOUND)
                   return false;
  -        } catch (DbException e) {
  +        } catch (DatabaseException e) {
               throw new IOException(e.getMessage());
           }
           
  @@ -214,7 +171,7 @@
   
           try {
               files.put(txn, key, data, 0);
  -        } catch (DbException e) {
  +        } catch (DatabaseException e) {
               throw new IOException(e.getMessage());
           }
           
  @@ -235,38 +192,36 @@
                   byte[] bytes = getKey();
                   int ulen = bytes.length + 8;
                   byte[] cursorBytes = new byte[ulen];
  -                Dbt cursorKey = new Dbt(cursorBytes);
  -                Dbt cursorData = new Dbt(null);
  +                DatabaseEntry cursorKey = new DatabaseEntry(cursorBytes);
  +                DatabaseEntry cursorData = new DatabaseEntry(null);
   
                   System.arraycopy(bytes, 0, cursorBytes, 0, bytes.length);
  -                cursorKey.setUserBufferLength(ulen);
  -                cursorKey.setFlags(Db.DB_DBT_USERMEM);
  -                cursorData.setPartialLength(0);
  -                cursorData.setFlags(Db.DB_DBT_PARTIAL);
  +                cursorKey.setUserBuffer(ulen, true);
  +                cursorData.setPartial(true);
   
                   cursor = blocks.cursor(txn, flags);
   
                   if (cursor.get(cursorKey, cursorData,
  -                               Db.DB_SET_RANGE | flags) != Db.DB_NOTFOUND)
  +                               DbConstants.DB_SET_RANGE | flags) != 
DbConstants.DB_NOTFOUND)
                   {
  -                    cursor.delete(0);
  +                    cursor.del(0);
   
                       while (cursor.get(cursorKey, cursorData,
  -                                      Db.DB_NEXT | flags) != Db.DB_NOTFOUND) 
{
  +                                      DbConstants.DB_NEXT | flags) != 
DbConstants.DB_NOTFOUND) {
                           for (int i = 0; i < bytes.length; i++)
                               if (bytes[i] != cursorBytes[i])
                                   return;
   
  -                        cursor.delete(0);
  +                        cursor.del(0);
                       }
                   }
   
  -                files.delete(txn, key, 0);
  +                files.del(txn, key, 0);
               } finally {
                   if (cursor != null)
                       cursor.close();
               }
  -        } catch (DbException e) {
  +        } catch (DatabaseException e) {
               throw new IOException(e.getMessage());
           }
       }
  @@ -284,10 +239,10 @@
               newFile.delete(files, blocks, txn, flags);
   
           try {
  -            files.delete(txn, key, 0);
  +            files.del(txn, key, 0);
               setName(name);
               files.put(txn, key, data, 0);
  -        } catch (DbException e) {
  +        } catch (DatabaseException e) {
               throw new IOException(e.getMessage());
           }
       }
  
  
  
  1.3       +49 -69    
jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbDirectory.java
  
  Index: DbDirectory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbDirectory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DbDirectory.java  1 Jun 2004 09:27:03 -0000       1.2
  +++ DbDirectory.java  18 Jan 2005 14:11:09 -0000      1.3
  @@ -1,59 +1,19 @@
   package org.apache.lucene.store.db;
   
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2004 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" and "Apache Software Foundation" and
  - *    "Apache Lucene" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Lucene", 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.
  - * ====================================================================
  +/**
  + * Copyright 2002-2004 The Apache Software Foundation
    *
  - * This software consists of voluntary contributions made by the Open Source
  - * Applications Foundation on behalf of the Apache Software Foundation.
  - * For more information on the Open Source Applications Foundation, please 
see
  - * <http://www.osafoundation.org>.
  - * For more information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
    */
   
   import java.io.IOException;
  @@ -67,17 +27,22 @@
   import org.apache.lucene.store.OutputStream;
   import org.apache.lucene.store.InputStream;
   
  -import com.sleepycat.db.DbEnv;
  -import com.sleepycat.db.Db;
  -import com.sleepycat.db.Dbt;
  -import com.sleepycat.db.Dbc;
  -import com.sleepycat.db.DbTxn;
  -import com.sleepycat.db.DbException;
  +import com.sleepycat.db.internal.DbEnv;
  +import com.sleepycat.db.internal.Db;
  +import com.sleepycat.db.internal.DbConstants;
  +import com.sleepycat.db.DatabaseEntry;
  +import com.sleepycat.db.internal.Dbc;
  +import com.sleepycat.db.internal.DbTxn;
  +import com.sleepycat.db.DatabaseException;
  +
  +import com.sleepycat.db.Database;
  +import com.sleepycat.db.Transaction;
  +import com.sleepycat.db.DbHandleExtractor;
   
   /**
  - * A DbDirectory is a Berkeley DB 4.2 based implementation of 
  + * A DbDirectory is a Berkeley DB 4.3 based implementation of 
    * [EMAIL PROTECTED] org.apache.lucene.store.Directory Directory}. It uses 
two
  - * [EMAIL PROTECTED] com.sleepycat.db.Db Db} database handles, one for 
storing file
  + * [EMAIL PROTECTED] com.sleepycat.db.internal.Db Db} database handles, one 
for storing file
    * records and another for storing file data blocks.
    *
    * @author Andi Vajda
  @@ -106,9 +71,25 @@
           super();
   
           this.txn = txn;
  -        this.flags = flags;
           this.files = files;
           this.blocks = blocks;
  +        this.flags = flags;
  +    }
  +
  +    public DbDirectory(Transaction txn, Database files, Database blocks,
  +                       int flags)
  +    {
  +        super();
  +
  +        this.txn = txn != null ? DbHandleExtractor.getDbTxn(txn) : null;
  +        this.files = DbHandleExtractor.getDb(files);
  +        this.blocks = DbHandleExtractor.getDb(blocks);
  +        this.flags = flags;
  +    }
  +
  +    public DbDirectory(Transaction txn, Database files, Database blocks)
  +    {
  +        this(txn, files, blocks, 0);
       }
   
       public void close()
  @@ -164,16 +145,15 @@
   
           try {
               try {
  -                Dbt key = new Dbt(new byte[0]);
  -                Dbt data = new Dbt(null);
  +                DatabaseEntry key = new DatabaseEntry(new byte[0]);
  +                DatabaseEntry data = new DatabaseEntry(null);
   
  -                data.setPartialLength(0);
  -                data.setFlags(Db.DB_DBT_PARTIAL);
  +                data.setPartial(true);
   
                   cursor = files.cursor(txn, flags);
   
                   if (cursor.get(key, data,
  -                               Db.DB_SET_RANGE | flags) != Db.DB_NOTFOUND)
  +                               DbConstants.DB_SET_RANGE | flags) != 
DbConstants.DB_NOTFOUND)
                   {
                       ByteArrayInputStream buffer =
                           new ByteArrayInputStream(key.getData());
  @@ -184,7 +164,7 @@
                       list.add(name);
   
                       while (cursor.get(key, data,
  -                                      Db.DB_NEXT | flags) != Db.DB_NOTFOUND) 
{
  +                                      DbConstants.DB_NEXT | flags) != 
DbConstants.DB_NOTFOUND) {
                           buffer = new ByteArrayInputStream(key.getData());
                           in = new DataInputStream(buffer);
                           name = in.readUTF();
  @@ -197,7 +177,7 @@
                   if (cursor != null)
                       cursor.close();
               }
  -        } catch (DbException e) {
  +        } catch (DatabaseException e) {
               throw new IOException(e.getMessage());
           }
   
  
  
  
  1.3       +24 -65    
jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/Block.java
  
  Index: Block.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/Block.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Block.java        1 Jun 2004 09:27:03 -0000       1.2
  +++ Block.java        18 Jan 2005 14:11:09 -0000      1.3
  @@ -1,86 +1,45 @@
   package org.apache.lucene.store.db;
   
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2004 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" and "Apache Software Foundation" and
  - *    "Apache Lucene" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Lucene", 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.
  - * ====================================================================
  +/**
  + * Copyright 2002-2004 The Apache Software Foundation
    *
  - * This software consists of voluntary contributions made by the Open Source
  - * Applications Foundation on behalf of the Apache Software Foundation.
  - * For more information on the Open Source Applications Foundation, please 
see
  - * <http://www.osafoundation.org>.
  - * For more information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
    */
   
   import java.io.IOException;
   
  -import com.sleepycat.db.Dbt;
  -import com.sleepycat.db.Db;
  -import com.sleepycat.db.DbTxn;
  -import com.sleepycat.db.DbException;
  +import com.sleepycat.db.DatabaseEntry;
  +import com.sleepycat.db.internal.Db;
  +import com.sleepycat.db.internal.DbTxn;
  +import com.sleepycat.db.DatabaseException;
   
   /**
    * @author Andi Vajda
    */
   
   public class Block extends Object {
  -    protected Dbt key, data;
  +    protected DatabaseEntry key, data;
   
       protected Block(File file)
           throws IOException
       {
           byte[] fileKey = file.getKey();
   
  -        key = new Dbt(new byte[fileKey.length + 8]);
  -        key.setFlags(Db.DB_DBT_USERMEM);
  +        key = new DatabaseEntry(new byte[fileKey.length + 8]);
  +        key.setUserBuffer(fileKey.length + 8, true);
   
  -        data = new Dbt(new byte[DbOutputStream.BLOCK_LEN]);
  -        data.setUserBufferLength(data.getSize());
  -        data.setFlags(Db.DB_DBT_USERMEM);
  +        data = new DatabaseEntry(new byte[DbOutputStream.BLOCK_LEN]);
  +        data.setUserBuffer(data.getSize(), true);
   
           System.arraycopy(fileKey, 0, key.getData(), 0, fileKey.length);
           seek(0L);
  @@ -119,7 +78,7 @@
       {
           try {
               blocks.get(txn, key, data, flags);
  -        } catch (DbException e) {
  +        } catch (DatabaseException e) {
               throw new IOException(e.getMessage());
           }
       }
  @@ -129,7 +88,7 @@
       {
           try {
               blocks.put(txn, key, data, 0);
  -        } catch (DbException e) {
  +        } catch (DatabaseException e) {
               throw new IOException(e.getMessage());
           }
       }
  
  
  
  1.3       +15 -57    
jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbInputStream.java
  
  Index: DbInputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene-sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbInputStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DbInputStream.java        1 Jun 2004 09:27:03 -0000       1.2
  +++ DbInputStream.java        18 Jan 2005 14:11:09 -0000      1.3
  @@ -1,69 +1,27 @@
   package org.apache.lucene.store.db;
   
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  +/**
  + * Copyright 2002-2004 The Apache Software Foundation
    *
  - * Copyright (c) 2004 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" and "Apache Software Foundation" and
  - *    "Apache Lucene" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Lucene", 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 the Open Source
  - * Applications Foundation on behalf of the Apache Software Foundation.
  - * For more information on the Open Source Applications Foundation, please 
see
  - * <http://www.osafoundation.org>.
  - * For more information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
    */
   
   import java.io.IOException;
   
   import org.apache.lucene.store.InputStream;
   
  -import com.sleepycat.db.Db;
  -import com.sleepycat.db.DbTxn;
  -import com.sleepycat.db.Dbt;
  -import com.sleepycat.db.DbException;
  +import com.sleepycat.db.internal.Db;
  +import com.sleepycat.db.internal.DbTxn;
   
   /**
    * @author Andi Vajda
  
  
  
  1.1                  
jakarta-lucene-sandbox/contributions/db/src/java/com/sleepycat/db/DbHandleExtractor.java
  
  Index: DbHandleExtractor.java
  ===================================================================
  package com.sleepycat.db;
  
  /**
   * Copyright 2002-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import com.sleepycat.db.internal.Db;
  import com.sleepycat.db.internal.DbTxn;
  
  
  /**
   * This class is a hack to workaround the need to rewrite the entire
   * org.apache.lucene.store.db package after Sleepycat radically changed its
   * Java API from version 4.2.52 to version 4.3.21.
   * 
   * The code below extracts the package-accessible internal handle instances
   * that were the entrypoint objects in the pre-4.3 Java API and that wrap the
   * actual Berkeley DB C objects via SWIG.
   *
   * @author Andi Vajda
   */
  
  public class DbHandleExtractor {
  
      private DbHandleExtractor()
      {
      }
  
      static public Db getDb(Database database)
      {
          return database.db;
      }
  
      static public DbTxn getDbTxn(Transaction transaction)
      {
          return transaction.txn;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to