Class ElementContainerStore
java.lang.Object
org.datanucleus.store.rdbms.scostore.BaseContainerStore
org.datanucleus.store.rdbms.scostore.ElementContainerStore
- All Implemented Interfaces:
org.datanucleus.store.types.scostore.Store
- Direct Known Subclasses:
AbstractArrayStore, AbstractCollectionStore
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 Summary
FieldsModifier and TypeFieldDescriptionprotected StringStatement for adding an element to the container.protected StringStatement for clearing the container.protected TableTable containing the link between owner and element.protected org.datanucleus.metadata.AbstractClassMetaDataMetaData for the "element-type" class.protected ComponentInfo[]Information for the elements of this container.protected booleanWhether the element is of a persistent-interface (defined using "{interface}") type.protected JavaTypeMappingMapping for the element.protected booleanWhether the elements are embedded.protected booleanWhether the elements are serialised.protected StringType of the element.protected booleanFlag to set whether the iterator statement will use a discriminator or not.protected JavaTypeMappingMapping for an ordering column to allow for duplicates in the container.protected JavaTypeMappingOptional mapping to distinguish elements of one collection from another when sharing the join table.protected StringValue to use to discriminate between elements of this collection from others using the same join table.protected StringStatement for removing an element from the container.protected StringStatement for getting the size of the container.Fields inherited from class BaseContainerStore
allowNulls, clr, dba, ownerMapping, ownerMemberMetaData, relationType, storeMgr -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedElementContainerStore(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear(org.datanucleus.state.DNStateManager ownerSM) Clear the association from owner to all elements.protected StringGenerates the statement for adding items to a (join table) container.protected StringGenerate statement for clearing the (join table) container.protected ComponentInfogetComponentInfoForElement(Object element) org.datanucleus.metadata.AbstractClassMetaDataintgetSize(org.datanucleus.state.DNStateManager ownerSM) protected StringGenerate statement for getting the size of the container.booleanAccessor for whether the store has an order mapping, to allow for duplicates or ordering.protected voidMethod to remove any stored statement for addition of an element.booleanbooleanabstract Iteratoriterator(org.datanucleus.state.DNStateManager ownerSM) Accessor for an iterator through the container elements.intsize(org.datanucleus.state.DNStateManager sm) Method to return the size of the container.protected booleanprotected booleanvalidateElementForReading(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.protected booleanvalidateElementForWriting(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.protected booleanvalidateElementType(org.datanucleus.ClassLoaderResolver clr, Object element) Method to validate an element against the accepted type.
-
Field Details
-
iterateUsingDiscriminator
protected boolean iterateUsingDiscriminatorFlag to set whether the iterator statement will use a discriminator or not. -
sizeStmt
Statement for getting the size of the container. -
clearStmt
Statement for clearing the container. -
addStmt
Statement for adding an element to the container. -
removeStmt
Statement for removing an element from the container. -
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 elementCmdMetaData for the "element-type" class. Not used for reference types since no metadata is present for the declared type. -
containerTable
Table containing the link between owner and element. -
elementMapping
Mapping for the element. -
elementType
Type of the element. -
elementsAreEmbedded
protected boolean elementsAreEmbeddedWhether the elements are embedded. -
elementsAreSerialised
protected boolean elementsAreSerialisedWhether the elements are serialised. -
elementIsPersistentInterface
protected boolean elementIsPersistentInterfaceWhether the element is of a persistent-interface (defined using "{interface}") type. -
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
Optional mapping to distinguish elements of one collection from another when sharing the join table. -
relationDiscriminatorValue
Value to use to discriminate between elements of this collection from others using the same join table.
-
-
Constructor Details
-
ElementContainerStore
protected ElementContainerStore(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr) Constructor.- Parameters:
storeMgr- Manager for the storeclr- ClassLoader resolver
-
-
Method Details
-
getElementMapping
-
getRelationDiscriminatorMapping
-
getRelationDiscriminatorValue
-
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
Method to validate an element against the accepted type.- Parameters:
clr- The ClassLoaderResolverelement- 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 ownerelement- 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 contextelement- The elementfieldValues- any initial field values to use if persisting the element- Returns:
- Whether the element was persisted during this call
-
iterator
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
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
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
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
-
usingJoinTable
protected boolean usingJoinTable()
-