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>
    RDBMS-specific implementation of a ListStore using join table.
    • 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.ObjectProvider op,
                                      int start,
                                      boolean atEnd,
                                      Collection<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:
        op - The ObjectProvider
        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.ObjectProvider op,
                     int index,
                     Object element,
                     boolean allowDependentField)
        Method to set an object in the List.
        Parameters:
        op - ObjectProvider for the owner
        index - The item index
        element - What to set it to.
        allowDependentField - Whether to allow dependent field deletes
        Returns:
        The value before setting.
      • update

        public void update​(org.datanucleus.state.ObjectProvider op,
                           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<E>
        Overrides:
        update in class AbstractCollectionStore<E>
        Parameters:
        op - ObjectProvider of the object
        coll - The collection to use
      • internalRemove

        protected boolean internalRemove​(org.datanucleus.state.ObjectProvider ownerOP,
                                         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
        ownerOP - ObjectProvider of the owner
        size - Current size of list if known. -1 if not known
        Returns:
        Whether the List was modified
      • removeAll

        public boolean removeAll​(org.datanucleus.state.ObjectProvider op,
                                 Collection elements,
                                 int size)
        Remove all elements from a collection from the association owner vs elements. Performs the removal in 3 steps. The first gets the indices that will be removed (and the highest index present). The second step removes these elements from the list. The third step updates the indices of the remaining indices to fill the holes created.
        Parameters:
        op - ObjectProvider
        elements - Collection of elements to remove
        Returns:
        Whether the database was updated
      • internalRemoveAt

        protected void internalRemoveAt​(org.datanucleus.state.ObjectProvider op,
                                        int index,
                                        int size)
        Method to remove an element from the specified position
        Specified by:
        internalRemoveAt in class AbstractListStore<E>
        Parameters:
        op - The ObjectProvider for the list
        index - The index of the element
        size - Current size of list (if known). -1 if not known
      • listIterator

        protected ListIterator<E> listIterator​(org.datanucleus.state.ObjectProvider ownerOP,
                                               int startIdx,
                                               int endIdx)
        Accessor for an iterator through the list elements.
        Specified by:
        listIterator in class AbstractListStore<E>
        Parameters:
        ownerOP - ObjectProvider for the 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 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 String getRemoveAllStmt​(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}]
         
        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