public class H2Map extends java.util.HashMap implements StoredCollection
Modifier and Type | Field and Description |
---|---|
protected LoggedCollection |
changes
The change logger for this collection.
|
private java.lang.String |
clearSql
The map's clear SQL.
|
private static java.util.Map<java.lang.Class<?>,java.lang.Class<? extends CustomExternalizable>> |
externalizables
A map defining custom serialization for certain values.
|
private DBHelper |
helper
The helper for SQL usage.
|
private java.lang.String |
insertSql
The map's insert SQL.
|
private java.lang.Class<?> |
keyClass
The map key class.
|
private AstManager |
manager
The AST manager.
|
private AstSymbolResolver |
resolver
The AST symbol resolver.
|
private java.lang.String |
tableName
The map's table name.
|
private java.lang.Class<?> |
valueClass
The map value class.
|
private java.lang.reflect.Constructor<? extends CustomExternalizable> |
valueCtor
A custom c'tor for serializing the value.
|
private java.lang.String |
workClearSql
The map's work table clear SQL.
|
private java.lang.String |
workInsertSql
The map's work table insert SQL.
|
private java.lang.String |
workTable
The map's work table name.
|
Modifier | Constructor and Description |
---|---|
protected |
H2Map()
Constructor used for sub-classes, which delegate the db-storage to another collection.
|
|
H2Map(java.lang.Class<?> keyClass,
java.lang.Class<?> valueClass,
java.lang.String table,
DBHelper helper)
Create a new db-backed map, with the specified name.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the map and all its changes.
|
void |
compact(long fileId)
Compact the elements of this collection, to reduce the memory footprint.
|
boolean |
containsKey(java.lang.Object key)
Check if the map contains the specified key.
|
void |
forceChange(java.lang.Object key,
java.lang.Object value)
Force the map to have logged a specific value for this key, in the context of the current
source AST.
|
java.lang.Object |
get(java.lang.Object key)
Get the value with the specified key.
|
private java.lang.reflect.Constructor<? extends CustomExternalizable> |
getCustomExternalizable(java.lang.Class<?> clazz)
Find the constructor to create a new custom externalizable, for (de)serialization purposes.
|
private void |
logChange(java.lang.Object key,
java.lang.Object value)
Log this access in the map as a change.
|
void |
persist()
Persist this map and all the changes to the database.
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Perform a put operation.
|
void |
putAll(java.util.Map m)
Merge the specified map into this one.
|
java.lang.Object |
remove(java.lang.Object key)
Remove this key from the map.
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
This API is not currently supported.
|
java.lang.Object |
unwrapValue(java.lang.Object value)
Unwrap a value from a
CustomExternalizable . |
java.lang.Object |
wrapValue(java.lang.Object value)
Wrap the value in a
CustomExternalizable . |
clone, compute, computeIfAbsent, computeIfPresent, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, putIfAbsent, replace, replace, replaceAll, size, values
finalize, getClass, notify, notifyAll, wait, wait, wait
inPersist
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<? extends CustomExternalizable>> externalizables
protected final LoggedCollection changes
private final AstSymbolResolver resolver
private final AstManager manager
private final DBHelper helper
private final java.lang.Class<?> keyClass
private final java.lang.Class<?> valueClass
private final java.lang.String tableName
private final java.lang.String workTable
private final java.lang.String insertSql
private final java.lang.String clearSql
private final java.lang.String workInsertSql
private final java.lang.String workClearSql
private final java.lang.reflect.Constructor<? extends CustomExternalizable> valueCtor
public H2Map(java.lang.Class<?> keyClass, java.lang.Class<?> valueClass, java.lang.String table, DBHelper helper)
keyClass
- The map's key class.valueClass
- The map's value class.table
- The map's (and main table) name.helper
- The SQL helper.protected H2Map()
public java.lang.Object get(java.lang.Object key)
If the value exists, the access will be logged. This assumes the source AST requires for the key to have this specific value.
get
in interface java.util.Map
get
in class java.util.HashMap
key
- The key to get the value.public boolean containsKey(java.lang.Object key)
If the value exists, the access will be logged. This assumes the source AST requires for the key to have this specific value.
containsKey
in interface java.util.Map
containsKey
in class java.util.HashMap
key
- The key to check.true
if the key exists in the map.public java.lang.Object put(java.lang.Object key, java.lang.Object value)
The access will be logged. This assumes the source AST requires for the key to have this specific value.
put
in interface java.util.Map
put
in class java.util.HashMap
key
- The key.value
- The value.public void putAll(java.util.Map m)
put(java.lang.Object, java.lang.Object)
to log the access
to the map.putAll
in interface java.util.Map
putAll
in class java.util.HashMap
m
- The map to merge.public java.lang.Object remove(java.lang.Object key)
If the key exists, then all changes related to it will be cleared.
remove
in interface java.util.Map
remove
in class java.util.HashMap
key
- The key to remove.public boolean remove(java.lang.Object key, java.lang.Object value)
remove
in interface java.util.Map
remove
in class java.util.HashMap
public void clear()
clear
in interface StoredCollection
clear
in interface java.util.Map
clear
in class java.util.HashMap
public void persist()
persist
in interface StoredCollection
public void forceChange(java.lang.Object key, java.lang.Object value)
key
- The map key.value
- The value to be logged as 'forced'.public void compact(long fileId)
compact
in interface StoredCollection
fileId
- The AST file ID which has finished processing.public java.lang.Object wrapValue(java.lang.Object value)
CustomExternalizable
.wrapValue
in interface StoredCollection
value
- The value to wrap.public java.lang.Object unwrapValue(java.lang.Object value)
CustomExternalizable
.unwrapValue
in interface StoredCollection
value
- The value to unwrap.CustomExternalizable.getValue()
.private void logChange(java.lang.Object key, java.lang.Object value)
key
- The map key.value
- The map value.private java.lang.reflect.Constructor<? extends CustomExternalizable> getCustomExternalizable(java.lang.Class<?> clazz)
clazz
- The value class.Object
argument.