Class FKMapStore<K,V>
- java.lang.Object
-
- org.datanucleus.store.rdbms.scostore.BaseContainerStore
-
- org.datanucleus.store.rdbms.scostore.AbstractMapStore<K,V>
-
- org.datanucleus.store.rdbms.scostore.FKMapStore<K,V>
-
- All Implemented Interfaces:
org.datanucleus.store.types.scostore.MapStore<K,V>
,org.datanucleus.store.types.scostore.Store
public class FKMapStore<K,V> extends AbstractMapStore<K,V>
Implementation of anMapStore
where either the value has a FK to the owner (and the key stored in the value), or whether the key has a FK to the owner (and the value stored in the key).
-
-
Field Summary
Fields Modifier and Type Field Description private StatementClassMapping
getMappingDef
private StatementParameterMapping
getMappingParams
private java.lang.String
getStmtLocked
JDBC statement to use for retrieving the value of the map for a key (locking).private java.lang.String
getStmtUnlocked
JDBC statement to use for retrieving the value of the map for a key (not locking).protected int
keyFieldNumber
Field number of key in value class (when key stored in value).protected DatastoreClass
mapTable
Table storing the values (either key table, or value table).private int
ownerFieldNumber
Field number of owner link in key/value class.private java.lang.String
updateFkStmt
Statement for updating a foreign key for the map.private int
valueFieldNumber
Field number of value in key class (when value stored in key).-
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 FKMapStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
Constructor for the backing store for an FK Map for RDBMS.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear(org.datanucleus.state.DNStateManager sm)
void
clearKeyOfValue(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object oldValue)
Utility to clear the key of a value from the Map.org.datanucleus.store.types.scostore.SetStore<java.util.Map.Entry<K,V>>
entrySetStore()
protected SelectStatement
getSQLStatementForGet(org.datanucleus.state.DNStateManager ownerSM)
Method to return an SQLStatement for retrieving the value for a key.private java.lang.String
getUpdateFkStmt()
Generate statement for updating a Foreign Key from key/value to owner in an inverse 1-N.protected V
getValue(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object key)
Method to retrieve a value from the Map given the key.protected void
initialise()
org.datanucleus.store.types.scostore.SetStore<K>
keySetStore()
V
put(org.datanucleus.state.DNStateManager sm, K newKey, V newValue)
V
remove(org.datanucleus.state.DNStateManager sm, java.lang.Object key)
void
remove(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object oldValue)
private void
removeValue(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object oldValue)
Utility to remove a value from the Map.boolean
updateEmbeddedKey(org.datanucleus.state.DNStateManager sm, java.lang.Object key, int fieldNumber, java.lang.Object newValue)
boolean
updateEmbeddedValue(org.datanucleus.state.DNStateManager sm, java.lang.Object value, int fieldNumber, java.lang.Object newValue)
private boolean
updateKeyFk(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object owner)
Utility to update a foreign-key in the key in the case of a unidirectional 1-N relationship.protected boolean
updateKeyFkInternal(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object owner)
private boolean
updateValueFk(org.datanucleus.state.DNStateManager sm, java.lang.Object value, java.lang.Object owner)
Utility to update a foreign-key in the value in the case of a unidirectional 1-N relationship.protected boolean
updateValueFkInternal(org.datanucleus.state.DNStateManager sm, java.lang.Object value, java.lang.Object owner)
protected void
validateValueType(org.datanucleus.ClassLoaderResolver clr, java.lang.Object value)
Utility to validate the type of a value for storing in the Map.org.datanucleus.store.types.scostore.CollectionStore<V>
valueCollectionStore()
-
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractMapStore
containsKey, containsValue, get, getContainsValueStmt, getKeyClassMetaData, getKeyMapping, getValueClassMetaData, getValueMapping, keysAreEmbedded, keysAreSerialised, putAll, validateKeyForReading, validateKeyForWriting, validateKeyType, validateValueForReading, validateValueForWriting, valuesAreEmbedded, valuesAreSerialised
-
Methods inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowsBatching, getComponentInformationForClass, getDatastoreAdapter, getOwnerMapping, getOwnerMemberMetaData, getRelationType, getStateManagerForEmbeddedPCObject, getStoreManager, isEmbeddedMapping, setOwner
-
-
-
-
Field Detail
-
mapTable
protected DatastoreClass mapTable
Table storing the values (either key table, or value table).
-
updateFkStmt
private java.lang.String updateFkStmt
Statement for updating a foreign key for the map.
-
getStmtLocked
private java.lang.String getStmtLocked
JDBC statement to use for retrieving the value of the map for a key (locking).
-
getStmtUnlocked
private java.lang.String getStmtUnlocked
JDBC statement to use for retrieving the value of the map for a key (not locking).
-
getMappingDef
private StatementClassMapping getMappingDef
-
getMappingParams
private StatementParameterMapping getMappingParams
-
ownerFieldNumber
private final int ownerFieldNumber
Field number of owner link in key/value class.
-
keyFieldNumber
protected int keyFieldNumber
Field number of key in value class (when key stored in value).
-
valueFieldNumber
private int valueFieldNumber
Field number of value in key class (when value stored in key).
-
-
Constructor Detail
-
FKMapStore
public FKMapStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
Constructor for the backing store for an FK Map for RDBMS.- Parameters:
mmd
- Field Meta-Data for the Map field.storeMgr
- The Store Manager we are using.clr
- The ClassLoaderResolver
-
-
Method Detail
-
initialise
protected void initialise()
-
updateValueFk
private boolean updateValueFk(org.datanucleus.state.DNStateManager sm, java.lang.Object value, java.lang.Object owner)
Utility to update a foreign-key in the value in the case of a unidirectional 1-N relationship.- Parameters:
sm
- StateManager for the ownervalue
- The value to updateowner
- The owner object to set in the FK- Returns:
- Whether it was performed successfully
-
updateKeyFk
private boolean updateKeyFk(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object owner)
Utility to update a foreign-key in the key in the case of a unidirectional 1-N relationship.- Parameters:
sm
- StateManager for the ownerkey
- The key to updateowner
- The owner object to set in the FK- Returns:
- Whether it was performed successfully
-
validateValueType
protected void validateValueType(org.datanucleus.ClassLoaderResolver clr, java.lang.Object value)
Utility to validate the type of a value for storing in the Map.- Overrides:
validateValueType
in classAbstractMapStore<K,V>
- Parameters:
value
- The value to check.clr
- The ClassLoaderResolver
-
remove
public V remove(org.datanucleus.state.DNStateManager sm, java.lang.Object key)
-
remove
public void remove(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object oldValue)
-
removeValue
private void removeValue(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object oldValue)
Utility to remove a value from the Map.- Parameters:
sm
- StateManager for the map.key
- Key of the objectoldValue
- Value to remove
-
clear
public void clear(org.datanucleus.state.DNStateManager sm)
-
clearKeyOfValue
public void clearKeyOfValue(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object oldValue)
Utility to clear the key of a value from the Map. If the key is non nullable, delete the value.- Parameters:
sm
- StateManager for the map.key
- Key of the objectoldValue
- Value to remove
-
keySetStore
public org.datanucleus.store.types.scostore.SetStore<K> keySetStore()
-
valueCollectionStore
public org.datanucleus.store.types.scostore.CollectionStore<V> valueCollectionStore()
-
entrySetStore
public org.datanucleus.store.types.scostore.SetStore<java.util.Map.Entry<K,V>> entrySetStore()
-
getUpdateFkStmt
private java.lang.String getUpdateFkStmt()
Generate statement for updating a Foreign Key from key/value to owner in an inverse 1-N.UPDATE MAPTABLE SET FK_COL_1 = ?, FK_COL_2 = ? WHERE ELEMENT_ID = ?
- Returns:
- Statement for updating the FK in an inverse 1-N
-
updateValueFkInternal
protected boolean updateValueFkInternal(org.datanucleus.state.DNStateManager sm, java.lang.Object value, java.lang.Object owner)
-
updateKeyFkInternal
protected boolean updateKeyFkInternal(org.datanucleus.state.DNStateManager sm, java.lang.Object key, java.lang.Object owner)
-
getValue
protected V getValue(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object key) throws java.util.NoSuchElementException
Method to retrieve a value from the Map given the key.- Specified by:
getValue
in 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:
java.util.NoSuchElementException
- if the key was not found
-
getSQLStatementForGet
protected SelectStatement getSQLStatementForGet(org.datanucleus.state.DNStateManager ownerSM)
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
-
updateEmbeddedKey
public boolean updateEmbeddedKey(org.datanucleus.state.DNStateManager sm, java.lang.Object key, int fieldNumber, java.lang.Object newValue)
-
updateEmbeddedValue
public boolean updateEmbeddedValue(org.datanucleus.state.DNStateManager sm, java.lang.Object value, int fieldNumber, java.lang.Object newValue)
-
-