|
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.Environment
A database environment. Environments include support for some or all of caching, locking, logging and transactions.
To open an existing environment with default attributes the application may use a default environment configuration object or null:
// Open an environment handle with default attributes. Environment env = new Environment(home, new EnvironmentConfig());
or
Environment env = new Environment(home, null);
Note that many Environment objects may access a single environment.
To create an environment or customize attributes, the application should customize the configuration class. For example:
EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(true); envConfig.setAllowCreate(true); envConfig.setCacheSize(1000000);Environment newlyCreatedEnv = new Environment(home, envConfig);
Note that environment configuration parameters can also be set through the <environment home>/je.properties file. This file takes precedence over any programmatically specified configuration parameters so that configuration changes can be made without recompiling. Environment configuration follows this order of precedence:
An environment handle is an Environment instance. More than one Environment instance may be created for the same physical directory, which is the same as saying that more than one Environment handle may be open at one time for a given environment.
The Environment handle should not be closed while any other
handle remains open that is using it as a reference (for example, Database
or Transaction
. Once Environment.close
is called, this object may not be accessed again, regardless of whether
or not it throws an exception.
Constructor Summary | |
Environment(File envHome, EnvironmentConfig envConfig)
Create a database environment handle. |
Method Summary | |
Transaction |
beginTransaction(Transaction parent, TransactionConfig txnConfig)
Create a new transaction in the database environment. |
void |
checkpoint(CheckpointConfig checkpointConfig)
Synchronously checkpoint the database environment. |
int |
cleanLog()
Synchronously invoke database environment log cleaning. |
void |
close()
The Environment.close method closes the Berkeley DB environment. |
void |
compress()
Synchronously invoke the compressor mechanism which compacts in memory data structures after delete operations. |
void |
evictMemory()
Synchronously invoke the mechanism for keeping memory usage within the cache size boundaries. |
EnvironmentConfig |
getConfig()
Return this object's configuration. |
List |
getDatabaseNames()
Return a List of database names for the database environment. |
File |
getHome()
Return the database environment's home directory. |
LockStats |
getLockStats(StatsConfig config) Return the database environment's locking statistics. |
EnvironmentMutableConfig |
getMutableConfig()
Return database environment attributes. |
EnvironmentStats |
getStats(StatsConfig config) Return the general database environment statistics. |
TransactionStats |
getTransactionStats(StatsConfig config) Return the database environment's transactional statistics. |
Database |
openDatabase(Transaction txn, String databaseName,
DatabaseConfig dbConfig) Open, and optionally create, a Database . |
SecondaryDatabase |
openSecondaryDatabase(Transaction txn, String databaseName,
Database primaryDatabase,
SecondaryConfig secConfig)
Open and optionally create a SecondaryDatabase . |
void |
removeDatabase(Transaction txn, String databaseName)
Remove a database. |
void |
renameDatabase(Transaction txn, String databaseName,
String newName) Rename a database. |
void |
setMutableConfig(EnvironmentMutableConfig envMutableConfig)
Set database environment attributes. |
void |
sync() Synchronously flush database environment databases to stable storage. |
long |
truncateDatabase(Transaction txn, String databaseName,
boolean returnCount) Empty the database, discarding all records it contains. |
boolean |
verify(VerifyConfig verifyConfig,
PrintStream out) Return if the database environment is consistent and correct. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Environment(File envHome, EnvironmentConfig envConfig) throws DatabaseException
envHome
- The database environment's home
directory.
envConfig
- The database environment attributes.
If null, default attributes are used.
IllegalArgumentException
-
if an invalid parameter was specified.
DatabaseException
- if a failure
occurs.
Method Detail |
public File getHome() throws DatabaseException
DatabaseException
- if a
failure occurs.
public EnvironmentConfig getConfig() throws DatabaseException
DatabaseException
- if a
failure occurs.
public Transaction beginTransaction(Transaction parent, TransactionConfig txnConfig) throws DatabaseException
Transaction handles are free-threaded; transactions handles may be used concurrently by multiple threads.
Cursors may not span transactions; that is, each cursor must be opened and closed within a single transaction. The parent parameter is a placeholder for nested transactions, and must currently be null.
txnConfig
- The transaction attributes. If null,
default attributes are used.
DatabaseException
- if a
failure occurs.
public void checkpoint(CheckpointConfig checkpointConfig) throws DatabaseException
This is an optional action for the application since this activity is, by default, handled by a database environment owned background thread.
checkpointConfig
- The checkpoint attributes. If
null, default attributes are used.
DatabaseException
- if a
failure occurs.
public LockStats getLockStats(StatsConfig config) throws DatabaseException
config
- The locking statistics attributes. If
null, default attributes are used.
DatabaseException
- if a
failure occurs.
public TransactionStats getTransactionStats(StatsConfig config) throws DatabaseException
config
- The transactional statistics
attributes. If null, default attributes are used.
DatabaseException
- if a
failure occurs.
public void close() throws DatabaseException
When the last environment handle is closed, allocated resources are freed, and daemon threads are stopped, even if they are performing work. For example, if the cleaner is still cleaning the log, it will be stopped at the next reasonable opportunity and perform no more cleaning operations.
The Environment handle should not be closed while any other
handle that refers to it is not yet closed; for example, database
environment handles must not be closed while database handles remain
open, or transactions in the environment have not yet committed or
aborted. Specifically, this includes Database
, Cursor
and Transaction
handles.
In multithreaded applications, only a single thread should call Environment.close. Other callers will see a DatabaseException complaining that the handle is already closed.
After Environment.close has been called, regardless of its return, the Berkeley DB environment handle may not be accessed again.
DatabaseException
- if a
failure occurs.
public Database openDatabase(Transaction txn, String databaseName, DatabaseConfig dbConfig) throws DatabaseException
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.
databaseName
- The name of the database.
dbConfig
- The database attributes. If null,
default attributes are used.
DatabaseNotFoundException
- if
the database file does not exist.
DatabaseException
- if a
failure occurs.
public SecondaryDatabase openSecondaryDatabase(Transaction txn, String databaseName, Database primaryDatabase, SecondaryConfig secConfig) throws DatabaseException
SecondaryDatabase
.
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.
databaseName
- The name of the database.
primaryDatabase
- the primary database with
which the secondary database will be associated. The primary database
must not be configured for duplicates.
secConfig
- The secondary database attributes.
If null, default attributes are used.
DatabaseNotFoundException
- if
the database file does not exist.
DatabaseException
- if a
failure occurs.
public void removeDatabase(Transaction txn, String databaseName) throws DatabaseException
Applications should never remove databases with open Database
handles.
txn
- For a transactional environment, an
explicit transaction may be specified or null may be specified to use
auto-commit. For a non-transactional environment, null must be
specified.
databaseName
- The database to be removed.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseNotFoundException
- if
the database file does not exist.
DatabaseException
- if a
failure occurs.
public void renameDatabase(Transaction txn, String databaseName, String newName) throws DatabaseException
Applications should never rename databases with open Database
handles.
txn
- For a transactional environment, an
explicit transaction may be specified or null may be specified to use
auto-commit. For a non-transactional environment, null must be
specified.
databaseName
- The new name of the database.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseNotFoundException
- if
the database file does not exist.
DatabaseException
- if a
failure occurs.
public long truncateDatabase(Transaction txn, String databaseName, boolean returnCount) throws DatabaseException
When called on a database configured with secondary indices, the application is responsible for also truncating all associated secondary indices.
Applications should never truncate databases with open Database
handles.
txn
- For a transactional environment, an
explicit transaction may be specified or null may be specified to use
auto-commit. For a non-transactional environment, null must be
specified.
databaseName
- The database to be truncated.
returnCount
- If true, count and return the
number of records discarded.
DeadlockException
- if the
operation was selected to resolve a deadlock.
DatabaseNotFoundException
- if
the database file does not exist.
DatabaseException
- if a
failure occurs.
public void sync() throws DatabaseException
DatabaseException
- if a
failure occurs.
public int cleanLog() throws DatabaseException
Zero or more log files will be cleaned as necessary to bring the
disk space utilization of the environment above the configured minimum
utilization threshold. The threshold is determined by the je.cleaner.minUtilization
configuration setting.
Note that the cleaned files will not deleted (or renamed) until
a checkpoint occurs, and at least N files have been cleaned by the
start of the checkpoint. N is determined by the je.cleaner.minFilesToDelete
configuration setting. Such a checkpoint must flush all dirty internal
nodes, and is therefore more expensive than a standard checkpoint.
This is an optional action for the application since this activity is, by default, handled by a database environment owned background thread.
DatabaseException
- if a
failure occurs.
public void evictMemory() throws DatabaseException
This is an optional action for the application since this activity is, by default, handled by a database environment owned background thread.
DatabaseException
- if a
failure occurs.
public void compress() throws DatabaseException
This is an optional action for the application since this activity is, by default, handled by a database environment owned background thread.
DatabaseException
- if a
failure occurs.
public void setMutableConfig(EnvironmentMutableConfig envMutableConfig) throws DatabaseException
Attributes only apply to a specific Environment object and are not necessarily shared by other Environment objects accessing this database environment.
envMutableConfig
- The database environment
attributes. If null, default attributes are used.
DatabaseException
- if a
failure occurs.
public EnvironmentMutableConfig getMutableConfig() throws DatabaseException
DatabaseException
- if a
failure occurs.
public EnvironmentStats getStats(StatsConfig config) throws DatabaseException
config
- The general statistics attributes. If
null, default attributes are used.
DatabaseException
- if a
failure occurs.
public List getDatabaseNames() throws DatabaseException
Each element in the list is a String.
DatabaseException
- if a
failure occurs.
public boolean verify(VerifyConfig verifyConfig, PrintStream out) throws DatabaseException
Verification is an expensive operation that should normally only be used for troubleshooting and debugging.
verifyConfig
- The verification attributes. If
null, default attributes are used.
out
- The stream to which verification debugging
information is written.
DatabaseException
- if a
failure occurs.
|
Berkeley
DB Java Edition version 1.7.1 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |