libjdbm-java-1.0.orig/ 0000775 0001750 0001750 00000000000 10276576000 014576 5 ustar twerner twerner libjdbm-java-1.0.orig/lib/ 0000775 0001750 0001750 00000000000 10276576000 015344 5 ustar twerner twerner libjdbm-java-1.0.orig/src/ 0000775 0001750 0001750 00000000000 10276576000 015365 5 ustar twerner twerner libjdbm-java-1.0.orig/src/etc/ 0000775 0001750 0001750 00000000000 10276576000 016140 5 ustar twerner twerner libjdbm-java-1.0.orig/src/etc/MANIFEST.MF 0000644 0001750 0001750 00000000357 10276576000 017575 0 ustar twerner twerner Manifest-Version: 1.0 Specification-Title: JDBM Specification-Vendor: JDBM at SourceForge Project Specification-Version: 0.09 Implementation-Title: JDBM Implementation-Vendor: JDBM at SourceForge Project Implementation-Version: $VERSION$ libjdbm-java-1.0.orig/src/examples/ 0000775 0001750 0001750 00000000000 10276576000 017203 5 ustar twerner twerner libjdbm-java-1.0.orig/src/examples/FamousPeople.java 0000644 0001750 0001750 00000011431 10276576000 022443 0 ustar twerner twerner import java.util.Properties; import jdbm.RecordManager; import jdbm.RecordManagerFactory; import jdbm.helper.Tuple; import jdbm.helper.TupleBrowser; import jdbm.helper.StringComparator; import jdbm.btree.BTree; /** * Famous People example. *
* Demonstrates the use of B+Tree data structure to manage a list of
* people and their occupation. The example covers insertion,
* ordered traversal, reverse traversal and range lookup of records.
*
* @author Alex Boisvert
* @version $Id: FamousPeople.java,v 1.6 2003/10/21 15:32:02 boisvert Exp $
*/
public class FamousPeople {
static String DATABASE = "people";
static String BTREE_NAME = "FamousPeople";
static String[] people =
{ "Greenspan, Alan",
"Williams-Byrd, Julie",
"Picasso, Pablo",
"Stallman, Richard",
"Fort, Paul",
"Søndergaard, Ole",
"Schwarzenegger, Arnold",
"Dulkinys, Susanna" };
static String[] occupations =
{ "Federal Reserve Board Chairman",
"Engineer",
"Painter",
"Programmer",
"Poet",
"Typographer",
"Actor",
"Designer" };
static String PREFIX = "S";
/**
* Example main entrypoint.
*/
public static void main( String[] args ) {
RecordManager recman;
long recid;
Tuple tuple = new Tuple();
TupleBrowser browser;
BTree tree;
Properties props;
props = new Properties();
try {
// open database and setup an object cache
recman = RecordManagerFactory.createRecordManager( DATABASE, props );
// try to reload an existing B+Tree
recid = recman.getNamedObject( BTREE_NAME );
if ( recid != 0 ) {
tree = BTree.load( recman, recid );
System.out.println( "Reloaded existing BTree with " + tree.size()
+ " famous people." );
} else {
// create a new B+Tree data structure and use a StringComparator
// to order the records based on people's name.
tree = BTree.createInstance( recman, new StringComparator() );
recman.setNamedObject( BTREE_NAME, tree.getRecid() );
System.out.println( "Created a new empty BTree" );
}
// insert people with their respective occupation
System.out.println();
for ( int i=0; i
* The page contains a number of key-value pairs. Keys are ordered to allow
* dichotomic search.
*
* If the page is a leaf page, the keys and values are user-defined and
* represent entries inserted by the user.
*
* If the page is non-leaf, each key represents the greatest key in the
* underlying BPages and the values are recids pointing to the children BPages.
* The only exception is the rightmost BPage, which is considered to have an
* "infinite" key value, meaning that any insert will be to the left of this
* pseudo-key
*
* @author Alex Boisvert
* @version $Id: BPage.java,v 1.6 2003/09/21 15:46:59 boisvert Exp $
*/
public final class BPage
implements Serializer
{
private static final boolean DEBUG = false;
/**
* Version id for serialization.
*/
final static long serialVersionUID = 1L;
/**
* Parent B+Tree.
*/
transient BTree _btree;
/**
* This BPage's record ID in the PageManager.
*/
protected transient long _recid;
/**
* Flag indicating if this is a leaf BPage.
*/
protected boolean _isLeaf;
/**
* Keys of children nodes
*/
protected Object[] _keys;
/**
* Values associated with keys. (Only valid if leaf BPage)
*/
protected Object[] _values;
/**
* Children pages (recids) associated with keys. (Only valid if non-leaf BPage)
*/
protected long[] _children;
/**
* Index of first used item at the page
*/
protected int _first;
/**
* Previous leaf BPage (only if this BPage is a leaf)
*/
protected long _previous;
/**
* Next leaf BPage (only if this BPage is a leaf)
*/
protected long _next;
/**
* No-argument constructor used by serialization.
*/
public BPage()
{
// empty
}
/**
* Root page overflow constructor
*/
BPage( BTree btree, BPage root, BPage overflow )
throws IOException
{
_btree = btree;
_isLeaf = false;
_first = _btree._pageSize-2;
_keys = new Object[ _btree._pageSize ];
_keys[ _btree._pageSize-2 ] = overflow.getLargestKey();
_keys[ _btree._pageSize-1 ] = root.getLargestKey();
_children = new long[ _btree._pageSize ];
_children[ _btree._pageSize-2 ] = overflow._recid;
_children[ _btree._pageSize-1 ] = root._recid;
_recid = _btree._recman.insert( this, this );
}
/**
* Root page (first insert) constructor.
*/
BPage( BTree btree, Object key, Object value )
throws IOException
{
_btree = btree;
_isLeaf = true;
_first = btree._pageSize-2;
_keys = new Object[ _btree._pageSize ];
_keys[ _btree._pageSize-2 ] = key;
_keys[ _btree._pageSize-1 ] = null; // I am the root BPage for now
_values = new Object[ _btree._pageSize ];
_values[ _btree._pageSize-2 ] = value;
_values[ _btree._pageSize-1 ] = null; // I am the root BPage for now
_recid = _btree._recman.insert( this, this );
}
/**
* Overflow page constructor. Creates an empty BPage.
*/
BPage( BTree btree, boolean isLeaf )
throws IOException
{
_btree = btree;
_isLeaf = isLeaf;
// page will initially be half-full
_first = _btree._pageSize/2;
_keys = new Object[ _btree._pageSize ];
if ( isLeaf ) {
_values = new Object[ _btree._pageSize ];
} else {
_children = new long[ _btree._pageSize ];
}
_recid = _btree._recman.insert( this, this );
}
/**
* Get largest key under this BPage. Null is considered to be the
* greatest possible key.
*/
Object getLargestKey()
{
return _keys[ _btree._pageSize-1 ];
}
/**
* Return true if BPage is empty.
*/
boolean isEmpty()
{
if ( _isLeaf ) {
return ( _first == _values.length-1 );
} else {
return ( _first == _children.length-1 );
}
}
/**
* Return true if BPage is full.
*/
boolean isFull() {
return ( _first == 0 );
}
/**
* Find the object associated with the given key.
*
* @param height Height of the current BPage (zero is leaf page)
* @param key The key
* @return TupleBrowser positionned just before the given key, or before
* next greater key if key isn't found.
*/
TupleBrowser find( int height, Object key )
throws IOException
{
int index = findChildren( key );
/*
if ( DEBUG ) {
System.out.println( "BPage.find() current: " + this
+ " height: " + height);
}
*/
height -= 1;
if ( height == 0 ) {
// leaf BPage
return new Browser( this, index );
} else {
// non-leaf BPage
BPage child = childBPage( index );
return child.find( height, key );
}
}
/**
* Find first entry and return a browser positioned before it.
*
* @return TupleBrowser positionned just before the first entry.
*/
TupleBrowser findFirst()
throws IOException
{
if ( _isLeaf ) {
return new Browser( this, _first );
} else {
BPage child = childBPage( _first );
return child.findFirst();
}
}
/**
* Insert the given key and value.
*
* Since the Btree does not support duplicate entries, the caller must
* specify whether to replace the existing value.
*
* @param height Height of the current BPage (zero is leaf page)
* @param key Insert key
* @param value Insert value
* @param replace Set to true to replace the existing value, if one exists.
* @return Insertion result containing existing value OR a BPage if the key
* was inserted and provoked a BPage overflow.
*/
InsertResult insert( int height, Object key, Object value, boolean replace )
throws IOException
{
InsertResult result;
long overflow;
int index = findChildren( key );
height -= 1;
if ( height == 0 ) {
result = new InsertResult();
// inserting on a leaf BPage
overflow = -1;
if ( DEBUG ) {
System.out.println( "Bpage.insert() Insert on leaf Bpage key=" + key
+ " value=" + value + " index="+index);
}
if ( compare( key, _keys[ index ] ) == 0 ) {
// key already exists
if ( DEBUG ) {
System.out.println( "Bpage.insert() Key already exists." ) ;
}
result._existing = _values[ index ];
if ( replace ) {
_values [ index ] = value;
_btree._recman.update( _recid, this, this );
}
// return the existing key
return result;
}
} else {
// non-leaf BPage
BPage child = childBPage( index );
result = child.insert( height, key, value, replace );
if ( result._existing != null ) {
// return existing key, if any.
return result;
}
if ( result._overflow == null ) {
// no overflow means we're done with insertion
return result;
}
// there was an overflow, we need to insert the overflow page
// on this BPage
if ( DEBUG ) {
System.out.println( "BPage.insert() Overflow page: " + result._overflow._recid );
}
key = result._overflow.getLargestKey();
overflow = result._overflow._recid;
// update child's largest key
_keys[ index ] = child.getLargestKey();
// clean result so we can reuse it
result._overflow = null;
}
// if we get here, we need to insert a new entry on the BPage
// before _children[ index ]
if ( !isFull() ) {
if ( height == 0 ) {
insertEntry( this, index-1, key, value );
} else {
insertChild( this, index-1, key, overflow );
}
_btree._recman.update( _recid, this, this );
return result;
}
// page is full, we must divide the page
int half = _btree._pageSize >> 1;
BPage newPage = new BPage( _btree, _isLeaf );
if ( index < half ) {
// move lower-half of entries to overflow BPage,
// including new entry
if ( DEBUG ) {
System.out.println( "Bpage.insert() move lower-half of entries to overflow BPage, including new entry." ) ;
}
if ( height == 0 ) {
copyEntries( this, 0, newPage, half, index );
setEntry( newPage, half+index, key, value );
copyEntries( this, index, newPage, half+index+1, half-index-1 );
} else {
copyChildren( this, 0, newPage, half, index );
setChild( newPage, half+index, key, overflow );
copyChildren( this, index, newPage, half+index+1, half-index-1 );
}
} else {
// move lower-half of entries to overflow BPage,
// new entry stays on this BPage
if ( DEBUG ) {
System.out.println( "Bpage.insert() move lower-half of entries to overflow BPage. New entry stays" ) ;
}
if ( height == 0 ) {
copyEntries( this, 0, newPage, half, half );
copyEntries( this, half, this, half-1, index-half );
setEntry( this, index-1, key, value );
} else {
copyChildren( this, 0, newPage, half, half );
copyChildren( this, half, this, half-1, index-half );
setChild( this, index-1, key, overflow );
}
}
_first = half-1;
// nullify lower half of entries
for ( int i=0; i<_first; i++ ) {
if ( height == 0 ) {
setEntry( this, i, null, null );
} else {
setChild( this, i, null, -1 );
}
}
if ( _isLeaf ) {
// link newly created BPage
newPage._previous = _previous;
newPage._next = _recid;
if ( _previous != 0 ) {
BPage previous = loadBPage( _previous );
previous._next = newPage._recid;
_btree._recman.update( _previous, previous, this );
}
_previous = newPage._recid;
}
_btree._recman.update( _recid, this, this );
_btree._recman.update( newPage._recid, newPage, this );
result._overflow = newPage;
return result;
}
/**
* Remove the entry associated with the given key.
*
* @param height Height of the current BPage (zero is leaf page)
* @param key Removal key
* @return Remove result object
*/
RemoveResult remove( int height, Object key )
throws IOException
{
RemoveResult result;
int half = _btree._pageSize / 2;
int index = findChildren( key );
height -= 1;
if ( height == 0 ) {
// remove leaf entry
if ( compare( _keys[ index ], key ) != 0 ) {
throw new IllegalArgumentException( "Key not found: " + key );
}
result = new RemoveResult();
result._value = _values[ index ];
removeEntry( this, index );
// update this BPage
_btree._recman.update( _recid, this, this );
} else {
// recurse into Btree to remove entry on a children page
BPage child = childBPage( index );
result = child.remove( height, key );
// update children
_keys[ index ] = child.getLargestKey();
_btree._recman.update( _recid, this, this );
if ( result._underflow ) {
// underflow occured
if ( child._first != half+1 ) {
throw new IllegalStateException( "Error during underflow [1]" );
}
if ( index < _children.length-1 ) {
// exists greater brother page
BPage brother = childBPage( index+1 );
int bfirst = brother._first;
if ( bfirst < half ) {
// steal entries from "brother" page
int steal = ( half - bfirst + 1 ) / 2;
brother._first += steal;
child._first -= steal;
if ( child._isLeaf ) {
copyEntries( child, half+1, child, half+1-steal, half-1 );
copyEntries( brother, bfirst, child, 2*half-steal, steal );
} else {
copyChildren( child, half+1, child, half+1-steal, half-1 );
copyChildren( brother, bfirst, child, 2*half-steal, steal );
}
for ( int i=bfirst; i
* B+Trees are n-airy, yeilding log(N) search cost. They are self-balancing,
* preventing search performance degradation when the size of the tree grows.
*
* Keys and associated values must be
* This implementation does not directly support duplicate keys, but it is
* possible to handle duplicates by inlining or referencing an object collection
* as a value.
*
* There is no limit on key size or value size, but it is recommended to keep
* both as small as possible to reduce disk I/O. This is especially true for
* the key size, which impacts all non-leaf
* The BTree cannot store duplicate entries. An existing entry can be
* replaced using the
* WARNING: If you make structural modifications to the BTree during
* browsing, you will get inconsistent browing results.
*
*
* @return Browser positionned at the beginning of the BTree.
*/
public synchronized TupleBrowser browse()
throws IOException
{
BPage rootPage = getRoot();
if ( rootPage == null ) {
return EmptyBrowser.INSTANCE;
}
TupleBrowser browser = rootPage.findFirst();
return browser;
}
/**
* Get a browser initially positioned just before the given key.
*
* WARNING: If you make structural modifications to the BTree during
* browsing, you will get inconsistent browing results.
*
*
* @param key Key used to position the browser. If null, the browser
* will be positionned after the last entry of the BTree.
* (Null is considered to be an "infinite" key)
* @return Browser positionned just before the given key.
*/
public synchronized TupleBrowser browse( Object key )
throws IOException
{
BPage rootPage = getRoot();
if ( rootPage == null ) {
return EmptyBrowser.INSTANCE;
}
TupleBrowser browser = rootPage.find( _height, key );
return browser;
}
/**
* Return the number of entries (size) of the BTree.
*/
public synchronized int size()
{
return _entries;
}
/**
* Return the persistent record identifier of the BTree.
*/
public long getRecid()
{
return _recid;
}
/**
* Return the root BPage, or null if it doesn't exist.
*/
private BPage getRoot()
throws IOException
{
if ( _root == 0 ) {
return null;
}
BPage root = (BPage) _recman.fetch( _root, _bpageSerializer );
root._recid = _root;
root._btree = this;
return root;
}
/**
* Implement Externalizable interface.
*/
public void readExternal( ObjectInput in )
throws IOException, ClassNotFoundException
{
_comparator = (Comparator) in.readObject();
_keySerializer = (Serializer) in.readObject();
_valueSerializer = (Serializer) in.readObject();
_height = in.readInt();
_root = in.readLong();
_pageSize = in.readInt();
_entries = in.readInt();
}
/**
* Implement Externalizable interface.
*/
public void writeExternal( ObjectOutput out )
throws IOException
{
out.writeObject( _comparator );
out.writeObject( _keySerializer );
out.writeObject( _valueSerializer );
out.writeInt( _height );
out.writeLong( _root );
out.writeInt( _pageSize );
out.writeInt( _entries );
}
/*
public void assert() throws IOException {
BPage root = getRoot();
if ( root != null ) {
root.assertRecursive( _height );
}
}
*/
/*
public void dump() throws IOException {
BPage root = getRoot();
if ( root != null ) {
root.dumpRecursive( _height, 0 );
}
}
*/
/** PRIVATE INNER CLASS
* Browser returning no element.
*/
static class EmptyBrowser
extends TupleBrowser
{
static TupleBrowser INSTANCE = new EmptyBrowser();
public boolean getNext( Tuple tuple )
{
return false;
}
public boolean getPrevious( Tuple tuple )
{
return false;
}
}
}
libjdbm-java-1.0.orig/src/main/jdbm/btree/package.html 0000644 0001750 0001750 00000000574 10276576000 022613 0 ustar twerner twerner
B+Tree (scalable persistent tree) data structure implementation.
* If the changes to the cache cause the eviction of any objects
* stored under other key(s), events corresponding to
* the evictions are fired for each object. If an event listener is
* unable to handle the eviction, and throws a cache eviction exception,
* that exception is propagated to the caller. If such an exception is
* thrown, the cache itself should be left as it was before the
*
* If this cache policy already contains a listener that is equal to
* the one being added, this call has no effect.
*
* @param listener the (non-null) listener to add to this policy
* @throws IllegalArgumentException if listener is null.
*/
public void addListener( CachePolicyListener listener )
throws IllegalArgumentException;
/**
* Remove a listener from this cache policy. The listener is found
* using object equality, not identity.
*
* @param listener the listener to remove from this policy
*/
public void removeListener( CachePolicyListener listener );
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/CachePolicyListener.java 0000644 0001750 0001750 00000006274 10276576000 025247 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000 (C) Cees de Groot. All Rights Reserved.
* Contributions are Copyright (C) 2000 by their associated contributors.
*
* $Id: CachePolicyListener.java,v 1.3 2003/11/01 13:25:41 dranatunga Exp $
*/
package jdbm.helper;
/**
* Callback interface between {@link CachePolicy} and a Cache implementation
* to notify about cached object eviction.
*
* Note that BPage
). In addition, the leaf nodes
* directly contain (inline) the values associated with the keys, allowing a
* single (or sequential) disk read of all the values on the page.
* Serializable
objects. The
* user is responsible to supply a serializable Comparator
object
* to be used for the ordering of entries, which are also called Tuple
.
* The B+Tree allows traversing the keys in forward and reverse order using a
* TupleBrowser obtained from the browse() methods.
* BPage
objects.
*
* @author Alex Boisvert
* @version $Id: BTree.java,v 1.6 2005/06/25 23:12:31 doomdark Exp $
*/
public class BTree
implements Externalizable
{
private static final boolean DEBUG = false;
/**
* Version id for serialization.
*/
final static long serialVersionUID = 1L;
/**
* Default page size (number of entries per node)
*/
public static final int DEFAULT_SIZE = 16;
/**
* Page manager used to persist changes in BPages
*/
protected transient RecordManager _recman;
/**
* This BTree's record ID in the PageManager.
*/
private transient long _recid;
/**
* Comparator used to index entries.
*/
protected Comparator _comparator;
/**
* Serializer used to serialize index keys (optional)
*/
protected Serializer _keySerializer;
/**
* Serializer used to serialize index values (optional)
*/
protected Serializer _valueSerializer;
/**
* Height of the B+Tree. This is the number of BPages you have to traverse
* to get to a leaf BPage, starting from the root.
*/
private int _height;
/**
* Recid of the root BPage
*/
private transient long _root;
/**
* Number of entries in each BPage.
*/
protected int _pageSize;
/**
* Total number of entries in the BTree
*/
protected int _entries;
/**
* Serializer used for BPages of this tree
*/
private transient BPage _bpageSerializer;
/**
* No-argument constructor used by serialization.
*/
public BTree()
{
// empty
}
/**
* Create a new persistent BTree, with 16 entries per node.
*
* @param recman Record manager used for persistence.
* @param comparator Comparator used to order index entries
*/
public static BTree createInstance( RecordManager recman,
Comparator comparator )
throws IOException
{
return createInstance( recman, comparator, null, null, DEFAULT_SIZE );
}
/**
* Create a new persistent BTree, with 16 entries per node.
*
* @param recman Record manager used for persistence.
* @param keySerializer Serializer used to serialize index keys (optional)
* @param valueSerializer Serializer used to serialize index values (optional)
* @param comparator Comparator used to order index entries
*/
public static BTree createInstance( RecordManager recman,
Comparator comparator,
Serializer keySerializer,
Serializer valueSerializer )
throws IOException
{
return createInstance( recman, comparator, keySerializer,
valueSerializer, DEFAULT_SIZE );
}
/**
* Create a new persistent BTree with the given number of entries per node.
*
* @param recman Record manager used for persistence.
* @param comparator Comparator used to order index entries
* @param keySerializer Serializer used to serialize index keys (optional)
* @param valueSerializer Serializer used to serialize index values (optional)
* @param pageSize Number of entries per page (must be even).
*/
public static BTree createInstance( RecordManager recman,
Comparator comparator,
Serializer keySerializer,
Serializer valueSerializer,
int pageSize )
throws IOException
{
BTree btree;
if ( recman == null ) {
throw new IllegalArgumentException( "Argument 'recman' is null" );
}
if ( comparator == null ) {
throw new IllegalArgumentException( "Argument 'comparator' is null" );
}
if ( ! ( comparator instanceof Serializable ) ) {
throw new IllegalArgumentException( "Argument 'comparator' must be serializable" );
}
if ( keySerializer != null && ! ( keySerializer instanceof Serializable ) ) {
throw new IllegalArgumentException( "Argument 'keySerializer' must be serializable" );
}
if ( valueSerializer != null && ! ( valueSerializer instanceof Serializable ) ) {
throw new IllegalArgumentException( "Argument 'valueSerializer' must be serializable" );
}
// make sure there's an even number of entries per BPage
if ( ( pageSize & 1 ) != 0 ) {
throw new IllegalArgumentException( "Argument 'pageSize' must be even" );
}
btree = new BTree();
btree._recman = recman;
btree._comparator = comparator;
btree._keySerializer = keySerializer;
btree._valueSerializer = valueSerializer;
btree._pageSize = pageSize;
btree._bpageSerializer = new BPage();
btree._bpageSerializer._btree = btree;
btree._recid = recman.insert( btree );
return btree;
}
/**
* Load a persistent BTree.
*
* @param recman RecordManager used to store the persistent btree
* @param recid Record id of the BTree
*/
public static BTree load( RecordManager recman, long recid )
throws IOException
{
BTree btree = (BTree) recman.fetch( recid );
btree._recid = recid;
btree._recman = recman;
btree._bpageSerializer = new BPage();
btree._bpageSerializer._btree = btree;
return btree;
}
/**
* Insert an entry in the BTree.
* replace
flag. If an entry with the
* same key already exists in the BTree, its value is returned.
*
* @param key Insert key
* @param value Insert value
* @param replace Set to true to replace an existing key-value pair.
* @return Existing value, if any.
*/
public synchronized Object insert( Object key, Object value,
boolean replace )
throws IOException
{
if ( key == null ) {
throw new IllegalArgumentException( "Argument 'key' is null" );
}
if ( value == null ) {
throw new IllegalArgumentException( "Argument 'value' is null" );
}
BPage rootPage = getRoot();
if ( rootPage == null ) {
// BTree is currently empty, create a new root BPage
if (DEBUG) {
System.out.println( "BTree.insert() new root BPage" );
}
rootPage = new BPage( this, key, value );
_root = rootPage._recid;
_height = 1;
_entries = 1;
_recman.update( _recid, this );
return null;
} else {
BPage.InsertResult insert = rootPage.insert( _height, key, value, replace );
boolean dirty = false;
if ( insert._overflow != null ) {
// current root page overflowed, we replace with a new root page
if ( DEBUG ) {
System.out.println( "BTree.insert() replace root BPage due to overflow" );
}
rootPage = new BPage( this, rootPage, insert._overflow );
_root = rootPage._recid;
_height += 1;
dirty = true;
}
if ( insert._existing == null ) {
_entries++;
dirty = true;
}
if ( dirty ) {
_recman.update( _recid, this );
}
// insert might have returned an existing value
return insert._existing;
}
}
/**
* Remove an entry with the given key from the BTree.
*
* @param key Removal key
* @return Value associated with the key, or null if no entry with given
* key existed in the BTree.
*/
public synchronized Object remove( Object key )
throws IOException
{
if ( key == null ) {
throw new IllegalArgumentException( "Argument 'key' is null" );
}
BPage rootPage = getRoot();
if ( rootPage == null ) {
return null;
}
boolean dirty = false;
BPage.RemoveResult remove = rootPage.remove( _height, key );
if ( remove._underflow && rootPage.isEmpty() ) {
_height -= 1;
dirty = true;
// TODO: check contract for BPages to be removed from recman.
if ( _height == 0 ) {
_root = 0;
} else {
_root = rootPage.childBPage( _pageSize-1 )._recid;
}
}
if ( remove._value != null ) {
_entries--;
dirty = true;
}
if ( dirty ) {
_recman.update( _recid, this );
}
return remove._value;
}
/**
* Find the value associated with the given key.
*
* @param key Lookup key.
* @return Value associated with the key, or null if not found.
*/
public synchronized Object find( Object key )
throws IOException
{
if ( key == null ) {
throw new IllegalArgumentException( "Argument 'key' is null" );
}
BPage rootPage = getRoot();
if ( rootPage == null ) {
return null;
}
Tuple tuple = new Tuple( null, null );
TupleBrowser browser = rootPage.find( _height, key );
if ( browser.getNext( tuple ) ) {
// find returns the matching key or the next ordered key, so we must
// check if we have an exact match
if ( _comparator.compare( key, tuple.getKey() ) != 0 ) {
return null;
} else {
return tuple.getValue();
}
} else {
return null;
}
}
/**
* Find the value associated with the given key, or the entry immediately
* following this key in the ordered BTree.
*
* @param key Lookup key.
* @return Value associated with the key, or a greater entry, or null if no
* greater entry was found.
*/
public synchronized Tuple findGreaterOrEqual( Object key )
throws IOException
{
Tuple tuple;
TupleBrowser browser;
if ( key == null ) {
// there can't be a key greater than or equal to "null"
// because null is considered an infinite key.
return null;
}
tuple = new Tuple( null, null );
browser = browse( key );
if ( browser.getNext( tuple ) ) {
return tuple;
} else {
return null;
}
}
/**
* Get a browser initially positioned at the beginning of the BTree.
*
libjdbm-java-1.0.orig/src/main/jdbm/helper/ 0000775 0001750 0001750 00000000000 10276576000 020504 5 ustar twerner twerner libjdbm-java-1.0.orig/src/main/jdbm/helper/ByteArrayComparator.java 0000644 0001750 0001750 00000010613 10276576000 025300 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
* Contributions are Copyright (C) 2001 by their associated contributors.
*
*/
package jdbm.helper;
import java.util.Comparator;
import java.io.Serializable;
/**
* Comparator for byte arrays.
*
* @author Alex Boisvert
* @version $Id: ByteArrayComparator.java,v 1.4 2002/05/31 06:33:20 boisvert Exp $
*/
public final class ByteArrayComparator
implements Comparator, Serializable
{
/**
* Version id for serialization.
*/
final static long serialVersionUID = 1L;
/**
* Compare two objects.
*
* @param obj1 First object
* @param obj2 Second object
* @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
* and a negative integer if obj1 < obj2
*/
public int compare( Object obj1, Object obj2 )
{
if ( obj1 == null ) {
throw new IllegalArgumentException( "Argument 'obj1' is null" );
}
if ( obj2 == null ) {
throw new IllegalArgumentException( "Argument 'obj2' is null" );
}
return compareByteArray( (byte[]) obj1, (byte[]) obj2 );
}
/**
* Compare two byte arrays.
*/
public static int compareByteArray( byte[] thisKey, byte[] otherKey )
{
int len = Math.min( thisKey.length, otherKey.length );
// compare the byte arrays
for ( int i=0; iput()
operation was invoked: the the object whose
* eviction failed is still in the cache, and the new insertion or
* modification is reverted.
*
* @param key key for the cached object
* @param value the cached object
* @throws CacheEvictionException propagated if, while evicting objects
* to make room for new object, an eviction listener encountered
* this problem.
*/
public void put( Object key, Object value )
throws CacheEvictionException;
/**
* Obtain the object stored under the key specified.
*
* @param key key the object was cached under
* @return the object if it is still in the cache, null otherwise.
*/
public Object get( Object key );
/**
* Remove the object stored under the key specified. Note that since
* eviction notices are only fired when objects under different
* keys are evicted, no event is fired for any object stored
* under this key (see {@link #put(Object, Object) put( )}).
*
* @param key key the object was stored in the cache under.
*/
public void remove( Object key );
/**
* Remove all objects from the cache. Consistent with
* {@link #remove(Object) remove( )}, no eviction notices are fired.
*/
public void removeAll();
/**
* Enumerate through the objects currently in the cache.
*/
public Enumeration elements();
/**
* Add a listener to this cache policy.
* CachePolicy
implementations typically use
* object equality when removing listeners, so concrete
* implementations of this interface should also pay attention to
* their {@link Object#equals(Object)} and {@link Object#hashCode()}
* methods.
*
* @author Alex Boisvert
* @version $Id: CachePolicyListener.java,v 1.3 2003/11/01 13:25:41 dranatunga Exp $
*/
public interface CachePolicyListener {
/**
* Notification that the cache this listener is attached to is evicting
* the object indicated.
*
* @param obj object being evited from cache
* @throws CacheEvictionException if this listener encountered problems
* while preparing for the specified object's eviction. For example,
* a listener may try to persist the object to disk, and encounter
* an IOException
.
*/
public void cacheObjectEvicted(Object obj) throws CacheEvictionException;
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/Conversion.java 0000644 0001750 0001750 00000015624 10276576000 023502 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
* Contributions are Copyright (C) 2001 by their associated contributors.
*
*/
package jdbm.helper;
/**
* Miscelaneous conversion utility methods.
*
* @author Alex Boisvert
* @version $Id: Conversion.java,v 1.3 2002/05/31 06:33:20 boisvert Exp $
*/
public class Conversion
{
/**
* Convert a string into a byte array.
*/
public static byte[] convertToByteArray( String s )
{
try {
// see the following page for character encoding
// http://java.sun.com/products/jdk/1.1/docs/guide/intl/encoding.doc.html
return s.getBytes( "UTF8" );
} catch ( java.io.UnsupportedEncodingException uee ) {
uee.printStackTrace();
throw new Error( "Platform doesn't support UTF8 encoding" );
}
}
/**
* Convert a byte into a byte array.
*/
public static byte[] convertToByteArray( byte n )
{
n = (byte)( n ^ ( (byte) 0x80 ) ); // flip MSB because "byte" is signed
return new byte[] { n };
}
/**
* Convert a short into a byte array.
*/
public static byte[] convertToByteArray( short n )
{
n = (short) ( n ^ ( (short) 0x8000 ) ); // flip MSB because "short" is signed
byte[] key = new byte[ 2 ];
pack2( key, 0, n );
return key;
}
/**
* Convert an int into a byte array.
*/
public static byte[] convertToByteArray( int n )
{
n = (n ^ 0x80000000); // flip MSB because "int" is signed
byte[] key = new byte[4];
pack4(key, 0, n);
return key;
}
/**
* Convert a long into a byte array.
*/
public static byte[] convertToByteArray( long n )
{
n = (n ^ 0x8000000000000000L); // flip MSB because "long" is signed
byte[] key = new byte[8];
pack8( key, 0, n );
return key;
}
/**
* Convert a byte array (encoded as UTF-8) into a String
*/
public static String convertToString( byte[] buf )
{
try {
// see the following page for character encoding
// http://java.sun.com/products/jdk/1.1/docs/guide/intl/encoding.doc.html
return new String( buf, "UTF8" );
} catch ( java.io.UnsupportedEncodingException uee ) {
uee.printStackTrace();
throw new Error( "Platform doesn't support UTF8 encoding" );
}
}
/**
* Convert a byte array into an integer (signed 32-bit) value.
*/
public static int convertToInt( byte[] buf )
{
int value = unpack4( buf, 0 );
value = ( value ^ 0x80000000 ); // flip MSB because "int" is signed
return value;
}
/**
* Convert a byte array into a long (signed 64-bit) value.
*/
public static long convertToLong( byte[] buf )
{
long value = ( (long) unpack4( buf, 0 ) << 32 )
+ ( unpack4( buf, 4 ) & 0xFFFFFFFFL );
value = ( value ^ 0x8000000000000000L ); // flip MSB because "long" is signed
return value;
}
static int unpack4( byte[] buf, int offset )
{
int value = ( buf[ offset ] << 24 )
| ( ( buf[ offset+1 ] << 16 ) & 0x00FF0000 )
| ( ( buf[ offset+2 ] << 8 ) & 0x0000FF00 )
| ( ( buf[ offset+3 ] << 0 ) & 0x000000FF );
return value;
}
static final void pack2( byte[] data, int offs, int val )
{
data[offs++] = (byte) ( val >> 8 );
data[offs++] = (byte) val;
}
static final void pack4( byte[] data, int offs, int val )
{
data[offs++] = (byte) ( val >> 24 );
data[offs++] = (byte) ( val >> 16 );
data[offs++] = (byte) ( val >> 8 );
data[offs++] = (byte) val;
}
static final void pack8( byte[] data, int offs, long val )
{
pack4( data, 0, (int) ( val >> 32 ) );
pack4( data, 4, (int) val );
}
/**
* Test static methods
*/
public static void main( String[] args )
{
byte[] buf;
buf = convertToByteArray( (int) 5 );
System.out.println( "int value of 5 is: " + convertToInt( buf ) );
buf = convertToByteArray( (int) -1 );
System.out.println( "int value of -1 is: " + convertToInt( buf ) );
buf = convertToByteArray( (int) 22111000 );
System.out.println( "int value of 22111000 is: " + convertToInt( buf ) );
buf = convertToByteArray( (long) 5L );
System.out.println( "long value of 5 is: " + convertToLong( buf ) );
buf = convertToByteArray( (long) -1L );
System.out.println( "long value of -1 is: " + convertToLong( buf ) );
buf = convertToByteArray( (long) 1112223334445556667L );
System.out.println( "long value of 1112223334445556667 is: " + convertToLong( buf ) );
}
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/DefaultSerializer.java 0000644 0001750 0001750 00000006572 10276576000 024775 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
* Contributions are Copyright (C) 2001 by their associated contributors.
*
*/
package jdbm.helper;
import java.io.IOException;
/**
* Default java serializer.
*
* @author Alex Boisvert
* @version $Id: DefaultSerializer.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
*/
public class DefaultSerializer
implements Serializer
{
public static final DefaultSerializer INSTANCE = new DefaultSerializer();
/**
* Construct a DefaultSerializer.
*/
public DefaultSerializer()
{
// no op
}
/**
* Serialize the content of an object into a byte array.
*
* @param obj Object to serialize
* @return a byte array representing the object's state
*/
public byte[] serialize( Object obj )
throws IOException
{
return Serialization.serialize( obj );
}
/**
* Deserialize the content of an object from a byte array.
*
* @param serialized Byte array representation of the object
* @return deserialized object
*/
public Object deserialize( byte[] serialized )
throws IOException
{
try {
return Serialization.deserialize( serialized );
} catch ( ClassNotFoundException except ) {
throw new WrappedRuntimeException( except );
}
}
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/FastIterator.java 0000644 0001750 0001750 00000005017 10276576000 023757 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000 (C) Cees de Groot. All Rights Reserved.
* Contributions are Copyright (C) 2000 by their associated contributors.
*
* $Id: FastIterator.java,v 1.2 2003/10/21 15:43:58 boisvert Exp $
*/
package jdbm.helper;
/**
* Fast and simple iterator.
*
* @version $Revision: 1.2 $
* @author Alex Boisvert
*/
public abstract class FastIterator
{
/**
* Returns the next element in the interation.
*
* @return the next element in the iteration, or null if no more element.
*/
public abstract Object next()
throws IterationException;
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/IntegerComparator.java 0000644 0001750 0001750 00000006573 10276576000 025005 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
* Contributions are Copyright (C) 2001 by their associated contributors.
*
*/
package jdbm.helper;
import java.io.Serializable;
import java.util.Comparator;
/**
* Comparator for Integer objects.
*
* @author Christof Dallermassl
* @version $Id: IntegerComparator.java,v 1.2 2002/05/31 06:33:20 boisvert Exp $
*/
public final class IntegerComparator
implements Comparator, Serializable
{
/**
* Version id for serialization.
*/
final static long serialVersionUID = 1L;
/**
* Compare two objects.
*
* @param obj1 First object
* @param obj2 Second object
* @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
* and a negative integer if obj1 < obj2
*/
public int compare( Object obj1, Object obj2 )
{
if ( obj1 == obj2 ) {
return 0;
}
if ( obj1 == null ) {
throw new IllegalArgumentException( "Argument 'obj1' is null" );
}
if ( obj2 == null ) {
throw new IllegalArgumentException( "Argument 'obj2' is null" );
}
// complicated to avoid usage of Integer.compareTo, as this
// method is Java 1.2 only!
int int1 = ( (Integer) obj1 ).intValue();
int int2 = ( (Integer) obj2 ).intValue();
if ( int1 == int2 ) {
return 0;
}
if ( int1 < int2 ) {
return -1;
} else {
return 1;
}
}
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/IntegerSerializer.java 0000644 0001750 0001750 00000006540 10276576000 025001 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
* Contributions are Copyright (C) 2001 by their associated contributors.
*
*/
package jdbm.helper;
import java.io.IOException;
/**
* Optimized serializer for integers.
*
* @author Alex Boisvert
* @version $Id: IntegerSerializer.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
*/
public class IntegerSerializer
implements Serializer
{
public static final IntegerSerializer INSTANCE = new IntegerSerializer();
/**
* Construct an IntegerSerializer.
*/
public IntegerSerializer()
{
// no op
}
/**
* Serialize the content of an object into a byte array.
*
* @param obj Object to serialize
* @return a byte array representing the object's state
*/
public byte[] serialize( Object obj )
throws IOException
{
Integer number = (Integer) obj;
return Conversion.convertToByteArray( number.intValue() );
}
/**
* Deserialize the content of an object from a byte array.
*
* @param serialized Byte array representation of the object
* @return deserialized object
*/
public Object deserialize( byte[] serialized )
throws IOException
{
int number = Conversion.convertToInt( serialized );
return new Integer( number );
}
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/IterationException.java 0000644 0001750 0001750 00000006207 10276576000 025167 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000 (C) Cees de Groot. All Rights Reserved.
* Contributions are Copyright (C) 2000 by their associated contributors.
*
* $Id: IterationException.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
*/
package jdbm.helper;
/**
* Iteration exception.
*
* @author Alex Boisvert
* @version $Revision: 1.2 $
*/
public class IterationException
extends WrappedRuntimeException
{
/**
* Construct a new iteration exception wrapping an underlying exception
* and providing a message.
*
* @param message The exception message
* @param except The underlying exception
*/
public IterationException( String message, Exception except )
{
super( message, except );
}
/**
* Construct a new iteration exception with a message.
*
* @param message The exception message
*/
public IterationException( String message )
{
super( message, null );
}
/**
* Construct a new iteration exception wrapping an underlying exception.
*
* @param except The underlying exception
*/
public IterationException( Exception except )
{
super( except );
}
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/LongComparator.java 0000644 0001750 0001750 00000006310 10276576000 024274 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
* Contributions are Copyright (C) 2001 by their associated contributors.
*
*/
package jdbm.helper;
import java.io.Serializable;
import java.util.Comparator;
/**
* Comparator for java.lang.Long objects.
*
* @author Alex Boisvert
* @version $Id: LongComparator.java,v 1.4 2002/05/31 06:33:20 boisvert Exp $
*/
public final class LongComparator
implements Comparator, Serializable
{
/**
* Version id for serialization.
*/
final static long serialVersionUID = 1L;
/**
* Compare two objects.
*
* @param obj1 First object
* @param obj2 Second object
* @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
* and a negative integer if obj1 < obj2
*/
public int compare( Object obj1, Object obj2 )
{
if ( obj1 == null ) {
throw new IllegalArgumentException( "Argument 'obj1' is null" );
}
if ( obj2 == null ) {
throw new IllegalArgumentException( "Argument 'obj2' is null" );
}
long l1 = ( (Long) obj1 ).longValue();
long l2 = ( (Long) obj2 ).longValue();
if ( l1 > l2 ) {
return 1;
} else if ( l1 == l2 ) {
return 0;
} else {
return -1;
}
}
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/LongSerializer.java 0000644 0001750 0001750 00000006515 10276576000 024305 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
* Contributions are Copyright (C) 2001 by their associated contributors.
*
*/
package jdbm.helper;
import java.io.IOException;
/**
* Optimized serializer for long integers.
*
* @author Alex Boisvert
* @version $Id: LongSerializer.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
*/
public class LongSerializer
implements Serializer
{
public static final LongSerializer INSTANCE = new LongSerializer();
/**
* Construct a LongSerializer.
*/
public LongSerializer()
{
// no op
}
/**
* Serialize the content of an object into a byte array.
*
* @param obj Object to serialize
* @return a byte array representing the object's state
*/
public byte[] serialize( Object obj )
throws IOException
{
Long number = (Long) obj;
return Conversion.convertToByteArray( number.longValue() );
}
/**
* Deserialize the content of an object from a byte array.
*
* @param serialized Byte array representation of the object
* @return deserialized object
*/
public Object deserialize( byte[] serialized )
throws IOException
{
long number = Conversion.convertToLong( serialized );
return new Long( number );
}
}
libjdbm-java-1.0.orig/src/main/jdbm/helper/MRU.java 0000644 0001750 0001750 00000020734 10276576000 022016 0 ustar twerner twerner /**
* JDBM LICENSE v1.00
*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "JDBM" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Cees de Groot. For written permission,
* please contact cg@cdegroot.com.
*
* 4. Products derived from this Software may not be called "JDBM"
* nor may "JDBM" appear in their names without prior written
* permission of Cees de Groot.
*
* 5. Due credit should be given to the JDBM Project
* (http://jdbm.sourceforge.net/).
*
* THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
* ``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
* CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000 (C) Cees de Groot. All Rights Reserved.
* Contributions are Copyright (C) 2000 by their associated contributors.
*
* $Id: MRU.java,v 1.8 2005/06/25 23:12:31 doomdark Exp $
*/
package jdbm.helper;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
/**
* MRU - Most Recently Used cache policy.
*
* Methods are *not* synchronized, so no concurrent access is allowed.
*
* @author Alex Boisvert
* @version $Id: MRU.java,v 1.8 2005/06/25 23:12:31 doomdark Exp $
*/
public class MRU implements CachePolicy {
/** Cached object hashtable */
Hashtable _hash = new Hashtable();
/**
* Maximum number of objects in the cache.
*/
int _max;
/**
* Beginning of linked-list of cache elements. First entry is element
* which has been used least recently.
*/
CacheEntry _first;
/**
* End of linked-list of cache elements. Last entry is element
* which has been used most recently.
*/
CacheEntry _last;
/**
* Cache eviction listeners
*/
Vector listeners = new Vector();
/**
* Construct an MRU with a given maximum number of objects.
*/
public MRU(int max) {
if (max <= 0) {
throw new IllegalArgumentException("MRU cache must contain at least one entry");
}
_max = max;
}
/**
* Place an object in the cache.
*/
public void put(Object key, Object value) throws CacheEvictionException {
CacheEntry entry = (CacheEntry)_hash.get(key);
if (entry != null) {
entry.setValue(value);
touchEntry(entry);
} else {
if (_hash.size() == _max) {
// purge and recycle entry
entry = purgeEntry();
entry.setKey(key);
entry.setValue(value);
} else {
entry = new CacheEntry(key, value);
}
addEntry(entry);
_hash.put(entry.getKey(), entry);
}
}
/**
* Obtain an object in the cache
*/
public Object get(Object key) {
CacheEntry entry = (CacheEntry)_hash.get(key);
if (entry != null) {
touchEntry(entry);
return entry.getValue();
} else {
return null;
}
}
/**
* Remove an object from the cache
*/
public void remove(Object key) {
CacheEntry entry = (CacheEntry)_hash.get(key);
if (entry != null) {
removeEntry(entry);
_hash.remove(entry.getKey());
}
}
/**
* Remove all objects from the cache
*/
public void removeAll() {
_hash = new Hashtable();
_first = null;
_last = null;
}
/**
* Enumerate elements' values in the cache
*/
public Enumeration elements() {
return new MRUEnumeration(_hash.elements());
}
/**
* Add a listener to this cache policy
*
* @param listener Listener to add to this policy
*/
public void addListener(CachePolicyListener listener) {
if (listener == null) {
throw new IllegalArgumentException("Cannot add null listener.");
}
if ( ! listeners.contains(listener)) {
listeners.addElement(listener);
}
}
/**
* Remove a listener from this cache policy
*
* @param listener Listener to remove from this policy
*/
public void removeListener(CachePolicyListener listener) {
listeners.removeElement(listener);
}
/**
* Add a CacheEntry. Entry goes at the end of the list.
*/
protected void addEntry(CacheEntry entry) {
if (_first == null) {
_first = entry;
_last = entry;
} else {
_last.setNext(entry);
entry.setPrevious(_last);
_last = entry;
}
}
/**
* Remove a CacheEntry from linked list
*/
protected void removeEntry(CacheEntry entry) {
if (entry == _first) {
_first = entry.getNext();
}
if (_last == entry) {
_last = entry.getPrevious();
}
CacheEntry previous = entry.getPrevious();
CacheEntry next = entry.getNext();
if (previous != null) {
previous.setNext(next);
}
if (next != null) {
next.setPrevious(previous);
}
entry.setPrevious(null);
entry.setNext(null);
}
/**
* Place entry at the end of linked list -- Most Recently Used
*/
protected void touchEntry(CacheEntry entry) {
if (_last == entry) {
return;
}
removeEntry(entry);
addEntry(entry);
}
/**
* Purge least recently used object from the cache
*
* @return recyclable CacheEntry
*/
protected CacheEntry purgeEntry() throws CacheEvictionException {
CacheEntry entry = _first;
// Notify policy listeners first. if any of them throw an
// eviction exception, then the internal data structure
// remains untouched.
CachePolicyListener listener;
for (int i=0; i