Class FKSetStore<E>

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

    public class FKSetStore<E>
    extends AbstractSetStore<E>
    Implementation of an SetStore using foreign keys.
    • Constructor Detail

      • FKSetStore

        public FKSetStore​(org.datanucleus.metadata.AbstractMemberMetaData mmd,
                          RDBMSStoreManager storeMgr,
                          org.datanucleus.ClassLoaderResolver clr)
        Constructor for the backing store of a FK set for RDBMS.
        Parameters:
        mmd - The MetaData for the field that this represents
        storeMgr - The StoreManager managing the associated datastore.
        clr - The ClassLoaderResolver
    • Method Detail

      • getFieldNumberInElementForBidirectional

        protected int getFieldNumberInElementForBidirectional​(org.datanucleus.state.DNStateManager sm)
        This seems to return the field number in the element of the relation when it is a bidirectional relation.
        Parameters:
        sm - StateManager for the owner.
        Returns:
        The field number in the element for this relation
      • update

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

        public boolean add​(org.datanucleus.state.DNStateManager ownerSM,
                           E element,
                           int size)
      • addAll

        public boolean addAll​(org.datanucleus.state.DNStateManager ownerSM,
                              Collection<E> elements,
                              int size)
      • remove

        public boolean remove​(org.datanucleus.state.DNStateManager ownerSM,
                              Object element,
                              int size,
                              boolean allowDependentField)
        Method to remove the link to the collection object specified. Depending on the column characteristics in the collection table, the id of the owner field may be NULLed, or the record may be deleted completely (as per cascade-delete in EJB).
        Specified by:
        remove in interface org.datanucleus.store.types.scostore.CollectionStore<E>
        Overrides:
        remove in class AbstractSetStore<E>
        Parameters:
        ownerSM - StateManager for the owner.
        element - The element of the collection to be deleted.
        allowDependentField - Whether to allow any cascade deletes caused by this removal
        size - Not used
        Returns:
        A success indicator.
      • removeAll

        public boolean removeAll​(org.datanucleus.state.DNStateManager ownerSM,
                                 Collection elements,
                                 int size)
        Method to remove the links to a collection of elements specified. Depending on the column characteristics in the collection table, the id of the owner fields may be NULLed, or the records may be deleted completely.
        Parameters:
        ownerSM - StateManager for the owner.
        elements - The elements of the collection to be deleted.
        size - Not used
        Returns:
        A success indicator.
      • checkRemovalOfElementShouldDelete

        protected boolean checkRemovalOfElementShouldDelete​(org.datanucleus.state.DNStateManager ownerSM)
        Convenience method to return if the removal of an element should delete the element.
        Parameters:
        ownerSM - StateManager for the owner.
        Returns:
        Whether we should delete the element on removing from the collection
      • manageRemovalOfElement

        protected void manageRemovalOfElement​(org.datanucleus.state.DNStateManager ownerSM,
                                              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:
        ownerSM - StateManager for the owner.
        element - The element
      • clear

        public void clear​(org.datanucleus.state.DNStateManager ownerSM)
        Method to allow the Set relationship to be cleared out. 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:
        ownerSM - StateManager for the owner.
      • getClearNullifyStmt

        protected String getClearNullifyStmt​(ComponentInfo info)
        Generates the statement for clearing items by nulling the owner link out. The statement will be of the form
         UPDATE LISTTABLE SET OWNERCOL=NULL [,DISTINGUISHER=NULL]
         WHERE OWNERCOL=?
         
        Parameters:
        info - ElementInfo for the element
        Returns:
        The Statement for clearing items for the owner.
      • iterator

        public Iterator<E> iterator​(org.datanucleus.state.DNStateManager ownerSM)
        Description copied from class: ElementContainerStore
        Accessor for an iterator through the container elements.
        Specified by:
        iterator in interface org.datanucleus.store.types.scostore.CollectionStore<E>
        Specified by:
        iterator in class AbstractSetStore<E>
        Parameters:
        ownerSM - StateManager for the container.
        Returns:
        The Iterator
      • getIteratorStatement

        public ElementIteratorStatement getIteratorStatement​(org.datanucleus.ExecutionContext ec,
                                                             org.datanucleus.FetchPlan fp,
                                                             boolean addRestrictionOnOwner)
        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}]
         
        This is public to provide access for BulkFetchXXXHandler class(es).
        Parameters:
        ec - ExecutionContext
        fp - FetchPlan to use in determining which fields of element to select
        addRestrictionOnOwner - Whether to restrict to a particular owner (otherwise functions as bulk fetch for many owners).
        Returns:
        The SQLStatement and its associated StatementClassMapping