Class JoinListStore<E>

  • All Implemented Interfaces:
    org.datanucleus.store.types.scostore.CollectionStore<E>, org.datanucleus.store.types.scostore.ListStore<E>, org.datanucleus.store.types.scostore.Store

    public class JoinListStore<E>
    extends AbstractListStore<E>
    Implementation of a ListStore using join table.
    • Field Detail

      • setStmt

        private java.lang.String setStmt
      • elementCls

        private java.lang.Class<E> elementCls
    • Constructor Detail

      • JoinListStore

        public JoinListStore​(org.datanucleus.metadata.AbstractMemberMetaData mmd,
                             CollectionTable joinTable,
                             org.datanucleus.ClassLoaderResolver clr)
        Constructor for a join list store for RDBMS.
        Parameters:
        mmd - Metadata for the member that has the list with join table
        joinTable - The Join table
        clr - ClassLoader resolver
    • Method Detail

      • internalAdd

        protected boolean internalAdd​(org.datanucleus.state.DNStateManager ownerSM,
                                      int start,
                                      boolean atEnd,
                                      java.util.Collection<? extends E> c,
                                      int size)
        Internal method to add element(s) to the List. Performs the add in 2 steps.
        1. Shift all existing elements into their new positions so we can insert.
        2. Insert all new elements directly at their desired positions
        Both steps can be batched (separately).
        Specified by:
        internalAdd in class AbstractListStore<E>
        Parameters:
        ownerSM - StateManager for the list owner
        start - The start location (if required)
        atEnd - Whether to add the element at the end
        c - The collection of objects to add.
        size - Current size of list if known. -1 if not known
        Returns:
        Whether it was successful
      • set

        public E set​(org.datanucleus.state.DNStateManager ownerSM,
                     int index,
                     E element,
                     boolean allowDependentField)
      • update

        public void update​(org.datanucleus.state.DNStateManager ownerSM,
                           java.util.Collection<? extends E> coll)
        Specified by:
        update in interface org.datanucleus.store.types.scostore.CollectionStore<E>
        Overrides:
        update in class AbstractCollectionStore<E>
      • remove

        public E remove​(org.datanucleus.state.DNStateManager ownerSM,
                        int index,
                        int size)
      • internalRemove

        protected boolean internalRemove​(org.datanucleus.state.DNStateManager ownerSM,
                                         java.lang.Object element,
                                         int size)
        Convenience method to remove the specified element from the List.
        Specified by:
        internalRemove in class AbstractListStore<E>
        Parameters:
        element - The element
        ownerSM - StateManager of the owner
        size - Current size of list if known. -1 if not known
        Returns:
        Whether the List was modified
      • internalRemove

        private int[] internalRemove​(org.datanucleus.state.DNStateManager ownerSM,
                                     org.datanucleus.store.connection.ManagedConnection conn,
                                     boolean batched,
                                     java.lang.Object element,
                                     boolean executeNow)
      • removeAll

        public boolean removeAll​(org.datanucleus.state.DNStateManager ownerSM,
                                 java.util.Collection elements,
                                 int size)
      • removeAll

        public boolean removeAll​(org.datanucleus.state.DNStateManager ownerSM,
                                 java.util.Collection elements,
                                 int size,
                                 int[] elementIndices)
      • internalRemoveAt

        protected void internalRemoveAt​(org.datanucleus.state.DNStateManager ownerSM,
                                        int index,
                                        int size)
        Method to remove an element from the specified position
        Parameters:
        ownerSM - StateManager for the list owner
        index - The index of the element
        size - Current size of list (if known). -1 if not known
      • listIterator

        protected java.util.ListIterator<E> listIterator​(org.datanucleus.state.DNStateManager ownerSM,
                                                         int startIdx,
                                                         int endIdx)
        Accessor for an iterator through the list elements.
        Specified by:
        listIterator in class AbstractListStore<E>
        Parameters:
        ownerSM - StateManager for the list owner
        startIdx - The start point in the list (only for indexed lists).
        endIdx - End index in the list (only for indexed lists).
        Returns:
        The List Iterator
      • getSetStmt

        protected java.lang.String getSetStmt()
        Generates the statement for setting an item.
         UPDATE LISTTABLE SET [ELEMENTCOL = ?]
         [EMBEDDEDFIELD1=?, EMBEDDEDFIELD2=?, ...]
         WHERE OWNERCOL = ?
         AND INDEXCOL = ?
         [AND DISTINGUISHER=?]
         
        Returns:
        The Statement for setting an item
      • getRemoveAllStmt

        protected java.lang.String getRemoveAllStmt​(java.util.Collection elements)
        Generate statement for removing a collection of items from the List.
         DELETE FROM LISTTABLE
         WHERE (OWNERCOL=? AND ELEMENTCOL=?) OR
         (OWNERCOL=? AND ELEMENTCOL=?) OR
         (OWNERCOL=? AND ELEMENTCOL=?)
         
        Parameters:
        elements - Collection of elements to remove
        Returns:
        Statement for deleting items from the List.
      • getIteratorStatement

        public ElementIteratorStatement getIteratorStatement​(org.datanucleus.ExecutionContext ec,
                                                             org.datanucleus.FetchPlan fp,
                                                             boolean addRestrictionOnOwner,
                                                             int startIdx,
                                                             int endIdx)
        Method to return the SQLStatement and mapping for an iterator for this backing store. Create a statement of the form
         SELECT ELEM_COLS
         FROM JOIN_TBL
           [JOIN ELEM_TBL ON ELEM_TBL.ID = JOIN_TBL.ELEM_ID]
         [WHERE]
           [JOIN_TBL.OWNER_ID = {value}] [AND]
           [JOIN_TBL.DISCRIM = {discrimValue}]
         [ORDER BY {orderClause}]
         
        This is public to provide access for BulkFetchXXXHandler class(es).
        Parameters:
        ec - ExecutionContext
        fp - FetchPlan to use in determing which fields of element to select
        addRestrictionOnOwner - Whether to restrict to a particular owner (otherwise functions as bulk fetch for many owners).
        startIdx - Start index for the iterator (or -1)
        endIdx - End index for the iterator (or -1)
        Returns:
        The SQLStatement and its associated StatementClassMapping