com.sun.sgs.service.store.db
Interface DbDatabase


public interface DbDatabase

The interface to a database. Databases are associated with a single database environment, and must be closed before the environment is closed. Databases must not be used after the close method is called.


Method Summary
 void close()
          Closes this database, releasing any associated resources.
 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.
 

Method Detail

get

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.

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
Throws:
IllegalArgumentException - if txn was not created by the associated environment
TransactionAbortedException - if the transaction should be aborted due to timeout or conflict
DbDatabaseException - if an unexpected database problem occurs

markForUpdate

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

Parameters:
txn - the transaction for this operation
key - the key
Throws:
IllegalArgumentException - if txn was not created by the associated environment
TransactionAbortedException - if the transaction should be aborted due to timeout or conflict
DbDatabaseException - if an unexpected database problem occurs

put

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.

Parameters:
txn - the transaction for this operation
key - the key
value - the value
Throws:
IllegalArgumentException - if txn was not created by the associated environment
TransactionAbortedException - if the transaction should be aborted due to timeout or conflict
DbDatabaseException - if an unexpected database problem occurs

putNoOverwrite

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.

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
Throws:
IllegalArgumentException - if txn was not created by the associated environment
TransactionAbortedException - if the transaction should be aborted due to timeout or conflict
DbDatabaseException - if an unexpected database problem occurs

delete

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

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
Throws:
IllegalArgumentException - if txn was not created by the associated environment
TransactionAbortedException - if the transaction should be aborted due to timeout or conflict
DbDatabaseException - if an unexpected database problem occurs

openCursor

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.

Parameters:
txn - the transaction for this operation
Returns:
the cursor
Throws:
IllegalArgumentException - if txn was not created by the associated environment
TransactionAbortedException - if the transaction should be aborted due to timeout or conflict
DbDatabaseException - if an unexpected database problem occurs

close

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.

Throws:
DbDatabaseException - if an unexpected database problem occurs

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