Top Description Inners Fields Constructors Methods
org.h2.mvstore.tx

public final Class TransactionMap<K, V>

extends AbstractMap<K, V>
Class Inheritance
Type Parameters
<K>
the key type
<V>
the value type
Imports
java.util.AbstractMap, .AbstractSet, .BitSet, .Iterator, .Map, .NoSuchElementException, .Set, java.util.concurrent.atomic.AtomicReference, java.util.function.BiFunction, org.h2.engine.IsolationLevel, org.h2.mvstore.Cursor, .DataUtils, .MVMap, .MVStoreException, .RootReference, org.h2.mvstore.type.DataType, org.h2.value.VersionedValue

A map that supports transactions.

Methods of this class may be changed at any time without notice. If you use this class directly make sure that your application or library requires exactly the same version of MVStore or H2 jar as the version that you use during its development and build.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
TransactionMap.CommittedIterator<
the type of keys
K
, V,
the type of elements
X
>

The iterator for read committed isolation level.

private static class
TransactionMap.RepeatableIterator<
the type of keys
K
, V,
the type of elements
X
>

The iterator for repeatable read and serializable isolation levels.

public abstract static class
private static class
TransactionMap.UncommittedIterator<
the type of keys
K
, V,
the type of elements
X
>

The iterator for read uncommitted isolation level.

private static class

Field Summary

Modifier and TypeField and Description
private boolean
hasChanges

Indicates whether underlying map was modified from within related transaction

private final TxDecisionMaker<K, V>
private final TxDecisionMaker<K, V>
public final MVMap<K, VersionedValue<V>>
map

The map used for writing (the latest version).

private Snapshot<K, VersionedValue<V>>
snapshot

Snapshot of this map as of beginning of transaction or first usage within transaction or beginning of the statement, depending on isolation level

private Snapshot<K, VersionedValue<V>>
statementSnapshot

Snapshot of this map as of beginning of beginning of the statement

private final Transaction
transaction

The transaction which is used for this map.

private final TxDecisionMaker<K, V>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private long
adjustSize(RootReference<Long, Record<?, ?>>[] undoLogRootReferences, RootReference<K, VersionedValue<V>> mapRootReference, BitSet committingTransactions, long size, long undoLogsTotalSize)

public void
append(K
should be higher in map's order than any existing key
key
,
V
to be appended
value
)

Appends entry to underlying map.

public Map.Entry<K, V>

Returns:

the result
ceilingEntry
(K
the key (may not be null)
key
)

Get the entry with smallest key that is larger than or equal to this key, or null if no such key exists.

public K

Returns:

the result
ceilingKey
(K
the key (may not be null)
key
)

Get the smallest key that is larger than or equal to this key, or null if no such key exists.

private <X> TransactionMap.TMIterator<K, V, X>
chooseIterator(K from, K to, boolean reverse, boolean forEntries)

public void
clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Clear the map.

public boolean

Returns:

true if the map contains an entry for this key
containsKey
(Object
the key
key
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Whether the map contains the key.

pack-priv Snapshot<K, VersionedValue<V>>

Returns:

the snapshot
createSnapshot
()

Create a new snapshot for this map.

public TransactionMap.TMIterator<K, V, Map.Entry<K, V>>

Returns:

the iterator
entryIterator
(final K
the first key to return
from
,
final K
the last key to return
to
)

Iterate over entries.

public TransactionMap.TMIterator<K, V, Map.Entry<K, V>>

Returns:

the iterator
entryIterator
(K
the first key to return
from
,
K
the last key to return
to
,
boolean
if true, iterate in reverse (descending) order
reverse
)

Iterate over entries.

public Set<Map.Entry<K, V>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public Map.Entry<K, V>

Returns:

the first entry, or null if empty
firstEntry
()

Get the first entry.

public K

Returns:

the first key, or null if empty
firstKey
()

Get the first key.

public Map.Entry<K, V>

Returns:

the result
floorEntry
(K
the key (may not be null)
key
)

Get the entry with largest key that is smaller than or equal to this key, or null if no such key exists.

public K

Returns:

the result
floorKey
(K
the key (may not be null)
key
)

Get the largest key that is smaller than or equal to this key, or null if no such key exists.

public V

Returns:

the value or null
get
(Object
the key
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Get the effective value for the given key.

public V

Returns:

the value, or null if not found
getFromSnapshot
(K
the key
key
)

Get the value for the given key, or null if value does not exist in accordance with transactional rules.

private V
getFromSnapshot(RootReference<K, VersionedValue<V>> rootRef, BitSet committingTransactions, K key)

public V

Returns:

the value, or null if not found
getImmediate
(K
the key
key
)

Get the value for the given key, or null if not found.

public TransactionMap<K, V>

Returns:

the map
getInstance
(Transaction
the transaction
transaction
)

Get a clone of this map for the given transaction.

public DataType<K>
pack-priv Snapshot<K, VersionedValue<V>>
pack-priv Snapshot<K, VersionedValue<V>>
public Transaction
public Map.Entry<K, V>

Returns:

the result
higherEntry
(K
the key (may not be null)
key
)

Get the entry with smallest key that is larger than the given key, or null if no such key exists.

public K

Returns:

the result
higherKey
(K
the key (may not be null)
key
)

Get the smallest key that is larger than the given key, or null if no such key exists.

private Map.Entry<K, V>
higherLowerEntry(K key, boolean lower)

private K
higherLowerKey(K key, boolean lower)

public boolean

Returns:

true if closed
isClosed
()

Check whether this map is closed.

public boolean

Returns:

true if it was
isDeletedByCurrentTransaction
(K
the key
key
)

Check if the row was deleted by this transaction.

private boolean
isIrrelevant(long operationId, VersionedValue<?> currentValue, BitSet committingTransactions)

public boolean

Returns:

true if yes
isSameTransaction
(K
the key
key
)

Whether the entry for this key was added or removed from this session.

public Iterator<K>

Returns:

the iterator
keyIterator
(K
the first key to return
from
)

Iterate over keys.

public TransactionMap.TMIterator<K, V, K>

Returns:

the iterator
keyIterator
(K
the first key to return
from
,
boolean
if true, iterate in reverse (descending) order
reverse
)

Iterate over keys in the specified order.

public TransactionMap.TMIterator<K, V, K>

Returns:

the iterator
keyIterator
(K
the first key to return
from
,
K
the last key to return or null if there is no limit
to
)

Iterate over keys.

public TransactionMap.TMIterator<K, V, K>

Returns:

the iterator
keyIterator
(K
the first key to return
from
,
K
the last key to return or null if there is no limit
to
,
boolean
if true, iterate in reverse (descending) order
reverse
)

Iterate over keys.

public TransactionMap.TMIterator<K, V, K>

Returns:

the iterator
keyIteratorUncommitted
(K
the first key to return
from
,
K
the last key to return or null if there is no limit
to
)

Iterate over keys, including keys from uncommitted entries.

public Map.Entry<K, V>

Returns:

the last entry, or null if empty
lastEntry
()

Get the last entry.

public K

Returns:

the last key, or null if empty
lastKey
()

Get the last key.

public V

Returns:

the locked value
lock
(K
the key
key
)

Lock row for the given key.

public V

Returns:

the locked value
lock
(K
the key
key
,
int
timeout in milliseconds, -1 for default, -2 to skip locking if row is already locked by another transaction
timeoutMillis
)

Lock row for the given key.

public Map.Entry<K, V>

Returns:

the result
lowerEntry
(K
the key (may not be null)
key
)

Get the entry with largest key that is smaller than the given key, or null if no such key exists.

public K

Returns:

the result
lowerKey
(K
the key (may not be null)
key
)

Get the largest key that is smaller than the given key, or null if no such key exists.

pack-priv void
public V

Returns:

the old value
put
(K
the key
key
,
V
the new value (not null)
value
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Update the value for the given key.

public V

Returns:

the old value
putCommitted
(K
the key
key
,
V
the value
value
)

Update the value for the given key, without adding an undo log entry.

public V

Returns:

the old value
putIfAbsent
(K
the key
key
,
V
the new value (not null)
value
)

Overrides default java.util.Map.putIfAbsent.

Put the value for the given key if entry for this key does not exist.

public V
remove(Object
the key
key
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Remove an entry.

private V
set(K key, V value)

private V
set(Object key, TxDecisionMaker<K, V> decisionMaker, int timeoutMillis)

pack-priv void
public int

Returns:

the number of entries, as an integer
size
()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Get the number of entries, as a integer.

public long

Returns:

the size
sizeAsLong
()

Get the size of the map as seen by this transaction.

public long

Returns:

the maximum size
sizeAsLongMax
()

Get the size of the raw map.

private long
public boolean

Returns:

whether the entry could be updated
tryPut
(K
the key
key
,
V
the new value
value
)

Try to update the value for the given key.

public boolean

Returns:

whether the entry could be removed
tryRemove
(K
the key
key
)

Try to remove the value for the given key.

public boolean

Returns:

true if the value was set, false if there was a concurrent update
trySet
(K
the key
key
,
V
the new value (null to remove the value)
value
)

Try to set or remove the value.

pack-priv <
type of the result
R
>
R

Returns:

function's result
useSnapshot
(BiFunction<RootReference<K, VersionedValue<V>>, BitSet, R>
function to invoke on a snapshot
snapshotConsumer
)

Gets a coherent picture of committing transactions and root reference, passes it to the specified function, and returns its result.

Inherited from java.util.AbstractMap:
clonecontainsValueequalshashCodeisEmptykeySetputAlltoStringvalues