Class JoinSetStore<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 JoinSetStore<E> extends AbstractSetStore<E>
Implementation of a SetStore using join table.
  • Field Details

    • locateStmt

      protected String locateStmt
      Statement to check the existence of an owner-element relation.
    • maxOrderColumnIdStmt

      protected String maxOrderColumnIdStmt
      Statement to get the maximum order column id so we can set the next insert value.
  • Constructor Details

    • JoinSetStore

      public JoinSetStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, CollectionTable joinTable, org.datanucleus.ClassLoaderResolver clr)
      Constructor for a join set store for RDBMS.
      Parameters:
      mmd - Metadata for the member that has the set with join table
      joinTable - The join table
      clr - The ClassLoaderResolver
  • Method Details

    • update

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

      private boolean elementAlreadyContainsOwnerInMtoN(org.datanucleus.state.DNStateManager ownerSM, Object element)
      Convenience method to check if an element already refers to the owner in an M-N relation (i.e added from other side).
      Parameters:
      ownerSM - StateManager of the owner
      element - The element
      Returns:
      Whether the element contains the owner
    • add

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

      public boolean addAll(org.datanucleus.state.DNStateManager sm, Collection<? extends E> elements, int size)
    • removeAll

      public boolean removeAll(org.datanucleus.state.DNStateManager sm, Collection elements, int size)
    • getRemoveStmt

      protected String getRemoveStmt(Object element)
      Generate statement for deleting items from the Set. The EMBEDDEDFIELDX is only present when the elements are PC(embedded).
       DELETE FROM SETTABLE
       WHERE OWNERCOL=?
       AND ELEMENTCOL = ?
       [AND EMBEDDEDFIELD1 = ? AND EMBEDDEDFIELD2 = ? AND EMBEDDEDFIELD3 = ?]
       [AND RELATION_DISCRIM = ?]
       
      Overrides:
      getRemoveStmt in class AbstractCollectionStore<E>
      Parameters:
      element - The element to remove
      Returns:
      Statement for deleting items from the Set.
    • getRemoveAllStmt

      protected String getRemoveAllStmt(org.datanucleus.state.DNStateManager sm, Collection elements)
      Generate statement for removing a collection of items from the Set.
       DELETE FROM SETTABLE
       WHERE (OWNERCOL=? AND ELEMENTCOL=?) OR
             (OWNERCOL=? AND ELEMENTCOL=?) OR
             (OWNERCOL=? AND ELEMENTCOL=?)
       
      Parameters:
      sm - StateManager for the owner
      elements - Collection of elements to remove
      Returns:
      Statement for deleting items from the Set.
    • locate

      private boolean locate(org.datanucleus.state.DNStateManager sm, Object element)
    • doInternalAdd

      protected int[] doInternalAdd(org.datanucleus.state.DNStateManager sm, E element, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, int orderId, boolean executeNow)
    • getLocateStmt

      private String getLocateStmt(Object element)
    • getLocateStatementString

      private String getLocateStatementString(Object element)
      Generate statement for checking the existence of an owner-element relation (used for M-N).
       SELECT 1 FROM JOINTABLE WHERE OWNERCOL = ? AND ELEMENTCOL = ?
       
      Parameters:
      element - The element to locate
      Returns:
      Statement for locating an owner-element relation in the join table
    • getNextIDForOrderColumn

      protected int getNextIDForOrderColumn(org.datanucleus.state.DNStateManager sm)
    • getMaxOrderColumnIdStmt

      private String getMaxOrderColumnIdStmt()
      Generate statement for obtaining the maximum id for the order column.
       SELECT MAX(SCOID) FROM SETTABLE
       WHERE OWNERCOL=?
       [AND RELATION_DISCRIM=?]
       
      Returns:
      The Statement returning the higher id
    • 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 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 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