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
public class JoinMapStore<K,V> extends AbstractMapStore<K,V>
RDBMS-specific implementation of aMapStoreusing join table.
-
-
Field Summary
Fields Modifier and Type Field Description protected JavaTypeMappingadapterMappingMapping for when the element mappings columns can't be part of the primary key due to datastore limitations (e.g BLOB types).protected MapTablemapTableJoin table storing the map relation between key and value.protected DatastoreClassvalueTableTable storing the values.-
Fields inherited from class org.datanucleus.store.rdbms.scostore.AbstractMapStore
containsValueStmt, iterateUsingDiscriminator, keyCmd, keyMapping, keysAreEmbedded, keysAreSerialised, keyType, valueCmd, valueMapping, valuesAreEmbedded, valuesAreSerialised, valueType
-
Fields inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowNulls, clr, dba, ownerMapping, ownerMemberMetaData, relationType, storeMgr
-
-
Constructor Summary
Constructors Constructor Description JoinMapStore(MapTable mapTable, org.datanucleus.ClassLoaderResolver clr)Constructor for the backing store of a join map for RDBMS.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear(org.datanucleus.state.ObjectProvider ownerOP)Method to clear the map of all values.protected voidclearInternal(org.datanucleus.state.ObjectProvider ownerOP)org.datanucleus.store.types.scostore.SetStoreentrySetStore()Accessor for the map entries in the Map.JavaTypeMappinggetAdapterMapping()protected SelectStatementgetSQLStatementForGet(org.datanucleus.state.ObjectProvider ownerOP)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.protected VgetValue(org.datanucleus.state.ObjectProvider ownerOP, Object key)Method to retrieve a value from the Map given the key.protected voidinitialise()protected int[]internalPut(org.datanucleus.state.ObjectProvider ownerOP, 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.ObjectProvider ownerOP, 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.SetStorekeySetStore()Accessor for the keys in the Map.Vput(org.datanucleus.state.ObjectProvider op, K key, V value)Method to put an item in the Map.voidputAll(org.datanucleus.state.ObjectProvider op, Map<? extends K,? extends V> m)Method to put all elements from a Map into our Map.Vremove(org.datanucleus.state.ObjectProvider op, Object key)Method to remove an entry from the map.Vremove(org.datanucleus.state.ObjectProvider op, Object key, Object oldValue)Method to remove an item from the map.protected voidremoveInternal(org.datanucleus.state.ObjectProvider op, Object key)booleanupdateEmbeddedKey(org.datanucleus.state.ObjectProvider op, Object key, int fieldNumber, Object newValue)Method to update a field of an embedded key.booleanupdateEmbeddedValue(org.datanucleus.state.ObjectProvider op, Object value, int fieldNumber, Object newValue)Method to update a field of an embedded key.org.datanucleus.store.types.scostore.CollectionStorevalueCollectionStore()Accessor for the values in the Map.-
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractMapStore
containsKey, containsValue, get, getContainsValueStmt, getKeyClassMetaData, getKeyMapping, getValueClassMetaData, getValueMapping, keysAreEmbedded, keysAreSerialised, validateKeyForReading, validateKeyForWriting, validateKeyType, validateValueForReading, validateValueForWriting, validateValueType, valuesAreEmbedded, valuesAreSerialised
-
Methods inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowsBatching, getComponentInformationForClass, getDatastoreAdapter, getObjectProviderForEmbeddedPCObject, getOwnerMapping, getOwnerMemberMetaData, getRelationType, getStoreManager, isEmbeddedMapping, setOwner
-
-
-
-
Field Detail
-
mapTable
protected MapTable mapTable
Join table storing the map relation between key and value.
-
valueTable
protected DatastoreClass valueTable
Table storing the values.
-
adapterMapping
protected final JavaTypeMapping 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 Detail
-
JoinMapStore
public JoinMapStore(MapTable mapTable, org.datanucleus.ClassLoaderResolver clr)
Constructor for the backing store of a join map for RDBMS.- Parameters:
mapTable- Join table for the Mapclr- The ClassLoaderResolver
-
-
Method Detail
-
initialise
protected void initialise()
-
putAll
public void putAll(org.datanucleus.state.ObjectProvider op, Map<? extends K,? extends V> m)Method to put all elements from a Map into our Map.
-
put
public V put(org.datanucleus.state.ObjectProvider op, K key, V value)
Method to put an item in the Map.- Parameters:
op- ObjectProvider for the map.key- The key to store the value againstvalue- The value to store.- Returns:
- The value stored.
-
remove
public V remove(org.datanucleus.state.ObjectProvider op, Object key)
Method to remove an entry from the map.- Parameters:
op- ObjectProvider for the map.key- Key of the entry to remove.- Returns:
- The value that was removed.
-
remove
public V remove(org.datanucleus.state.ObjectProvider op, Object key, Object oldValue)
Method to remove an item from the map.- Parameters:
op- ObjectProvider for the map.key- Key of the item to remove.- Returns:
- The value that was removed.
-
clear
public void clear(org.datanucleus.state.ObjectProvider ownerOP)
Method to clear the map of all values.- Parameters:
ownerOP- ObjectProvider for the map.
-
keySetStore
public org.datanucleus.store.types.scostore.SetStore keySetStore()
Accessor for the keys in the Map.- Returns:
- The keys
-
valueCollectionStore
public org.datanucleus.store.types.scostore.CollectionStore valueCollectionStore()
Accessor for the values in the Map.- Returns:
- The values.
-
entrySetStore
public org.datanucleus.store.types.scostore.SetStore entrySetStore()
Accessor for the map entries in the Map.- Returns:
- The map entries.
-
getAdapterMapping
public JavaTypeMapping getAdapterMapping()
-
getValue
protected V getValue(org.datanucleus.state.ObjectProvider ownerOP, Object key) throws NoSuchElementException
Method to retrieve a value from the Map given the key.- Specified by:
getValuein classAbstractMapStore<K,V>- Parameters:
ownerOP- ObjectProvider 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
protected SelectStatement getSQLStatementForGet(org.datanucleus.state.ObjectProvider ownerOP)
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:
ownerOP- ObjectProvider for the owning object- Returns:
- The SQLStatement
-
clearInternal
protected void clearInternal(org.datanucleus.state.ObjectProvider ownerOP)
-
removeInternal
protected void removeInternal(org.datanucleus.state.ObjectProvider op, Object key)
-
internalUpdate
protected void internalUpdate(org.datanucleus.state.ObjectProvider ownerOP, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, Object key, Object value, boolean executeNow) throws MappedDatastoreExceptionMethod to process an "update" statement (where the key already has a value in the join table).- Parameters:
ownerOP- ObjectProvider 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- Throws:
MappedDatastoreException- Thrown if an error occurs
-
internalPut
protected int[] internalPut(org.datanucleus.state.ObjectProvider ownerOP, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, Object key, Object value, boolean executeNow) throws MappedDatastoreExceptionMethod to process a "put" statement (where the key has no value in the join table).- Parameters:
ownerOP- ObjectProvider 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
- Throws:
MappedDatastoreException- Thrown if an error occurs
-
updateEmbeddedKey
public boolean updateEmbeddedKey(org.datanucleus.state.ObjectProvider op, Object key, int fieldNumber, Object newValue)Method to update a field of an embedded key.- Parameters:
op- ObjectProvider of the ownerkey- The key to updatefieldNumber- The number of the field to updatenewValue- The new value
-
updateEmbeddedValue
public boolean updateEmbeddedValue(org.datanucleus.state.ObjectProvider op, Object value, int fieldNumber, Object newValue)Method to update a field of an embedded key.- Parameters:
op- ObjectProvider of the ownervalue- The value to updatefieldNumber- The number of the field to updatenewValue- The new value
-
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
-
-