Class TxEngine
- java.lang.Object
-
- org.mapdb.TxEngine
-
- All Implemented Interfaces:
- java.io.Closeable, java.lang.AutoCloseable, Engine
public class TxEngine extends java.lang.Object implements Engine
Naive implementation of Snapshots on top of StorageEngine. On update it takes old value and stores it aside.
TODO merge snapshots down with Storage for best performance
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description classTxEngine.Tx-
Nested classes/interfaces inherited from interface org.mapdb.Engine
Engine.CloseOnJVMShutdown, Engine.ReadOnly, Engine.ReadOnlyWrapper
-
-
Field Summary
-
Fields inherited from interface org.mapdb.Engine
CLOSED_ENGINE, RECID_CLASS_CATALOG, RECID_FIRST, RECID_LAST_RESERVED, RECID_NAME_CATALOG, RECID_RECORD_CHECK
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleancanRollback()booleancanSnapshot()voidclearCache()clears any underlying cachevoidclose()Close store/cache.voidcommit()Makes all changes made since the previous commit/rollback permanent.voidcompact()<A> booleancompareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer)Updates existing record in atomic (Compare And Swap) manner.static EnginecreateSnapshotFor(Engine engine)<A> voiddelete(long recid, Serializer<A> serializer)Remove existing record from store/cache<A> Aget(long recid, Serializer<A> serializer)Get existing record.EnginegetWrappedEngine()if this is wrapper return underlying engine, or nullbooleanisClosed()Checks whether Engine was closed.booleanisReadOnly()Check if you can write into this Engine.longpreallocate()Preallocates recid for not yet created record.<A> longput(A value, Serializer<A> serializer)Insert new record.voidrollback()Undoes all changes made in the current transaction.Enginesnapshot()Returns read-only snapshot of data in Engine.<A> voidupdate(long recid, A value, Serializer<A> serializer)Update existing record with new value.
-
-
-
Method Detail
-
canSnapshot
public boolean canSnapshot()
- Specified by:
canSnapshotin interfaceEngine- Returns:
- true if engine can create read-only snapshots
-
snapshot
public Engine snapshot()
Description copied from interface:EngineReturns read-only snapshot of data in Engine.
-
getWrappedEngine
public Engine getWrappedEngine()
Description copied from interface:Engineif this is wrapper return underlying engine, or null- Specified by:
getWrappedEnginein interfaceEngine
-
clearCache
public void clearCache()
Description copied from interface:Engineclears any underlying cache- Specified by:
clearCachein interfaceEngine
-
preallocate
public long preallocate()
Description copied from interface:EnginePreallocates recid for not yet created record. It does not insert any data into it.- Specified by:
preallocatein interfaceEngine- Returns:
- new recid
-
put
public <A> long put(A value, Serializer<A> serializer)Description copied from interface:EngineInsert new record.
-
get
public <A> A get(long recid, Serializer<A> serializer)Description copied from interface:EngineGet existing record.
Recid must be a number returned by 'put' method. Behaviour for invalid recid (random number or already deleted record) is not defined, typically it returns null or throws 'EndOfFileException'
-
update
public <A> void update(long recid, A value, Serializer<A> serializer)Description copied from interface:EngineUpdate existing record with new value.
Recid must be a number returned by 'put' method. Behaviour for invalid recid (random number or already deleted record) is not defined, typically it throws 'EndOfFileException', but it may also corrupt store.
-
compareAndSwap
public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer)Description copied from interface:EngineUpdates existing record in atomic (Compare And Swap) manner. Value is modified only if old value matches expected value. There are three ways to match values, MapDB may use any of them:
- Equality check
oldValue==expectedOldValuewhen old value is found in instance cache - Deserializing
oldValueusingserializerand checkingoldValue.equals(expectedOldValue) - Serializing
expectedOldValueusingserializerand comparing binary array with already serializedoldValue
Recid must be a number returned by 'put' method. Behaviour for invalid recid (random number or already deleted record) is not defined, typically it throws 'EndOfFileException', but it may also corrupt store.
- Specified by:
compareAndSwapin interfaceEngine- Parameters:
recid- (record identifier) under which record was persisted.expectedOldValue- old value to be compared with existing recordnewValue- to be written if values are matchingserializer- used to serialize record into binary form- Returns:
- true if values matched and newValue was written
- Equality check
-
delete
public <A> void delete(long recid, Serializer<A> serializer)Description copied from interface:EngineRemove existing record from store/cache
Recid must be a number returned by 'put' method. Behaviour for invalid recid (random number or already deleted record) is not defined, typically it throws 'EndOfFileException', but it may also corrupt store.
-
close
public void close()
Description copied from interface:EngineClose store/cache. This method must be called before JVM exits to flush all caches and prevent store corruption. Also it releases resources used by MapDB (disk, memory..).
Engine can no longer be used after this method was called. If Engine is used after closing, it may throw any exception including
NullPointerExceptionThere is an configuration option
DBMaker.Maker.closeOnJvmShutdown()which uses shutdown hook to automatically close Engine when JVM shutdowns.
-
isClosed
public boolean isClosed()
Description copied from interface:EngineChecks whether Engine was closed.
-
commit
public void commit()
Description copied from interface:EngineMakes all changes made since the previous commit/rollback permanent. In transactional mode (on by default) it means creating journal file and replaying it to storage. In other modes it may flush disk caches or do nothing at all (check your config options)
-
rollback
public void rollback()
Description copied from interface:EngineUndoes all changes made in the current transaction. If transactions are disabled it throwsUnsupportedOperationException.
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:EngineCheck if you can write into this Engine. It may be readonly in some cases (snapshot, read-only files).- Specified by:
isReadOnlyin interfaceEngine- Returns:
- true if engine is read-only
-
canRollback
public boolean canRollback()
- Specified by:
canRollbackin interfaceEngine- Returns:
- true if engine supports rollback
-
-
DataMelt 3.0 © DataMelt by jWork.ORG