Apache Lucene open-source search software
Update of DBDirectory from Andi.
Erik Hatchercd284c4bc673
diff --git a/sandbox/contributions/db/src/java/com/sleepycat/db/DbHandleExtractor.java b/sandbox/contributions/db/src/java/com/sleepycat/db/DbHandleExtractor.javanew file mode 100644index 00000000000..88a98c1d224--- /dev/null+++ b/sandbox/contributions/db/src/java/com/sleepycat/db/DbHandleExtractor.java@@ -0,0 +1,50 @@+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;+ }+}diff --git a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/Block.java b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/Block.javaindex 176dd689d3e..fefb83efbea 100644--- a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/Block.java+++ b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/Block.java@@ -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].+/**+ * Copyright 2002-2004 The Apache Software Foundation*- * 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.+ * 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*- * 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.- * ====================================================================+ * http://www.apache.org/licenses/LICENSE-2.0*- * 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/>.+ * 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 @@ public class Block extends Object {{try {blocks.get(txn, key, data, flags);- } catch (DbException e) {+ } catch (DatabaseException e) {throw new IOException(e.getMessage());}}@@ -129,7 +88,7 @@ public class Block extends Object {{try {blocks.put(txn, key, data, 0);- } catch (DbException e) {+ } catch (DatabaseException e) {throw new IOException(e.getMessage());}}diff --git a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbDirectory.java b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbDirectory.javaindex f4495525f2f..f0731520e8c 100644--- a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbDirectory.java+++ b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbDirectory.java@@ -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].+/**+ * Copyright 2002-2004 The Apache Software Foundation*- * 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.+ * 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*- * 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.- * ====================================================================+ * http://www.apache.org/licenses/LICENSE-2.0*- * 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/>.+ * 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.Lock;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* {@link org.apache.lucene.store.Directory Directory}. It uses two- * {@link com.sleepycat.db.Db Db} database handles, one for storing file+ * {@link 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 @@ public class DbDirectory extends Directory {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 @@ public class DbDirectory extends Directory {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 @@ public class DbDirectory extends Directory {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 @@ public class DbDirectory extends Directory {if (cursor != null)cursor.close();}- } catch (DbException e) {+ } catch (DatabaseException e) {throw new IOException(e.getMessage());}diff --git a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbInputStream.java b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbInputStream.javaindex 599306a6aac..80084b7b993 100644--- a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbInputStream.java+++ b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbInputStream.java@@ -1,69 +1,27 @@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].+/**+ * Copyright 2002-2004 The Apache Software Foundation*- * 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.+ * 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*- * 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.- * ====================================================================+ * http://www.apache.org/licenses/LICENSE-2.0*- * 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/>.+ * 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 Vajdadiff --git a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbLock.java b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbLock.javaindex f53a57154b6..e435ee9ccdc 100644--- a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbLock.java+++ b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbLock.java@@ -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].+/**+ * Copyright 2002-2004 The Apache Software Foundation*- * 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.+ * 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*- * 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.- * ====================================================================+ * http://www.apache.org/licenses/LICENSE-2.0*- * 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/>.+ * 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;diff --git a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbOutputStream.java b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbOutputStream.javaindex 2ff3c20dec8..2e22527565a 100644--- a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbOutputStream.java+++ b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/DbOutputStream.java@@ -1,67 +1,27 @@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].+/**+ * Copyright 2002-2004 The Apache Software Foundation*- * 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.+ * 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*- * 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.- * ====================================================================+ * http://www.apache.org/licenses/LICENSE-2.0*- * 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/>.+ * 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 Vajdadiff --git a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/File.java b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/File.javaindex 465f6bfcd70..b8753c4009a 100644--- a/sandbox/contributions/db/src/java/org/apache/lucene/store/db/File.java+++ b/sandbox/contributions/db/src/java/org/apache/lucene/store/db/File.java@@ -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].+/**+ * Copyright 2002-2004 The Apache Software Foundation*- * 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.+ * 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*- * 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.- * ====================================================================+ * http://www.apache.org/licenses/LICENSE-2.0*- * 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/>.+ * 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.ByteArrayInputStream;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 @@ public class File extends Object {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 @@ public class File extends Object {{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 @@ public class File extends Object {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 @@ public class File extends Object {(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 @@ public class File extends Object {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 @@ public class File extends Object {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 @@ public class File extends Object {try {files.put(txn, key, data, 0);- } catch (DbException e) {+ } catch (DatabaseException e) {throw new IOException(e.getMessage());}@@ -235,38 +192,36 @@ public class File extends Object {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 @@ public class File extends Object {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());}}