org.h2.mvstore.db
Class TransactionStore.TransactionMap<K,V>

java.lang.Object
  extended by org.h2.mvstore.db.TransactionStore.TransactionMap<K,V>
Type Parameters:
K - the key type
V - the value type
Enclosing class:
TransactionStore

public static class TransactionStore.TransactionMap<K,V>
extends java.lang.Object

A map that supports transactions.


Method Summary
 void clear()
          Clear the map.
 boolean containsKey(K key)
          Whether the map contains the key.
 java.util.Iterator<java.util.Map.Entry<K,V>> entryIterator(K from)
          Iterate over entries.
 K firstKey()
          Get the first key.
 V get(K key)
          Get the value for the given key at the time when this map was opened.
 V get(K key, long maxLogId)
          Get the value for the given key.
 TransactionStore.TransactionMap<K,V> getInstance(TransactionStore.Transaction transaction, long savepoint)
          Get a clone of this map for the given transaction.
 DataType getKeyType()
           
 V getLatest(K key)
          Get the most recent value for the given key.
 K getLatestCeilingKey(K key)
          Get the most recent smallest key that is larger or equal to this key.
 TransactionStore.Transaction getTransaction()
           
 K higherKey(K key)
          Get the smallest key that is larger than the given key, or null if no such key exists.
 boolean isClosed()
          Check whether this map is closed.
 boolean isSameTransaction(K key)
          Whether the entry for this key was added or removed from this session.
 java.util.Iterator<K> keyIterator(K from)
          Iterate over keys.
 java.util.Iterator<K> keyIterator(K from, boolean includeUncommitted)
          Iterate over keys.
 K lastKey()
          Get the last key.
 K lowerKey(K key)
          Get the largest key that is smaller than the given key, or null if no such key exists.
 V put(K key, V value)
          Update the value for the given key.
 V putCommitted(K key, V value)
          Update the value for the given key, without adding an undo log entry.
 K relativeKey(K key, long offset)
          Get one of the previous or next keys.
 V remove(K key)
          Remove an entry.
 void setSavepoint(long savepoint)
          Set the savepoint.
 long sizeAsLong()
          Get the size of the map as seen by this transaction.
 long sizeAsLongMax()
          Get the size of the raw map.
 boolean tryPut(K key, V value)
          Try to update the value for the given key.
 boolean tryRemove(K key)
          Try to remove the value for the given key.
 boolean trySet(K key, V value, boolean onlyIfUnchanged)
          Try to set or remove the value.
 java.util.Iterator<K> wrapIterator(java.util.Iterator<K> iterator, boolean includeUncommitted)
          Iterate over keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setSavepoint

public void setSavepoint(long savepoint)
Set the savepoint. Afterwards, reads are based on the specified savepoint.

Parameters:
savepoint - the savepoint

getInstance

public TransactionStore.TransactionMap<K,V> getInstance(TransactionStore.Transaction transaction,
                                                        long savepoint)
Get a clone of this map for the given transaction.

Parameters:
transaction - the transaction
savepoint - the savepoint
Returns:
the map

sizeAsLongMax

public long sizeAsLongMax()
Get the size of the raw map. This includes uncommitted entries, and transiently removed entries, so it is the maximum number of entries.

Returns:
the maximum size

sizeAsLong

public long sizeAsLong()
Get the size of the map as seen by this transaction.

Returns:
the size

remove

public V remove(K key)
Remove an entry.

If the row is locked, this method will retry until the row could be updated or until a lock timeout.

Parameters:
key - the key
Throws:
java.lang.IllegalStateException - if a lock timeout occurs

put

public V put(K key,
             V value)
Update the value for the given key.

If the row is locked, this method will retry until the row could be updated or until a lock timeout.

Parameters:
key - the key
value - the new value (not null)
Returns:
the old value
Throws:
java.lang.IllegalStateException - if a lock timeout occurs

putCommitted

public V putCommitted(K key,
                      V value)
Update the value for the given key, without adding an undo log entry.

Parameters:
key - the key
value - the value
Returns:
the old value

tryRemove

public boolean tryRemove(K key)
Try to remove the value for the given key.

This will fail if the row is locked by another transaction (that means, if another open transaction changed the row).

Parameters:
key - the key
Returns:
whether the entry could be removed

tryPut

public boolean tryPut(K key,
                      V value)
Try to update the value for the given key.

This will fail if the row is locked by another transaction (that means, if another open transaction changed the row).

Parameters:
key - the key
value - the new value
Returns:
whether the entry could be updated

trySet

public boolean trySet(K key,
                      V value,
                      boolean onlyIfUnchanged)
Try to set or remove the value. When updating only unchanged entries, then the value is only changed if it was not changed after opening the map.

Parameters:
key - the key
value - the new value (null to remove the value)
onlyIfUnchanged - only set the value if it was not changed (by this or another transaction) since the map was opened
Returns:
true if the value was set, false if there was a concurrent update

get

public V get(K key)
Get the value for the given key at the time when this map was opened.

Parameters:
key - the key
Returns:
the value or null

getLatest

public V getLatest(K key)
Get the most recent value for the given key.

Parameters:
key - the key
Returns:
the value or null

containsKey

public boolean containsKey(K key)
Whether the map contains the key.

Parameters:
key - the key
Returns:
true if the map contains an entry for this key

get

public V get(K key,
             long maxLogId)
Get the value for the given key.

Parameters:
key - the key
maxLogId - the maximum log id
Returns:
the value or null

isSameTransaction

public boolean isSameTransaction(K key)
Whether the entry for this key was added or removed from this session.

Parameters:
key - the key
Returns:
true if yes

isClosed

public boolean isClosed()
Check whether this map is closed.

Returns:
true if closed

clear

public void clear()
Clear the map.


firstKey

public K firstKey()
Get the first key.

Returns:
the first key, or null if empty

lastKey

public K lastKey()
Get the last key.

Returns:
the last key, or null if empty

getLatestCeilingKey

public K getLatestCeilingKey(K key)
Get the most recent smallest key that is larger or equal to this key.

Parameters:
key - the key (may not be null)
Returns:
the result

higherKey

public K higherKey(K key)
Get the smallest key that is larger than the given key, or null if no such key exists.

Parameters:
key - the key (may not be null)
Returns:
the result

relativeKey

public K relativeKey(K key,
                     long offset)
Get one of the previous or next keys. There might be no value available for the returned key.

Parameters:
key - the key (may not be null)
offset - how many keys to skip (-1 for previous, 1 for next)
Returns:
the key

lowerKey

public K lowerKey(K key)
Get the largest key that is smaller than the given key, or null if no such key exists.

Parameters:
key - the key (may not be null)
Returns:
the result

keyIterator

public java.util.Iterator<K> keyIterator(K from)
Iterate over keys.

Parameters:
from - the first key to return
Returns:
the iterator

keyIterator

public java.util.Iterator<K> keyIterator(K from,
                                         boolean includeUncommitted)
Iterate over keys.

Parameters:
from - the first key to return
includeUncommitted - whether uncommitted entries should be included
Returns:
the iterator

entryIterator

public java.util.Iterator<java.util.Map.Entry<K,V>> entryIterator(K from)
Iterate over entries.

Parameters:
from - the first key to return
Returns:
the iterator

wrapIterator

public java.util.Iterator<K> wrapIterator(java.util.Iterator<K> iterator,
                                          boolean includeUncommitted)
Iterate over keys.

Parameters:
iterator - the iterator to wrap
includeUncommitted - whether uncommitted entries should be included
Returns:
the iterator

getTransaction

public TransactionStore.Transaction getTransaction()

getKeyType

public DataType getKeyType()