org.datanucleus.store.rdbms.scostore
Class AbstractListStore

java.lang.Object
  extended by org.datanucleus.store.rdbms.scostore.BaseContainerStore
      extended by org.datanucleus.store.rdbms.scostore.ElementContainerStore
          extended by org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
              extended by org.datanucleus.store.rdbms.scostore.AbstractListStore
All Implemented Interfaces:
org.datanucleus.store.scostore.CollectionStore, org.datanucleus.store.scostore.ListStore, org.datanucleus.store.scostore.Store
Direct Known Subclasses:
RDBMSFKListStore, RDBMSJoinListStore

public abstract class AbstractListStore
extends AbstractCollectionStore
implements org.datanucleus.store.scostore.ListStore

Abstract representation of a backing store for a List.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
protected  boolean indexedList
          Whether the list is indexed (like with JDO).
protected  String indexOfStmt
           
protected  String lastIndexOfStmt
           
protected  String removeAtStmt
           
protected  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, clr, containerTable, elementInfo, elementIsPersistentInterface, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, emd, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, removeStmt, sizeStmt, usingDiscriminatorInSizeStmt
 
Fields inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowNulls, dba, LOCALISER, ownerMapping, ownerMemberMetaData, relationType, storeMgr
 
Constructor Summary
protected AbstractListStore(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 boolean add(org.datanucleus.store.ObjectProvider sm, Object element, int size)
          Method to add an element to the List.
 void add(org.datanucleus.store.ObjectProvider sm, Object element, int index, int size)
          Method to add an element to the List.
 boolean addAll(org.datanucleus.store.ObjectProvider sm, Collection elements, int size)
          Method to add a collection of elements to the List.
 boolean addAll(org.datanucleus.store.ObjectProvider sm, Collection elements, int index, int size)
          Method to add all elements from a Collection to the List.
 Object get(org.datanucleus.store.ObjectProvider op, int index)
          Method to retrieve an element from the List.
protected  String getIndexOfStmt(Object element)
          Generate statement for getting the index of an item.
protected  int[] getIndicesOf(org.datanucleus.store.ObjectProvider op, Collection elements)
          Utility to find the indices of a collection of elements.
protected  String getIndicesOfStmt(Collection elements)
          Generates the statement for getting the indices of a collection of element.
protected  String getLastIndexOfStmt(Object element)
          Generates the statement for getting the index of the last item.
protected  String getRemoveAtStmt()
          Generates the statement for removing an item.
protected  String getShiftStmt()
          Generates the statement for shifting items.
 int indexOf(org.datanucleus.store.ObjectProvider op, Object element)
          Accessor for the indexOf an object in the List.
protected abstract  boolean internalAdd(org.datanucleus.store.ObjectProvider sm, int startAt, boolean atEnd, Collection elements, int size)
          Internal method for adding an item to the List.
protected  int internalIndexOf(org.datanucleus.store.ObjectProvider op, Object element, String stmt)
          Internal method to find the index of an element.
protected abstract  boolean internalRemove(org.datanucleus.store.ObjectProvider op, Object element, int size)
          Convenience method to remove the specified element from the List.
protected abstract  void internalRemoveAt(org.datanucleus.store.ObjectProvider op, int index, int size)
          Internal method to remove an object at a location from the List.
protected  void internalRemoveAt(org.datanucleus.store.ObjectProvider op, int index, String stmt, int size)
          Internal method to remove an object at a location in the List.
protected  int[] internalShift(org.datanucleus.store.ObjectProvider op, org.datanucleus.store.connection.ManagedConnection conn, boolean batched, int oldIndex, int amount, boolean executeNow)
          Method to process a "shift" statement, updating the index in the list of the specified index.
 Iterator iterator(org.datanucleus.store.ObjectProvider sm)
          Accessor for an iterator through the list elements.
 int lastIndexOf(org.datanucleus.store.ObjectProvider op, Object element)
          Method to retrieve the last index of an object in the list.
 ListIterator listIterator(org.datanucleus.store.ObjectProvider sm)
          Accessor for an iterator through the list elements.
protected abstract  ListIterator listIterator(org.datanucleus.store.ObjectProvider ownerSM, int startIdx, int endIdx)
          Accessor for an iterator through the list elements.
 Object remove(org.datanucleus.store.ObjectProvider op, int index, int size)
          Method to remove an object at an index in the List.
 boolean remove(org.datanucleus.store.ObjectProvider op, Object element, int size, boolean allowDependentField)
          Method to remove the specified element from the List.
 boolean removeAll(org.datanucleus.store.ObjectProvider op, Collection elements, int size)
          Remove all elements from a collection from the association owner vs elements.
 List subList(org.datanucleus.store.ObjectProvider op, int startIdx, int endIdx)
          Method to retrieve a list of elements in a range.
 
Methods inherited from class org.datanucleus.store.rdbms.scostore.AbstractCollectionStore
contains, containsInternal, getRemoveStmt, getUpdateEmbeddedElementStmt, internalRemove, update, updateEmbeddedElement, updateEmbeddedElement
 
Methods inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
clear, executeClear, getAddStmt, getClearStmt, getContainerTable, getElementInfo, getElementInformationForClass, getElementMapping, getEmd, getOrderMapping, getRelationDiscriminatorMapping, getRelationDiscriminatorValue, getSize, getSizeStmt, hasOrderMapping, invalidateAddStmt, isElementsAreEmbedded, isElementsAreSerialised, size, validateElementForReading, validateElementForWriting, validateElementType
 
Methods inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowsBatching, 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.scostore.ListStore
set
 
Methods inherited from interface org.datanucleus.store.scostore.CollectionStore
clear, contains, hasOrderMapping, size, update, updateEmbeddedElement
 
Methods inherited from interface org.datanucleus.store.scostore.Store
getStoreManager
 

Field Detail

indexedList

protected boolean indexedList
Whether the list is indexed (like with JDO). If false then it will have no orderMapping (like with JPA).


indexOfStmt

protected String indexOfStmt

lastIndexOfStmt

protected String lastIndexOfStmt

removeAtStmt

protected String removeAtStmt

shiftStmt

protected String shiftStmt
Constructor Detail

AbstractListStore

protected AbstractListStore(RDBMSStoreManager storeMgr,
                            org.datanucleus.ClassLoaderResolver clr)
Constructor. Protected to prevent instantiation.

Parameters:
storeMgr - Manager for the store
clr - ClassLoader resolver
Method Detail

iterator

public Iterator iterator(org.datanucleus.store.ObjectProvider sm)
Accessor for an iterator through the list elements.

Specified by:
iterator in interface org.datanucleus.store.scostore.CollectionStore
Specified by:
iterator in class ElementContainerStore
Parameters:
sm - State Manager for the container.
Returns:
The Iterator

listIterator

public ListIterator listIterator(org.datanucleus.store.ObjectProvider sm)
Accessor for an iterator through the list elements.

Specified by:
listIterator in interface org.datanucleus.store.scostore.ListStore
Parameters:
sm - State Manager for the container.
Returns:
The List Iterator

listIterator

protected abstract ListIterator listIterator(org.datanucleus.store.ObjectProvider ownerSM,
                                             int startIdx,
                                             int endIdx)
Accessor for an iterator through the list elements.

Parameters:
ownerSM - State Manager 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.store.ObjectProvider sm,
                   Object element,
                   int size)
Method to add an element to the List.

Specified by:
add in interface org.datanucleus.store.scostore.CollectionStore
Parameters:
sm - The state manager
element - The element to remove
size - Size of the current list (if known, -1 if not)
Returns:
Whether it was added successfully.

add

public void add(org.datanucleus.store.ObjectProvider sm,
                Object element,
                int index,
                int size)
Method to add an element to the List.

Specified by:
add in interface org.datanucleus.store.scostore.ListStore
Parameters:
element - The element to add.
index - The location to add at
sm - The state manager.

addAll

public boolean addAll(org.datanucleus.store.ObjectProvider sm,
                      Collection elements,
                      int size)
Method to add a collection of elements to the List.

Specified by:
addAll in interface org.datanucleus.store.scostore.CollectionStore
Parameters:
sm - The state manager
elements - The elements to remove
size - Current size of the list (if known). -1 if not known
Returns:
Whether they were added successfully.

addAll

public boolean addAll(org.datanucleus.store.ObjectProvider sm,
                      Collection elements,
                      int index,
                      int size)
Method to add all elements from a Collection to the List.

Specified by:
addAll in interface org.datanucleus.store.scostore.ListStore
Parameters:
sm - The state manager
elements - The collection
index - The location to add at
size - Current size of the list (if known). -1 if not known
Returns:
Whether it was successful

internalAdd

protected abstract boolean internalAdd(org.datanucleus.store.ObjectProvider sm,
                                       int startAt,
                                       boolean atEnd,
                                       Collection elements,
                                       int size)
Internal method for adding an item to the List.

Parameters:
sm - The state manager
startAt - The start position
atEnd - Whether to add at the end
elements - The Collection of elements to add.
size - Current size of List (if known). -1 if not known
Returns:
Whether it was successful

get

public Object get(org.datanucleus.store.ObjectProvider op,
                  int index)
Method to retrieve an element from the List.

Specified by:
get in interface org.datanucleus.store.scostore.ListStore
Parameters:
op - ObjectProvider for the owner
index - The index of the element required.
Returns:
The object

indexOf

public int indexOf(org.datanucleus.store.ObjectProvider op,
                   Object element)
Accessor for the indexOf an object in the List.

Specified by:
indexOf in interface org.datanucleus.store.scostore.ListStore
Parameters:
op - ObjectProvider for the owner
element - The element.
Returns:
The index

lastIndexOf

public int lastIndexOf(org.datanucleus.store.ObjectProvider op,
                       Object element)
Method to retrieve the last index of an object in the list.

Specified by:
lastIndexOf in interface org.datanucleus.store.scostore.ListStore
Parameters:
op - ObjectProvider for the owner
element - The object
Returns:
The last index

removeAll

public boolean removeAll(org.datanucleus.store.ObjectProvider op,
                         Collection elements,
                         int size)
Remove all elements from a collection from the association owner vs elements. TODO : Change the query to do all in one go for efficiency. Currently removes an element and shuffles the indexes, then removes an element and shuffles the indexes, then removes an element and shuffles the indexes etc ... a bit inefficient !!!

Specified by:
removeAll in interface org.datanucleus.store.scostore.CollectionStore
Parameters:
op - ObjectProvider for the owner
elements - Collection of elements to remove
Returns:
Whether the database was updated

remove

public boolean remove(org.datanucleus.store.ObjectProvider op,
                      Object element,
                      int size,
                      boolean allowDependentField)
Method to remove the specified element from the List.

Specified by:
remove in interface org.datanucleus.store.scostore.CollectionStore
Parameters:
op - ObjectProvider for the owner
element - The element to remove.
size - Current size of list if known. -1 if not known
allowDependentField - Whether to allow any cascade deletes caused by this removal
Returns:
Whether it was removed successfully.

internalRemove

protected abstract boolean internalRemove(org.datanucleus.store.ObjectProvider op,
                                          Object element,
                                          int size)
Convenience method to remove the specified element from the List.

Parameters:
op - ObjectProvider of the owner
element - The element
size - Current size of list if known. -1 if not known
Returns:
Whether the List was modified

remove

public Object remove(org.datanucleus.store.ObjectProvider op,
                     int index,
                     int size)
Method to remove an object at an index in the List. If the list is ordered, will remove the element completely since no index positions exist.

Specified by:
remove in interface org.datanucleus.store.scostore.ListStore
Parameters:
op - ObjectProvider
index - The location
size - Current size of the list (if known). -1 if not known
Returns:
The object that was removed

internalRemoveAt

protected abstract void internalRemoveAt(org.datanucleus.store.ObjectProvider op,
                                         int index,
                                         int size)
Internal method to remove an object at a location from the List.

Parameters:
op - ObjectProvider
index - The index of the element to remove
size - Current list size (if known). -1 if not known

subList

public List subList(org.datanucleus.store.ObjectProvider op,
                    int startIdx,
                    int endIdx)
Method to retrieve a list of elements in a range.

Specified by:
subList in interface org.datanucleus.store.scostore.ListStore
Parameters:
op - ObjectProvider
startIdx - From index (inclusive).
endIdx - To index (exclusive)
Returns:
Sub List of elements in this range.

getIndicesOf

protected int[] getIndicesOf(org.datanucleus.store.ObjectProvider op,
                             Collection elements)
Utility to find the indices of a collection of elements. The returned list are in reverse order (highest index first).

Parameters:
op - ObjectProvider
elements - The elements
Returns:
The indices of the elements in the List.

internalIndexOf

protected int internalIndexOf(org.datanucleus.store.ObjectProvider op,
                              Object element,
                              String stmt)
Internal method to find the index of an element.

Parameters:
op - ObjectProvider
element - The element
stmt - The statement to find the element.
Returns:
The index of the element in the List.

internalRemoveAt

protected void internalRemoveAt(org.datanucleus.store.ObjectProvider op,
                                int index,
                                String stmt,
                                int size)
Internal method to remove an object at a location in the List.

Parameters:
op - ObjectProvider
index - The location
stmt - The statement to remove the element from the List
size - Current list size (if known). -1 if not known

internalShift

protected int[] internalShift(org.datanucleus.store.ObjectProvider op,
                              org.datanucleus.store.connection.ManagedConnection conn,
                              boolean batched,
                              int oldIndex,
                              int amount,
                              boolean executeNow)
                       throws org.datanucleus.store.mapped.exceptions.MappedDatastoreException
Method to process a "shift" statement, updating the index in the list of the specified index.

Parameters:
op - ObjectProvider
conn - The connection
batched - Whether the statement is batched
oldIndex - The old index
amount - Amount to shift by (negative means shift down)
executeNow - Whether to execute the statement now (or wait for batching)
Returns:
Return code(s) from any executed statements
Throws:
org.datanucleus.store.mapped.exceptions.MappedDatastoreException - Thrown if an error occurs

getIndexOfStmt

protected String getIndexOfStmt(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

getLastIndexOfStmt

protected String getLastIndexOfStmt(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
 

Returns:
The Statement for getting the last item

getIndicesOfStmt

protected String getIndicesOfStmt(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 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 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


Copyright © 2012. All Rights Reserved.