no.priv.garshol.duke
Class InMemoryKeyValueStore

java.lang.Object
  extended by no.priv.garshol.duke.InMemoryKeyValueStore
All Implemented Interfaces:
KeyValueStore

public class InMemoryKeyValueStore
extends Object
implements KeyValueStore

A simple key value store that keeps all data in memory.

Since:
1.0

Constructor Summary
InMemoryKeyValueStore()
           
 
Method Summary
 void close()
          Stores state to disk and closes all open resources.
 void commit()
          Flushes all changes to disk.
 Record findRecordById(long id)
          Returns the record with the given internal ID.
 Record findRecordById(String extid)
          Returns the record with the given external ID.
 boolean isInMemory()
          Returns true iff the database is held entirely in memory, and thus is not persistent.
 Bucket lookupToken(String propname, String token)
          Returns the IDs of all records which have the given token in a value for this property.
 long makeNewRecordId()
          Returns a new internal record ID.
 void registerId(long id, String extid)
          Records that this external ID refers to the given internal record ID.
 void registerRecord(long id, Record record)
          Stores the entire record under the given internal record ID.
 void registerToken(long id, String propname, String token)
          Records that the given token occurred in the given record.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InMemoryKeyValueStore

public InMemoryKeyValueStore()
Method Detail

isInMemory

public boolean isInMemory()
Description copied from interface: KeyValueStore
Returns true iff the database is held entirely in memory, and thus is not persistent.

Specified by:
isInMemory in interface KeyValueStore

commit

public void commit()
Description copied from interface: KeyValueStore
Flushes all changes to disk. For in-memory databases this is a no-op.

Specified by:
commit in interface KeyValueStore

close

public void close()
Description copied from interface: KeyValueStore
Stores state to disk and closes all open resources.

Specified by:
close in interface KeyValueStore

makeNewRecordId

public long makeNewRecordId()
Description copied from interface: KeyValueStore
Returns a new internal record ID.

Specified by:
makeNewRecordId in interface KeyValueStore

registerRecord

public void registerRecord(long id,
                           Record record)
Description copied from interface: KeyValueStore
Stores the entire record under the given internal record ID.

Specified by:
registerRecord in interface KeyValueStore

registerId

public void registerId(long id,
                       String extid)
Description copied from interface: KeyValueStore
Records that this external ID refers to the given internal record ID.

Specified by:
registerId in interface KeyValueStore
Parameters:
id - the internal record ID
extid - the external ID

registerToken

public void registerToken(long id,
                          String propname,
                          String token)
Description copied from interface: KeyValueStore
Records that the given token occurred in the given record.

Specified by:
registerToken in interface KeyValueStore
Parameters:
id - the ID of the record the token occurred in
propname - the property the token occurred in
token - the actual token

findRecordById

public Record findRecordById(String extid)
Description copied from interface: KeyValueStore
Returns the record with the given external ID.

Specified by:
findRecordById in interface KeyValueStore

findRecordById

public Record findRecordById(long id)
Description copied from interface: KeyValueStore
Returns the record with the given internal ID. This method must be thread-safe.

Specified by:
findRecordById in interface KeyValueStore

lookupToken

public Bucket lookupToken(String propname,
                          String token)
Description copied from interface: KeyValueStore
Returns the IDs of all records which have the given token in a value for this property. This method must be thread-safe.

Specified by:
lookupToken in interface KeyValueStore

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013. All Rights Reserved.