libdb-je-java-3.3.98.orig/ 0000755 0001750 0001750 00000000000 11353144074 015104 5 ustar twerner twerner libdb-je-java-3.3.98.orig/lib/ 0000755 0001750 0001750 00000000000 11353144157 015654 5 ustar twerner twerner libdb-je-java-3.3.98.orig/src/ 0000755 0001750 0001750 00000000000 11353143620 015667 5 ustar twerner twerner libdb-je-java-3.3.98.orig/src/com/ 0000755 0001750 0001750 00000000000 11353143620 016445 5 ustar twerner twerner libdb-je-java-3.3.98.orig/src/com/sleepycat/ 0000755 0001750 0001750 00000000000 11353143646 020446 5 ustar twerner twerner libdb-je-java-3.3.98.orig/src/com/sleepycat/util/ 0000755 0001750 0001750 00000000000 11353143646 021423 5 ustar twerner twerner libdb-je-java-3.3.98.orig/src/com/sleepycat/util/keyrange/ 0000755 0001750 0001750 00000000000 11353143646 023230 5 ustar twerner twerner libdb-je-java-3.3.98.orig/src/com/sleepycat/util/keyrange/KeyRangeException.java 0000444 0001750 0001750 00000001000 11014607746 027444 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: KeyRangeException.java,v 1.7 2008/05/20 17:52:38 linda Exp $
*/
package com.sleepycat.util.keyrange;
/**
* An exception thrown when a key is out of range.
*
* @author Mark Hayes
*/
public class KeyRangeException extends IllegalArgumentException {
/**
* Creates a key range exception.
*/
public KeyRangeException(String msg) {
super(msg);
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/keyrange/RangeCursor.java 0000444 0001750 0001750 00000110772 11320404642 026321 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2002,2010 Oracle. All rights reserved.
*
* $Id: RangeCursor.java,v 1.10.2.2 2010/01/04 15:30:41 cwl Exp $
*/
package com.sleepycat.util.keyrange;
import com.sleepycat.compat.DbCompat;
import com.sleepycat.je.Cursor;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.LockMode;
import com.sleepycat.je.OperationStatus;
import com.sleepycat.je.SecondaryCursor;
/**
* A cursor-like interface that enforces a key range. The method signatures
* are actually those of SecondaryCursor, but the pKey parameter may be null.
* It was done this way to avoid doubling the number of methods.
*
*
This is not a fully general implementation of a range cursor and should
* not be used directly by applications; however, it may evolve into a
* generally useful range cursor some day.
*
* @author Mark Hayes
*/
public class RangeCursor implements Cloneable {
/**
* The cursor and secondary cursor are the same object. The secCursor is
* null if the database is not a secondary database.
*/
private Cursor cursor;
private SecondaryCursor secCursor;
/**
* The range is always non-null, but may be unbounded meaning that it is
* open and not used.
*/
private KeyRange range;
/**
* The pkRange may be non-null only if the range is a single-key range
* and the cursor is a secondary cursor. It further restricts the range of
* primary keys in a secondary database.
*/
private KeyRange pkRange;
/**
* If the DB supported sorted duplicates, then calling
* Cursor.getSearchBothRange is allowed.
*/
private boolean sortedDups;
/**
* The privXxx entries are used only when the range is bounded. We read
* into these private entries to avoid modifying the caller's entry
* parameters in the case where we read successfully but the key is out of
* range. In that case we return NOTFOUND and we want to leave the entry
* parameters unchanged.
*/
private DatabaseEntry privKey;
private DatabaseEntry privPKey;
private DatabaseEntry privData;
/**
* The initialized flag is set to true whenever we successfully position
* the cursor. It is used to implement the getNext/Prev logic for doing a
* getFirst/Last when the cursor is not initialized. We can't rely on
* Cursor to do that for us, since if we position the underlying cursor
* successfully but the key is out of range, we have no way to set the
* underlying cursor to uninitialized. A range cursor always starts in the
* uninitialized state.
*/
private boolean initialized;
/**
* Creates a range cursor with a duplicate range.
*/
public RangeCursor(KeyRange range,
KeyRange pkRange,
boolean sortedDups,
Cursor cursor)
throws DatabaseException {
if (pkRange != null && !range.singleKey) {
throw new IllegalArgumentException();
}
this.range = range;
this.pkRange = pkRange;
this.sortedDups = sortedDups;
this.cursor = cursor;
init();
if (pkRange != null && secCursor == null) {
throw new IllegalArgumentException();
}
}
/**
* Create a cloned range cursor. The caller must clone the underlying
* cursor before using this constructor, because cursor open/close is
* handled specially for CDS cursors outside this class.
*/
public RangeCursor dup(boolean samePosition)
throws DatabaseException {
try {
RangeCursor c = (RangeCursor) super.clone();
c.cursor = dupCursor(cursor, samePosition);
c.init();
return c;
} catch (CloneNotSupportedException neverHappens) {
return null;
}
}
/**
* Used for opening and duping (cloning).
*/
private void init() {
if (cursor instanceof SecondaryCursor) {
secCursor = (SecondaryCursor) cursor;
} else {
secCursor = null;
}
if (range.hasBound()) {
privKey = new DatabaseEntry();
privPKey = new DatabaseEntry();
privData = new DatabaseEntry();
} else {
privKey = null;
privPKey = null;
privData = null;
}
}
/**
* Returns whether the cursor is initialized at a valid position.
*/
public boolean isInitialized() {
return initialized;
}
/**
* Returns the underlying cursor. Used for cloning.
*/
public Cursor getCursor() {
return cursor;
}
/**
* When an unbounded range is used, this method is called to use the
* callers entry parameters directly, to avoid the extra step of copying
* between the private entries and the caller's entries.
*/
private void setParams(DatabaseEntry key, DatabaseEntry pKey,
DatabaseEntry data) {
privKey = key;
privPKey = pKey;
privData = data;
}
/**
* Dups the cursor, sets the cursor and secCursor fields to the duped
* cursor, and returns the old cursor. Always call endOperation in a
* finally clause after calling beginOperation.
*
*
If the returned cursor == the cursor field, the cursor is
* uninitialized and was not duped; this case is handled correctly by
* endOperation.
*/
private Cursor beginOperation()
throws DatabaseException {
Cursor oldCursor = cursor;
if (initialized) {
cursor = dupCursor(cursor, true);
if (secCursor != null) {
secCursor = (SecondaryCursor) cursor;
}
} else {
return cursor;
}
return oldCursor;
}
/**
* If the operation succeded, leaves the duped cursor in place and closes
* the oldCursor. If the operation failed, moves the oldCursor back in
* place and closes the duped cursor. oldCursor may be null if
* beginOperation was not called, in cases where we don't need to dup
* the cursor. Always call endOperation when a successful operation ends,
* in order to set the initialized field.
*/
private void endOperation(Cursor oldCursor, OperationStatus status,
DatabaseEntry key, DatabaseEntry pKey,
DatabaseEntry data)
throws DatabaseException {
if (status == OperationStatus.SUCCESS) {
if (oldCursor != null && oldCursor != cursor) {
closeCursor(oldCursor);
}
if (key != null) {
swapData(key, privKey);
}
if (pKey != null && secCursor != null) {
swapData(pKey, privPKey);
}
if (data != null) {
swapData(data, privData);
}
initialized = true;
} else {
if (oldCursor != null && oldCursor != cursor) {
closeCursor(cursor);
cursor = oldCursor;
if (secCursor != null) {
secCursor = (SecondaryCursor) cursor;
}
}
}
}
/**
* Swaps the contents of the two entries. Used to return entry data to
* the caller when the operation was successful.
*/
private static void swapData(DatabaseEntry e1, DatabaseEntry e2) {
byte[] d1 = e1.getData();
int o1 = e1.getOffset();
int s1 = e1.getSize();
e1.setData(e2.getData(), e2.getOffset(), e2.getSize());
e2.setData(d1, o1, s1);
}
/**
* Shares the same byte array, offset and size between two entries.
* Used when copying the entry data is not necessary because it is known
* that the underlying operation will not modify the entry, for example,
* with getSearchKey.
*/
private static void shareData(DatabaseEntry from, DatabaseEntry to) {
if (from != null) {
to.setData(from.getData(), from.getOffset(), from.getSize());
}
}
public OperationStatus getFirst(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetFirst(lockMode);
endOperation(null, status, null, null, null);
return status;
}
if (pkRange != null) {
KeyRange.copy(range.beginKey, privKey);
if (pkRange.singleKey) {
KeyRange.copy(pkRange.beginKey, privPKey);
status = doGetSearchBoth(lockMode);
endOperation(null, status, key, pKey, data);
} else {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
if (pkRange.beginKey == null || !sortedDups) {
status = doGetSearchKey(lockMode);
} else {
KeyRange.copy(pkRange.beginKey, privPKey);
status = doGetSearchBothRange(lockMode);
if (status == OperationStatus.SUCCESS &&
!pkRange.beginInclusive &&
pkRange.compare(privPKey, pkRange.beginKey) == 0) {
status = doGetNextDup(lockMode);
}
}
if (status == OperationStatus.SUCCESS &&
!pkRange.check(privPKey)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
}
} else if (range.singleKey) {
KeyRange.copy(range.beginKey, privKey);
status = doGetSearchKey(lockMode);
endOperation(null, status, key, pKey, data);
} else {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
if (range.beginKey == null) {
status = doGetFirst(lockMode);
} else {
KeyRange.copy(range.beginKey, privKey);
status = doGetSearchKeyRange(lockMode);
if (status == OperationStatus.SUCCESS &&
!range.beginInclusive &&
range.compare(privKey, range.beginKey) == 0) {
status = doGetNextNoDup(lockMode);
}
}
if (status == OperationStatus.SUCCESS &&
!range.check(privKey)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
}
return status;
}
public OperationStatus getLast(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status = OperationStatus.NOTFOUND;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetLast(lockMode);
endOperation(null, status, null, null, null);
return status;
}
Cursor oldCursor = beginOperation();
try {
if (pkRange != null) {
KeyRange.copy(range.beginKey, privKey);
boolean doLast = false;
if (!sortedDups) {
status = doGetSearchKey(lockMode);
} else if (pkRange.endKey == null) {
doLast = true;
} else {
KeyRange.copy(pkRange.endKey, privPKey);
status = doGetSearchBothRange(lockMode);
if (status == OperationStatus.SUCCESS) {
if (!pkRange.endInclusive ||
pkRange.compare(pkRange.endKey, privPKey) != 0) {
status = doGetPrevDup(lockMode);
}
} else {
KeyRange.copy(range.beginKey, privKey);
doLast = true;
}
}
if (doLast) {
status = doGetSearchKey(lockMode);
if (status == OperationStatus.SUCCESS) {
status = doGetNextNoDup(lockMode);
if (status == OperationStatus.SUCCESS) {
status = doGetPrev(lockMode);
} else {
status = doGetLast(lockMode);
}
}
}
if (status == OperationStatus.SUCCESS &&
!pkRange.check(privPKey)) {
status = OperationStatus.NOTFOUND;
}
} else if (range.endKey == null) {
status = doGetLast(lockMode);
} else {
KeyRange.copy(range.endKey, privKey);
status = doGetSearchKeyRange(lockMode);
if (status == OperationStatus.SUCCESS) {
if (range.endInclusive &&
range.compare(range.endKey, privKey) == 0) {
/* Skip this step if dups are not configured? */
status = doGetNextNoDup(lockMode);
if (status == OperationStatus.SUCCESS) {
status = doGetPrev(lockMode);
} else {
status = doGetLast(lockMode);
}
} else {
status = doGetPrev(lockMode);
}
} else {
status = doGetLast(lockMode);
}
}
if (status == OperationStatus.SUCCESS &&
!range.checkBegin(privKey, true)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
return status;
}
public OperationStatus getNext(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status;
if (!initialized) {
return getFirst(key, pKey, data, lockMode);
}
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetNext(lockMode);
endOperation(null, status, null, null, null);
return status;
}
if (pkRange != null) {
if (pkRange.endKey == null) {
status = doGetNextDup(lockMode);
endOperation(null, status, key, pKey, data);
} else {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
status = doGetNextDup(lockMode);
if (status == OperationStatus.SUCCESS &&
!pkRange.checkEnd(privPKey, true)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
}
} else if (range.singleKey) {
status = doGetNextDup(lockMode);
endOperation(null, status, key, pKey, data);
} else {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
status = doGetNext(lockMode);
if (status == OperationStatus.SUCCESS &&
!range.check(privKey)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
}
return status;
}
public OperationStatus getNextNoDup(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status;
if (!initialized) {
return getFirst(key, pKey, data, lockMode);
}
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetNextNoDup(lockMode);
endOperation(null, status, null, null, null);
return status;
}
if (range.singleKey) {
status = OperationStatus.NOTFOUND;
} else {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
status = doGetNextNoDup(lockMode);
if (status == OperationStatus.SUCCESS &&
!range.check(privKey)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
}
return status;
}
public OperationStatus getPrev(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status;
if (!initialized) {
return getLast(key, pKey, data, lockMode);
}
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetPrev(lockMode);
endOperation(null, status, null, null, null);
return status;
}
if (pkRange != null) {
if (pkRange.beginKey == null) {
status = doGetPrevDup(lockMode);
endOperation(null, status, key, pKey, data);
} else {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
status = doGetPrevDup(lockMode);
if (status == OperationStatus.SUCCESS &&
!pkRange.checkBegin(privPKey, true)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
}
} else if (range.singleKey) {
status = doGetPrevDup(lockMode);
endOperation(null, status, key, pKey, data);
} else {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
status = doGetPrev(lockMode);
if (status == OperationStatus.SUCCESS &&
!range.check(privKey)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
}
return status;
}
public OperationStatus getPrevNoDup(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status;
if (!initialized) {
return getLast(key, pKey, data, lockMode);
}
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetPrevNoDup(lockMode);
endOperation(null, status, null, null, null);
return status;
}
if (range.singleKey) {
status = OperationStatus.NOTFOUND;
} else {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
status = doGetPrevNoDup(lockMode);
if (status == OperationStatus.SUCCESS &&
!range.check(privKey)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
}
return status;
}
public OperationStatus getSearchKey(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetSearchKey(lockMode);
endOperation(null, status, null, null, null);
return status;
}
if (!range.check(key)) {
status = OperationStatus.NOTFOUND;
} else if (pkRange != null) {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
shareData(key, privKey);
status = doGetSearchKey(lockMode);
if (status == OperationStatus.SUCCESS &&
!pkRange.check(privPKey)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
} else {
shareData(key, privKey);
status = doGetSearchKey(lockMode);
endOperation(null, status, key, pKey, data);
}
return status;
}
public OperationStatus getSearchBoth(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetSearchBoth(lockMode);
endOperation(null, status, null, null, null);
return status;
}
if (!range.check(key) ||
(pkRange != null && !pkRange.check(pKey))) {
status = OperationStatus.NOTFOUND;
} else {
shareData(key, privKey);
if (secCursor != null) {
shareData(pKey, privPKey);
} else {
shareData(data, privData);
}
status = doGetSearchBoth(lockMode);
endOperation(null, status, key, pKey, data);
}
return status;
}
public OperationStatus getSearchKeyRange(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status = OperationStatus.NOTFOUND;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetSearchKeyRange(lockMode);
endOperation(null, status, null, null, null);
return status;
}
Cursor oldCursor = beginOperation();
try {
shareData(key, privKey);
status = doGetSearchKeyRange(lockMode);
if (status == OperationStatus.SUCCESS &&
(!range.check(privKey) ||
(pkRange != null && !pkRange.check(pKey)))) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
return status;
}
public OperationStatus getSearchBothRange(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status = OperationStatus.NOTFOUND;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetSearchBothRange(lockMode);
endOperation(null, status, null, null, null);
return status;
}
Cursor oldCursor = beginOperation();
try {
shareData(key, privKey);
if (secCursor != null) {
shareData(pKey, privPKey);
} else {
shareData(data, privData);
}
status = doGetSearchBothRange(lockMode);
if (status == OperationStatus.SUCCESS &&
(!range.check(privKey) ||
(pkRange != null && !pkRange.check(pKey)))) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
return status;
}
public OperationStatus getSearchRecordNumber(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
OperationStatus status;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetSearchRecordNumber(lockMode);
endOperation(null, status, null, null, null);
return status;
}
if (!range.check(key)) {
status = OperationStatus.NOTFOUND;
} else {
shareData(key, privKey);
status = doGetSearchRecordNumber(lockMode);
endOperation(null, status, key, pKey, data);
}
return status;
}
public OperationStatus getNextDup(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
if (!initialized) {
throw new DatabaseException("Cursor not initialized");
}
OperationStatus status;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetNextDup(lockMode);
endOperation(null, status, null, null, null);
} else if (pkRange != null && pkRange.endKey != null) {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
status = doGetNextDup(lockMode);
if (status == OperationStatus.SUCCESS &&
!pkRange.checkEnd(privPKey, true)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
} else {
status = doGetNextDup(lockMode);
endOperation(null, status, key, pKey, data);
}
return status;
}
public OperationStatus getPrevDup(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
if (!initialized) {
throw new DatabaseException("Cursor not initialized");
}
OperationStatus status;
if (!range.hasBound()) {
setParams(key, pKey, data);
status = doGetPrevDup(lockMode);
endOperation(null, status, null, null, null);
} else if (pkRange != null && pkRange.beginKey != null) {
status = OperationStatus.NOTFOUND;
Cursor oldCursor = beginOperation();
try {
status = doGetPrevDup(lockMode);
if (status == OperationStatus.SUCCESS &&
!pkRange.checkBegin(privPKey, true)) {
status = OperationStatus.NOTFOUND;
}
} finally {
endOperation(oldCursor, status, key, pKey, data);
}
} else {
status = doGetPrevDup(lockMode);
endOperation(null, status, key, pKey, data);
}
return status;
}
public OperationStatus getCurrent(DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
if (!initialized) {
throw new DatabaseException("Cursor not initialized");
}
if (secCursor != null && pKey != null) {
return secCursor.getCurrent(key, pKey, data, lockMode);
} else {
return cursor.getCurrent(key, data, lockMode);
}
}
/*
* Pass-thru methods.
*/
public void close()
throws DatabaseException {
closeCursor(cursor);
}
public int count()
throws DatabaseException {
return cursor.count();
}
public OperationStatus delete()
throws DatabaseException {
return cursor.delete();
}
public OperationStatus put(DatabaseEntry key, DatabaseEntry data)
throws DatabaseException {
return cursor.put(key, data);
}
public OperationStatus putNoOverwrite(DatabaseEntry key,
DatabaseEntry data)
throws DatabaseException {
return cursor.putNoOverwrite(key, data);
}
public OperationStatus putNoDupData(DatabaseEntry key, DatabaseEntry data)
throws DatabaseException {
return cursor.putNoDupData(key, data);
}
public OperationStatus putCurrent(DatabaseEntry data)
throws DatabaseException {
return cursor.putCurrent(data);
}
public OperationStatus putAfter(DatabaseEntry key, DatabaseEntry data)
throws DatabaseException {
return DbCompat.putAfter(cursor, key, data);
}
public OperationStatus putBefore(DatabaseEntry key, DatabaseEntry data)
throws DatabaseException {
return DbCompat.putBefore(cursor, key, data);
}
private OperationStatus doGetFirst(LockMode lockMode)
throws DatabaseException {
if (secCursor != null && privPKey != null) {
return secCursor.getFirst(privKey, privPKey, privData, lockMode);
} else {
return cursor.getFirst(privKey, privData, lockMode);
}
}
private OperationStatus doGetLast(LockMode lockMode)
throws DatabaseException {
if (secCursor != null && privPKey != null) {
return secCursor.getLast(privKey, privPKey, privData, lockMode);
} else {
return cursor.getLast(privKey, privData, lockMode);
}
}
private OperationStatus doGetNext(LockMode lockMode)
throws DatabaseException {
if (secCursor != null && privPKey != null) {
return secCursor.getNext(privKey, privPKey, privData, lockMode);
} else {
return cursor.getNext(privKey, privData, lockMode);
}
}
private OperationStatus doGetNextDup(LockMode lockMode)
throws DatabaseException {
if (secCursor != null && privPKey != null) {
return secCursor.getNextDup(privKey, privPKey, privData, lockMode);
} else {
return cursor.getNextDup(privKey, privData, lockMode);
}
}
private OperationStatus doGetNextNoDup(LockMode lockMode)
throws DatabaseException {
if (secCursor != null && privPKey != null) {
return secCursor.getNextNoDup(privKey, privPKey, privData,
lockMode);
} else {
return cursor.getNextNoDup(privKey, privData, lockMode);
}
}
private OperationStatus doGetPrev(LockMode lockMode)
throws DatabaseException {
if (secCursor != null && privPKey != null) {
return secCursor.getPrev(privKey, privPKey, privData, lockMode);
} else {
return cursor.getPrev(privKey, privData, lockMode);
}
}
private OperationStatus doGetPrevDup(LockMode lockMode)
throws DatabaseException {
if (secCursor != null && privPKey != null) {
return secCursor.getPrevDup(privKey, privPKey, privData, lockMode);
} else {
return cursor.getPrevDup(privKey, privData, lockMode);
}
}
private OperationStatus doGetPrevNoDup(LockMode lockMode)
throws DatabaseException {
if (secCursor != null && privPKey != null) {
return secCursor.getPrevNoDup(privKey, privPKey, privData,
lockMode);
} else {
return cursor.getPrevNoDup(privKey, privData, lockMode);
}
}
private OperationStatus doGetSearchKey(LockMode lockMode)
throws DatabaseException {
if (checkRecordNumber() && DbCompat.getRecordNumber(privKey) <= 0) {
return OperationStatus.NOTFOUND;
}
if (secCursor != null && privPKey != null) {
return secCursor.getSearchKey(privKey, privPKey, privData,
lockMode);
} else {
return cursor.getSearchKey(privKey, privData, lockMode);
}
}
private OperationStatus doGetSearchKeyRange(LockMode lockMode)
throws DatabaseException {
if (checkRecordNumber() && DbCompat.getRecordNumber(privKey) <= 0) {
return OperationStatus.NOTFOUND;
}
if (secCursor != null && privPKey != null) {
return secCursor.getSearchKeyRange(privKey, privPKey, privData,
lockMode);
} else {
return cursor.getSearchKeyRange(privKey, privData, lockMode);
}
}
private OperationStatus doGetSearchBoth(LockMode lockMode)
throws DatabaseException {
if (checkRecordNumber() && DbCompat.getRecordNumber(privKey) <= 0) {
return OperationStatus.NOTFOUND;
}
if (secCursor != null && privPKey != null) {
return secCursor.getSearchBoth(privKey, privPKey, privData,
lockMode);
} else {
return cursor.getSearchBoth(privKey, privData, lockMode);
}
}
private OperationStatus doGetSearchBothRange(LockMode lockMode)
throws DatabaseException {
if (checkRecordNumber() && DbCompat.getRecordNumber(privKey) <= 0) {
return OperationStatus.NOTFOUND;
}
if (secCursor != null && privPKey != null) {
return secCursor.getSearchBothRange(privKey, privPKey,
privData, lockMode);
} else {
return cursor.getSearchBothRange(privKey, privData, lockMode);
}
}
private OperationStatus doGetSearchRecordNumber(LockMode lockMode)
throws DatabaseException {
if (DbCompat.getRecordNumber(privKey) <= 0) {
return OperationStatus.NOTFOUND;
}
if (secCursor != null && privPKey != null) {
return DbCompat.getSearchRecordNumber(secCursor, privKey, privPKey,
privData, lockMode);
} else {
return DbCompat.getSearchRecordNumber(cursor, privKey, privData,
lockMode);
}
}
/*
* Protected methods for duping and closing cursors. These are overridden
* by the collections API to implement cursor pooling for CDS.
*/
/**
* Dups the given cursor.
*/
protected Cursor dupCursor(Cursor cursor, boolean samePosition)
throws DatabaseException {
return cursor.dup(samePosition);
}
/**
* Closes the given cursor.
*/
protected void closeCursor(Cursor cursor)
throws DatabaseException {
cursor.close();
}
/**
* If the database is a RECNO or QUEUE database, we know its keys are
* record numbers. We treat a non-positive record number as out of bounds,
* that is, we return NOTFOUND rather than throwing
* IllegalArgumentException as would happen if we passed a non-positive
* record number into the DB cursor. This behavior is required by the
* collections interface.
*/
protected boolean checkRecordNumber() {
return false;
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/keyrange/KeyRange.java 0000444 0001750 0001750 00000023235 11320404642 025571 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2002,2010 Oracle. All rights reserved.
*
* $Id: KeyRange.java,v 1.9.2.2 2010/01/04 15:30:41 cwl Exp $
*/
package com.sleepycat.util.keyrange;
import java.util.Comparator;
import com.sleepycat.je.DatabaseEntry;
/**
* Encapsulates a key range for use with a RangeCursor.
*/
public class KeyRange {
/*
* We can return the same byte[] for 0 length arrays.
*/
public static final byte[] ZERO_LENGTH_BYTE_ARRAY = new byte[0];
Comparator comparator;
DatabaseEntry beginKey;
DatabaseEntry endKey;
boolean singleKey;
boolean beginInclusive;
boolean endInclusive;
/**
* Creates an unconstrained key range.
*/
public KeyRange(Comparator comparator) {
this.comparator = comparator;
}
/**
* Creates a range for a single key.
*/
public KeyRange subRange(DatabaseEntry key)
throws KeyRangeException {
if (!check(key)) {
throw new KeyRangeException("singleKey out of range");
}
KeyRange range = new KeyRange(comparator);
range.beginKey = key;
range.endKey = key;
range.beginInclusive = true;
range.endInclusive = true;
range.singleKey = true;
return range;
}
/**
* Creates a range that is the intersection of this range and the given
* range parameters.
*/
public KeyRange subRange(DatabaseEntry beginKey, boolean beginInclusive,
DatabaseEntry endKey, boolean endInclusive)
throws KeyRangeException {
if (beginKey == null) {
beginKey = this.beginKey;
beginInclusive = this.beginInclusive;
} else if (!check(beginKey, beginInclusive)) {
throw new KeyRangeException("beginKey out of range");
}
if (endKey == null) {
endKey = this.endKey;
endInclusive = this.endInclusive;
} else if (!check(endKey, endInclusive)) {
throw new KeyRangeException("endKey out of range");
}
KeyRange range = new KeyRange(comparator);
range.beginKey = beginKey;
range.endKey = endKey;
range.beginInclusive = beginInclusive;
range.endInclusive = endInclusive;
return range;
}
/**
* Returns whether this is a single-key range.
*/
public final boolean isSingleKey() {
return singleKey;
}
/**
* Returns the key of a single-key range, or null if not a single-key
* range.
*/
public final DatabaseEntry getSingleKey() {
return singleKey ? beginKey : null;
}
/**
* Returns whether this range has a begin or end bound.
*/
public final boolean hasBound() {
return endKey != null || beginKey != null;
}
/**
* Formats this range as a string for debugging.
*/
@Override
public String toString() {
return "[KeyRange " + beginKey + ' ' + beginInclusive +
endKey + ' ' + endInclusive +
(singleKey ? " single" : "");
}
/**
* Returns whether a given key is within range.
*/
public boolean check(DatabaseEntry key) {
if (singleKey) {
return (compare(key, beginKey) == 0);
} else {
return checkBegin(key, true) && checkEnd(key, true);
}
}
/**
* Returns whether a given key is within range.
*/
public boolean check(DatabaseEntry key, boolean inclusive) {
if (singleKey) {
return (compare(key, beginKey) == 0);
} else {
return checkBegin(key, inclusive) && checkEnd(key, inclusive);
}
}
/**
* Returns whether the given key is within range with respect to the
* beginning of the range.
*
*
The inclusive parameter should be true for checking a key read from
* the database; this will require that the key is within range. When
* inclusive=false the key is allowed to be equal to the beginKey for the
* range; this is used for checking a new exclusive bound of a
* sub-range.
*
*
Note that when inclusive=false and beginInclusive=true our check is
* not exactly correct because in theory we should allow the key to be "one
* less" than the existing bound; however, checking for "one less" is
* impossible so we do the best we can and test the bounds
* conservatively.
*/
public boolean checkBegin(DatabaseEntry key, boolean inclusive) {
if (beginKey == null) {
return true;
} else if (!beginInclusive && inclusive) {
return compare(key, beginKey) > 0;
} else {
return compare(key, beginKey) >= 0;
}
}
/**
* Returns whether the given key is within range with respect to the
* end of the range. See checkBegin for details.
*/
public boolean checkEnd(DatabaseEntry key, boolean inclusive) {
if (endKey == null) {
return true;
} else if (!endInclusive && inclusive) {
return compare(key, endKey) < 0;
} else {
return compare(key, endKey) <= 0;
}
}
/**
* Compares two keys, using the user comparator if there is one.
*/
public int compare(DatabaseEntry key1, DatabaseEntry key2) {
if (comparator != null) {
return comparator.compare(getByteArray(key1), getByteArray(key2));
} else {
return compareBytes
(key1.getData(), key1.getOffset(), key1.getSize(),
key2.getData(), key2.getOffset(), key2.getSize());
}
}
/**
* Copies a byte array.
*/
public static byte[] copyBytes(byte[] bytes) {
byte[] a = new byte[bytes.length];
System.arraycopy(bytes, 0, a, 0, a.length);
return a;
}
/**
* Compares two keys as unsigned byte arrays, which is the default
* comparison used by JE/DB.
*/
public static int compareBytes(byte[] data1, int offset1, int size1,
byte[] data2, int offset2, int size2) {
for (int i = 0; i < size1 && i < size2; i++) {
int b1 = 0xFF & data1[offset1 + i];
int b2 = 0xFF & data2[offset2 + i];
if (b1 < b2)
return -1;
else if (b1 > b2)
return 1;
}
if (size1 < size2)
return -1;
else if (size1 > size2)
return 1;
else
return 0;
}
/**
* Compares two byte arrays for equality.
*/
public static boolean equalBytes(byte[] data1, int offset1, int size1,
byte[] data2, int offset2, int size2) {
if (size1 != size2) {
return false;
}
for (int i = 0; i < size1; i += 1) {
if (data1[i + offset1] != data2[i + offset2]) {
return false;
}
}
return true;
}
/**
* Returns a copy of an entry.
*/
public static DatabaseEntry copy(DatabaseEntry from) {
return new DatabaseEntry(getByteArray(from));
}
/**
* Copies one entry to another.
*/
public static void copy(DatabaseEntry from, DatabaseEntry to) {
to.setData(getByteArray(from));
to.setOffset(0);
}
/**
* Returns an entry's byte array, copying it if the entry offset is
* non-zero.
*/
public static byte[] getByteArray(DatabaseEntry entry) {
return getByteArrayInternal(entry, Integer.MAX_VALUE);
}
public static byte[] getByteArray(DatabaseEntry entry, int maxBytes) {
return getByteArrayInternal(entry, maxBytes);
}
private static byte[] getByteArrayInternal(DatabaseEntry entry,
int maxBytes) {
byte[] bytes = entry.getData();
if (bytes == null) return null;
int size = Math.min(entry.getSize(), maxBytes);
byte[] data;
if (size == 0) {
data = ZERO_LENGTH_BYTE_ARRAY;
} else {
data = new byte[size];
System.arraycopy(bytes, entry.getOffset(), data, 0, size);
}
return data;
}
/**
* Returns the two DatabaseEntry objects have the same data value.
*/
public static boolean equalBytes(DatabaseEntry e1, DatabaseEntry e2) {
if (e1 == null && e2 == null) {
return true;
}
if (e1 == null || e2 == null) {
return false;
}
byte[] d1 = e1.getData();
byte[] d2 = e2.getData();
int s1 = e1.getSize();
int s2 = e2.getSize();
int o1 = e1.getOffset();
int o2 = e2.getOffset();
if (d1 == null && d2 == null) {
return true;
}
if (d1 == null || d2 == null) {
return false;
}
if (s1 != s2) {
return false;
}
for (int i = 0; i < s1; i += 1) {
if (d1[o1 + i] != d2[o2 + i]) {
return false;
}
}
return true;
}
/**
* Converts the byte array of this thang to space-separated integers,
* and suffixed by the record number if applicable.
*
* @param dbt the thang to convert.
*
* @return the resulting string.
*/
public static String toString(DatabaseEntry dbt) {
int len = dbt.getOffset() + dbt.getSize();
StringBuffer buf = new StringBuffer(len * 2);
byte[] data = dbt.getData();
for (int i = dbt.getOffset(); i < len; i++) {
String num = Integer.toHexString(data[i]);
if (num.length() < 2) buf.append('0');
buf.append(num);
}
return buf.toString();
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/package.html 0000444 0001750 0001750 00000000217 10032071636 023672 0 ustar twerner twerner
General utilities used throughout Berkeley DB.
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/ExceptionUnwrapper.java 0000444 0001750 0001750 00000003561 10740433454 026131 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: ExceptionUnwrapper.java,v 1.18 2008/01/07 14:29:00 cwl Exp $
*/
package com.sleepycat.util;
/**
* Unwraps nested exceptions by calling the {@link
* ExceptionWrapper#getCause()} method for exceptions that implement the
* {@link ExceptionWrapper} interface. Does not currently support the Java 1.4
* Throwable.getCause() method.
*
* @author Mark Hayes
*/
public class ExceptionUnwrapper {
/**
* Unwraps an Exception and returns the underlying Exception, or throws an
* Error if the underlying Throwable is an Error.
*
* @param e is the Exception to unwrap.
*
* @return the underlying Exception.
*
* @throws Error if the underlying Throwable is an Error.
*
* @throws IllegalArgumentException if the underlying Throwable is not an
* Exception or an Error.
*/
public static Exception unwrap(Exception e) {
Throwable t = unwrapAny(e);
if (t instanceof Exception) {
return (Exception) t;
} else if (t instanceof Error) {
throw (Error) t;
} else {
throw new IllegalArgumentException("Not Exception or Error: " + t);
}
}
/**
* Unwraps an Exception and returns the underlying Throwable.
*
* @param e is the Exception to unwrap.
*
* @return the underlying Throwable.
*/
public static Throwable unwrapAny(Throwable e) {
while (true) {
if (e instanceof ExceptionWrapper) {
Throwable e2 = ((ExceptionWrapper) e).getCause();
if (e2 == null) {
return e;
} else {
e = e2;
}
} else {
return e;
}
}
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/IOExceptionWrapper.java 0000444 0001750 0001750 00000001371 11023366142 026005 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: IOExceptionWrapper.java,v 1.20 2008/06/10 02:52:17 cwl Exp $
*/
package com.sleepycat.util;
import java.io.IOException;
/**
* An IOException that can contain nested exceptions.
*
* @author Mark Hayes
*/
public class IOExceptionWrapper
extends IOException implements ExceptionWrapper {
private Throwable e;
public IOExceptionWrapper(Throwable e) {
super(e.getMessage());
this.e = e;
}
/**
* @deprecated replaced by {@link #getCause}.
*/
public Throwable getDetail() {
return e;
}
@Override
public Throwable getCause() {
return e;
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/RuntimeExceptionWrapper.java 0000444 0001750 0001750 00000001364 11023366142 027123 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: RuntimeExceptionWrapper.java,v 1.19 2008/06/10 02:52:17 cwl Exp $
*/
package com.sleepycat.util;
/**
* A RuntimeException that can contain nested exceptions.
*
* @author Mark Hayes
*/
public class RuntimeExceptionWrapper extends RuntimeException
implements ExceptionWrapper {
private Throwable e;
public RuntimeExceptionWrapper(Throwable e) {
super(e.getMessage());
this.e = e;
}
/**
* @deprecated replaced by {@link #getCause}.
*/
public Throwable getDetail() {
return e;
}
@Override
public Throwable getCause() {
return e;
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/PackedInteger.java 0000444 0001750 0001750 00000026476 10740433454 025006 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: PackedInteger.java,v 1.8 2008/01/07 14:29:00 cwl Exp $
*/
package com.sleepycat.util;
/**
* Static methods for reading and writing packed integers.
*
*
Note that packed integers are not sorted naturally for a byte-by-byte
* comparison because they have a preceding length and are little endian;
* therefore, they are typically not used for keys.
*
*
Values in the inclusive range [-119,119] are stored in a single byte.
* For values outside that range, the first byte stores the sign and the number
* of additional bytes. The additional bytes store (abs(value) - 119) as an
* unsigned little endian integer.
*
*
To read and write packed integer values, call {@link #readInt} and {@link
* #writeInt} or for long values {@link #readLong} and {@link #writeLong}. To
* get the length of a packed integer without reading it, call {@link
* #getReadIntLength} or {@link #getReadLongLength}. To get the length of an
* unpacked integer without writing it, call {@link #getWriteIntLength} or
* {@link #getWriteLongLength}.
*
*
Because the same packed format is used for int and long values, stored
* int values may be expanded to long values without introducing a format
* incompatibility. You can treat previously stored packed int values as long
* values by calling {@link #readLong} and {@link #getReadLongLength}.
*
* @author Mark Hayes
*/
public class PackedInteger {
/**
* The maximum number of bytes needed to store an int value (5).
*/
public static final int MAX_LENGTH = 5;
/**
* The maximum number of bytes needed to store a long value (9).
*/
public static final int MAX_LONG_LENGTH = 9;
/**
* Reads a packed integer at the given buffer offset and returns it.
*
* @param buf the buffer to read from.
*
* @param off the offset in the buffer at which to start reading.
*
* @return the integer that was read.
*/
public static int readInt(byte[] buf, int off) {
boolean negative;
int byteLen;
int b1 = buf[off++];
if (b1 < -119) {
negative = true;
byteLen = -b1 - 119;
} else if (b1 > 119) {
negative = false;
byteLen = b1 - 119;
} else {
return b1;
}
int value = buf[off++] & 0xFF;
if (byteLen > 1) {
value |= (buf[off++] & 0xFF) << 8;
if (byteLen > 2) {
value |= (buf[off++] & 0xFF) << 16;
if (byteLen > 3) {
value |= (buf[off++] & 0xFF) << 24;
}
}
}
return negative ? (-value - 119) : (value + 119);
}
/**
* Reads a packed long integer at the given buffer offset and returns it.
*
* @param buf the buffer to read from.
*
* @param off the offset in the buffer at which to start reading.
*
* @return the long integer that was read.
*/
public static long readLong(byte[] buf, int off) {
boolean negative;
int byteLen;
int b1 = buf[off++];
if (b1 < -119) {
negative = true;
byteLen = -b1 - 119;
} else if (b1 > 119) {
negative = false;
byteLen = b1 - 119;
} else {
return b1;
}
long value = buf[off++] & 0xFFL;
if (byteLen > 1) {
value |= (buf[off++] & 0xFFL) << 8;
if (byteLen > 2) {
value |= (buf[off++] & 0xFFL) << 16;
if (byteLen > 3) {
value |= (buf[off++] & 0xFFL) << 24;
if (byteLen > 4) {
value |= (buf[off++] & 0xFFL) << 32;
if (byteLen > 5) {
value |= (buf[off++] & 0xFFL) << 40;
if (byteLen > 6) {
value |= (buf[off++] & 0xFFL) << 48;
if (byteLen > 7) {
value |= (buf[off++] & 0xFFL) << 56;
}
}
}
}
}
}
}
return negative ? (-value - 119) : (value + 119);
}
/**
* Returns the number of bytes that would be read by {@link #readInt}.
*
*
Because the length is stored in the first byte, this method may be
* called with only the first byte of the packed integer in the given
* buffer. This method only accesses one byte at the given offset.
*
* @param buf the buffer to read from.
*
* @param off the offset in the buffer at which to start reading.
*
* @return the number of bytes that would be read.
*/
public static int getReadIntLength(byte[] buf, int off) {
int b1 = buf[off];
if (b1 < -119) {
return -b1 - 119 + 1;
} else if (b1 > 119) {
return b1 - 119 + 1;
} else {
return 1;
}
}
/**
* Returns the number of bytes that would be read by {@link #readLong}.
*
*
Because the length is stored in the first byte, this method may be
* called with only the first byte of the packed integer in the given
* buffer. This method only accesses one byte at the given offset.
*
* @param buf the buffer to read from.
*
* @param off the offset in the buffer at which to start reading.
*
* @return the number of bytes that would be read.
*/
public static int getReadLongLength(byte[] buf, int off) {
/* The length is stored in the same way for int and long. */
return getReadIntLength(buf, off);
}
/**
* Writes a packed integer starting at the given buffer offset and returns
* the next offset to be written.
*
* @param buf the buffer to write to.
*
* @param offset the offset in the buffer at which to start writing.
*
* @param value the integer to be written.
*
* @return the offset past the bytes written.
*/
public static int writeInt(byte[] buf, int offset, int value) {
int byte1Off = offset;
boolean negative;
if (value < -119) {
negative = true;
value = -value - 119;
} else if (value > 119) {
negative = false;
value = value - 119;
} else {
buf[offset++] = (byte) value;
return offset;
}
offset++;
buf[offset++] = (byte) value;
if ((value & 0xFFFFFF00) == 0) {
buf[byte1Off] = negative ? (byte) -120 : (byte) 120;
return offset;
}
buf[offset++] = (byte) (value >>> 8);
if ((value & 0xFFFF0000) == 0) {
buf[byte1Off] = negative ? (byte) -121 : (byte) 121;
return offset;
}
buf[offset++] = (byte) (value >>> 16);
if ((value & 0xFF000000) == 0) {
buf[byte1Off] = negative ? (byte) -122 : (byte) 122;
return offset;
}
buf[offset++] = (byte) (value >>> 24);
buf[byte1Off] = negative ? (byte) -123 : (byte) 123;
return offset;
}
/**
* Writes a packed long integer starting at the given buffer offset and
* returns the next offset to be written.
*
* @param buf the buffer to write to.
*
* @param offset the offset in the buffer at which to start writing.
*
* @param value the long integer to be written.
*
* @return the offset past the bytes written.
*/
public static int writeLong(byte[] buf, int offset, long value) {
int byte1Off = offset;
boolean negative;
if (value < -119) {
negative = true;
value = -value - 119;
} else if (value > 119) {
negative = false;
value = value - 119;
} else {
buf[offset++] = (byte) value;
return offset;
}
offset++;
buf[offset++] = (byte) value;
if ((value & 0xFFFFFFFFFFFFFF00L) == 0) {
buf[byte1Off] = negative ? (byte) -120 : (byte) 120;
return offset;
}
buf[offset++] = (byte) (value >>> 8);
if ((value & 0xFFFFFFFFFFFF0000L) == 0) {
buf[byte1Off] = negative ? (byte) -121 : (byte) 121;
return offset;
}
buf[offset++] = (byte) (value >>> 16);
if ((value & 0xFFFFFFFFFF000000L) == 0) {
buf[byte1Off] = negative ? (byte) -122 : (byte) 122;
return offset;
}
buf[offset++] = (byte) (value >>> 24);
if ((value & 0xFFFFFFFF00000000L) == 0) {
buf[byte1Off] = negative ? (byte) -123 : (byte) 123;
return offset;
}
buf[offset++] = (byte) (value >>> 32);
if ((value & 0xFFFFFF0000000000L) == 0) {
buf[byte1Off] = negative ? (byte) -124 : (byte) 124;
return offset;
}
buf[offset++] = (byte) (value >>> 40);
if ((value & 0xFFFF000000000000L) == 0) {
buf[byte1Off] = negative ? (byte) -125 : (byte) 125;
return offset;
}
buf[offset++] = (byte) (value >>> 48);
if ((value & 0xFF00000000000000L) == 0) {
buf[byte1Off] = negative ? (byte) -126 : (byte) 126;
return offset;
}
buf[offset++] = (byte) (value >>> 56);
buf[byte1Off] = negative ? (byte) -127 : (byte) 127;
return offset;
}
/**
* Returns the number of bytes that would be written by {@link #writeInt}.
*
* @param value the integer to be written.
*
* @return the number of bytes that would be used to write the given
* integer.
*/
public static int getWriteIntLength(int value) {
if (value < -119) {
value = -value - 119;
} else if (value > 119) {
value = value - 119;
} else {
return 1;
}
if ((value & 0xFFFFFF00) == 0) {
return 2;
}
if ((value & 0xFFFF0000) == 0) {
return 3;
}
if ((value & 0xFF000000) == 0) {
return 4;
}
return 5;
}
/**
* Returns the number of bytes that would be written by {@link #writeLong}.
*
* @param value the long integer to be written.
*
* @return the number of bytes that would be used to write the given long
* integer.
*/
public static int getWriteLongLength(long value) {
if (value < -119) {
value = -value - 119;
} else if (value > 119) {
value = value - 119;
} else {
return 1;
}
if ((value & 0xFFFFFFFFFFFFFF00L) == 0) {
return 2;
}
if ((value & 0xFFFFFFFFFFFF0000L) == 0) {
return 3;
}
if ((value & 0xFFFFFFFFFF000000L) == 0) {
return 4;
}
if ((value & 0xFFFFFFFF00000000L) == 0) {
return 5;
}
if ((value & 0xFFFFFF0000000000L) == 0) {
return 6;
}
if ((value & 0xFFFF000000000000L) == 0) {
return 7;
}
if ((value & 0xFF00000000000000L) == 0) {
return 8;
}
return 9;
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/UtfOps.java 0000444 0001750 0001750 00000021747 10740433454 023515 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: UtfOps.java,v 1.19 2008/01/07 14:29:00 cwl Exp $
*/
package com.sleepycat.util;
/**
* UTF operations with more flexibility than is provided by DataInput and
* DataOutput.
*
* @author Mark Hayes
*/
public class UtfOps {
private static byte[] EMPTY_BYTES = {};
private static String EMPTY_STRING = "";
/**
* Returns the byte length of a null terminated UTF string, not including
* the terminator.
*
* @param bytes the data containing the UTF string.
*
* @param offset the beginning of the string the measure.
*
* @throws IndexOutOfBoundsException if no zero terminator is found.
*
* @return the number of bytes.
*/
public static int getZeroTerminatedByteLength(byte[] bytes, int offset)
throws IndexOutOfBoundsException {
int len = 0;
while (bytes[offset++] != 0) {
len++;
}
return len;
}
/**
* Returns the byte length of the UTF string that would be created by
* converting the given characters to UTF.
*
* @param chars the characters that would be converted.
*
* @return the byte length of the equivalent UTF data.
*/
public static int getByteLength(char[] chars) {
return getByteLength(chars, 0, chars.length);
}
/**
* Returns the byte length of the UTF string that would be created by
* converting the given characters to UTF.
*
* @param chars the characters that would be converted.
*
* @param offset the first character to be converted.
*
* @param length the number of characters to be converted.
*
* @return the byte length of the equivalent UTF data.
*/
public static int getByteLength(char[] chars, int offset, int length) {
int len = 0;
length += offset;
for (int i = offset; i < length; i++) {
int c = chars[i];
if ((c >= 0x0001) && (c <= 0x007F)) {
len++;
} else if (c > 0x07FF) {
len += 3;
} else {
len += 2;
}
}
return len;
}
/**
* Returns the number of characters represented by the given UTF string.
*
* @param bytes the UTF string.
*
* @return the number of characters.
*
* @throws IndexOutOfBoundsException if a UTF character sequence at the end
* of the data is not complete.
*
* @throws IllegalArgumentException if an illegal UTF sequence is
* encountered.
*/
public static int getCharLength(byte[] bytes)
throws IllegalArgumentException, IndexOutOfBoundsException {
return getCharLength(bytes, 0, bytes.length);
}
/**
* Returns the number of characters represented by the given UTF string.
*
* @param bytes the data containing the UTF string.
*
* @param offset the first byte to be converted.
*
* @param length the number of byte to be converted.
*
* @throws IndexOutOfBoundsException if a UTF character sequence at the end
* of the data is not complete.
*
* @throws IllegalArgumentException if an illegal UTF sequence is
* encountered.
*/
public static int getCharLength(byte[] bytes, int offset, int length)
throws IllegalArgumentException, IndexOutOfBoundsException {
int charCount = 0;
length += offset;
while (offset < length) {
switch ((bytes[offset] & 0xff) >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
offset++;
break;
case 12: case 13:
offset += 2;
break;
case 14:
offset += 3;
break;
default:
throw new IllegalArgumentException();
}
charCount++;
}
return charCount;
}
/**
* Converts byte arrays into character arrays.
*
* @param bytes the source byte data to convert
*
* @param byteOffset the offset into the byte array at which
* to start the conversion
*
* @param chars the destination array
*
* @param charOffset the offset into chars at which to begin the copy
*
* @param len the amount of information to copy into chars
*
* @param isByteLen if true then len is a measure of bytes, otherwise
* len is a measure of characters
*
* @throws IndexOutOfBoundsException if a UTF character sequence at the end
* of the data is not complete.
*
* @throws IllegalArgumentException if an illegal UTF sequence is
* encountered.
*/
public static int bytesToChars(byte[] bytes, int byteOffset,
char[] chars, int charOffset,
int len, boolean isByteLen)
throws IllegalArgumentException, IndexOutOfBoundsException {
int char1, char2, char3;
len += isByteLen ? byteOffset : charOffset;
while ((isByteLen ? byteOffset : charOffset) < len) {
char1 = bytes[byteOffset++] & 0xff;
switch ((char1 & 0xff) >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
chars[charOffset++] = (char) char1;
break;
case 12: case 13:
char2 = bytes[byteOffset++];
if ((char2 & 0xC0) != 0x80) {
throw new IllegalArgumentException();
}
chars[charOffset++] = (char)(((char1 & 0x1F) << 6) |
(char2 & 0x3F));
break;
case 14:
char2 = bytes[byteOffset++];
char3 = bytes[byteOffset++];
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
throw new IllegalArgumentException();
chars[charOffset++] = (char)(((char1 & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
default:
throw new IllegalArgumentException();
}
}
return byteOffset;
}
/**
* Converts character arrays into byte arrays.
*
* @param chars the source character data to convert
*
* @param charOffset the offset into the character array at which
* to start the conversion
*
* @param bytes the destination array
*
* @param byteOffset the offset into bytes at which to begin the copy
*
* @param charLength the length of characters to copy into bytes
*/
public static void charsToBytes(char[] chars, int charOffset,
byte[] bytes, int byteOffset,
int charLength) {
charLength += charOffset;
for (int i = charOffset; i < charLength; i++) {
int c = chars[i];
if ((c >= 0x0001) && (c <= 0x007F)) {
bytes[byteOffset++] = (byte) c;
} else if (c > 0x07FF) {
bytes[byteOffset++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
bytes[byteOffset++] = (byte) (0x80 | ((c >> 6) & 0x3F));
bytes[byteOffset++] = (byte) (0x80 | ((c >> 0) & 0x3F));
} else {
bytes[byteOffset++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
bytes[byteOffset++] = (byte) (0x80 | ((c >> 0) & 0x3F));
}
}
}
/**
* Converts byte arrays into strings.
*
* @param bytes the source byte data to convert
*
* @param offset the offset into the byte array at which
* to start the conversion
*
* @param length the number of bytes to be converted.
*
* @return the string.
*
* @throws IndexOutOfBoundsException if a UTF character sequence at the end
* of the data is not complete.
*
* @throws IllegalArgumentException if an illegal UTF sequence is
* encountered.
*/
public static String bytesToString(byte[] bytes, int offset, int length)
throws IllegalArgumentException, IndexOutOfBoundsException {
if (length == 0) return EMPTY_STRING;
int charLen = UtfOps.getCharLength(bytes, offset, length);
char[] chars = new char[charLen];
UtfOps.bytesToChars(bytes, offset, chars, 0, length, true);
return new String(chars, 0, charLen);
}
/**
* Converts strings to byte arrays.
*
* @param string the string to convert.
*
* @return the UTF byte array.
*/
public static byte[] stringToBytes(String string) {
if (string.length() == 0) return EMPTY_BYTES;
char[] chars = string.toCharArray();
byte[] bytes = new byte[UtfOps.getByteLength(chars)];
UtfOps.charsToBytes(chars, 0, bytes, 0, chars.length);
return bytes;
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/ExceptionWrapper.java 0000444 0001750 0001750 00000002070 10740433454 025560 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: ExceptionWrapper.java,v 1.18 2008/01/07 14:29:00 cwl Exp $
*/
package com.sleepycat.util;
/**
* Interface implemented by exceptions that can contain nested exceptions.
*
* @author Mark Hayes
*/
public interface ExceptionWrapper {
/**
* Returns the nested exception or null if none is present.
*
* @return the nested exception or null if none is present.
*
* @deprecated replaced by {@link #getCause}.
*/
Throwable getDetail();
/**
* Returns the nested exception or null if none is present.
*
*
This method is intentionally defined to be the same signature as the
* java.lang.Throwable.getCause method in Java 1.4 and
* greater. By defining this method to return a nested exception, the Java
* 1.4 runtime will print the nested stack trace.
*
* @return the nested exception or null if none is present.
*/
Throwable getCause();
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/FastInputStream.java 0000444 0001750 0001750 00000010313 11023366142 025343 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: FastInputStream.java,v 1.21 2008/06/10 02:52:17 cwl Exp $
*/
package com.sleepycat.util;
import java.io.IOException;
import java.io.InputStream;
/**
* A replacement for ByteArrayInputStream that does not synchronize every
* byte read.
*
*
This class extends {@link InputStream} and its read()
* methods allow it to be used as a standard input stream. In addition, it
* provides readFast() methods that are not declared to throw
* IOException. IOException is never thrown by this
* class.
*
* @author Mark Hayes
*/
public class FastInputStream extends InputStream {
protected int len;
protected int off;
protected int mark;
protected byte[] buf;
/**
* Creates an input stream.
*
* @param buffer the data to read.
*/
public FastInputStream(byte[] buffer) {
buf = buffer;
len = buffer.length;
}
/**
* Creates an input stream.
*
* @param buffer the data to read.
*
* @param offset the byte offset at which to begin reading.
*
* @param length the number of bytes to read.
*/
public FastInputStream(byte[] buffer, int offset, int length) {
buf = buffer;
off = offset;
len = offset + length;
}
// --- begin ByteArrayInputStream compatible methods ---
@Override
public int available() {
return len - off;
}
@Override
public boolean markSupported() {
return true;
}
@Override
public void mark(int readLimit) {
mark = off;
}
@Override
public void reset() {
off = mark;
}
@Override
public long skip(long count) {
int myCount = (int) count;
if (myCount + off > len) {
myCount = len - off;
}
skipFast(myCount);
return myCount;
}
@Override
public int read() throws IOException {
return readFast();
}
@Override
public int read(byte[] toBuf) throws IOException {
return readFast(toBuf, 0, toBuf.length);
}
@Override
public int read(byte[] toBuf, int offset, int length) throws IOException {
return readFast(toBuf, offset, length);
}
// --- end ByteArrayInputStream compatible methods ---
/**
* Equivalent to skip() but takes an int parameter instead of a
* long, and does not check whether the count given is larger than the
* number of remaining bytes.
* @see #skip(long)
*/
public final void skipFast(int count) {
off += count;
}
/**
* Equivalent to read() but does not throw
* IOException.
* @see #read()
*/
public final int readFast() {
return (off < len) ? (buf[off++] & 0xff) : (-1);
}
/**
* Equivalent to read(byte[]) but does not throw
* IOException.
* @see #read(byte[])
*/
public final int readFast(byte[] toBuf) {
return readFast(toBuf, 0, toBuf.length);
}
/**
* Equivalent to read(byte[],int,int) but does not throw
* IOException.
* @see #read(byte[],int,int)
*/
public final int readFast(byte[] toBuf, int offset, int length) {
int avail = len - off;
if (avail <= 0) {
return -1;
}
if (length > avail) {
length = avail;
}
System.arraycopy(buf, off, toBuf, offset, length);
off += length;
return length;
}
/**
* Returns the underlying data being read.
*
* @return the underlying data.
*/
public final byte[] getBufferBytes() {
return buf;
}
/**
* Returns the offset at which data is being read from the buffer.
*
* @return the offset at which data is being read.
*/
public final int getBufferOffset() {
return off;
}
/**
* Returns the end of the buffer being read.
*
* @return the end of the buffer.
*/
public final int getBufferLength() {
return len;
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/util/FastOutputStream.java 0000444 0001750 0001750 00000015071 11023366142 025552 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: FastOutputStream.java,v 1.24 2008/06/10 02:52:17 cwl Exp $
*/
package com.sleepycat.util;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
/**
* A replacement for ByteArrayOutputStream that does not synchronize every
* byte read.
*
*
This class extends {@link OutputStream} and its write()
* methods allow it to be used as a standard output stream. In addition, it
* provides writeFast() methods that are not declared to throw
* IOException. IOException is never thrown by this
* class.
*
* @author Mark Hayes
*/
public class FastOutputStream extends OutputStream {
/**
* The default initial size of the buffer if no initialSize parameter is
* specified. This constant is 100 bytes.
*/
public static final int DEFAULT_INIT_SIZE = 100;
/**
* The default amount that the buffer is increased when it is full. This
* constant is zero, which means to double the current buffer size.
*/
public static final int DEFAULT_BUMP_SIZE = 0;
private int len;
private int bumpLen;
private byte[] buf;
/*
* We can return the same byte[] for 0 length arrays.
*/
private static byte[] ZERO_LENGTH_BYTE_ARRAY = new byte[0];
/**
* Creates an output stream with default sizes.
*/
public FastOutputStream() {
initBuffer(DEFAULT_INIT_SIZE, DEFAULT_BUMP_SIZE);
}
/**
* Creates an output stream with a default bump size and a given initial
* size.
*
* @param initialSize the initial size of the buffer.
*/
public FastOutputStream(int initialSize) {
initBuffer(initialSize, DEFAULT_BUMP_SIZE);
}
/**
* Creates an output stream with a given bump size and initial size.
*
* @param initialSize the initial size of the buffer.
*
* @param bumpSize the amount to increment the buffer.
*/
public FastOutputStream(int initialSize, int bumpSize) {
initBuffer(initialSize, bumpSize);
}
/**
* Creates an output stream with a given initial buffer and a default
* bump size.
*
* @param buffer the initial buffer; will be owned by this object.
*/
public FastOutputStream(byte[] buffer) {
buf = buffer;
bumpLen = DEFAULT_BUMP_SIZE;
}
/**
* Creates an output stream with a given initial buffer and a given
* bump size.
*
* @param buffer the initial buffer; will be owned by this object.
*
* @param bumpSize the amount to increment the buffer. If zero (the
* default), the current buffer size will be doubled when the buffer is
* full.
*/
public FastOutputStream(byte[] buffer, int bumpSize) {
buf = buffer;
bumpLen = bumpSize;
}
private void initBuffer(int bufferSize, int bumpLen) {
buf = new byte[bufferSize];
this.bumpLen = bumpLen;
}
// --- begin ByteArrayOutputStream compatible methods ---
public int size() {
return len;
}
public void reset() {
len = 0;
}
public void write(int b) throws IOException {
writeFast(b);
}
@Override
public void write(byte[] fromBuf) throws IOException {
writeFast(fromBuf);
}
@Override
public void write(byte[] fromBuf, int offset, int length)
throws IOException {
writeFast(fromBuf, offset, length);
}
public void writeTo(OutputStream out) throws IOException {
out.write(buf, 0, len);
}
@Override
public String toString() {
return new String(buf, 0, len);
}
public String toString(String encoding)
throws UnsupportedEncodingException {
return new String(buf, 0, len, encoding);
}
public byte[] toByteArray() {
if (len == 0) {
return ZERO_LENGTH_BYTE_ARRAY;
} else {
byte[] toBuf = new byte[len];
System.arraycopy(buf, 0, toBuf, 0, len);
return toBuf;
}
}
// --- end ByteArrayOutputStream compatible methods ---
/**
* Equivalent to write(int) but does not throw
* IOException.
* @see #write(int)
*/
public final void writeFast(int b) {
if (len + 1 > buf.length)
bump(1);
buf[len++] = (byte) b;
}
/**
* Equivalent to write(byte[]) but does not throw
* IOException.
* @see #write(byte[])
*/
public final void writeFast(byte[] fromBuf) {
int needed = len + fromBuf.length - buf.length;
if (needed > 0)
bump(needed);
System.arraycopy(fromBuf, 0, buf, len, fromBuf.length);
len += fromBuf.length;
}
/**
* Equivalent to write(byte[],int,int) but does not throw
* IOException.
* @see #write(byte[],int,int)
*/
public final void writeFast(byte[] fromBuf, int offset, int length) {
int needed = len + length - buf.length;
if (needed > 0)
bump(needed);
System.arraycopy(fromBuf, offset, buf, len, length);
len += length;
}
/**
* Returns the buffer owned by this object.
*
* @return the buffer.
*/
public byte[] getBufferBytes() {
return buf;
}
/**
* Returns the offset of the internal buffer.
*
* @return always zero currently.
*/
public int getBufferOffset() {
return 0;
}
/**
* Returns the length used in the internal buffer, i.e., the offset at
* which data will be written next.
*
* @return the buffer length.
*/
public int getBufferLength() {
return len;
}
/**
* Ensure that at least the given number of bytes are available in the
* internal buffer.
*
* @param sizeNeeded the number of bytes desired.
*/
public void makeSpace(int sizeNeeded) {
int needed = len + sizeNeeded - buf.length;
if (needed > 0)
bump(needed);
}
/**
* Skip the given number of bytes in the buffer.
*
* @param sizeAdded number of bytes to skip.
*/
public void addSize(int sizeAdded) {
len += sizeAdded;
}
private void bump(int needed) {
/* Double the buffer if the bumpLen is zero. */
int bump = (bumpLen > 0) ? bumpLen : buf.length;
byte[] toBuf = new byte[buf.length + needed + bump];
System.arraycopy(buf, 0, toBuf, 0, len);
buf = toBuf;
}
}
libdb-je-java-3.3.98.orig/src/com/sleepycat/collections/ 0000755 0001750 0001750 00000000000 11353143624 022760 5 ustar twerner twerner libdb-je-java-3.3.98.orig/src/com/sleepycat/collections/StoredCollection.java 0000444 0001750 0001750 00000047006 11017024432 027074 0 ustar twerner twerner /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2000,2008 Oracle. All rights reserved.
*
* $Id: StoredCollection.java,v 1.46 2008/05/27 15:30:34 mark Exp $
*/
package com.sleepycat.collections;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import com.sleepycat.compat.DbCompat;
import com.sleepycat.je.CursorConfig;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.JoinConfig;
import com.sleepycat.je.OperationStatus;
/**
* A abstract base class for all stored collections. This class, and its
* base class {@link StoredContainer}, provide implementations of most methods
* in the {@link Collection} interface. Other methods, such as {@link #add}
* and {@link #remove}, are provided by concrete classes that extend this
* class.
*
*
In addition, this class provides the following methods for stored
* collections only. Note that the use of these methods is not compatible with
* the standard Java collections interface.
*
*
{@link #getIteratorBlockSize}
*
{@link #setIteratorBlockSize}
*
{@link #storedIterator()}
*
{@link #storedIterator(boolean)}
*
{@link #join}
*
{@link #toList()}
*
*
* @author Mark Hayes
*/
public abstract class StoredCollection extends StoredContainer
implements Collection {
/**
* The default number of records read at one time by iterators.
* @see #setIteratorBlockSize
*/
public static final int DEFAULT_ITERATOR_BLOCK_SIZE = 10;
private int iteratorBlockSize = DEFAULT_ITERATOR_BLOCK_SIZE;
StoredCollection(DataView view) {
super(view);
}
/**
* Returns the number of records read at one time by iterators returned by
* the {@link #iterator} method. By default this value is {@link
* #DEFAULT_ITERATOR_BLOCK_SIZE}.
*/
public int getIteratorBlockSize() {
return iteratorBlockSize;
}
/**
* Changes the number of records read at one time by iterators returned by
* the {@link #iterator} method. By default this value is {@link
* #DEFAULT_ITERATOR_BLOCK_SIZE}.
*
* @throws IllegalArgumentException if the blockSize is less than two.
*/
public void setIteratorBlockSize(int blockSize) {
if (blockSize < 2) {
throw new IllegalArgumentException
("blockSize is less than two: " + blockSize);
}
iteratorBlockSize = blockSize;
}
final boolean add(Object key, Object value) {
DataCursor cursor = null;
boolean doAutoCommit = beginAutoCommit();
try {
cursor = new DataCursor(view, true);
OperationStatus status =
cursor.putNoDupData(key, value, null, false);
closeCursor(cursor);
commitAutoCommit(doAutoCommit);
return (status == OperationStatus.SUCCESS);
} catch (Exception e) {
closeCursor(cursor);
throw handleException(e, doAutoCommit);
}
}
BlockIterator blockIterator() {
return new BlockIterator(this, isWriteAllowed(), iteratorBlockSize);
}
/**
* Returns an iterator over the elements in this collection.
* The iterator will be read-only if the collection is read-only.
* This method conforms to the {@link Collection#iterator} interface.
*
*
The iterator returned by this method does not keep a database cursor
* open and therefore it does not need to be closed. It reads blocks of
* records as needed, opening and closing a cursor to read each block of
* records. The number of records per block is 10 by default and can be
* changed with {@link #setIteratorBlockSize}.
*
*
Because this iterator does not keep a cursor open, if it is used
* without transactions, the iterator does not have cursor
* stability characteristics. In other words, the record at the
* current iterator position can be changed or deleted by another thread.
* To prevent this from happening, call this method within a transaction or
* use the {@link #storedIterator()} method instead.
*
* @return a standard {@link Iterator} for this collection.
*
* @see #isWriteAllowed
*/
public Iterator iterator() {
return blockIterator();
}
/**
* Returns an iterator over the elements in this collection.
* The iterator will be read-only if the collection is read-only.
* This method does not exist in the standard {@link Collection} interface.
*
*
If {@code Iterator.set} or {@code Iterator.remove} will be called
* and the underlying Database is transactional, then a transaction must be
* active when calling this method and must remain active while using the
* iterator.
*
*
Warning: The iterator returned must be explicitly
* closed using {@link StoredIterator#close()} or {@link
* StoredIterator#close(java.util.Iterator)} to release the underlying
* database cursor resources.
*
* @return a {@link StoredIterator} for this collection.
*
* @see #isWriteAllowed
*/
public StoredIterator storedIterator() {
return storedIterator(isWriteAllowed());
}
/**
* Returns a read or read-write iterator over the elements in this
* collection.
* This method does not exist in the standard {@link Collection} interface.
*
*
If {@code Iterator.set} or {@code Iterator.remove} will be called
* and the underlying Database is transactional, then a transaction must be
* active when calling this method and must remain active while using the
* iterator.
*
*
Warning: The iterator returned must be explicitly
* closed using {@link StoredIterator#close()} or {@link
* StoredIterator#close(java.util.Iterator)} to release the underlying
* database cursor resources.
*
* @param writeAllowed is true to open a read-write iterator or false to
* open a read-only iterator. If the collection is read-only the iterator
* will always be read-only.
*
* @return a {@link StoredIterator} for this collection.
*
* @throws IllegalStateException if writeAllowed is true but the collection
* is read-only.
*
* @throws RuntimeExceptionWrapper if a {@link DatabaseException} is
* thrown.
*
* @see #isWriteAllowed
*/
public StoredIterator storedIterator(boolean writeAllowed) {
try {
return new StoredIterator(this, writeAllowed && isWriteAllowed(),
null);
} catch (Exception e) {
throw StoredContainer.convertException(e);
}
}
/**
* @deprecated Please use {@link #storedIterator()} or {@link
* #storedIterator(boolean)} instead. Because the iterator returned must
* be closed, the method name {@code iterator} is confusing since standard
* Java iterators do not need to be closed.
*/
public StoredIterator iterator(boolean writeAllowed) {
return storedIterator(writeAllowed);
}
/**
* Returns an array of all the elements in this collection.
* This method conforms to the {@link Collection#toArray()} interface.
*
* @throws RuntimeExceptionWrapper if a {@link DatabaseException} is
* thrown.
*/
public Object[] toArray() {
ArrayList