Class 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 an MapStore 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 Details

    • mapTable

      protected DatastoreClass mapTable
      Table storing the values (either key table, or value table).
    • updateFkStmt

      private String updateFkStmt
      Statement for updating a foreign key for the map.
    • getStmtLocked

      private String getStmtLocked
      JDBC statement to use for retrieving the value of the map for a key (locking).
    • getStmtUnlocked

      private 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 Details

    • 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 Details

    • initialise

      protected void initialise()
    • updateValueFk

      private boolean updateValueFk(org.datanucleus.state.DNStateManager sm, Object value, 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 owner
      value - The value to update
      owner - The owner object to set in the FK
      Returns:
      Whether it was performed successfully
    • updateKeyFk

      private boolean updateKeyFk(org.datanucleus.state.DNStateManager sm, Object key, 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 owner
      key - The key to update
      owner - The owner object to set in the FK
      Returns:
      Whether it was performed successfully
    • validateValueType

      protected void validateValueType(org.datanucleus.ClassLoaderResolver clr, Object value)
      Utility to validate the type of a value for storing in the Map.
      Overrides:
      validateValueType in class AbstractMapStore<K,V>
      Parameters:
      clr - The ClassLoaderResolver
      value - The value to check.
    • put

      public V put(org.datanucleus.state.DNStateManager sm, K newKey, V newValue)
    • remove

      public V remove(org.datanucleus.state.DNStateManager sm, Object key)
    • remove

      public void remove(org.datanucleus.state.DNStateManager sm, Object key, Object oldValue)
    • removeValue

      private void removeValue(org.datanucleus.state.DNStateManager sm, Object key, Object oldValue)
      Utility to remove a value from the Map.
      Parameters:
      sm - StateManager for the map.
      key - Key of the object
      oldValue - Value to remove
    • clear

      public void clear(org.datanucleus.state.DNStateManager sm)
    • clearKeyOfValue

      public void clearKeyOfValue(org.datanucleus.state.DNStateManager sm, Object key, 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 object
      oldValue - 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<Map.Entry<K,V>> entrySetStore()
    • getUpdateFkStmt

      private 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, Object value, Object owner)
    • updateKeyFkInternal

      protected boolean updateKeyFkInternal(org.datanucleus.state.DNStateManager sm, Object key, Object owner)
    • 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:
      getValue in class AbstractMapStore<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 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, Object key, int fieldNumber, Object newValue)
    • updateEmbeddedValue

      public boolean updateEmbeddedValue(org.datanucleus.state.DNStateManager sm, Object value, int fieldNumber, Object newValue)