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
,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
-
Fields inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
nativeHandle
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Fork
createFork(Cleaner cleaner)
Creates a new database fork.Snapshot
createSnapshot(Cleaner cleaner)
Creates a new snapshot of the database state.protected void
disposeInternal()
Releases any resources owned by this proxy (e.g., the corresponding native object).void
merge(Fork fork)
Applies the changes from the given fork to the database state.static TemporaryDb
newInstance()
Creates a new empty TemporaryDb.-
Methods inherited from class com.exonum.binding.core.proxy.AbstractCloseableNativeProxy
close, getNativeHandle
-
Methods inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
isValidHandle
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.exonum.binding.core.proxy.CloseableNativeProxy
close
-
-
-
-
Method Detail
-
newInstance
public static TemporaryDb newInstance()
Creates a new empty TemporaryDb.
-
createSnapshot
public Snapshot createSnapshot(Cleaner cleaner)
Description copied from interface:Database
Creates a new snapshot of the database state.- Specified by:
createSnapshot
in interfaceDatabase
- Parameters:
cleaner
- a cleaner to register the snapshot- Returns:
- a new snapshot of the database state
-
createFork
public Fork createFork(Cleaner cleaner)
Description copied from interface:Database
Creates 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:
createFork
in interfaceDatabase
- Parameters:
cleaner
- a cleaner to register the fork- Returns:
- a new database fork
-
merge
public void merge(Fork fork)
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:
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:AbstractCloseableNativeProxy
Releases 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:
disposeInternal
in classAbstractCloseableNativeProxy
-
-