Class JoinSetStore<E>
java.lang.Object
org.datanucleus.store.rdbms.scostore.BaseContainerStore
org.datanucleus.store.rdbms.scostore.ElementContainerStore
org.datanucleus.store.rdbms.scostore.AbstractCollectionStore<E>
org.datanucleus.store.rdbms.scostore.AbstractSetStore<E>
org.datanucleus.store.rdbms.scostore.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
Implementation of a
SetStore using join table.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringStatement to check the existence of an owner-element relation.protected StringStatement to get the maximum order column id so we can set the next insert value.Fields inherited from class AbstractCollectionStore
containsStmtFields inherited from class ElementContainerStore
addStmt, clearStmt, containerTable, elementCmd, elementInfo, elementIsPersistentInterface, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, removeStmt, sizeStmtFields inherited from class BaseContainerStore
allowNulls, clr, dba, ownerMapping, ownerMemberMetaData, relationType, storeMgr -
Constructor Summary
ConstructorsConstructorDescriptionJoinSetStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, CollectionTable joinTable, org.datanucleus.ClassLoaderResolver clr) Constructor for a join set store for RDBMS. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(org.datanucleus.state.DNStateManager sm, Collection<? extends E> elements, int size) protected int[]doInternalAdd(org.datanucleus.state.DNStateManager sm, E element, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, int orderId, boolean executeNow) private booleanelementAlreadyContainsOwnerInMtoN(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).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.private StringgetLocateStatementString(Object element) Generate statement for checking the existence of an owner-element relation (used for M-N).private StringgetLocateStmt(Object element) private StringGenerate statement for obtaining the maximum id for the order column.protected intgetNextIDForOrderColumn(org.datanucleus.state.DNStateManager sm) protected StringgetRemoveAllStmt(org.datanucleus.state.DNStateManager sm, Collection elements) Generate statement for removing a collection of items from the Set.protected StringgetRemoveStmt(Object element) Generate statement for deleting items from the Set.iterator(org.datanucleus.state.DNStateManager ownerSM) Accessor for an iterator through the container elements.private booleanbooleanremoveAll(org.datanucleus.state.DNStateManager sm, Collection elements, int size) voidupdate(org.datanucleus.state.DNStateManager sm, Collection<? extends E> coll) Methods inherited from class AbstractSetStore
removeMethods inherited from class AbstractCollectionStore
contains, getUpdateEmbeddedElementStmt, updateEmbeddedElementMethods inherited from class ElementContainerStore
clear, getAddStmtForJoinTable, getClearStmt, getComponentInfoForElement, getContainerTable, getElementClassMetaData, getElementMapping, getRelationDiscriminatorMapping, getRelationDiscriminatorValue, getSize, getSizeStmt, hasOrderMapping, invalidateAddStmt, isElementsAreEmbedded, isElementsAreSerialised, size, usingJoinTable, validateElementForReading, validateElementForWriting, validateElementTypeMethods inherited from class BaseContainerStore
allowsBatching, getComponentInformationForClass, getDatastoreAdapter, getOwnerMapping, getOwnerMemberMetaData, getRelationType, getStateManagerForEmbeddedPCObject, getStoreManager, isEmbeddedMapping, setOwnerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.datanucleus.store.types.scostore.CollectionStore
clear, contains, hasOrderMapping, size, updateEmbeddedElementMethods inherited from interface org.datanucleus.store.types.scostore.Store
getOwnerMemberMetaData, getStoreManager
-
Field Details
-
locateStmt
Statement to check the existence of an owner-element relation. -
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 tablejoinTable- The join tableclr- The ClassLoaderResolver
-
-
Method Details
-
update
- Specified by:
updatein interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>- Overrides:
updatein classAbstractCollectionStore<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 ownerelement- The element- Returns:
- Whether the element contains the owner
-
add
-
addAll
public boolean addAll(org.datanucleus.state.DNStateManager sm, Collection<? extends E> elements, int size) -
removeAll
-
getRemoveStmt
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:
getRemoveStmtin classAbstractCollectionStore<E>- Parameters:
element- The element to remove- Returns:
- Statement for deleting items from the Set.
-
getRemoveAllStmt
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 ownerelements- Collection of elements to remove- Returns:
- Statement for deleting items from the Set.
-
locate
-
doInternalAdd
protected int[] doInternalAdd(org.datanucleus.state.DNStateManager sm, E element, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, int orderId, boolean executeNow) -
getLocateStmt
-
getLocateStatementString
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
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
Description copied from class:ElementContainerStoreAccessor for an iterator through the container elements.- Specified by:
iteratorin interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>- Specified by:
iteratorin classAbstractSetStore<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 formSELECT 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- ExecutionContextfp- FetchPlan to use in determining which fields of element to selectaddRestrictionOnOwner- Whether to restrict to a particular owner (otherwise functions as bulk fetch for many owners).- Returns:
- The SQLStatement and its associated StatementClassMapping
-