Class FKListStore<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 FKListStore<E>
    extends AbstractListStore<E>
    RDBMS-specific implementation of an ListStore using foreign keys.
    • Constructor Detail

      • FKListStore

        public FKListStore​(org.datanucleus.metadata.AbstractMemberMetaData mmd,
                           RDBMSStoreManager storeMgr,
                           org.datanucleus.ClassLoaderResolver clr)
        Parameters:
        mmd - Metadata for owning field/property
        storeMgr - Manager for the datastore
        clr - ClassLoader resolver
    • Method Detail

      • set

        public E set​(org.datanucleus.state.ObjectProvider ownerOP,
                     int index,
                     Object element,
                     boolean allowDependentField)
        Method to set an object in the List at a position.
        Parameters:
        ownerOP - ObjectProvider for the owner
        index - The item index
        element - What to set it to.
        allowDependentField - Whether to enable dependent-field deletes during the set
        Returns:
        The value before setting.
      • update

        public void update​(org.datanucleus.state.ObjectProvider ownerOP,
                           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:
        ownerOP - ObjectProvider for the owner
        coll - The collection to use
      • internalAdd

        protected boolean internalAdd​(org.datanucleus.state.ObjectProvider ownerOP,
                                      int startAt,
                                      boolean atEnd,
                                      Collection<E> c,
                                      int size)
        Internal method for adding an item to the List.
        Specified by:
        internalAdd in class AbstractListStore<E>
        Parameters:
        ownerOP - ObjectProvider for the owner
        startAt - The start position
        atEnd - Whether to add at the end
        c - The Collection of elements to add.
        size - Current size of list (if known). -1 if not known
        Returns:
        Whether it was successful
      • removeAll

        public boolean removeAll​(org.datanucleus.state.ObjectProvider ownerOP,
                                 Collection elements,
                                 int size)
        Remove all elements from a collection from the association owner vs elements. TODO : Change the query to do all in one go for efficiency. Currently removes an element and shuffles the indexes, then removes an element and shuffles the indexes, then removes an element and shuffles the indexes etc ... a bit inefficient !!!
        Parameters:
        ownerOP - ObjectProvider for the owner
        elements - Collection of elements to remove
        Returns:
        Whether the database was updated
      • 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:
        ownerOP - ObjectProvider for the owner
        element - The element
        size - Current size of list if known. -1 if not known
        Returns:
        Whether the List was modified
      • manageRemovalOfElement

        protected void manageRemovalOfElement​(org.datanucleus.state.ObjectProvider ownerOP,
                                              Object element)
        Convenience method to manage the removal of an element from the collection, performing any necessary "managed relationship" updates when the field is bidirectional.
        Parameters:
        ownerOP - ObjectProvider for the collection owner
        element - The element
      • internalRemoveAt

        protected void internalRemoveAt​(org.datanucleus.state.ObjectProvider ownerOP,
                                        int index,
                                        int size)
        Internal method to remove an object at a location in the List. Differs from the JoinTable List in that it nulls out the owner FK.
        Specified by:
        internalRemoveAt in class AbstractListStore<E>
        Parameters:
        ownerOP - ObjectProvider for the owner
        index - The location
        size - Current size of list (if known). -1 if not known
      • clear

        public void clear​(org.datanucleus.state.ObjectProvider ownerOP)
        Method to clear the List. This is called by the List.clear() method, or when the container object is being deleted and the elements are to be removed (maybe for dependent field), or also when updating a Collection and removing all existing prior to adding all new.
        Specified by:
        clear in interface org.datanucleus.store.types.scostore.CollectionStore<E>
        Overrides:
        clear in class ElementContainerStore
        Parameters:
        ownerOP - ObjectProvider for the owner
      • validateElementForWriting

        protected boolean validateElementForWriting​(org.datanucleus.state.ObjectProvider op,
                                                    Object element,
                                                    int index)
        Method to validate that an element is valid for writing to the datastore. TODO Minimise differences to super.validateElementForWriting()
        Parameters:
        op - ObjectProvider for the List
        element - The element to validate
        index - The position that the element is being stored at in the list
        Returns:
        Whether the element was inserted
      • 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 index in the list (only for indexed lists)
        endIdx - The end index in the list (only for indexed lists)
        Returns:
        The List Iterator
      • 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 ELEM_TBL
         [WHERE]
           [ELEM_TBL.OWNER_ID = {value}] [AND]
           [ELEM_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