Class FKListStore<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.AbstractListStore<E>
-
- org.datanucleus.store.rdbms.scostore.FKListStore<E>
-
- All Implemented Interfaces:
org.datanucleus.store.types.scostore.CollectionStore<E>,org.datanucleus.store.types.scostore.ListStore<E>,org.datanucleus.store.types.scostore.Store
public class FKListStore<E> extends AbstractListStore<E>
Implementation of aListStoreusing foreign keys.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringclearNullifyStmtprivate java.lang.StringremoveAtNullifyStmtprivate java.lang.StringsetStmtprivate java.lang.StringunsetStmtprivate java.lang.StringupdateFkStmtStatement for updating a foreign key in a 1-N unidirectional-
Fields inherited from class org.datanucleus.store.rdbms.scostore.AbstractListStore
indexedList, indexOfStmt, lastIndexOfStmt, removeAtStmt, shiftBulkStmt, shiftStmt
-
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
Constructors Constructor Description FKListStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear(org.datanucleus.state.DNStateManager ownerSM)Method to clear the List.private java.lang.StringgetClearNullifyStmt()Generates the statement for clearing items by nulling the owner link out.ElementIteratorStatementgetIteratorStatement(org.datanucleus.ExecutionContext ec, org.datanucleus.FetchPlan fp, boolean addRestrictionOnOwner, int startIdx, int endIdx)Method to return the SQLStatement and mapping for an iterator for this backing store.private java.lang.StringgetRemoveAtNullifyBulkStmt(int[] indices)Generates the statement for removing an item by nulling it out (setting owner to null, and index to -1).private java.lang.StringgetRemoveAtNullifyStmt()Generates the statement for removing an item by nulling it out (setting owner to null, and index to -1).private java.lang.StringgetSetStatementString(java.lang.Object element)private java.lang.StringgetSetStmt(java.lang.Object element)Generates the statement for setting an item to be at a position.private java.lang.StringgetUnsetStmt()Generates the statement for unsetting an item from a list position.private java.lang.StringgetUpdateFkStatementString(java.lang.Object element)private java.lang.StringgetUpdateFkStmt(java.lang.Object element)Generate statement for updating the owner, index columns in an inverse 1-N.protected booleaninternalAdd(org.datanucleus.state.DNStateManager ownerSM, int startAt, boolean atEnd, java.util.Collection<? extends E> c, int size)Internal method for adding item(s) to the List as a specific position.protected booleaninternalRemove(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, int size)Convenience method to remove the specified element from the List.protected voidinternalRemoveAt(org.datanucleus.state.DNStateManager ownerSM, int index, int size)Internal method to remove an object at a location in the List.protected voidinternalRemoveAtNullify(org.datanucleus.state.DNStateManager ownerSM, int index, org.datanucleus.store.connection.ManagedConnection mconn, boolean batched, boolean executeNow)Internal method to remove an object at a location in the List by nulling its owner and setting its List index to -1.protected voidinternalRemoveAtNullifyBulk(org.datanucleus.state.DNStateManager ownerSM, int[] indices, org.datanucleus.store.connection.ManagedConnection mconn, boolean batched, boolean executeNow)Internal method to remove an object at a location in the List by nulling its owner and setting its List index to -1.protected java.util.ListIterator<E>listIterator(org.datanucleus.state.DNStateManager ownerSM, int startIdx, int endIdx)Accessor for an iterator through the list elements.Eremove(org.datanucleus.state.DNStateManager ownerSM, int index, int size)booleanremoveAll(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection elements, int size)booleanremoveAll(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection elements, int size, int[] elementIndices)Eset(org.datanucleus.state.DNStateManager ownerSM, int index, E element, boolean allowDependentField)voidupdate(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection<? extends E> coll)private booleanupdateElementFk(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, java.lang.Object owner, int index)Utility to update a foreign-key in the element in the case of a unidirectional 1-N relationship.protected booleanvalidateElementForWriting(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, int index)Method to validate that an element is valid for writing to the datastore.-
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractListStore
add, add, addAll, addAll, get, getIndexOfStmt, getIndicesOf, getIndicesOfStmt, getLastIndexOfStmt, getRemoveAtStmt, getShiftBulkStmt, getShiftStmt, indexOf, internalIndexOf, internalRemoveAt, internalShift, internalShiftBulk, iterator, lastIndexOf, listIterator, remove, subList
-
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
-
-
-
-
Field Detail
-
updateFkStmt
private java.lang.String updateFkStmt
Statement for updating a foreign key in a 1-N unidirectional
-
clearNullifyStmt
private java.lang.String clearNullifyStmt
-
removeAtNullifyStmt
private java.lang.String removeAtNullifyStmt
-
setStmt
private java.lang.String setStmt
-
unsetStmt
private java.lang.String unsetStmt
-
-
Constructor Detail
-
FKListStore
public FKListStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)- Parameters:
mmd- Metadata for owning field/propertystoreMgr- Manager for the datastoreclr- ClassLoader resolver
-
-
Method Detail
-
set
public E set(org.datanucleus.state.DNStateManager ownerSM, int index, E element, boolean allowDependentField)
-
updateElementFk
private boolean updateElementFk(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, java.lang.Object owner, int index)Utility to update a foreign-key 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 FKindex- The index position (or -1 if not known)- Returns:
- Whether it was performed successfully
-
update
public void update(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection<? extends E> coll)- Specified by:
updatein interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>- Overrides:
updatein classAbstractCollectionStore<E>
-
internalAdd
protected boolean internalAdd(org.datanucleus.state.DNStateManager ownerSM, int startAt, boolean atEnd, java.util.Collection<? extends E> c, int size)Internal method for adding item(s) to the List as a specific position.- Specified by:
internalAddin classAbstractListStore<E>- Parameters:
ownerSM- StateManager for the ownerstartAt- The start positionatEnd- Whether to add at the endc- The Collection of elements to add.size- Current size of list (if known). -1 if not known- Returns:
- Whether it was successful
-
remove
public E remove(org.datanucleus.state.DNStateManager ownerSM, int index, int size)
-
removeAll
public boolean removeAll(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection elements, int size)
-
removeAll
public boolean removeAll(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection elements, int size, int[] elementIndices)
-
internalRemove
protected boolean internalRemove(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, int size)Convenience method to remove the specified element from the List.- Specified by:
internalRemovein classAbstractListStore<E>- Parameters:
ownerSM- StateManager for the ownerelement- The elementsize- Current size of list if known. -1 if not known- Returns:
- Whether the List was modified
-
internalRemoveAt
protected void internalRemoveAt(org.datanucleus.state.DNStateManager ownerSM, int index, int size)Internal method to remove an object at a location in the List. Differs from the JoinTable List in that it typically nulls out the owner FK (unless not nullable).- Parameters:
ownerSM- StateManager for the ownerindex- The locationsize- Current size of list (if known). -1 if not known
-
internalRemoveAtNullify
protected void internalRemoveAtNullify(org.datanucleus.state.DNStateManager ownerSM, int index, org.datanucleus.store.connection.ManagedConnection mconn, boolean batched, boolean executeNow)Internal method to remove an object at a location in the List by nulling its owner and setting its List index to -1.- Parameters:
ownerSM- StateManager for the list ownerindex- The index to nullifymconn- Managed Connection to use for datastore connectivitybatched- Whether this statement should be batchedexecuteNow- Whether we should execute this statement now
-
internalRemoveAtNullifyBulk
protected void internalRemoveAtNullifyBulk(org.datanucleus.state.DNStateManager ownerSM, int[] indices, org.datanucleus.store.connection.ManagedConnection mconn, boolean batched, boolean executeNow)Internal method to remove an object at a location in the List by nulling its owner and setting its List index to -1.- Parameters:
ownerSM- StateManager for the list ownerindices- The indexes to nullifymconn- Managed Connection to use for datastore connectivitybatched- Whether this statement should be batchedexecuteNow- Whether we should execute this statement now
-
clear
public void clear(org.datanucleus.state.DNStateManager ownerSM)
Method to clear the List. 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:
clearin interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>- Overrides:
clearin classElementContainerStore- Parameters:
ownerSM- StateManager for the owner
-
validateElementForWriting
protected boolean validateElementForWriting(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, int index)Method to validate that an element is valid for writing to the datastore. TODO Minimise differences to super.validateElementForWriting()- Parameters:
ownerSM- StateManager for the List ownerelement- The element to validateindex- The position that the element is being stored at in the list- Returns:
- Whether the element was inserted
-
listIterator
protected java.util.ListIterator<E> listIterator(org.datanucleus.state.DNStateManager ownerSM, int startIdx, int endIdx)
Accessor for an iterator through the list elements.- Specified by:
listIteratorin classAbstractListStore<E>- Parameters:
ownerSM- StateManager for the owner.startIdx- The start index in the list (only for indexed lists)endIdx- The end index in the list (only for indexed lists)- Returns:
- The List Iterator
-
getUpdateFkStmt
private java.lang.String getUpdateFkStmt(java.lang.Object element)
Generate statement for updating the owner, index columns in an inverse 1-N. Will result in the statementUPDATE ELEMENTTABLE SET FK_COL_1 = ?, FK_COL_2 = ?, FK_IDX = ? [,DISTINGUISHER=?] WHERE ELEMENT_ID = ?
when we have a single element table, andUPDATE ? SET FK_COL_1=?, FK_COL_2=?, FK_IDX=? [,DISTINGUISHER=?] WHERE ELEMENT_ID=?
when we have multiple element tables possible- Returns:
- Statement for updating the owner/index of an element in an inverse 1-N
-
getUpdateFkStatementString
private java.lang.String getUpdateFkStatementString(java.lang.Object element)
-
getClearNullifyStmt
private java.lang.String getClearNullifyStmt()
Generates the statement for clearing items by nulling the owner link out. The statement will beUPDATE LISTTABLE SET OWNERCOL=NULL, INDEXCOL=-1 [,DISTINGUISHER=NULL] WHERE OWNERCOL=? [AND DISTINGUISHER=?]
when there is only one element table, and will beUPDATE ? SET OWNERCOL=NULL, INDEXCOL=-1 [,DISTINGUISHER=NULL] WHERE OWNERCOL=? [AND DISTINGUISHER=?]
when there is more than 1 element table.- Returns:
- The Statement for clearing items for the owner.
-
getSetStmt
private java.lang.String getSetStmt(java.lang.Object element)
Generates the statement for setting an item to be at a position.UPDATE LISTTABLE SET OWNERCOL=?, INDEXCOL = ? [,DISTINGUISHER=?] WHERE ELEMENTCOL = ?
- Parameters:
element- The element to set- Returns:
- The Statement for setting an item
-
getSetStatementString
private java.lang.String getSetStatementString(java.lang.Object element)
-
getUnsetStmt
private java.lang.String getUnsetStmt()
Generates the statement for unsetting an item from a list position.UPDATE LISTTABLE SET OWNERCOL=NULL, INDEXCOL=-1 [, DISTINGUISHER = NULL] WHERE OWNERCOL = ? AND INDEXCOL = ? [AND DISTINGUISHER = ?]
- Returns:
- The Statement for unsetting an item
-
getRemoveAtNullifyStmt
private java.lang.String getRemoveAtNullifyStmt()
Generates the statement for removing an item by nulling it out (setting owner to null, and index to -1). When there is only a single element table the statement will beUPDATE LISTTABLE SET OWNERCOL=NULL, INDEXCOL=-1 WHERE OWNERCOL = ? AND INDEXCOL = ? [AND DISTINGUISHER = ?]
- Returns:
- The Statement for removing an item from a position
-
getRemoveAtNullifyBulkStmt
private java.lang.String getRemoveAtNullifyBulkStmt(int[] indices)
Generates the statement for removing an item by nulling it out (setting owner to null, and index to -1). When there is only a single element table the statement will beUPDATE LISTTABLE SET OWNERCOL=NULL, INDEXCOL=-1 WHERE (OWNERCOL=? AND INDEXCOL=? [AND DISTINGUISHER=?]) OR (OWNERCOL=? AND INDEXCOL=? [AND DISTINGUISHER=?]) OR ...
- Parameters:
indices- The indexes to nullify at (only uses the length of the array)- Returns:
- The Statement for removing an item from a position
-
getIteratorStatement
public ElementIteratorStatement getIteratorStatement(org.datanucleus.ExecutionContext ec, org.datanucleus.FetchPlan fp, boolean addRestrictionOnOwner, int startIdx, int endIdx)
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 determing which fields of element to selectaddRestrictionOnOwner- Whether to restrict to a particular owner (otherwise functions as bulk fetch for many owners).startIdx- Start index for the iterator (or -1)endIdx- End index for the iterator (or -1)- Returns:
- The SQLStatement and its associated StatementClassMapping
-
-