ehatcher 2004/06/01 02:27:04
Modified: contributions/db/src/java/org/apache/lucene/store/db
Block.java DbDirectory.java DbInputStream.java
DbOutputStream.java File.java
Log:
applied latest patch from Andi Vajda
Revision Changes Path
1.2 +14 -9
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Block.java 14 Jan 2004 00:29:45 -0000 1.1
+++ Block.java 1 Jun 2004 09:27:03 -0000 1.2
@@ -99,27 +99,32 @@
protected void seek(long position)
throws IOException
{
- position = position >>> DbOutputStream.BLOCK_SHIFT;
byte[] data = key.getData();
- int last = data.length - 1;
+ int index = data.length - 8;
- for (int i = 0; i < 8; i++) {
- data[last - i] = (byte) (position & 0xff);
- position >>>= 8;
- }
+ position >>>= DbOutputStream.BLOCK_SHIFT;
+
+ data[index + 0] = (byte) (0xff & (position >>> 56));
+ data[index + 1] = (byte) (0xff & (position >>> 48));
+ data[index + 2] = (byte) (0xff & (position >>> 40));
+ data[index + 3] = (byte) (0xff & (position >>> 32));
+ data[index + 4] = (byte) (0xff & (position >>> 24));
+ data[index + 5] = (byte) (0xff & (position >>> 16));
+ data[index + 6] = (byte) (0xff & (position >>> 8));
+ data[index + 7] = (byte) (0xff & (position >>> 0));
}
- protected void get(Db blocks, DbTxn txn)
+ protected void get(Db blocks, DbTxn txn, int flags)
throws IOException
{
try {
- blocks.get(txn, key, data, 0);
+ blocks.get(txn, key, data, flags);
} catch (DbException e) {
throw new IOException(e.getMessage());
}
}
- protected void put(Db blocks, DbTxn txn)
+ protected void put(Db blocks, DbTxn txn, int flags)
throws IOException
{
try {
1.2 +18 -13
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DbDirectory.java 14 Jan 2004 00:29:45 -0000 1.1
+++ DbDirectory.java 1 Jun 2004 09:27:03 -0000 1.2
@@ -87,6 +87,7 @@
protected Db files, blocks;
protected DbTxn txn;
+ protected int flags;
/**
* Instantiate a DbDirectory. The same threading rules that apply to
@@ -97,13 +98,15 @@
* <code>null</code>.
* @param files a db handle to store file records.
* @param blocks a db handle to store file data blocks.
+ * @param flags flags used for db read operations.
*/
- public DbDirectory(DbTxn txn, Db files, Db blocks)
+ public DbDirectory(DbTxn txn, Db files, Db blocks, int flags)
{
super();
this.txn = txn;
+ this.flags = flags;
this.files = files;
this.blocks = blocks;
}
@@ -116,19 +119,19 @@
public OutputStream createFile(String name)
throws IOException
{
- return new DbOutputStream(files, blocks, txn, name, true);
+ return new DbOutputStream(files, blocks, txn, flags, name, true);
}
public void deleteFile(String name)
throws IOException
{
- new File(name).delete(files, blocks, txn);
+ new File(name).delete(files, blocks, txn, flags);
}
public boolean fileExists(String name)
throws IOException
{
- return new File(name).exists(files, txn);
+ return new File(name).exists(files, txn, flags);
}
public long fileLength(String name)
@@ -136,7 +139,7 @@
{
File file = new File(name);
- if (file.exists(files, txn))
+ if (file.exists(files, txn, flags))
return file.getLength();
throw new IOException("File does not exist: " + name);
@@ -147,7 +150,7 @@
{
File file = new File(name);
- if (file.exists(files, txn))
+ if (file.exists(files, txn, flags))
return file.getTimeModified();
throw new IOException("File does not exist: " + name);
@@ -167,9 +170,10 @@
data.setPartialLength(0);
data.setFlags(Db.DB_DBT_PARTIAL);
- cursor = files.cursor(txn, 0);
+ cursor = files.cursor(txn, flags);
- if (cursor.get(key, data, Db.DB_SET_RANGE) != Db.DB_NOTFOUND)
+ if (cursor.get(key, data,
+ Db.DB_SET_RANGE | flags) != Db.DB_NOTFOUND)
{
ByteArrayInputStream buffer =
new ByteArrayInputStream(key.getData());
@@ -179,7 +183,8 @@
in.close();
list.add(name);
- while (cursor.get(key, data, Db.DB_NEXT) != Db.DB_NOTFOUND) {
+ while (cursor.get(key, data,
+ Db.DB_NEXT | flags) != Db.DB_NOTFOUND) {
buffer = new ByteArrayInputStream(key.getData());
in = new DataInputStream(buffer);
name = in.readUTF();
@@ -202,7 +207,7 @@
public InputStream openFile(String name)
throws IOException
{
- return new DbInputStream(files, blocks, txn, name);
+ return new DbInputStream(files, blocks, txn, flags, name);
}
public Lock makeLock(String name)
@@ -213,7 +218,7 @@
public void renameFile(String from, String to)
throws IOException
{
- new File(from).rename(files, blocks, txn, to);
+ new File(from).rename(files, blocks, txn, flags, to);
}
public void touchFile(String name)
@@ -222,9 +227,9 @@
File file = new File(name);
long length = 0L;
- if (file.exists(files, txn))
+ if (file.exists(files, txn, flags))
length = file.getLength();
- file.modify(files, txn, length, System.currentTimeMillis());
+ file.modify(files, txn, flags, length, System.currentTimeMillis());
}
}
1.2 +9 -6
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DbInputStream.java 14 Jan 2004 00:29:45 -0000 1.1
+++ DbInputStream.java 1 Jun 2004 09:27:03 -0000 1.2
@@ -76,8 +76,10 @@
protected Block block;
protected DbTxn txn;
protected Db files, blocks;
+ protected int flags;
- protected DbInputStream(Db files, Db blocks, DbTxn txn, String name)
+ protected DbInputStream(Db files, Db blocks, DbTxn txn, int flags,
+ String name)
throws IOException
{
super();
@@ -85,15 +87,16 @@
this.files = files;
this.blocks = blocks;
this.txn = txn;
+ this.flags = flags;
this.file = new File(name);
- if (!file.exists(files, txn))
+ if (!file.exists(files, txn, flags))
throw new IOException("File does not exist: " + name);
length = file.getLength();
block = new Block(file);
- block.get(blocks, txn);
+ block.get(blocks, txn, flags);
}
public Object clone()
@@ -103,7 +106,7 @@
clone.block = new Block(file);
clone.block.seek(position);
- clone.block.get(blocks, txn);
+ clone.block.get(blocks, txn, flags);
return clone;
} catch (IOException e) {
@@ -134,7 +137,7 @@
position += blockLen;
block.seek(position);
- block.get(blocks, txn);
+ block.get(blocks, txn, flags);
blockPos = 0;
}
@@ -155,7 +158,7 @@
(position >>> DbOutputStream.BLOCK_SHIFT))
{
block.seek(pos);
- block.get(blocks, txn);
+ block.get(blocks, txn, flags);
}
position = pos;
1.2 +11 -9
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DbOutputStream.java 14 Jan 2004 00:29:45 -0000 1.1
+++ DbOutputStream.java 1 Jun 2004 09:27:03 -0000 1.2
@@ -84,8 +84,9 @@
protected Block block;
protected DbTxn txn;
protected Db files, blocks;
+ protected int flags;
- protected DbOutputStream(Db files, Db blocks, DbTxn txn,
+ protected DbOutputStream(Db files, Db blocks, DbTxn txn, int flags,
String name, boolean create)
throws IOException
{
@@ -94,13 +95,14 @@
this.files = files;
this.blocks = blocks;
this.txn = txn;
+ this.flags = flags;
- file = new File(files, blocks, txn, name, create);
+ file = new File(files, blocks, txn, flags, name, create);
block = new Block(file);
length = file.getLength();
seek(length);
- block.get(blocks, txn);
+ block.get(blocks, txn, flags);
}
public void close()
@@ -108,9 +110,9 @@
{
flush();
if (length > 0)
- block.put(blocks, txn);
+ block.put(blocks, txn, flags);
- file.modify(files, txn, length, System.currentTimeMillis());
+ file.modify(files, txn, flags, length, System.currentTimeMillis());
}
protected void flushBuffer(byte[] b, int len)
@@ -123,14 +125,14 @@
int blockLen = BLOCK_LEN - blockPos;
System.arraycopy(b, offset, block.getData(), blockPos, blockLen);
- block.put(blocks, txn);
+ block.put(blocks, txn, flags);
len -= blockLen;
offset += blockLen;
position += blockLen;
block.seek(position);
- block.get(blocks, txn);
+ block.get(blocks, txn, flags);
blockPos = 0;
}
@@ -167,9 +169,9 @@
position = pos;
else
{
- block.put(blocks, txn);
+ block.put(blocks, txn, flags);
block.seek(pos);
- block.get(blocks, txn);
+ block.get(blocks, txn, flags);
position = pos;
}
}
1.2 +20 -16
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- File.java 14 Jan 2004 00:29:45 -0000 1.1
+++ File.java 1 Jun 2004 09:27:03 -0000 1.2
@@ -92,12 +92,13 @@
data.setFlags(Db.DB_DBT_USERMEM);
}
- protected File(Db files, Db blocks, DbTxn txn, String name, boolean create)
+ protected File(Db files, Db blocks, DbTxn txn, int flags,
+ String name, boolean create)
throws IOException
{
this(name);
- if (!exists(files, txn))
+ if (!exists(files, txn, flags))
{
if (!create)
throw new IOException("File does not exist: " + name);
@@ -122,7 +123,8 @@
uuid[8] = (byte) ((byte) 0x80 |
(uuid[8] & (byte) 0x3f));
System.arraycopy(uuid, 0, key.getData(), 0, 16);
- } while (blocks.get(txn, key, data, 0) != Db.DB_NOTFOUND);
+ } while (blocks.get(txn, key, data,
+ flags) != Db.DB_NOTFOUND);
} catch (DbException e) {
throw new IOException(e.getMessage());
}
@@ -172,11 +174,11 @@
return timeModified;
}
- protected boolean exists(Db files, DbTxn txn)
+ protected boolean exists(Db files, DbTxn txn, int flags)
throws IOException
{
try {
- if (files.get(txn, key, data, 0) == Db.DB_NOTFOUND)
+ if (files.get(txn, key, data, flags) == Db.DB_NOTFOUND)
return false;
} catch (DbException e) {
throw new IOException(e.getMessage());
@@ -196,7 +198,8 @@
return true;
}
- protected void modify(Db files, DbTxn txn, long length, long timeModified)
+ protected void modify(Db files, DbTxn txn, int flags,
+ long length, long timeModified)
throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream(32);
@@ -219,10 +222,10 @@
this.timeModified = timeModified;
}
- protected void delete(Db files, Db blocks, DbTxn txn)
+ protected void delete(Db files, Db blocks, DbTxn txn, int flags)
throws IOException
{
- if (!exists(files, txn))
+ if (!exists(files, txn, flags))
throw new IOException("File does not exist: " + getName());
Dbc cursor = null;
@@ -241,15 +244,15 @@
cursorData.setPartialLength(0);
cursorData.setFlags(Db.DB_DBT_PARTIAL);
- cursor = blocks.cursor(txn, 0);
+ cursor = blocks.cursor(txn, flags);
if (cursor.get(cursorKey, cursorData,
- Db.DB_SET_RANGE) != Db.DB_NOTFOUND)
+ Db.DB_SET_RANGE | flags) != Db.DB_NOTFOUND)
{
cursor.delete(0);
- while (cursor.get(cursorKey, cursorData, Db.DB_NEXT) !=
- Db.DB_NOTFOUND) {
+ while (cursor.get(cursorKey, cursorData,
+ Db.DB_NEXT | flags) != Db.DB_NOTFOUND) {
for (int i = 0; i < bytes.length; i++)
if (bytes[i] != cursorBytes[i])
return;
@@ -268,16 +271,17 @@
}
}
- protected void rename(Db files, Db blocks, DbTxn txn, String name)
+ protected void rename(Db files, Db blocks, DbTxn txn, int flags,
+ String name)
throws IOException
{
- if (!exists(files, txn))
+ if (!exists(files, txn, flags))
throw new IOException("File does not exist: " + getName());
File newFile = new File(name);
- if (newFile.exists(files, txn))
- newFile.delete(files, blocks, txn);
+ if (newFile.exists(files, txn, flags))
+ newFile.delete(files, blocks, txn, flags);
try {
files.delete(txn, key, 0);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]