Class 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 a MapStore using join table.
    • Field Detail

      • mapTable

        protected MapTable mapTable
        Join table storing the map relation between key and value.
      • valueTable

        protected DatastoreClass valueTable
        Table storing the values.
      • putStmt

        private java.lang.String putStmt
      • updateStmt

        private java.lang.String updateStmt
      • removeStmt

        private java.lang.String removeStmt
      • clearStmt

        private java.lang.String clearStmt
      • maxAdapterColumnIdStmt

        private java.lang.String maxAdapterColumnIdStmt
      • getStmtLocked

        private volatile java.lang.String getStmtLocked
        JDBC statement to use for retrieving keys of the map (locking).
      • getStmtUnlocked

        private java.lang.String getStmtUnlocked
        JDBC statement to use for retrieving keys of the map (not locking).
      • keySetStore

        private org.datanucleus.store.types.scostore.SetStore<K> keySetStore
      • valueSetStore

        private org.datanucleus.store.types.scostore.CollectionStore<V> valueSetStore
      • entrySetStore

        private org.datanucleus.store.types.scostore.SetStore entrySetStore
      • 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 Map
        clr - The ClassLoaderResolver
    • Method Detail

      • initialise

        protected void initialise()
      • putAll

        public void putAll​(org.datanucleus.state.DNStateManager<?> sm,
                           java.util.Map<? extends K,​? extends V> m,
                           java.util.Map<K,​V> currentMap)
      • putAll

        public void putAll​(org.datanucleus.state.DNStateManager sm,
                           java.util.Map<? extends K,​? extends V> m)
        Specified by:
        putAll in interface org.datanucleus.store.types.scostore.MapStore<K,​V>
        Overrides:
        putAll in class AbstractMapStore<K,​V>
      • processPutsAndUpdates

        protected void processPutsAndUpdates​(org.datanucleus.state.DNStateManager sm,
                                             java.util.Set<java.util.Map.Entry> puts,
                                             java.util.Set<java.util.Map.Entry> updates)
      • put

        public void put​(org.datanucleus.state.DNStateManager sm,
                        K key,
                        V value,
                        V previousValue,
                        boolean present)
      • put

        public V put​(org.datanucleus.state.DNStateManager sm,
                     K key,
                     V value)
      • 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)
      • clear

        public void clear​(org.datanucleus.state.DNStateManager ownerSM)
      • 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()
      • getPutStmt

        private java.lang.String 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

        private java.lang.String 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

        private java.lang.String 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

        private java.lang.String 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,
                             java.lang.Object key)
                      throws java.util.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:
        java.util.NoSuchElementException - if the value for 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
      • clearInternal

        protected void clearInternal​(org.datanucleus.state.DNStateManager ownerSM)
      • removeInternal

        protected void removeInternal​(org.datanucleus.state.DNStateManager sm,
                                      java.lang.Object key)
      • internalUpdate

        protected void internalUpdate​(org.datanucleus.state.DNStateManager ownerSM,
                                      org.datanucleus.store.connection.ManagedConnection conn,
                                      boolean batched,
                                      java.lang.Object key,
                                      java.lang.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 owner
        conn - The Connection
        batched - Whether we are batching it
        key - The key
        value - The new value
        executeNow - 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,
                                    java.lang.Object key,
                                    java.lang.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 owner
        conn - The Connection
        batched - Whether we are batching it
        key - The key
        value - The value
        executeNow - 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

        private java.lang.String getMaxAdapterColumnIdStmt()
        Generate statement for obtaining the maximum id.
         SELECT MAX(SCOID) FROM MAPTABLE WHERE OWNERCOL=?
         
        Returns:
        The Statement returning the higher id
      • 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)
      • getUpdateEmbeddedKeyStmt

        protected java.lang.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 updated
        ownerMapping - The owner mapping
        keyMapping - The key mapping
        mapTable - The map table
        Returns:
        Statement for updating an embedded key in the Set
      • getUpdateEmbeddedValueStmt

        protected java.lang.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 updated
        ownerMapping - The owner mapping
        valueMapping - mapping for the value
        mapTable - The map table
        Returns:
        Statement for updating an embedded value in the Set