Class FKSetStore<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.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
Implementation of an
SetStore
using foreign keys.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
Statement for clearing a FK in the element.private String
Statement for updating a FK in the element.Fields inherited from class org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
containsStmt
Fields inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
addStmt, clearStmt, containerTable, elementCmd, elementInfo, elementIsPersistentInterface, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, removeStmt, sizeStmt
Fields inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowNulls, clr, dba, ownerMapping, ownerMemberMetaData, relationType, storeMgr
-
Constructor Summary
ConstructorsConstructorDescriptionFKSetStore
(org.datanucleus.metadata.AbstractMemberMetaData mmd, RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr) Constructor for the backing store of a FK set for RDBMS. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(org.datanucleus.state.DNStateManager ownerSM, Collection<? extends E> elements, int size) protected boolean
checkRemovalOfElementShouldDelete
(org.datanucleus.state.DNStateManager ownerSM) Convenience method to return if the removal of an element should delete the element.void
clear
(org.datanucleus.state.DNStateManager ownerSM) Method to allow the Set relationship to be cleared out.protected String
Generates the statement for clearing items by nulling the owner link out.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.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 String
getUpdateFkStatementString
(Object element) private String
getUpdateFkStmt
(Object element) Generate statement for updating a Foreign Key in a FK 1-N.iterator
(org.datanucleus.state.DNStateManager ownerSM) Accessor for an iterator through the container elements.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.boolean
remove
(org.datanucleus.state.DNStateManager ownerSM, Object element, int size, boolean allowDependentField) Method to remove the link to the collection object specified.boolean
removeAll
(org.datanucleus.state.DNStateManager ownerSM, Collection elements, int size) Method to remove the links to a collection of elements specified.void
update
(org.datanucleus.state.DNStateManager ownerSM, Collection<? extends E> coll) private boolean
updateElementFk
(org.datanucleus.state.DNStateManager ownerSM, Object element, Object owner) Utility to update a foreign-key (and distinguisher) in the element in the case of a unidirectional 1-N relationship.Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
contains, getRemoveStmt, getUpdateEmbeddedElementStmt, updateEmbeddedElement
Methods inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
getAddStmtForJoinTable, getClearStmt, getComponentInfoForElement, getContainerTable, getElementClassMetaData, getElementMapping, getRelationDiscriminatorMapping, getRelationDiscriminatorValue, getSize, getSizeStmt, hasOrderMapping, invalidateAddStmt, isElementsAreEmbedded, isElementsAreSerialised, size, usingJoinTable, validateElementForReading, validateElementForWriting, validateElementType
Methods inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowsBatching, getComponentInformationForClass, getDatastoreAdapter, getOwnerMapping, getOwnerMemberMetaData, getRelationType, getStateManagerForEmbeddedPCObject, getStoreManager, isEmbeddedMapping, setOwner
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.datanucleus.store.types.scostore.CollectionStore
contains, hasOrderMapping, size, updateEmbeddedElement
Methods inherited from interface org.datanucleus.store.types.scostore.Store
getOwnerMemberMetaData, getStoreManager
-
Field Details
-
updateFkStmt
Statement for updating a FK in the element. -
clearNullifyStmt
Statement for clearing a FK in the element.
-
-
Constructor Details
-
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 representsstoreMgr
- The StoreManager managing the associated datastore.clr
- The ClassLoaderResolver
-
-
Method Details
-
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
-
updateElementFk
private boolean updateElementFk(org.datanucleus.state.DNStateManager ownerSM, Object element, Object owner) Utility to update a foreign-key (and distinguisher) in the element in the case of a unidirectional 1-N relationship.- Parameters:
ownerSM
- StateManager for the ownerelement
- The element to updateowner
- The owner object to set in the FK- Returns:
- Whether it was performed successfully
-
update
- Specified by:
update
in interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>
- Overrides:
update
in classAbstractCollectionStore<E>
-
add
-
addAll
public boolean addAll(org.datanucleus.state.DNStateManager ownerSM, Collection<? extends 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 interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>
- Overrides:
remove
in classAbstractSetStore<E>
- Parameters:
ownerSM
- StateManager for the owner.element
- The element of the collection to be deleted.size
- Not usedallowDependentField
- Whether to allow any cascade deletes caused by this removal- 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
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 interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>
- Overrides:
clear
in classElementContainerStore
- Parameters:
ownerSM
- StateManager for the owner.
-
getClearNullifyStmt
Generates the statement for clearing items by nulling the owner link out. The statement will be of the formUPDATE LISTTABLE SET OWNERCOL=NULL [,DISTINGUISHER=NULL] WHERE OWNERCOL=?
- Parameters:
info
- ElementInfo for the element- Returns:
- The Statement for clearing items for the owner.
-
getUpdateFkStmt
Generate statement for updating a Foreign Key in a FK 1-N. The statement generated will be of the formUPDATE ELEMENTTABLE SET FK_COL_1=?, FK_COL_2=?, [DISTINGUISHER=?] WHERE ELEMENT_ID = ?
- Returns:
- Statement for updating the FK in a FK 1-N
-
getUpdateFkStatementString
-
iterator
Description copied from class:ElementContainerStore
Accessor for an iterator through the container elements.- Specified by:
iterator
in interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>
- Specified by:
iterator
in 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 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
- 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
-