Class TemporaryDb
java.lang.Object
com.exonum.binding.core.proxy.AbstractNativeProxy
com.exonum.binding.core.proxy.AbstractCloseableNativeProxy
com.exonum.binding.core.storage.database.TemporaryDb
- All Implemented Interfaces:
CloseableNativeProxy,Database,java.lang.AutoCloseable
public final class TemporaryDb extends AbstractCloseableNativeProxy implements Database
A MerkleDB which stores its data in the temporary directory for testing purposes.
It can create both read-only snapshots and read-write forks. The changes made to
database forks can be applied to the database state.
The corresponding database is deleted when TemporaryDb is closed.
- See Also:
NodeFake
-
Field Summary
-
Method Summary
Modifier and Type Method Description ForkcreateFork(Cleaner cleaner)Creates a new database fork.SnapshotcreateSnapshot(Cleaner cleaner)Creates a new snapshot of the database state.protected voiddisposeInternal()Releases any resources owned by this proxy (e.g., the corresponding native object).voidmerge(Fork fork)Applies the changes from the given fork to the database state.static TemporaryDbnewInstance()Creates a new empty TemporaryDb.Methods inherited from class com.exonum.binding.core.proxy.AbstractCloseableNativeProxy
close, getNativeHandle
-
Method Details
-
newInstance
Creates a new empty TemporaryDb. -
createSnapshot
Description copied from interface:DatabaseCreates a new snapshot of the database state.- Specified by:
createSnapshotin interfaceDatabase- Parameters:
cleaner- a cleaner to register the snapshot- Returns:
- a new snapshot of the database state
-
createFork
Description copied from interface:DatabaseCreates a new database fork.A fork allows to perform a transaction: a number of independent writes to a database, which then may be atomically applied to the database.
- Specified by:
createForkin interfaceDatabase- Parameters:
cleaner- a cleaner to register the fork- Returns:
- a new database fork
-
merge
Applies the changes from the given fork to the database state. TemporaryDb can only merge forks that it created itself.Once this method completes, any indexes created with the fork and the fork itself are closed and cannot be used anymore. Any subsequent operations on these objects will result in
IllegalStateException.- Parameters:
fork- a fork to get changes from- Throws:
java.lang.RuntimeException- if the fork cannot be applied to the database state. The provided fork will be closed
-
disposeInternal
protected void disposeInternal()Description copied from class:AbstractCloseableNativeProxyReleases any resources owned by this proxy (e.g., the corresponding native object).This method is only called once from
AbstractCloseableNativeProxy.close()for a valid proxy and shall not be called directly.- Specified by:
disposeInternalin classAbstractCloseableNativeProxy
-