abstract class AbstractJDBCHashMap<K : Any, V : Any, out T : JDBCHashedTable> : MutableMap<K, V>, AbstractMap<K, V>
A base class for a JDBC table backed hash map that iterates in insertion order by using an ever increasing sequence number on entries. Iterators supports remove() but entries are not really mutable and do not support setValue() method from MutableMap.MutableEntry.
You should only use keys that have overridden Object.hashCode and that have a good hash code distribution. Beware changing the hashCode() implementation once objects have been persisted. A process to re-hash the entries persisted would be necessary if you do this.
Subclasses must provide their own mapping to and from keys/values and the database table columns, but there are inherited columns that all tables must provide to support iteration order and hashing.
The map operates in one of two modes.
All operations require a databaseTransaction to be started.
The keys/values/entries collections are really designed just for iterating and other uses might turn out to be costly in terms of performance. Beware when loadOnInit=true, the iterator first sorts the entries which could be costly too.
This class is
TODO: consider caching size once calculated for the first time. TODO: buckets just use a list and so are vulnerable to poor hash code implementations with collisions. TODO: if iterators are used extensively when loadOnInit=true, consider maintaining a collection of keys in iteration order to avoid sorting each time. TODO: revisit whether we need the loadOnInit==true functionality and remove if not.
<init> |
AbstractJDBCHashMap(table: T, loadOnInit: Boolean = false, maxBuckets: Int = DEFAULT_MAX_BUCKETS)
A base class for a JDBC table backed hash map that iterates in insertion order by using an ever increasing sequence number on entries. Iterators supports remove() but entries are not really mutable and do not support setValue() method from MutableMap.MutableEntry. |
entries |
open val entries: MutableSet<MutableEntry<K, V>> |
keys |
open val keys: MutableSet<K> |
loadOnInit |
val loadOnInit: Boolean |
maxBuckets |
val maxBuckets: Int |
size |
open val size: Int |
table |
val table: T |
values |
open val values: MutableCollection<V> |
addKeyToInsert |
abstract fun addKeyToInsert(insert: InsertStatement, entry: Entry<K, V>, finalizables: MutableList<() -> Unit>): Unit
Implementation should marshall the key to the insert statement. |
addValueToInsert |
abstract fun addValueToInsert(insert: InsertStatement, entry: Entry<K, V>, finalizables: MutableList<() -> Unit>): Unit
Implementation should marshall the value to the insert statement. |
clear |
open fun clear(): Unit |
containsKey |
open fun containsKey(key: K): Boolean |
containsValue |
open fun containsValue(value: V): Boolean |
get |
open fun get(key: K): V? |
isEmpty |
open fun isEmpty(): Boolean |
keyFromRow |
abstract fun keyFromRow(row: ResultRow): K
Implementation should return the key object marshalled from the database table row. |
put |
open fun put(key: K, value: V): V? |
remove |
open fun remove(key: K): V? |
valueFromRow |
abstract fun valueFromRow(row: ResultRow): V
Implementation should return the value object marshalled from the database table row. |
log |
val log: Logger |
JDBCHashMap |
class JDBCHashMap<K : Any, V : Any> : AbstractJDBCHashMap<K, V, BlobMapTable>
A convenient JDBC table backed hash map with iteration order based on insertion order. See AbstractJDBCHashMap for further implementation details. |