Class AbstractListStore<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>
-
- All Implemented Interfaces:
org.datanucleus.store.types.scostore.CollectionStore<E>
,org.datanucleus.store.types.scostore.ListStore<E>
,org.datanucleus.store.types.scostore.Store
- Direct Known Subclasses:
FKListStore
,JoinListStore
public abstract class AbstractListStore<E> extends AbstractCollectionStore<E> implements org.datanucleus.store.types.scostore.ListStore<E>
Abstract representation of a backing store for a List.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
indexedList
Whether the list is indexed.protected java.lang.String
indexOfStmt
protected java.lang.String
lastIndexOfStmt
protected java.lang.String
removeAtStmt
protected java.lang.String
shiftBulkStmt
protected java.lang.String
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 Modifier Constructor Description protected
AbstractListStore(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
add(org.datanucleus.state.DNStateManager ownerSM, E element, int size)
void
add(org.datanucleus.state.DNStateManager ownerSM, E element, int index, int size)
boolean
addAll(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection<? extends E> elements, int size)
boolean
addAll(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection<? extends E> elements, int index, int size)
E
get(org.datanucleus.state.DNStateManager ownerSM, int index)
private java.lang.String
getIndexOfStatementString(java.lang.Object element)
protected java.lang.String
getIndexOfStmt(java.lang.Object element)
Generate statement for getting the index of an item.protected int[]
getIndicesOf(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection elements)
Utility to find the indices of a collection of elements.protected java.lang.String
getIndicesOfStmt(java.util.Collection elements)
Generates the statement for getting the indices of a collection of element.private java.lang.String
getLastIndexOfStatementString(java.lang.Object element)
protected java.lang.String
getLastIndexOfStmt(java.lang.Object element)
Generates the statement for getting the index of the last item.protected java.lang.String
getRemoveAtStmt()
Generates the statement for removing an item.protected java.lang.String
getShiftBulkStmt()
Generates the statement for shifting items in bulk.protected java.lang.String
getShiftStmt()
Generates the statement for shifting items.int
indexOf(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element)
protected abstract boolean
internalAdd(org.datanucleus.state.DNStateManager ownerSM, int startAt, boolean atEnd, java.util.Collection<? extends E> elements, int size)
Internal method for adding an item to the List.protected int
internalIndexOf(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, java.lang.String stmt)
Internal method to find the index of an element.protected abstract boolean
internalRemove(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, int size)
Internal method to remove the specified element from the List.protected void
internalRemoveAt(org.datanucleus.state.DNStateManager ownerSM, int index, java.lang.String stmt, int size)
Internal method to remove an object at a location in the List.protected int[]
internalShift(org.datanucleus.state.DNStateManager ownerSM, int oldIndex, int amount, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, boolean executeNow)
Method to process a "shift" statement, updating the index in the list of the specified index.protected int[]
internalShiftBulk(org.datanucleus.state.DNStateManager ownerSM, int start, int amount, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, boolean executeNow)
Method to process a "shift" statement for all rows from the start point, updating the index in the list for the specified owner.java.util.Iterator<E>
iterator(org.datanucleus.state.DNStateManager ownerSM)
Accessor for an iterator through the container elements.int
lastIndexOf(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element)
java.util.ListIterator<E>
listIterator(org.datanucleus.state.DNStateManager ownerSM)
protected abstract java.util.ListIterator<E>
listIterator(org.datanucleus.state.DNStateManager ownerSM, int startIdx, int endIdx)
Accessor for an iterator through the list elements.boolean
remove(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, int size, boolean allowDependentField)
java.util.List<E>
subList(org.datanucleus.state.DNStateManager sm, int startIdx, int endIdx)
-
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
contains, getRemoveStmt, getUpdateEmbeddedElementStmt, update, 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, 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
clear, contains, hasOrderMapping, removeAll, size, update, updateEmbeddedElement
-
-
-
-
Field Detail
-
indexedList
protected boolean indexedList
Whether the list is indexed. If false then it will have no orderMapping.
-
indexOfStmt
protected java.lang.String indexOfStmt
-
lastIndexOfStmt
protected java.lang.String lastIndexOfStmt
-
removeAtStmt
protected java.lang.String removeAtStmt
-
shiftStmt
protected java.lang.String shiftStmt
-
shiftBulkStmt
protected java.lang.String shiftBulkStmt
-
-
Constructor Detail
-
AbstractListStore
protected AbstractListStore(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
Constructor. Protected to prevent instantiation.- Parameters:
storeMgr
- Manager for the storeclr
- ClassLoader resolver
-
-
Method Detail
-
iterator
public java.util.Iterator<E> iterator(org.datanucleus.state.DNStateManager ownerSM)
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 classElementContainerStore
- Parameters:
ownerSM
- StateManager for the container.- Returns:
- The Iterator
-
listIterator
public java.util.ListIterator<E> listIterator(org.datanucleus.state.DNStateManager ownerSM)
- Specified by:
listIterator
in interfaceorg.datanucleus.store.types.scostore.ListStore<E>
-
listIterator
protected abstract java.util.ListIterator<E> listIterator(org.datanucleus.state.DNStateManager ownerSM, int startIdx, int endIdx)
Accessor for an iterator through the list elements.- Parameters:
ownerSM
- StateManager for the container.startIdx
- The start point in the list (only for indexed lists).endIdx
- The end point in the list (only for indexed lists).- Returns:
- The List Iterator
-
add
public boolean add(org.datanucleus.state.DNStateManager ownerSM, E element, int size)
- Specified by:
add
in interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>
-
add
public void add(org.datanucleus.state.DNStateManager ownerSM, E element, int index, int size)
- Specified by:
add
in interfaceorg.datanucleus.store.types.scostore.ListStore<E>
-
addAll
public boolean addAll(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection<? extends E> elements, int size)
- Specified by:
addAll
in interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>
-
addAll
public boolean addAll(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection<? extends E> elements, int index, int size)
- Specified by:
addAll
in interfaceorg.datanucleus.store.types.scostore.ListStore<E>
-
internalAdd
protected abstract boolean internalAdd(org.datanucleus.state.DNStateManager ownerSM, int startAt, boolean atEnd, java.util.Collection<? extends E> elements, int size)
Internal method for adding an item to the List.- Parameters:
ownerSM
- StateManagerstartAt
- The start positionatEnd
- Whether to add at the endelements
- The Collection of elements to add.size
- Current size of List (if known). -1 if not known- Returns:
- Whether it was successful
-
get
public E get(org.datanucleus.state.DNStateManager ownerSM, int index)
- Specified by:
get
in interfaceorg.datanucleus.store.types.scostore.ListStore<E>
-
indexOf
public int indexOf(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element)
- Specified by:
indexOf
in interfaceorg.datanucleus.store.types.scostore.ListStore<E>
-
lastIndexOf
public int lastIndexOf(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element)
- Specified by:
lastIndexOf
in interfaceorg.datanucleus.store.types.scostore.ListStore<E>
-
remove
public boolean remove(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, int size, boolean allowDependentField)
- Specified by:
remove
in interfaceorg.datanucleus.store.types.scostore.CollectionStore<E>
-
internalRemove
protected abstract boolean internalRemove(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, int size)
Internal method to remove the specified element from the List.- Parameters:
ownerSM
- StateManager of the ownerelement
- The elementsize
- Current size of list if known. -1 if not known- Returns:
- Whether the List was modified
-
subList
public java.util.List<E> subList(org.datanucleus.state.DNStateManager sm, int startIdx, int endIdx)
- Specified by:
subList
in interfaceorg.datanucleus.store.types.scostore.ListStore<E>
-
getIndicesOf
protected int[] getIndicesOf(org.datanucleus.state.DNStateManager ownerSM, java.util.Collection elements)
Utility to find the indices of a collection of elements. The returned list are in reverse order (highest index first).- Parameters:
ownerSM
- StateManagerelements
- The elements- Returns:
- The indices of the elements in the List.
-
internalIndexOf
protected int internalIndexOf(org.datanucleus.state.DNStateManager ownerSM, java.lang.Object element, java.lang.String stmt)
Internal method to find the index of an element.- Parameters:
ownerSM
- StateManagerelement
- The elementstmt
- The statement to find the element.- Returns:
- The index of the element in the List.
-
internalRemoveAt
protected void internalRemoveAt(org.datanucleus.state.DNStateManager ownerSM, int index, java.lang.String stmt, int size)
Internal method to remove an object at a location in the List.- Parameters:
ownerSM
- StateManager for the list ownerindex
- The locationstmt
- The statement to remove the element from the Listsize
- Current list size (if known). -1 if not known
-
internalShiftBulk
protected int[] internalShiftBulk(org.datanucleus.state.DNStateManager ownerSM, int start, int amount, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, boolean executeNow)
Method to process a "shift" statement for all rows from the start point, updating the index in the list for the specified owner.- Parameters:
ownerSM
- StateManager for the list ownerstart
- The start index for the shiftamount
- Amount to shift by (negative means shift down)conn
- The connectionbatched
- Whether the statement is batchedexecuteNow
- Whether to execute the statement now (or wait for batching)- Returns:
- Return code(s) from any executed statements
- Throws:
org.datanucleus.exceptions.NucleusDataStoreException
- Thrown if an error occurs
-
internalShift
protected int[] internalShift(org.datanucleus.state.DNStateManager ownerSM, int oldIndex, int amount, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, boolean executeNow)
Method to process a "shift" statement, updating the index in the list of the specified index.- Parameters:
ownerSM
- StateManager for the list owneroldIndex
- The old indexamount
- Amount to shift by (negative means shift down)conn
- The connectionbatched
- Whether the statement is batchedexecuteNow
- Whether to execute the statement now (or wait for batching)- Returns:
- Return code(s) from any executed statements
- Throws:
org.datanucleus.exceptions.NucleusDataStoreException
- Thrown if an error occurs
-
getIndexOfStmt
protected java.lang.String getIndexOfStmt(java.lang.Object element)
Generate statement for getting the index of an item.SELECT INDEXCOL FROM LISTTABLE WHERE OWNERCOL=? AND ELEMENTCOL=? [AND EMBEDDEDFIELD1=? AND EMBEDDEDFIELD2=? AND ...] [AND DISTINGUISHER=?] ORDER BY INDEXCOL
- Parameters:
element
- The element to get the index of- Returns:
- The Statement for getting the index of an item
-
getIndexOfStatementString
private java.lang.String getIndexOfStatementString(java.lang.Object element)
-
getLastIndexOfStmt
protected java.lang.String getLastIndexOfStmt(java.lang.Object element)
Generates the statement for getting the index of the last item.SELECT INDEXCOL FROM LISTTABLE WHERE OWNERCOL=? AND ELEMENTCOL=? [AND EMBEDDEDFIELD1=? AND EMBEDDEDFIELD2=? AND ...] [AND DISTINGUISHER=?] ORDER BY INDEXCOL DESC
- Parameters:
element
- The element to get index of- Returns:
- The Statement for getting the last item
-
getLastIndexOfStatementString
private java.lang.String getLastIndexOfStatementString(java.lang.Object element)
-
getIndicesOfStmt
protected java.lang.String getIndicesOfStmt(java.util.Collection elements)
Generates the statement for getting the indices of a collection of element. Order into descending index order (highest first) so they will NOT be in the same order as they appear in the input collection "elements".SELECT INDEXCOL FROM LISTTABLE WHERE (OWNERCOL=? AND ELEMENT_COL=? [AND DISTINGUISHER=?]) OR (OWNERCOL=? AND ELEMENT_COL=? [AND DISTINGUISHER=?]) OR (OWNERCOL=? AND ELEMENT_COL=? [AND DISTINGUISHER=?]) ORDER BY INDEXCOL DESC
- Parameters:
elements
- The elements to retrieve the indices for.- Returns:
- The Statement for getting the indices of the collection.
-
getRemoveAtStmt
protected java.lang.String getRemoveAtStmt()
Generates the statement for removing an item.DELETE FROM LISTTABLE WHERE OWNERCOL = ? AND INDEXCOL = ? [AND DISTINGUISHER=?]
- Returns:
- The Statement for removing an item from a position
-
getShiftStmt
protected java.lang.String getShiftStmt()
Generates the statement for shifting items.UPDATE LISTTABLE SET INDEXCOL = ? + INDEXCOL WHERE OWNERCOL = ? AND INDEXCOL = ? [AND DISTINGUISHER=?]
- Returns:
- The Statement for shifting elements
-
getShiftBulkStmt
protected java.lang.String getShiftBulkStmt()
Generates the statement for shifting items in bulk.UPDATE LISTTABLE SET INDEXCOL = INDEXCOL + ? WHERE OWNERCOL = ? AND INDEXCOL > ? [AND DISTINGUISHER=?]
- Returns:
- The Statement for shifting elements in bulk
-
-