public interface Environment extends java.io.Closeable, Backupable
Environment can be created with the help of the Environments utility class:
Environment env = Environments.newInstance("/home/me/.myAppData");
Environment will be created if specified database directory doesn't contain database files. It's impossible to share
single database directory amongst different Environment instances. An attempt to do this (from within
any process, current or not) will fail.
Environment env = Environments.newInstance("/home/me/.myAppData", new EnvironmentConfig().setGcEnabled(false));
After finishing working with the Environment you should close() it.| Modifier and Type | Method and Description |
|---|---|
@NotNull Transaction |
beginExclusiveTransaction()
Starts new exclusive transaction which can be used to read and write data.
|
@NotNull Transaction |
beginExclusiveTransaction(java.lang.Runnable beginHook)
Starts new exclusive transaction which can be used to read and write data.
|
@NotNull Transaction |
beginReadonlyTransaction()
Starts new transaction which can be used to only read data.
|
@NotNull Transaction |
beginReadonlyTransaction(java.lang.Runnable beginHook)
Starts new transaction which can be used to only read data.
|
@NotNull Transaction |
beginTransaction()
Starts new transaction which can be used to read and write data.
|
@NotNull Transaction |
beginTransaction(java.lang.Runnable beginHook)
Starts new transaction which can be used to read and write data.
|
void |
clear()
Clears all the data in the environment.
|
void |
close()
Closes environment instance.
|
<T> T |
computeInExclusiveTransaction(@NotNull TransactionalComputable<T> computable)
Computes and returns a value by calling specified computable in a new exclusive transaction.
|
<T> T |
computeInReadonlyTransaction(@NotNull TransactionalComputable<T> computable)
Computes and returns a value by calling specified computable in a new read-only transaction.
|
<T> T |
computeInTransaction(@NotNull TransactionalComputable<T> computable)
Computes and returns a value by calling specified computable in a new transaction.
|
void |
executeInExclusiveTransaction(@NotNull TransactionalExecutable executable)
Executes specified executable in a new exclusive transaction.
|
void |
executeInReadonlyTransaction(@NotNull TransactionalExecutable executable)
Executes specified executable in a new read-only transaction.
|
void |
executeInTransaction(@NotNull TransactionalExecutable executable)
Executes specified executable in a new transaction.
|
void |
executeTransactionSafeTask(@NotNull java.lang.Runnable task)
Executes a task after all currently started transactions finish.
|
void |
gc()
Says environment to quicken background database garbage collector activity.
|
@NotNull java.util.List<java.lang.String> |
getAllStoreNames(@NotNull Transaction txn) |
long |
getCipherBasicIV()
Returns cipher basic IV (initialization vector) to use for database encryption.
|
@Nullable byte[] |
getCipherKey()
Returns cipher key to use for database encryption, or
null if the environment is not configured
to be encrypted. |
@Nullable StreamCipherProvider |
getCipherProvider()
Returns instance of StreamCipherProvider if the environment is configured to be encrypted,
or
null. |
long |
getCreated()
Returns the value of System.currentTimeMillis() when this environment was created.
|
@NotNull EnvironmentConfig |
getEnvironmentConfig()
Returns EnvironmentConfig instance used during creation of the environment.
|
@NotNull java.lang.String |
getLocation()
Returns location of database files on storage device.
|
@NotNull Statistics |
getStatistics() |
boolean |
isOpen() |
@NotNull Store |
openStore(@NotNull java.lang.String name,
@NotNull StoreConfig config,
@NotNull Transaction transaction)
|
@Nullable Store |
openStore(@NotNull java.lang.String name,
@NotNull StoreConfig config,
@NotNull Transaction transaction,
boolean creationRequired)
|
void |
removeStore(@NotNull java.lang.String storeName,
@NotNull Transaction txn)
Removes store with specified name.
|
void |
resumeGC()
Resumes earlier suspended database garbage collector activity.
|
boolean |
storeExists(@NotNull java.lang.String storeName,
@NotNull Transaction txn) |
void |
suspendGC()
Suspends database garbage collector activity unless resumeGC() is called.
|
void |
truncateStore(@NotNull java.lang.String storeName,
@NotNull Transaction txn)
Truncates store with specified name.
|
getBackupStrategylong getCreated()
Environment instance was created.@NotNull @NotNull java.lang.String getLocation()
@NotNull @NotNull Store openStore(@NotNull @NotNull java.lang.String name, @NotNull @NotNull StoreConfig config, @NotNull @NotNull Transaction transaction)
name and
config inside a transaction. StoreConfig provides meta-information
used to create store. If it is known that the store with specified name exists, then
StoreConfig.USE_EXISTING can be used.name - name of storeconfig - StoreConfig used to create storetransaction - Transaction used to create store@Nullable @Nullable Store openStore(@NotNull @NotNull java.lang.String name, @NotNull @NotNull StoreConfig config, @NotNull @NotNull Transaction transaction, boolean creationRequired)
name and
config inside a transaction. StoreConfig provides meta-information
used to create the store. If it is known that the store with specified name exists, then
StoreConfig.USE_EXISTING can be used.
true as creationRequired if creating new store is required or allowed. In that case,
the method will do the same as openStore(String, StoreConfig, Transaction). If you pass
false the method will return null for non-existing store.name - name of storeconfig - StoreConfig used to create storetransaction - Transaction used to create storecreationRequired - pass false if you wish to get null for non-existing store
rather than create itvoid executeTransactionSafeTask(@NotNull
@NotNull java.lang.Runnable task)
task - task to executevoid clear()
ExodusException - if there is a Transaction in current threadTransactionvoid close()
true. After environment is closed
another instance of Environment by the same location can be created.close in interface java.lang.AutoCloseableclose in interface java.io.CloseableExodusException - if there are unfinished transactionsEnvironmentClosedException - if environment is already closedboolean isOpen()
false is the instance is closed@NotNull
@NotNull java.util.List<java.lang.String> getAllStoreNames(@NotNull
@NotNull Transaction txn)
txn - transaction instanceboolean storeExists(@NotNull
@NotNull java.lang.String storeName,
@NotNull
@NotNull Transaction txn)
storeName - name of storetxn - transaction instancetrue if store with specified name existsvoid truncateStore(@NotNull
@NotNull java.lang.String storeName,
@NotNull
@NotNull Transaction txn)
storeName - name of storetxn - transaction instancevoid removeStore(@NotNull
@NotNull java.lang.String storeName,
@NotNull
@NotNull Transaction txn)
storeName - name of storetxn - transaction instancevoid gc()
void suspendGC()
EnvironmentConfig.setGcEnabled(boolean)void resumeGC()
@NotNull @NotNull Transaction beginTransaction()
Transaction@NotNull @NotNull Transaction beginTransaction(java.lang.Runnable beginHook)
beginHook is called each time
when the transaction holds the new database snapshot. First time it is called during beginTransaction()
execution, then during each call to Transaction.flush() or Transaction.revert().beginHook - begin hookTransaction@NotNull @NotNull Transaction beginExclusiveTransaction()
Transaction,
Transaction.isExclusive()@NotNull @NotNull Transaction beginExclusiveTransaction(java.lang.Runnable beginHook)
beginHook is called each time when the transaction holds the new database
snapshot. First time it is called during beginTransaction() execution, then during each call to
Transaction.flush() or Transaction.revert().beginHook - begin hookTransaction@NotNull @NotNull Transaction beginReadonlyTransaction()
Transaction,
Transaction.isReadonly()@NotNull @NotNull Transaction beginReadonlyTransaction(java.lang.Runnable beginHook)
beginHook is called each time
when the transaction holds the new database snapshot. First time it is called during beginTransaction()
execution, then during each call to Transaction.revert().beginHook - begin hookTransaction,
Transaction.isReadonly()void executeInTransaction(@NotNull
@NotNull TransactionalExecutable executable)
executable - transactional executableTransactionalExecutablevoid executeInExclusiveTransaction(@NotNull
@NotNull TransactionalExecutable executable)
executable - transactional executableTransactionalExecutablevoid executeInReadonlyTransaction(@NotNull
@NotNull TransactionalExecutable executable)
executable - transactional executableTransactionalExecutable,
Transaction.isReadonly()<T> T computeInTransaction(@NotNull
@NotNull TransactionalComputable<T> computable)
computable - transactional computableTransactionalComputable<T> T computeInExclusiveTransaction(@NotNull
@NotNull TransactionalComputable<T> computable)
computable - transactional computableTransactionalComputable<T> T computeInReadonlyTransaction(@NotNull
@NotNull TransactionalComputable<T> computable)
computable - transactional computableTransactionalComputable,
Transaction.isReadonly()@NotNull @NotNull EnvironmentConfig getEnvironmentConfig()
@NotNull @NotNull Statistics getStatistics()
Environment instance@Nullable @Nullable StreamCipherProvider getCipherProvider()
null.nullStreamCipherProvider,
EnvironmentConfig.getCipherId()@Nullable @Nullable byte[] getCipherKey()
null if the environment is not configured
to be encrypted.null if the environment is not configured
to be encryptedStreamCipher.init(byte[], long),
EnvironmentConfig.getCipherKey()long getCipherBasicIV()
StreamCipher.init(byte[], long),
EnvironmentConfig.getCipherBasicIV()