org.mapdb
Class EngineWrapper.ReadOnlyEngine

java.lang.Object
  extended by org.mapdb.EngineWrapper
      extended by org.mapdb.EngineWrapper.ReadOnlyEngine
All Implemented Interfaces:
Engine
Enclosing class:
EngineWrapper

public static class EngineWrapper.ReadOnlyEngine
extends EngineWrapper

Wraps an Engine and throws UnsupportedOperationException("Read-only") on any modification attempt.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.mapdb.EngineWrapper
EngineWrapper.CloseOnJVMShutdown, EngineWrapper.ImmutabilityCheckEngine, EngineWrapper.ReadOnlyEngine, EngineWrapper.SerializerCheckEngineWrapper, EngineWrapper.SynchronizedEngineWrapper
 
Field Summary
 
Fields inherited from class org.mapdb.EngineWrapper
CLOSED
 
Fields inherited from interface org.mapdb.Engine
CATALOG_RECID, CHECK_RECORD, CLASS_INFO_RECID, LAST_RESERVED_RECID
 
Constructor Summary
EngineWrapper.ReadOnlyEngine(Engine engine)
           
 
Method Summary
 boolean canSnapshot()
           
 void commit()
          Makes all changes made since the previous commit/rollback permanent.
<A> boolean
compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer)
          Updates existing record in atomic (Compare And Swap) manner.
<A> void
delete(long recid, Serializer<A> serializer)
          Remove existing record from store/cache

Recid must be a number returned by 'put' method.

 boolean isReadOnly()
          Check if you can write into this Engine.
 long preallocate()
          Preallocates recid for not yet created record.
 void preallocate(long[] recids)
          Preallocates recids for not yet created record.
<A> long
put(A value, Serializer<A> serializer)
          Insert new record.
 void rollback()
          Undoes all changes made in the current transaction.
 Engine snapshot()
          Returns read-only snapshot of data in Engine.
<A> void
update(long recid, A value, Serializer<A> serializer)
          Update existing record with new value.
 
Methods inherited from class org.mapdb.EngineWrapper
canRollback, checkClosed, clearCache, close, closeListenerRegister, closeListenerUnregister, compact, get, getSerializerPojo, getWrappedEngine, isClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EngineWrapper.ReadOnlyEngine

public EngineWrapper.ReadOnlyEngine(Engine engine)
Method Detail

preallocate

public long preallocate()
Description copied from interface: Engine
Preallocates recid for not yet created record. It does not insert any data into it.

Specified by:
preallocate in interface Engine
Overrides:
preallocate in class EngineWrapper
Returns:
new recid

preallocate

public void preallocate(long[] recids)
Description copied from interface: Engine
Preallocates recids for not yet created record. It does not insert any data into it. This is done in batch of given size (determied by size of array in argument)

Specified by:
preallocate in interface Engine
Overrides:
preallocate in class EngineWrapper
Parameters:
recids - array to put result into

compareAndSwap

public <A> boolean compareAndSwap(long recid,
                                  A expectedOldValue,
                                  A newValue,
                                  Serializer<A> serializer)
Description copied from interface: Engine
Updates 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:
  1. Equality check oldValue==expectedOldValue when old value is found in instance cache
  2. Deserializing oldValue using serializer and checking oldValue.equals(expectedOldValue)
  3. Serializing expectedOldValue using serializer and comparing binary array with already serialized oldValue

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:
compareAndSwap in interface Engine
Overrides:
compareAndSwap in class EngineWrapper
Parameters:
recid - (record identifier) under which record was persisted.
expectedOldValue - old value to be compared with existing record
newValue - to be written if values are matching
serializer - used to serialize record into binary form
Returns:
true if values matched and newValue was written

put

public <A> long put(A value,
                    Serializer<A> serializer)
Description copied from interface: Engine
Insert new record.

Specified by:
put in interface Engine
Overrides:
put in class EngineWrapper
Parameters:
value - records to be added
serializer - used to convert record into/from binary form
Returns:
recid (record identifier) under which record is stored.

update

public <A> void update(long recid,
                       A value,
                       Serializer<A> serializer)
Description copied from interface: Engine
Update 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.

Specified by:
update in interface Engine
Overrides:
update in class EngineWrapper
Parameters:
recid - (record identifier) under which record was persisted.
value - new record value to be stored
serializer - used to serialize record into binary form

delete

public <A> void delete(long recid,
                       Serializer<A> serializer)
Description copied from interface: Engine
Remove 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.

Specified by:
delete in interface Engine
Overrides:
delete in class EngineWrapper
Parameters:
recid - (record identifier) under which was record persisted
serializer - which may be used in some circumstances to deserialize and store old object

commit

public void commit()
Description copied from interface: Engine
Makes 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)

Specified by:
commit in interface Engine
Overrides:
commit in class EngineWrapper

rollback

public void rollback()
Description copied from interface: Engine
Undoes all changes made in the current transaction. If transactions are disabled it throws UnsupportedOperationException.

Specified by:
rollback in interface Engine
Overrides:
rollback in class EngineWrapper

isReadOnly

public boolean isReadOnly()
Description copied from interface: Engine
Check if you can write into this Engine. It may be readonly in some cases (snapshot, read-only files).

Specified by:
isReadOnly in interface Engine
Overrides:
isReadOnly in class EngineWrapper
Returns:
true if engine is read-only

canSnapshot

public boolean canSnapshot()
Specified by:
canSnapshot in interface Engine
Overrides:
canSnapshot in class EngineWrapper
Returns:
true if engine can create read-only snapshots

snapshot

public Engine snapshot()
                throws UnsupportedOperationException
Description copied from interface: Engine
Returns read-only snapshot of data in Engine.

Specified by:
snapshot in interface Engine
Overrides:
snapshot in class EngineWrapper
Throws:
UnsupportedOperationException - if snapshots are not supported/enabled
See Also:
EngineWrapper.canSnapshot()


Copyright © 2014. All Rights Reserved.