Class JoinListStore<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.JoinListStore<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 JoinListStore<E> extends AbstractListStore<E>
RDBMS-specific implementation of aListStore
using join table.
-
-
Field Summary
-
Fields inherited from class org.datanucleus.store.rdbms.scostore.AbstractListStore
indexedList, indexOfStmt, lastIndexOfStmt, removeAtStmt, 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 JoinListStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, CollectionTable joinTable, org.datanucleus.ClassLoaderResolver clr)
Constructor for a join list store for RDBMS.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.protected String
getRemoveAllStmt(Collection elements)
Generate statement for removing a collection of items from the List.protected String
getSetStmt()
Generates the statement for setting an item.protected boolean
internalAdd(org.datanucleus.state.ObjectProvider op, int start, boolean atEnd, Collection<E> c, int size)
Internal method to add element(s) to the List.protected boolean
internalRemove(org.datanucleus.state.ObjectProvider ownerOP, Object element, int size)
Convenience method to remove the specified element from the List.protected void
internalRemoveAt(org.datanucleus.state.ObjectProvider op, int index, int size)
Method to remove an element from the specified positionprotected ListIterator<E>
listIterator(org.datanucleus.state.ObjectProvider ownerOP, int startIdx, int endIdx)
Accessor for an iterator through the list elements.boolean
removeAll(org.datanucleus.state.ObjectProvider op, Collection elements, int size)
Remove all elements from a collection from the association owner vs elements.E
set(org.datanucleus.state.ObjectProvider op, int index, Object element, boolean allowDependentField)
Method to set an object in the List.void
update(org.datanucleus.state.ObjectProvider op, Collection coll)
Method to update the collection to be the supplied collection of elements.-
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractListStore
add, add, addAll, addAll, get, getIndexOfStmt, getIndicesOf, getIndicesOfStmt, getLastIndexOfStmt, getRemoveAtStmt, getShiftStmt, indexOf, internalIndexOf, internalRemoveAt, internalShift, iterator, lastIndexOf, listIterator, remove, remove, subList
-
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
contains, getRemoveStmt, getUpdateEmbeddedElementStmt, updateEmbeddedElement, updateEmbeddedElement
-
Methods inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
clear, 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, getObjectProviderForEmbeddedPCObject, getOwnerMapping, getOwnerMemberMetaData, getRelationType, getStoreManager, isEmbeddedMapping, setOwner
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
JoinListStore
public JoinListStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, CollectionTable joinTable, org.datanucleus.ClassLoaderResolver clr)
Constructor for a join list store for RDBMS.- Parameters:
mmd
- Metadata for the member that has the list with join tablejoinTable
- The Join tableclr
- ClassLoader resolver
-
-
Method Detail
-
internalAdd
protected boolean internalAdd(org.datanucleus.state.ObjectProvider op, int start, boolean atEnd, Collection<E> c, int size)
Internal method to add element(s) to the List. Performs the add in 2 steps.- Shift all existing elements into their new positions so we can insert.
- Insert all new elements directly at their desired positions
- Specified by:
internalAdd
in classAbstractListStore<E>
- Parameters:
op
- The ObjectProviderstart
- The start location (if required)atEnd
- Whether to add the element at the endc
- The collection of objects to add.size
- Current size of list if known. -1 if not known- Returns:
- Whether it was successful
-
set
public E set(org.datanucleus.state.ObjectProvider op, int index, Object element, boolean allowDependentField)
Method to set an object in the List.- Parameters:
op
- ObjectProvider for the ownerindex
- The item indexelement
- What to set it to.allowDependentField
- Whether to allow dependent field deletes- Returns:
- The value before setting.
-
update
public void update(org.datanucleus.state.ObjectProvider op, Collection coll)
Method to update the collection to be the supplied collection of elements.- Specified by:
update
in interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>
- Overrides:
update
in classAbstractCollectionStore<E>
- Parameters:
op
- ObjectProvider of the objectcoll
- The collection to use
-
internalRemove
protected boolean internalRemove(org.datanucleus.state.ObjectProvider ownerOP, Object element, int size)
Convenience method to remove the specified element from the List.- Specified by:
internalRemove
in classAbstractListStore<E>
- Parameters:
element
- The elementownerOP
- ObjectProvider of the ownersize
- Current size of list if known. -1 if not known- Returns:
- Whether the List was modified
-
removeAll
public boolean removeAll(org.datanucleus.state.ObjectProvider op, Collection elements, int size)
Remove all elements from a collection from the association owner vs elements. Performs the removal in 3 steps. The first gets the indices that will be removed (and the highest index present). The second step removes these elements from the list. The third step updates the indices of the remaining indices to fill the holes created.- Parameters:
op
- ObjectProviderelements
- Collection of elements to remove- Returns:
- Whether the database was updated
-
internalRemoveAt
protected void internalRemoveAt(org.datanucleus.state.ObjectProvider op, int index, int size)
Method to remove an element from the specified position- Specified by:
internalRemoveAt
in classAbstractListStore<E>
- Parameters:
op
- The ObjectProvider for the listindex
- The index of the elementsize
- Current size of list (if known). -1 if not known
-
listIterator
protected ListIterator<E> listIterator(org.datanucleus.state.ObjectProvider ownerOP, int startIdx, int endIdx)
Accessor for an iterator through the list elements.- Specified by:
listIterator
in classAbstractListStore<E>
- Parameters:
ownerOP
- ObjectProvider for the ownerstartIdx
- The start point in the list (only for indexed lists).endIdx
- End index in the list (only for indexed lists).- Returns:
- The List Iterator
-
getSetStmt
protected String getSetStmt()
Generates the statement for setting an item.UPDATE LISTTABLE SET [ELEMENTCOL = ?] [EMBEDDEDFIELD1=?, EMBEDDEDFIELD2=?, ...] WHERE OWNERCOL = ? AND INDEXCOL = ? [AND DISTINGUISHER=?]
- Returns:
- The Statement for setting an item
-
getRemoveAllStmt
protected String getRemoveAllStmt(Collection elements)
Generate statement for removing a collection of items from the List.DELETE FROM LISTTABLE WHERE (OWNERCOL=? AND ELEMENTCOL=?) OR (OWNERCOL=? AND ELEMENTCOL=?) OR (OWNERCOL=? AND ELEMENTCOL=?)
- Parameters:
elements
- Collection of elements to remove- Returns:
- Statement for deleting items from the List.
-
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 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}]
- 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
-
-