|
Berkeley DB Java Edition version ${release.version} |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sleepycat.je.Database
com.sleepycat.je.SecondaryDatabase
public class SecondaryDatabase
A secondary database handle.
Secondary databases are opened with Environment.openSecondaryDatabase
and are
always associated with a single primary database. The distinguishing
characteristics of a secondary database are:
put()
methods on a secondary database are
prohibited.delete
method of a secondary database will delete
the primary record and as well as all its associated secondary records.get()
methods will return the data from the
associated primary database.get()
method signatures are provided to return
the primary key in an additional pKey
parameter.openCursor
will return a SecondaryCursor
, which itself has get()
methods that return
the data of the primary database and additional get()
method
signatures for returning the primary key.openSecondaryCursor
method is provided
to return a SecondaryCursor
that doesn't require casting.Before opening or creating a secondary database you must implement
the SecondaryKeyCreator
or SecondaryMultiKeyCreator
interface.
For example, to create a secondary database that supports duplicates:
Database primaryDb; // The primary database must already be open. SecondaryKeyCreator keyCreator; // Your key creator implementation. SecondaryConfig secConfig = new SecondaryConfig(); secConfig.setAllowCreate(true); secConfig.setSortedDuplicates(true); secConfig.setKeyCreator(keyCreator); SecondaryDatabase newDb = env.openSecondaryDatabase(transaction, "myDatabaseName", primaryDb, secConfig)
If a primary database is to be associated with one or more secondary databases, it may not be configured for duplicates.
Note that the associations between primary and secondary databases are not stored persistently. Whenever a primary database is opened for write access by the application, the appropriate associated secondary databases should also be opened by the application. This is necessary to ensure data integrity when changes are made to the primary database.
Method Summary | |
---|---|
void |
close()
Closes a secondary database and dis-associates it from its primary database. |
OperationStatus |
delete(Transaction txn,
DatabaseEntry key)
Deletes the primary key/data pair associated with the specified secondary key. |
OperationStatus |
get(Transaction txn,
DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
Retrieves the key/data pair with the given key. |
OperationStatus |
get(Transaction txn,
DatabaseEntry key,
DatabaseEntry data,
LockMode lockMode)
Retrieves the key/data pair with the given key. |
Database |
getPrimaryDatabase()
Returns the primary database associated with this secondary database. |
SecondaryConfig |
getPrivateSecondaryConfig()
Returns the secondary config without cloning, for internal use. |
OperationStatus |
getSearchBoth(Transaction txn,
DatabaseEntry key,
DatabaseEntry pKey,
DatabaseEntry data,
LockMode lockMode)
Retrieves the key/data pair with the specified secondary and primary key, that is, both the primary and secondary key items must match. |
OperationStatus |
getSearchBoth(Transaction txn,
DatabaseEntry key,
DatabaseEntry data,
LockMode lockMode)
This operation is not allowed with this method signature. |
SecondaryConfig |
getSecondaryConfig()
Returns a copy of the secondary configuration of this database. |
JoinCursor |
join(Cursor[] cursors,
JoinConfig config)
This operation is not allowed on a secondary database. |
SecondaryCursor |
openSecondaryCursor(Transaction txn,
CursorConfig cursorConfig)
Obtain a cursor on a database, returning a SecondaryCursor . |
OperationStatus |
put(Transaction txn,
DatabaseEntry key,
DatabaseEntry data)
This operation is not allowed on a secondary database. |
OperationStatus |
putNoDupData(Transaction txn,
DatabaseEntry key,
DatabaseEntry data)
This operation is not allowed on a secondary database. |
OperationStatus |
putNoOverwrite(Transaction txn,
DatabaseEntry key,
DatabaseEntry data)
This operation is not allowed on a secondary database. |
Methods inherited from class com.sleepycat.je.Database |
---|
count, getConfig, getDatabaseName, getEnvironment, getSecondaryDatabases, getStats, openCursor, openSequence, preload, preload, preload, removeSequence, sync, verify |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public void close() throws DatabaseException
When closing the last open handle for a deferred-write database, any
cached database information is flushed to disk as if Database.sync()
were
called.
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.
close
in class Database
DatabaseException
- if a failure occurs.DatabaseConfig.setDeferredWrite
public Database getPrimaryDatabase() throws DatabaseException
DatabaseException
public SecondaryConfig getSecondaryConfig() throws DatabaseException
DatabaseException
- if a failure occurs.public SecondaryConfig getPrivateSecondaryConfig()
public SecondaryCursor openSecondaryCursor(Transaction txn, CursorConfig cursorConfig) throws DatabaseException
SecondaryCursor
. Calling this method is the equivalent of
calling Database.openCursor(com.sleepycat.je.Transaction, com.sleepycat.je.CursorConfig)
and casting the result to SecondaryCursor
.
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 OperationStatus delete(Transaction txn, DatabaseEntry key) throws DatabaseException
Database.delete(com.sleepycat.je.Transaction, com.sleepycat.je.DatabaseEntry)
were called. This includes,
but is not limited to, the secondary record referenced by the given key.
delete
in class 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.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.
get
in class Database
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 secondary key used as input. It must be initialized with
a non-null byte array by the caller. *data
- the primary 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 get(Transaction txn, DatabaseEntry key, DatabaseEntry pKey, 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 secondary key used as input. It must be initialized with
a non-null byte array by the caller.pKey
- the primary key returned as output. Its byte array does not
need to be initialized by the caller.data
- the primary 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
UnsupportedOperationException
will always be thrown by this method.
The corresponding method with the pKey
parameter should be
used instead.
getSearchBoth
in class Database
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 keyused as input. It must be initialized with a non-null
byte array by the caller.data
- the dataused 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.
DatabaseException
- if a failure occurs.public OperationStatus getSearchBoth(Transaction txn, DatabaseEntry key, DatabaseEntry pKey, 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 secondary keyused as input. It must be initialized with
a non-null byte array by the caller.pKey
- the primary keyused as input. It must be initialized with a
non-null byte array by the caller.data
- the primary 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 put(Transaction txn, DatabaseEntry key, DatabaseEntry data) throws DatabaseException
UnsupportedOperationException
will always be thrown by this method.
The corresponding method on the primary database should be used instead.
put
in class 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.key
- the key DatabaseEntry
operated on.data
- the data DatabaseEntry
stored.
OperationStatus.SUCCESS
if the operation succeeds.
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
UnsupportedOperationException
will always be thrown by this method.
The corresponding method on the primary database should be used instead.
putNoOverwrite
in class 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.key
- the key DatabaseEntry
operated on.data
- the data DatabaseEntry
stored.
OperationStatus.KEYEXIST
if the key already appears in the database,
else OperationStatus.SUCCESS
DeadlockException
- if the operation was selected to resolve a
deadlock.
DatabaseException
- if any other failure occurs.public OperationStatus putNoDupData(Transaction txn, DatabaseEntry key, DatabaseEntry data) throws DatabaseException
UnsupportedOperationException
will always be thrown by this method.
The corresponding method on the primary database should be used instead.
putNoDupData
in class 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.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 JoinCursor join(Cursor[] cursors, JoinConfig config) throws DatabaseException
UnsupportedOperationException
will always be thrown by this method.
The corresponding method on the primary database should be used instead.
join
in class Database
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. @see JoinCursor
|
Berkeley DB Java Edition version ${release.version} |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |