com.sun.sgs.impl.service.data.store.db.je
Class JeDatabase

java.lang.Object
  extended by com.sun.sgs.impl.service.data.store.db.je.JeDatabase
All Implemented Interfaces:
DbDatabase

public class JeDatabase
extends Object
implements DbDatabase

Provides a database implementation using Berkeley DB Java Edition.


Constructor Summary
JeDatabase(com.sleepycat.je.Environment env, com.sleepycat.je.Transaction txn, String fileName, boolean create)
          Creates an instance of this class.
 
Method Summary
 void close()
          Closes this database, releasing any associated resources.
(package private) static byte[] convertData(byte[] bytes)
          Converts a Berkeley DB DatabaseEntry data value, replacing the null that BDB uses if the data is empty with an empty array.
 boolean delete(DbTransaction txn, byte[] key)
          Removes the value associated with a key in this database.
 byte[] get(DbTransaction txn, byte[] key, boolean forUpdate)
          Gets the value associated with a key in this database.
 void markForUpdate(DbTransaction txn, byte[] key)
          Locks the key and associated value for update.
 DbCursor openCursor(DbTransaction txn)
          Returns a cursor for iterating over the contents of this database.
 void put(DbTransaction txn, byte[] key, byte[] value)
          Sets the value associated with a key in this database, regardless of whether the key already has an associated value.
 boolean putNoOverwrite(DbTransaction txn, byte[] key, byte[] value)
          Sets the value associated with a key in this database, but only if the key does not already have an associated value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JeDatabase

JeDatabase(com.sleepycat.je.Environment env,
           com.sleepycat.je.Transaction txn,
           String fileName,
           boolean create)
     throws FileNotFoundException
Creates an instance of this class.

Parameters:
env - the Berkeley DB environment
txn - the Berkeley DB transaction
fileName - the name of the file containing the database
create - whether to create the database if it does not exist
Throws:
FileNotFoundException - if the database file is not found
DbDatabaseException - if an unexpected database problem occurs
Method Detail

convertData

static byte[] convertData(byte[] bytes)
Converts a Berkeley DB DatabaseEntry data value, replacing the null that BDB uses if the data is empty with an empty array.


get

public byte[] get(DbTransaction txn,
                  byte[] key,
                  boolean forUpdate)
Gets the value associated with a key in this database. Returns null if the key is not found.

Specified by:
get in interface DbDatabase
Parameters:
txn - the transaction for this operation
key - the key
forUpdate - whether the object should be locked for update
Returns:
the associated value, or null if the key was not found

markForUpdate

public void markForUpdate(DbTransaction txn,
                          byte[] key)
Locks the key and associated value for update.

Specified by:
markForUpdate in interface DbDatabase
Parameters:
txn - the transaction for this operation
key - the key

put

public void put(DbTransaction txn,
                byte[] key,
                byte[] value)
Sets the value associated with a key in this database, regardless of whether the key already has an associated value.

Specified by:
put in interface DbDatabase
Parameters:
txn - the transaction for this operation
key - the key
value - the value

putNoOverwrite

public boolean putNoOverwrite(DbTransaction txn,
                              byte[] key,
                              byte[] value)
Sets the value associated with a key in this database, but only if the key does not already have an associated value.

Specified by:
putNoOverwrite in interface DbDatabase
Parameters:
txn - the transaction for this operation
key - the key
value - the value
Returns:
true if a value was stored for the key, and false if the key already had a value

delete

public boolean delete(DbTransaction txn,
                      byte[] key)
Removes the value associated with a key in this database.

Specified by:
delete in interface DbDatabase
Parameters:
txn - the transaction for this operation
key - the key
Returns:
true if the value was removed, and false if the key had no associated value

openCursor

public DbCursor openCursor(DbTransaction txn)
Returns a cursor for iterating over the contents of this database. The cursor needs to be closed before the associated transaction ends.

Specified by:
openCursor in interface DbDatabase
Parameters:
txn - the transaction for this operation
Returns:
the cursor

close

public void close()
Closes this database, releasing any associated resources. This database should not be used after this method is called. This method should not be called if the transactions associated with any operations performed on this database are still open. This method should be called before closing the associated environment.

Specified by:
close in interface DbDatabase

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved