org.datanucleus.store.rdbms.scostore
Class RDBMSJoinListStore

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
                  extended by org.datanucleus.store.rdbms.scostore.RDBMSJoinListStore
All Implemented Interfaces:
org.datanucleus.store.scostore.CollectionStore, org.datanucleus.store.scostore.ListStore, org.datanucleus.store.scostore.Store

public class RDBMSJoinListStore
extends AbstractListStore

RDBMS-specific implementation of a ListStore using join table.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.datanucleus.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
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, 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
RDBMSJoinListStore(org.datanucleus.metadata.AbstractMemberMetaData mmd, CollectionTable collTable, org.datanucleus.ClassLoaderResolver clr)
          Constructor for an RDBMS implementation of a join list store.
 
Method Summary
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  SQLStatement getSQLStatementForIterator(org.datanucleus.store.ObjectProvider op, int startIdx, int endIdx, org.datanucleus.store.mapped.StatementClassMapping resultMapping, StatementParameterMapping paramMapping)
          Method to generate an SQLStatement for iterating through elements of the set.
protected  boolean internalAdd(org.datanucleus.store.ObjectProvider sm, int start, boolean atEnd, Collection c, int size)
          Internal method to add element(s) to the List.
protected  boolean internalRemove(org.datanucleus.store.ObjectProvider ownerSM, Object element, int size)
          Convenience method to remove the specified element from the List.
protected  void internalRemoveAt(org.datanucleus.store.ObjectProvider sm, int index, int size)
          Method to remove an element from the specified position
protected  ListIterator listIterator(org.datanucleus.store.ObjectProvider op, int startIdx, int endIdx)
          Accessor for an iterator through the list elements.
 boolean removeAll(org.datanucleus.store.ObjectProvider op, Collection elements, int size)
          Remove all elements from a collection from the association owner vs elements.
 Object set(org.datanucleus.store.ObjectProvider op, int index, Object element, boolean allowDependentField)
          Method to set an object in the List.
 void update(org.datanucleus.store.ObjectProvider sm, 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, containsInternal, getRemoveStmt, getUpdateEmbeddedElementStmt, internalRemove, 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.CollectionStore
clear, contains, hasOrderMapping, size, updateEmbeddedElement
 
Methods inherited from interface org.datanucleus.store.scostore.Store
getStoreManager
 

Constructor Detail

RDBMSJoinListStore

public RDBMSJoinListStore(org.datanucleus.metadata.AbstractMemberMetaData mmd,
                          CollectionTable collTable,
                          org.datanucleus.ClassLoaderResolver clr)
Constructor for an RDBMS implementation of a join list store.

Parameters:
mmd - Metadata for the owning field/property
collTable - The Join table
clr - ClassLoader resolver
Method Detail

internalAdd

protected boolean internalAdd(org.datanucleus.store.ObjectProvider sm,
                              int start,
                              boolean atEnd,
                              Collection c,
                              int size)
Internal method to add element(s) to the List. Performs the add in 2 steps.
  1. Shift all existing elements into their new positions so we can insert.
  2. Insert all new elements directly at their desired positions>/li>
Both steps can be batched (separately).

Specified by:
internalAdd in class AbstractListStore
Parameters:
sm - The state manager
start - The start location (if required)
atEnd - Whether to add the element at the end
c - The collection of objects to add.
size - Current size of list if known. -1 if not known
Returns:
Whether it was successful

set

public Object set(org.datanucleus.store.ObjectProvider op,
                  int index,
                  Object element,
                  boolean allowDependentField)
Method to set an object in the List.

Parameters:
op - ObjectProvider for the owner
index - The item index
element - What to set it to.
allowDependentField - Whether to allow dependent field deletes
Returns:
The value before setting.

update

public void update(org.datanucleus.store.ObjectProvider sm,
                   Collection coll)
Method to update the collection to be the supplied collection of elements.

Specified by:
update in interface org.datanucleus.store.scostore.CollectionStore
Overrides:
update in class AbstractCollectionStore
Parameters:
sm - StateManager of the object
coll - The collection to use

internalRemove

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

Specified by:
internalRemove in class AbstractListStore
Parameters:
element - The element
ownerSM - StateManager of the owner
size - Current size of list if known. -1 if not known
Returns:
Whether the List was modified

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

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

internalRemoveAt

protected void internalRemoveAt(org.datanucleus.store.ObjectProvider sm,
                                int index,
                                int size)
Method to remove an element from the specified position

Specified by:
internalRemoveAt in class AbstractListStore
Parameters:
sm - The State Manager for the list
index - The index of the element
size - Current size of list (if known). -1 if not known

listIterator

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

Specified by:
listIterator in class AbstractListStore
Parameters:
op - ObjectProvider for the owner
startIdx - The start point in the list (only for indexed lists).
endIdx - End index in the list (only for indexed lists).
Returns:
The List Iterator

getSQLStatementForIterator

protected SQLStatement getSQLStatementForIterator(org.datanucleus.store.ObjectProvider op,
                                                  int startIdx,
                                                  int endIdx,
                                                  org.datanucleus.store.mapped.StatementClassMapping resultMapping,
                                                  StatementParameterMapping paramMapping)
Method to generate an SQLStatement for iterating through elements of the set. Selects the join table. Populates the resultMapping and paramMapping argument objects.

Parameters:
op - ObjectProvider for the owner object
startIdx - start index to be retrieved (inclusive). Only for indexed list
endIdx - end index to be retrieved (exclusive). Only for indexed list
resultMapping - Mapping for the candidate result columns
paramMapping - Mapping for the input parameters
Returns:
The SQLStatement

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.


Copyright © 2012. All Rights Reserved.