Class MemoryDb
- java.lang.Object
-
- com.exonum.binding.core.proxy.AbstractNativeProxy
-
- com.exonum.binding.core.proxy.AbstractCloseableNativeProxy
-
- com.exonum.binding.core.storage.database.MemoryDb
-
- All Implemented Interfaces:
CloseableNativeProxy
,Database
,AutoCloseable
public final class MemoryDb extends AbstractCloseableNativeProxy implements Database
An in-memory database 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.- See Also:
NodeFake
-
-
Field Summary
-
Fields inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
nativeHandle
-
-
Method Summary
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 MemoryDb
newInstance()
Creates a new empty MemoryDb.-
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 MemoryDb newInstance()
Creates a new empty MemoryDb.
-
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.- Parameters:
fork
- a fork to get changes from
-
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
-
-