|
Berkeley
DB Java Edition version 1.7.1 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sleepycat.je.Database
A database handle.
Database attributes are specified in the DatabaseConfig
class. Database handles are free-threaded and may be used concurrently
by multiple threads.
To open an existing database with default attributes:
To create a transactional database that supports duplicates:Environment env = new Environment(home, null); Database myDatabase = env.openDatabase(null, "mydatabase", null);
DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(true); dbConfig.setAllowCreate(true); dbConfig.setSortedDuplicates(true); Database newlyCreateDb = env.openDatabase(txn, "mydatabase", dbConfig);
Method Summary | |
void |
close() Flush any cached database information to disk and discard the database handle. |
OperationStatus |
delete(Transaction txn, DatabaseEntry key) Remove key/data pairs from the database. |
OperationStatus |
get(Transaction txn, DatabaseEntry key, DatabaseEntry data, LockMode lockMode) Retrieves the key/data pair with the given key. |
DatabaseConfig |
getConfig()
Return this Database object's configuration. |
String |
getDatabaseName()
Return the database name. |
Environment |
getEnvironment()
Return the Environment handle
for the database environment underlying the Database . |
OperationStatus |
getSearchBoth(Transaction txn, DatabaseEntry key, DatabaseEntry data, LockMode lockMode) Retrieves the key/data pair with the given key and data value, that is, both the key and data items must match. |
List |
getSecondaryDatabases()
Return a list of all SecondaryDatabase
objects associated with a primary database. |
DatabaseStats |
getStats(StatsConfig statsConfig) Return database statistics. |
JoinCursor |
join(Cursor[] cursors, JoinConfig config) Creates a specialized join cursor for use in performing equality or natural joins on secondary indices. |
Cursor |
openCursor(Transaction txn, CursorConfig cursorConfig)
Return a cursor into the database. |
void |
preload(long maxBytes)
Preload the cache. |
OperationStatus |
put(Transaction txn, DatabaseEntry key, DatabaseEntry data) Store the key/data pair into the database. |
OperationStatus |
putNoDupData(Transaction txn, DatabaseEntry key, DatabaseEntry data) Store the key/data pair into the database if it does not already appear in the database. |
OperationStatus |
putNoOverwrite(Transaction txn, DatabaseEntry key, DatabaseEntry data) Store the key/data pair into the database if the key does not already appear in the database. |
int |
truncate(Transaction txn,
boolean returnCount) Deprecated. As of JE 1.7, replaced by Environment.truncateDatabase(Transaction,
String, boolean) .
The Database class is thread safe and may be used concurrently by multiple threads, using multiple transactions. It was not possible to supply correct transactional semantics for this method in all cases without imposing a performance penalty on all operations. Specifically, a truncate operation executed within one transaction can be incorrectly seen before commit by other transactions if those later transactions use the same Database handle. The replacement method, Environment.truncateDatabase(), avoids these issues because all Database handles must be closed before the truncateDatabase() method is called.
|
DatabaseStats |
verify(VerifyConfig config) Verify the integrity of the database. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public OperationStatus delete(Transaction txn, DatabaseEntry key) throws DatabaseException
The key/data pair associated with the specified key is discarded from the database. In the presence of duplicate key values, all records associated with the designated key will be discarded.
The key/data pair is also deleted from any associated secondary databases.
txn
- For a transactional database, an explicit
transaction may be specified, or null may be specified to use
auto-commit. For a non-transactional database, null must be specified.
key
- the key DatabaseEntry
operated on.
OperationStatus.NOTFOUND
if the specified key is not found in the database; otherwise the
method will return OperationStatus.SUCCESS
.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseException
- if a
failure occurs.
public OperationStatus get(Transaction txn, DatabaseEntry key, DatabaseEntry data, LockMode lockMode) throws DatabaseException
Cursor
operations.
txn
- For a transactional database, an explicit
transaction may be specified to transaction-protect the operation, or
null may be specified to perform the operation without transaction
protection. For a non-transactional database, null must be specified.
key
- the key used as input. It must be
initialized with a non-null byte array by the caller.
data
- the data returned as output. Its byte
array does not need to be initialized by the caller.
lockMode
- the locking attributes; if null,
default attributes are used.
OperationStatus.NOTFOUND
if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS
.
DeadlockException
- if the
operation was selected to resolve a deadlock.
IllegalArgumentException
- if an invalid parameter was specified.
DatabaseException
- if a
failure occurs.
public OperationStatus getSearchBoth(Transaction txn, DatabaseEntry key, DatabaseEntry data, LockMode lockMode) throws DatabaseException
txn
- For a transactional database, an explicit
transaction may be specified to transaction-protect the operation, or
null may be specified to perform the operation without transaction
protection. For a non-transactional database, null must be specified.
key
- the key used as input. It must be
initialized with a non-null byte array by the caller.
data
- the data used as input. It must be
initialized with a non-null byte array by the caller.
lockMode
- the locking attributes; if null,
default attributes are used.
OperationStatus.NOTFOUND
if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS
.
DeadlockException
- if the
operation was selected to resolve a deadlock.
IllegalArgumentException
- if an invalid parameter was specified.
DatabaseException
- if a
failure occurs.
public OperationStatus put(Transaction txn, DatabaseEntry key, DatabaseEntry data) throws DatabaseException
Store the key/data pair into the database.
If the key already appears in the database and duplicates are not configured, the existing key/data pair will be replaced. If the key already appears in the database and sorted duplicates are configured, the new data value is inserted at the correct sorted location.
txn
- For a transactional database, an explicit
transaction may be specified, or null may be specified to use
auto-commit. For a non-transactional database, null must be specified.
key
- the key DatabaseEntry
operated on.
data
- the data DatabaseEntry
stored.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseException
- if a
failure occurs.
public OperationStatus putNoOverwrite(Transaction txn, DatabaseEntry key, DatabaseEntry data) throws DatabaseException
Store the key/data pair into the database if the key does not already appear in the database.
This method will fail if the key already exists in the database, even if the database supports duplicates.
txn
- For a transactional database, an explicit
transaction may be specified, or null may be specified to use
auto-commit. For a non-transactional database, null must be specified.
key
- the key DatabaseEntry
operated on.
data
- the data DatabaseEntry
stored.
OperationStatus.KEYEXIST
.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseException
- if a
failure occurs.
public OperationStatus putNoDupData(Transaction txn, DatabaseEntry key, DatabaseEntry data) throws DatabaseException
Store the key/data pair into the database if it does not already appear in the database.
This method may only be called if the underlying database has been configured to support sorted duplicates.
txn
- For a transactional database, an explicit
transaction may be specified, or null may be specified to use
auto-commit. For a non-transactional database, null must be specified.
key
- the key DatabaseEntry
operated on.
data
- the data DatabaseEntry
stored.
OperationStatus.KEYEXIST
.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseException
- if a
failure occurs.
public String getDatabaseName() throws DatabaseException
This method may be called at any time during the life of the application.
DatabaseException
public DatabaseConfig getConfig() throws DatabaseException
This may differ from the configuration used to open this object if the database existed previously.
DatabaseException
- if a
failure occurs.
public Environment getEnvironment() throws DatabaseException
Environment
handle
for the database environment underlying the Database
.
This method may be called at any time during the life of the application.
Environment
handle
for the database environment underlying the Database
.
DatabaseException
- if a
failure occurs.
public void close() throws DatabaseException
The database handle should not be closed while any other handle
that refers to it is not yet closed; for example, database handles
should not be closed while cursor handles into the database remain
open, or transactions that include operations on the database have not
yet been committed or aborted. Specifically, this includes Cursor
and Transaction
handles.
When multiple threads are using the Database
handle
concurrently, only a single thread may call this method.
The database handle may not be accessed again after this method is called, regardless of the method's success or failure.
When called on a database that is the primary database for a secondary index, the primary database should be closed only after all secondary indices which reference it have been closed.
DatabaseException
- if a
failure occurs.
public Cursor openCursor(Transaction txn, CursorConfig cursorConfig) throws DatabaseException
txn
- To use a cursor for writing to a
transactional database, an explicit transaction must be specified. For
read-only access to a transactional database, the transaction may be
null. For a non-transactional database, the transaction must be null.
To transaction-protect cursor operations, cursors must be opened and closed within the context of a transaction, and the txn parameter specifies the transaction context in which the cursor will be used.
cursorConfig
- The cursor attributes. If null,
default attributes are used.
DatabaseException
- if a
failure occurs.
public DatabaseStats getStats(StatsConfig statsConfig) throws DatabaseException
If this method has not been configured to avoid expensive
operations (using the StatsConfig.setFast
method), it will access some of or all the pages in the database,
incurring a severe performance penalty as well as possibly flushing the
underlying cache.
In the presence of multiple threads or processes accessing an active database, the information returned by this method may be out-of-date.
statsConfig
- The statistics returned; if null,
default statistics are returned.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseException
- if a
failure occurs.
public int truncate(Transaction txn, boolean returnCount) throws DatabaseException
Environment.truncateDatabase(Transaction,
String, boolean)
.
The Database class is thread safe and may be used concurrently by multiple threads, using multiple transactions. It was not possible to supply correct transactional semantics for this method in all cases without imposing a performance penalty on all operations. Specifically, a truncate operation executed within one transaction can be incorrectly seen before commit by other transactions if those later transactions use the same Database handle.
The replacement method, Environment.truncateDatabase(), avoids these issues because all Database handles must be closed before the truncateDatabase() method is called.
When called on a database configured with secondary indices, this method truncates the primary database and all secondary indices. If configured to return a count of the records discarded, the returned count is the count of records discarded from the primary database.
txn
- For a transactional database, an explicit
transaction may be specified, or null may be specified to use
auto-commit. For a non-transactional database, null must be specified.
returnCount
- If true, count and return the
number of records discarded.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseException
- if a
failure occurs.
public JoinCursor join(Cursor[] cursors, JoinConfig config) throws DatabaseException
Each cursor in the cursors
array must have been
initialized to refer to the key on which the underlying database should
be joined. Typically, this initialization is done by calling Cursor.getSearchKey
.
Once the cursors have been passed to this method, they should not be accessed or modified until the newly created join cursor has been closed, or else inconsistent results may be returned. However, the position of the cursors will not be changed by this method or by the methods of the join cursor.
cursors
- an array of cursors associated with
this primary database.
config
- The join attributes. If null, default
attributes are used.
DatabaseException
- if a
failure occurs.
JoinCursor
public void preload(long maxBytes) throws DatabaseException
maxBytes
- The maximum number of bytes to load.
If maxBytes is 0, je.evictor.maxMemory is used.
DatabaseException
- if a
failure occurs.
public DatabaseStats verify(VerifyConfig config) throws DatabaseException
Verification is an expensive operation that should normally only be used for troubleshooting and debugging.
config
- Configures the verify operation; if
null, the default operation is performed.
IllegalArgumentException
- if an invalid parameter was specified.
DatabaseException
- if a
failure occurs.
public List getSecondaryDatabases() throws DatabaseException
SecondaryDatabase
objects associated with a primary database.
If no secondaries are associated or this is itself a secondary database, an empty list is returned.
SecondaryDatabase
objects associated with a primary database.
DatabaseException
|
Berkeley
DB Java Edition version 1.7.1 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |