org.datanucleus.store.mapped.scostore
Class AbstractListStore

java.lang.Object
  extended by org.datanucleus.store.mapped.scostore.BaseContainerStore
      extended by org.datanucleus.store.mapped.scostore.ElementContainerStore
          extended by org.datanucleus.store.mapped.scostore.AbstractCollectionStore
              extended by org.datanucleus.store.mapped.scostore.AbstractListStore
All Implemented Interfaces:
CollectionStoreQueryable, CollectionStore, ListStore, Store
Direct Known Subclasses:
FKListStore, JoinListStore

public abstract class AbstractListStore
extends AbstractCollectionStore
implements ListStore

Abstract representation of a backing store for a List.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.datanucleus.store.mapped.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
protected  boolean indexedList
          Whether the list is indexed (like with JDO).
 
Fields inherited from class org.datanucleus.store.mapped.scostore.ElementContainerStore
clr, containerTable, elementInfo, elementIsPersistentInterface, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, emd, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, specialization
 
Fields inherited from class org.datanucleus.store.mapped.scostore.BaseContainerStore
allowsNull, dba, LOCALISER, ownerMapping, ownerMemberMetaData, relationType, storeMgr
 
Constructor Summary
protected AbstractListStore(StoreManager storeMgr, ClassLoaderResolver clr, AbstractListStoreSpecialization specialization)
          Constructor.
 
Method Summary
 boolean add(StateManager sm, java.lang.Object element, int size)
          Method to add an element to the List.
 void add(StateManager sm, java.lang.Object element, int index, int size)
          Method to add an element to the List.
 boolean addAll(StateManager sm, java.util.Collection elements, int size)
          Method to add a collection of elements to the List.
 boolean addAll(StateManager sm, java.util.Collection elements, int index, int size)
          Method to add all elements from a Collection to the List.
 java.lang.Object get(StateManager sm, int index)
          Method to retrieve an element from the List.
protected  int[] getIndicesOf(StateManager sm, java.util.Collection elements)
          Utility to find the indices of a collection of elements.
 int indexOf(StateManager sm, java.lang.Object element)
          Accessor for the indexOf an object in the List.
protected abstract  boolean internalAdd(StateManager sm, int startAt, boolean atEnd, java.util.Collection elements, int size)
          Internal method for adding an item to the List.
protected abstract  boolean internalRemove(StateManager sm, java.lang.Object element, int size)
          Convenience method to remove the specified element from the List.
 java.util.Iterator iterator(StateManager sm)
          Accessor for an iterator through the list elements.
 int lastIndexOf(StateManager sm, java.lang.Object element)
          Method to retrieve the last index of an object in the list.
 java.util.ListIterator listIterator(StateManager sm)
          Accessor for an iterator through the list elements.
protected abstract  java.util.ListIterator listIterator(StateManager ownerSM, int startIdx, int endIdx)
          Accessor for an iterator through the list elements.
 java.lang.Object remove(StateManager sm, int index, int size)
          Method to remove an object at an index in the List.
 boolean remove(StateManager sm, java.lang.Object element, int size, boolean allowDependentField)
          Method to remove the specified element from the List.
 boolean removeAll(StateManager sm, java.util.Collection elements, int size)
          Remove all elements from a collection from the association owner vs elements.
protected abstract  void removeAt(StateManager sm, int index, int size)
          Internal method to remove an object at a location from the List.
 java.util.List subList(StateManager sm, int startIdx, int endIdx)
          Method to retrieve a list of elements in a range.
 
Methods inherited from class org.datanucleus.store.mapped.scostore.AbstractCollectionStore
contains, getExistsSubquery, getSizeSubquery, update, updateEmbeddedElement
 
Methods inherited from class org.datanucleus.store.mapped.scostore.ElementContainerStore
clear, getContainerTable, getElementInfo, getElementInformationForClass, getElementMapping, getElementType, getEmd, getOrderMapping, getRelationDiscriminatorMapping, getRelationDiscriminatorValue, hasOrderMapping, isElementsAreEmbedded, isElementsAreSerialised, size, validateElementForReading, validateElementForWriting, validateElementType
 
Methods inherited from class org.datanucleus.store.mapped.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, getElementType, hasOrderMapping, size, update, updateEmbeddedElement
 
Methods inherited from interface org.datanucleus.store.scostore.Store
getStoreManager
 
Methods inherited from interface org.datanucleus.store.mapped.expression.CollectionStoreQueryable
joinElementsTo
 

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).

Constructor Detail

AbstractListStore

protected AbstractListStore(StoreManager storeMgr,
                            ClassLoaderResolver clr,
                            AbstractListStoreSpecialization specialization)
Constructor. Protected to prevent instantiation.

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

iterator

public java.util.Iterator iterator(StateManager sm)
Accessor for an iterator through the list elements.

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

listIterator

public java.util.ListIterator listIterator(StateManager sm)
Accessor for an iterator through the list elements.

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

listIterator

protected abstract java.util.ListIterator listIterator(StateManager 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(StateManager sm,
                   java.lang.Object element,
                   int size)
Method to add an element to the List.

Specified by:
add in interface 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(StateManager sm,
                java.lang.Object element,
                int index,
                int size)
Method to add an element to the List.

Specified by:
add in interface ListStore
Parameters:
element - The element to add.
index - The location to add at
sm - The state manager.
size - Current size of list (if known). -1 if not known

addAll

public boolean addAll(StateManager sm,
                      java.util.Collection elements,
                      int size)
Method to add a collection of elements to the List.

Specified by:
addAll in interface 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(StateManager sm,
                      java.util.Collection elements,
                      int index,
                      int size)
Method to add all elements from a Collection to the List.

Specified by:
addAll in interface 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(StateManager sm,
                                       int startAt,
                                       boolean atEnd,
                                       java.util.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 java.lang.Object get(StateManager sm,
                            int index)
Method to retrieve an element from the List.

Specified by:
get in interface ListStore
Parameters:
sm - The state manager
index - The index of the element required.
Returns:
The object

indexOf

public int indexOf(StateManager sm,
                   java.lang.Object element)
Accessor for the indexOf an object in the List.

Specified by:
indexOf in interface ListStore
Parameters:
sm - The state manager
element - The element.
Returns:
The index

lastIndexOf

public int lastIndexOf(StateManager sm,
                       java.lang.Object element)
Method to retrieve the last index of an object in the list.

Specified by:
lastIndexOf in interface ListStore
Parameters:
sm - The state manager.
element - The object
Returns:
The last index

removeAll

public boolean removeAll(StateManager sm,
                         java.util.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 CollectionStore
Parameters:
sm - State Manager for the container
elements - Collection of elements to remove
size - Current size of collection if known. -1 if not known
Returns:
Whether the database was updated

remove

public boolean remove(StateManager sm,
                      java.lang.Object element,
                      int size,
                      boolean allowDependentField)
Method to remove the specified element from the List.

Specified by:
remove in interface CollectionStore
Parameters:
sm - The state manager
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(StateManager sm,
                                          java.lang.Object element,
                                          int size)
Convenience method to remove the specified element from the List.

Parameters:
sm - StateManager 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 java.lang.Object remove(StateManager sm,
                               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 ListStore
Parameters:
index - The location
sm - The state manager
size - Current size of the list (if known). -1 if not known
Returns:
The object that was removed

removeAt

protected abstract void removeAt(StateManager sm,
                                 int index,
                                 int size)
Internal method to remove an object at a location from the List.

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

subList

public java.util.List subList(StateManager sm,
                              int startIdx,
                              int endIdx)
Method to retrieve a list of elements in a range.

Specified by:
subList in interface ListStore
Parameters:
sm - The state manager.
startIdx - From index (inclusive).
endIdx - To index (exclusive)
Returns:
Sub List of elements in this range.

getIndicesOf

protected int[] getIndicesOf(StateManager sm,
                             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:
sm - The state manager.
elements - The elements
Returns:
The indices of the elements in the List.


Copyright © 2010. All Rights Reserved.