Class ElementContainerStore

  • All Implemented Interfaces:
    org.datanucleus.store.types.scostore.Store
    Direct Known Subclasses:
    AbstractArrayStore, AbstractCollectionStore

    public abstract class ElementContainerStore
    extends BaseContainerStore
    Representation of the store of an element-based container. This is used to represent either a collection or an array. There are the following types of situation that we try to cater for with respect to elements.
    • element-type is PC with "new-table" or "superclass-table" inheritance. In this case we will have elementInfo with 1 entry.
    • element-type is PC with "subclass-table" inheritance. In this case we will have elementInfo with "n" entries (1 for each subclass type with its own table). We also have emd being the MetaData for the element-type.
    • element-type is Reference type. In this case we will have elementInfo with "n" entries (1 for each implementation type).
    • element-type is non-PC. In this case we have no elementInfo and no emd
    • Field Detail

      • iterateUsingDiscriminator

        protected boolean iterateUsingDiscriminator
        Flag to set whether the iterator statement will use a discriminator or not.
      • sizeStmt

        protected String sizeStmt
        Statement for getting the size of the container.
      • clearStmt

        protected String clearStmt
        Statement for clearing the container.
      • addStmt

        protected String addStmt
        Statement for adding an element to the container.
      • removeStmt

        protected String removeStmt
        Statement for removing an element from the container.
      • elementInfo

        protected ComponentInfo[] elementInfo
        Information for the elements of this container. When the "element-type" table is new-table, or superclass-table then there is 1 value here. When the "element-type" table uses subclass-table, or when it is a reference type then there can be multiple. When the element is embedded/serialised (into join table) this will be null.
      • elementCmd

        protected org.datanucleus.metadata.AbstractClassMetaData elementCmd
        MetaData for the "element-type" class. Not used for reference types since no metadata is present for the declared type.
      • containerTable

        protected Table containerTable
        Table containing the link between owner and element.
      • elementMapping

        protected JavaTypeMapping elementMapping
        Mapping for the element.
      • elementType

        protected String elementType
        Type of the element.
      • elementsAreEmbedded

        protected boolean elementsAreEmbedded
        Whether the elements are embedded.
      • elementsAreSerialised

        protected boolean elementsAreSerialised
        Whether the elements are serialised.
      • elementIsPersistentInterface

        protected boolean elementIsPersistentInterface
        Whether the element is of a persistent-interface (defined using "{interface}") type.
      • orderMapping

        protected JavaTypeMapping orderMapping
        Mapping for an ordering column to allow for duplicates in the container. Can also be used for ordering elements in a List/array. Can also be used where we have an embedded object and so need to form the PK with something.
      • relationDiscriminatorMapping

        protected JavaTypeMapping relationDiscriminatorMapping
        Optional mapping to distinguish elements of one collection from another when sharing the join table.
      • relationDiscriminatorValue

        protected String relationDiscriminatorValue
        Value to use to discriminate between elements of this collection from others using the same join table.
    • Constructor Detail

      • ElementContainerStore

        protected ElementContainerStore​(RDBMSStoreManager storeMgr,
                                        org.datanucleus.ClassLoaderResolver clr)
        Constructor.
        Parameters:
        storeMgr - Manager for the store
        clr - ClassLoader resolver
    • Method Detail

      • getRelationDiscriminatorMapping

        public JavaTypeMapping getRelationDiscriminatorMapping()
      • getRelationDiscriminatorValue

        public String getRelationDiscriminatorValue()
      • getContainerTable

        public Table getContainerTable()
      • getElementClassMetaData

        public org.datanucleus.metadata.AbstractClassMetaData getElementClassMetaData()
      • isElementsAreSerialised

        public boolean isElementsAreSerialised()
      • isElementsAreEmbedded

        public boolean isElementsAreEmbedded()
      • hasOrderMapping

        public boolean hasOrderMapping()
        Accessor for whether the store has an order mapping, to allow for duplicates or ordering.
        Returns:
        Whether an order mapping is present.
      • validateElementType

        protected boolean validateElementType​(org.datanucleus.ClassLoaderResolver clr,
                                              Object element)
        Method to validate an element against the accepted type.
        Parameters:
        clr - The ClassLoaderResolver
        element - The element to validate
        Returns:
        Whether it is valid.
      • validateElementForReading

        protected boolean validateElementForReading​(org.datanucleus.state.DNStateManager sm,
                                                    Object element)
        Method to check if an element is already persistent or is persistent but managed by a different ExecutionContext.
        Parameters:
        sm - StateManager of this owner
        element - The element
        Returns:
        Whether it is valid for reading.
      • validateElementForWriting

        protected boolean validateElementForWriting​(org.datanucleus.ExecutionContext ec,
                                                    Object element,
                                                    org.datanucleus.store.FieldValues fieldValues)
        Method to check if an element is already persistent, or is managed by a different ExecutionContext. If not persistent, this will persist it.
        Parameters:
        ec - execution context
        element - The element
        fieldValues - any initial field values to use if persisting the element
        Returns:
        Whether the element was persisted during this call
      • iterator

        public abstract Iterator iterator​(org.datanucleus.state.DNStateManager ownerSM)
        Accessor for an iterator through the container elements.
        Parameters:
        ownerSM - StateManager for the container.
        Returns:
        The Iterator
      • clear

        public void clear​(org.datanucleus.state.DNStateManager ownerSM)
        Clear the association from owner to all elements. Provides cascade-delete when the elements being deleted are PC types.
        Parameters:
        ownerSM - StateManager for the container.
      • getClearStmt

        protected String getClearStmt()
        Generate statement for clearing the (join table) container.
         DELETE FROM CONTAINERTABLE WHERE OWNERCOL = ? [AND RELATION_DISCRIM=?]
         
        TODO Add a discriminator restriction on this statement so we only clear ones with a valid discriminator value
        Returns:
        Statement for clearing the container.
      • invalidateAddStmt

        protected void invalidateAddStmt()
        Method to remove any stored statement for addition of an element.
      • getAddStmtForJoinTable

        protected String getAddStmtForJoinTable()
        Generates the statement for adding items to a (join table) container. The EMBEDDEDFIELDX columns are only added for embedded PC elements.
         INSERT INTO COLLTABLE (OWNERCOL,[ELEMENTCOL],[EMBEDDEDFIELD1, EMBEDDEDFIELD2,...],[ORDERCOL]) VALUES (?,?,?)
         
        Returns:
        The Statement for adding an item
      • size

        public int size​(org.datanucleus.state.DNStateManager sm)
        Method to return the size of the container.
        Parameters:
        sm - StateManager.
        Returns:
        The size.
      • getSize

        public int getSize​(org.datanucleus.state.DNStateManager ownerSM)
      • getSizeStmt

        protected String getSizeStmt()
        Generate statement for getting the size of the container. The order part is only present when an order mapping is used. The discriminator part is only present when the element has a discriminator.
         SELECT COUNT(*) FROM TBL THIS
         [INNER JOIN ELEM_TBL ELEM ON TBL.COL = ELEM.ID] - when no null
         [LEFT OUTER JOIN ELEM_TBL ELEM ON TBL.COL = ELEM.ID] - when allows null
         WHERE THIS.OWNERCOL=?
         [AND THIS.ORDERCOL IS NOT NULL]
         [AND (DISCRIMINATOR=? OR DISCRMINATOR=? OR DISCRIMINATOR=? [OR DISCRIMINATOR IS NULL])]
         [AND RELATION_DISCRIM=?]
         
        The discriminator part includes all subclasses of the element type. If the element is in a different table to the container then an INNER JOIN will be present to link the two tables, and table aliases will be present also.
        Returns:
        The Statement returning the size of the container.
      • getComponentInfoForElement

        protected ComponentInfo getComponentInfoForElement​(Object element)
      • usingJoinTable

        protected boolean usingJoinTable()