Class MapEntrySetStore<K,​V>

  • All Implemented Interfaces:
    org.datanucleus.store.types.scostore.CollectionStore<java.util.Map.Entry<K,​V>>, org.datanucleus.store.types.scostore.SetStore<java.util.Map.Entry<K,​V>>, org.datanucleus.store.types.scostore.Store

    class MapEntrySetStore<K,​V>
    extends BaseContainerStore
    implements org.datanucleus.store.types.scostore.SetStore<java.util.Map.Entry<K,​V>>
    RDBMS-specific implementation of a SetStore for map entries.
    • Field Detail

      • mapTable

        protected Table mapTable
        Table containing the key and value forming the entry. This may be a join table, or key table (with value "FK"), or value table (with key "FK").
      • mapStore

        protected org.datanucleus.store.types.scostore.MapStore<K,​V> mapStore
        The backing store for the Map.
      • valueMapping

        protected JavaTypeMapping valueMapping
        Mapping for the value.
      • sizeStmt

        private java.lang.String sizeStmt
      • iteratorSelectStmtSql

        private java.lang.String iteratorSelectStmtSql
        SQL statement to use for retrieving data from the map (normal).
      • iteratorSelectStmtLockedSql

        private java.lang.String iteratorSelectStmtLockedSql
        SQL statement to use for retrieving data from the map (locking).
      • iteratorKeyResultCols

        private int[] iteratorKeyResultCols
      • iteratorValueResultCols

        private int[] iteratorValueResultCols
    • Constructor Detail

      • MapEntrySetStore

        MapEntrySetStore​(MapTable mapTable,
                         JoinMapStore<K,​V> mapStore,
                         org.datanucleus.ClassLoaderResolver clr)
        Constructor for a store of the entries in a map when represented in a join table.
        Parameters:
        mapTable - Table for the map
        mapStore - Backing store for the Map using join table
        clr - ClassLoader resolver
      • MapEntrySetStore

        MapEntrySetStore​(DatastoreClass mapTable,
                         FKMapStore<K,​V> mapStore,
                         org.datanucleus.ClassLoaderResolver clr)
        Constructor for a store of the entries in a map when represented by either the key table or value table.
        Parameters:
        mapTable - The table storing the map relation (key table or value table)
        mapStore - The backing store for the FK map itself
        clr - ClassLoader resolver
    • Method Detail

      • hasOrderMapping

        public boolean hasOrderMapping()
        Specified by:
        hasOrderMapping in interface org.datanucleus.store.types.scostore.CollectionStore<K>
      • getMapStore

        public org.datanucleus.store.types.scostore.MapStore<K,​V> getMapStore()
      • updateEmbeddedElement

        public boolean updateEmbeddedElement​(org.datanucleus.state.DNStateManager sm,
                                             java.util.Map.Entry<K,​V> element,
                                             int fieldNumber,
                                             java.lang.Object value)
        Method to update an embedded element.
        Specified by:
        updateEmbeddedElement in interface org.datanucleus.store.types.scostore.CollectionStore<K>
        Parameters:
        sm - StateManager of the owner
        element - The element to update
        fieldNumber - The number of the field to update
        value - The value
        Returns:
        Whether the element was modified
      • validateElementType

        protected boolean validateElementType​(java.lang.Object element)
      • update

        public void update​(org.datanucleus.state.DNStateManager sm,
                           java.util.Collection coll)
        Method to update the collection to be the supplied collection of elements.
        Specified by:
        update in interface org.datanucleus.store.types.scostore.CollectionStore<K>
        Parameters:
        sm - StateManager of the object
        coll - The collection to use
      • contains

        public boolean contains​(org.datanucleus.state.DNStateManager sm,
                                java.lang.Object element)
        Specified by:
        contains in interface org.datanucleus.store.types.scostore.CollectionStore<K>
      • add

        public boolean add​(org.datanucleus.state.DNStateManager sm,
                           java.util.Map.Entry<K,​V> entry,
                           int size)
        Specified by:
        add in interface org.datanucleus.store.types.scostore.CollectionStore<K>
      • addAll

        public boolean addAll​(org.datanucleus.state.DNStateManager sm,
                              java.util.Collection entries,
                              int size)
        Specified by:
        addAll in interface org.datanucleus.store.types.scostore.CollectionStore<K>
      • remove

        public boolean remove​(org.datanucleus.state.DNStateManager sm,
                              java.lang.Object element,
                              int size,
                              boolean allowDependentField)
        Method to remove an entry from the Map.
        Specified by:
        remove in interface org.datanucleus.store.types.scostore.CollectionStore<K>
        Parameters:
        sm - StateManager for the owner
        element - Entry to remove
        Returns:
        Whether it was removed
      • removeAll

        public boolean removeAll​(org.datanucleus.state.DNStateManager sm,
                                 java.util.Collection elements,
                                 int size)
        Method to remove entries from the Map.
        Specified by:
        removeAll in interface org.datanucleus.store.types.scostore.CollectionStore<K>
        Parameters:
        sm - StateManager for the owner
        elements - Entries to remove
        Returns:
        Whether they were removed
      • clear

        public void clear​(org.datanucleus.state.DNStateManager sm)
        Method to clear the Map.
        Specified by:
        clear in interface org.datanucleus.store.types.scostore.CollectionStore<K>
        Parameters:
        sm - StateManager for the owner.
      • size

        public int size​(org.datanucleus.state.DNStateManager sm)
        Specified by:
        size in interface org.datanucleus.store.types.scostore.CollectionStore<K>
      • getSizeStmt

        private java.lang.String getSizeStmt()
        Method to return a size statement.
         SELECT COUNT(*) FROM MAP_TABLE WHERE OWNER=? AND KEY IS NOT NULL
         
        Returns:
        The size statement
      • iterator

        public java.util.Iterator<java.util.Map.Entry<K,​V>> iterator​(org.datanucleus.state.DNStateManager ownerSM)
        Method returning an iterator across the entries in the map for this owner object.
        Specified by:
        iterator in interface org.datanucleus.store.types.scostore.CollectionStore<K>
        Parameters:
        ownerSM - StateManager of the owning object
        Returns:
        The iterator for the entries (
        map.entrySet().iterator()
        ).
      • getSQLStatementForIterator

        protected SelectStatement getSQLStatementForIterator​(org.datanucleus.state.DNStateManager ownerSM,
                                                             org.datanucleus.FetchPlan fp,
                                                             boolean addRestrictionOnOwner)
        Method to generate a SelectStatement for iterating through entries of the map. Creates a statement that selects the table holding the map definition (key/value mappings). Adds a restriction on the ownerMapping of the containerTable so we can restrict to the owner object. Adds a restriction on the keyMapping not being null.
         SELECT KEY, VALUE FROM MAP_TABLE WHERE OWNER_ID=? AND KEY IS NOT NULL
         
        Parameters:
        ownerSM - StateManager for the owner object
        fp - Fetch Plan to observe when selecting key/value
        addRestrictionOnOwner - Whether to add a restriction on the owner object for this map
        Returns:
        The SelectStatement TODO Change this to return KeyValueIteratorStatement