Class JoinMapStore<K,V>
java.lang.Object
org.datanucleus.store.rdbms.scostore.BaseContainerStore
org.datanucleus.store.rdbms.scostore.AbstractMapStore<K,V>
org.datanucleus.store.rdbms.scostore.JoinMapStore<K,V>
- All Implemented Interfaces:
org.datanucleus.store.types.scostore.MapStore<K,V>, org.datanucleus.store.types.scostore.Store
RDBMS-specific implementation of a
MapStore using join table.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JavaTypeMappingMapping for when the element mappings columns can't be part of the primary key due to datastore limitations (e.g BLOB types).private Stringprivate org.datanucleus.store.types.scostore.SetStoreprivate StatementClassMappingprivate StatementParameterMappingprivate StringJDBC statement to use for retrieving keys of the map (locking).private StringJDBC statement to use for retrieving keys of the map (not locking).private org.datanucleus.store.types.scostore.SetStore<K> protected MapTableJoin table storing the map relation between key and value.private Stringprivate Stringprivate Stringprivate Stringprivate org.datanucleus.store.types.scostore.CollectionStore<V> protected DatastoreClassTable storing the values.Fields inherited from class AbstractMapStore
containsValueStmt, iterateUsingDiscriminator, keyCmd, keyMapping, keysAreEmbedded, keysAreSerialised, keyType, valueCmd, valueMapping, valuesAreEmbedded, valuesAreSerialised, valueTypeFields inherited from class BaseContainerStore
allowNulls, clr, dba, ownerMapping, ownerMemberMetaData, relationType, storeMgr -
Constructor Summary
ConstructorsConstructorDescriptionJoinMapStore(MapTable mapTable, org.datanucleus.ClassLoaderResolver clr) Constructor for the backing store of a join map for RDBMS. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear(org.datanucleus.state.DNStateManager ownerSM) protected voidclearInternal(org.datanucleus.state.DNStateManager ownerSM) private StringGenerate statement to clear the Map.private StringGenerate statement for obtaining the maximum id.private intgetNextIDForAdapterColumn(org.datanucleus.state.DNStateManager sm) Accessor for the higher id when elements primary key can't be part of the primary key by datastore limitations (e.g BLOB types can't be primary keys).private StringGenerate statement to add an item to the Map.private StringGenerate statement to remove an item from the Map.protected SelectStatementgetSQLStatementForGet(org.datanucleus.state.DNStateManager ownerSM) Method to return an SQLStatement for retrieving the value for a key.protected StringgetUpdateEmbeddedKeyStmt(JavaTypeMapping fieldMapping, JavaTypeMapping ownerMapping, JavaTypeMapping keyMapping, Table mapTable) Generate statement for update the field of an embedded key.protected StringgetUpdateEmbeddedValueStmt(JavaTypeMapping fieldMapping, JavaTypeMapping ownerMapping, JavaTypeMapping valueMapping, Table mapTable) Generate statement for update the field of an embedded value.private StringGenerate statement to update an item in the Map.protected VMethod to retrieve a value from the Map given the key.protected voidprotected int[]internalPut(org.datanucleus.state.DNStateManager ownerSM, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, Object key, Object value, boolean executeNow) Method to process a "put" statement (where the key has no value in the join table).protected voidinternalUpdate(org.datanucleus.state.DNStateManager ownerSM, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, Object key, Object value, boolean executeNow) Method to process an "update" statement (where the key already has a value in the join table).org.datanucleus.store.types.scostore.SetStore<K> protected voidprocessPutsAndUpdates(org.datanucleus.state.DNStateManager sm, Set<Map.Entry> puts, Set<Map.Entry> updates) voidvoidputAll(org.datanucleus.state.DNStateManager<?> sm, Map<? extends K, ? extends V> m, Map<K, V> currentMap) voidvoidprotected voidremoveInternal(org.datanucleus.state.DNStateManager sm, Object key) booleanupdateEmbeddedKey(org.datanucleus.state.DNStateManager sm, Object key, int fieldNumber, Object newValue) booleanupdateEmbeddedValue(org.datanucleus.state.DNStateManager sm, Object value, int fieldNumber, Object newValue) org.datanucleus.store.types.scostore.CollectionStore<V> Methods inherited from class AbstractMapStore
containsKey, containsValue, get, getContainsValueStmt, getKeyClassMetaData, getKeyMapping, getValueClassMetaData, getValueMapping, keysAreEmbedded, keysAreSerialised, validateKeyForReading, validateKeyForWriting, validateKeyType, validateValueForReading, validateValueForWriting, validateValueType, valuesAreEmbedded, valuesAreSerialisedMethods inherited from class BaseContainerStore
allowsBatching, getComponentInformationForClass, getDatastoreAdapter, getOwnerMapping, getOwnerMemberMetaData, getRelationType, getStateManagerForEmbeddedPCObject, getStoreManager, isEmbeddedMapping, setOwnerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.datanucleus.store.types.scostore.MapStore
updateMethods inherited from interface org.datanucleus.store.types.scostore.Store
getOwnerMemberMetaData, getStoreManager
-
Field Details
-
mapTable
Join table storing the map relation between key and value. -
valueTable
Table storing the values. -
putStmt
-
updateStmt
-
removeStmt
-
clearStmt
-
maxAdapterColumnIdStmt
-
getStmtLocked
JDBC statement to use for retrieving keys of the map (locking). -
getStmtUnlocked
JDBC statement to use for retrieving keys of the map (not locking). -
getMappingDef
-
getMappingParams
-
keySetStore
-
valueSetStore
-
entrySetStore
private org.datanucleus.store.types.scostore.SetStore entrySetStore -
adapterMapping
Mapping for when the element mappings columns can't be part of the primary key due to datastore limitations (e.g BLOB types).
-
-
Constructor Details
-
JoinMapStore
Constructor for the backing store of a join map for RDBMS.- Parameters:
mapTable- Join table for the Mapclr- The ClassLoaderResolver
-
-
Method Details
-
initialise
protected void initialise() -
putAll
-
putAll
-
processPutsAndUpdates
-
put
-
put
-
remove
-
remove
-
clear
public void clear(org.datanucleus.state.DNStateManager ownerSM) -
keySetStore
-
valueCollectionStore
-
entrySetStore
-
getAdapterMapping
-
getPutStmt
Generate statement to add an item to the Map. Adds a row to the link table, linking container with value object.INSERT INTO MAPTABLE (VALUECOL, OWNERCOL, KEYCOL) VALUES (?, ?, ?)
- Returns:
- Statement to add an item to the Map.
-
getUpdateStmt
Generate statement to update an item in the Map. Updates the link table row, changing the value object for this key.UPDATE MAPTABLE SET VALUECOL=? WHERE OWNERCOL=? AND KEYCOL=?
- Returns:
- Statement to update an item in the Map.
-
getRemoveStmt
Generate statement to remove an item from the Map. Deletes the link from the join table, leaving the value object in its own table.DELETE FROM MAPTABLE WHERE OWNERCOL=? AND KEYCOL=?
- Returns:
- Return an item from the Map.
-
getClearStmt
Generate statement to clear the Map. Deletes the links from the join table for this Map, leaving the value objects in their own table(s).DELETE FROM MAPTABLE WHERE OWNERCOL=?
- Returns:
- Statement to clear the Map.
-
getValue
protected V getValue(org.datanucleus.state.DNStateManager ownerSM, Object key) throws NoSuchElementException Method to retrieve a value from the Map given the key.- Specified by:
getValuein classAbstractMapStore<K,V> - Parameters:
ownerSM- StateManager for the owner of the map.key- The key to retrieve the value for.- Returns:
- The value for this key
- Throws:
NoSuchElementException- if the value for the key was not found
-
getSQLStatementForGet
Method to return an SQLStatement for retrieving the value for a key. Selects the join table and optionally joins to the value table if it has its own table.- Parameters:
ownerSM- StateManager for the owning object- Returns:
- The SQLStatement
-
clearInternal
protected void clearInternal(org.datanucleus.state.DNStateManager ownerSM) -
removeInternal
-
internalUpdate
protected void internalUpdate(org.datanucleus.state.DNStateManager ownerSM, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, Object key, Object value, boolean executeNow) Method to process an "update" statement (where the key already has a value in the join table).- Parameters:
ownerSM- StateManager for the ownerconn- The Connectionbatched- Whether we are batching itkey- The keyvalue- The new valueexecuteNow- Whether to execute the statement now or wait til any batch
-
internalPut
protected int[] internalPut(org.datanucleus.state.DNStateManager ownerSM, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, Object key, Object value, boolean executeNow) Method to process a "put" statement (where the key has no value in the join table).- Parameters:
ownerSM- StateManager for the ownerconn- The Connectionbatched- Whether we are batching itkey- The keyvalue- The valueexecuteNow- Whether to execute the statement now or wait til batching- Returns:
- The return codes from any executed statement
-
getNextIDForAdapterColumn
private int getNextIDForAdapterColumn(org.datanucleus.state.DNStateManager sm) Accessor for the higher id when elements primary key can't be part of the primary key by datastore limitations (e.g BLOB types can't be primary keys).- Parameters:
sm- StateManager for container- Returns:
- The next id
-
getMaxAdapterColumnIdStmt
Generate statement for obtaining the maximum id.SELECT MAX(SCOID) FROM MAPTABLE WHERE OWNERCOL=?
- Returns:
- The Statement returning the higher id
-
updateEmbeddedKey
-
updateEmbeddedValue
-
getUpdateEmbeddedKeyStmt
protected String getUpdateEmbeddedKeyStmt(JavaTypeMapping fieldMapping, JavaTypeMapping ownerMapping, JavaTypeMapping keyMapping, Table mapTable) Generate statement for update the field of an embedded key.UPDATE MAPTABLE SET EMBEDDEDKEYCOL1 = ? WHERE OWNERCOL=? AND EMBEDDEDKEYCOL1 = ? AND EMBEDDEDKEYCOL2 = ? ...
- Parameters:
fieldMapping- The mapping for the field (of the key) to be updatedownerMapping- The owner mappingkeyMapping- The key mappingmapTable- The map table- Returns:
- Statement for updating an embedded key in the Set
-
getUpdateEmbeddedValueStmt
protected String getUpdateEmbeddedValueStmt(JavaTypeMapping fieldMapping, JavaTypeMapping ownerMapping, JavaTypeMapping valueMapping, Table mapTable) Generate statement for update the field of an embedded value.UPDATE MAPTABLE SET EMBEDDEDVALUECOL1 = ? WHERE OWNERCOL=? AND EMBEDDEDVALUECOL1 = ? AND EMBEDDEDVALUECOL2 = ? ...
- Parameters:
fieldMapping- The mapping for the field to be updatedownerMapping- The owner mappingvalueMapping- mapping for the valuemapTable- The map table- Returns:
- Statement for updating an embedded value in the Set
-