org.datanucleus.store.rdbms.scostore
Class RDBMSJoinListStoreSpecialization

java.lang.Object
  extended by org.datanucleus.store.mapped.scostore.BaseElementContainerStoreSpecialization
      extended by org.datanucleus.store.rdbms.scostore.RDBMSJoinListStoreSpecialization
All Implemented Interfaces:
org.datanucleus.store.mapped.scostore.AbstractCollectionStoreSpecialization, org.datanucleus.store.mapped.scostore.AbstractListStoreSpecialization, org.datanucleus.store.mapped.scostore.ElementContainerStoreSpecialization, org.datanucleus.store.mapped.scostore.JoinListStoreSpecialization

public class RDBMSJoinListStoreSpecialization
extends org.datanucleus.store.mapped.scostore.BaseElementContainerStoreSpecialization
implements org.datanucleus.store.mapped.scostore.JoinListStoreSpecialization

RDBMS-specific implementation of a JoinListStoreSpecialization.


Field Summary
protected  java.lang.String addStmt
          Statement for adding an element to the container.
protected  java.lang.String clearStmt
          Statement for clearing the container.
protected  java.lang.String indexOfStmt
           
protected  java.lang.String lastIndexOfStmt
           
protected  java.lang.String removeAtStmt
           
protected  java.lang.String removeStmt
          Statement for removing an element from the container.
protected  java.lang.String setStmt
           
protected  java.lang.String shiftStmt
           
protected  java.lang.String sizeStmt
          Statement for getting the size of the container.
protected  RDBMSManager storeMgr
           
protected  boolean usingDiscriminatorInSizeStmt
          Whether we are using a discriminator in the "size" statement.
 
Fields inherited from class org.datanucleus.store.mapped.scostore.BaseElementContainerStoreSpecialization
clr, localiser
 
Method Summary
 boolean contains(org.datanucleus.StateManager sm, java.lang.Object element, org.datanucleus.store.mapped.scostore.AbstractCollectionStore acs)
           
 void executeClear(org.datanucleus.StateManager ownerSM, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
protected  java.lang.String getAddStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generates the statement for adding items.
protected  java.lang.String getClearStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generate statement for clearing the container.
protected  java.lang.String getIndexOfStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generate statement for getting the index of an item.
 int[] getIndicesOf(org.datanucleus.StateManager sm, java.util.Collection elements, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
protected  java.lang.String getIndicesOfStmt(java.util.Collection elements, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generates the statement for getting the indices of a collection of element.
protected  java.lang.String getLastIndexOfStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generates the statement for getting the index of the last item.
protected  java.lang.String getRemoveAllStmt(java.util.Collection elements, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generate statement for removing a collection of items from the List.
protected  java.lang.String getRemoveAtStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generates the statement for removing an item.
protected  java.lang.String getRemoveStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generate statement for removing an element from the Collection.
protected  java.lang.String getSetStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generates the statement for setting an item.
protected  java.lang.String getShiftStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generates the statement for shifting items.
 int getSize(org.datanucleus.StateManager ownerSM, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
protected  java.lang.String getSizeStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generate statement for getting the size of thecontainer.
protected  java.lang.String getUpdateEmbeddedElementStmt(org.datanucleus.store.mapped.mapping.JavaTypeMapping fieldMapping, org.datanucleus.store.mapped.scostore.ElementContainerStore acs)
          Generate statement for update the field of an embedded element.
 int indexOf(org.datanucleus.StateManager sm, java.lang.Object element, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
 boolean internalAdd(org.datanucleus.StateManager sm, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs, int start, boolean atEnd, java.util.Collection c, int currentListSize, int shift)
           
protected  int internalIndexOf(org.datanucleus.StateManager sm, java.lang.Object element, java.lang.String stmt, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Internal method to find the index of an element.
 int[] internalRemove(org.datanucleus.StateManager ownerSM, org.datanucleus.ManagedConnection conn, boolean batched, java.lang.Object element, boolean executeNow, org.datanucleus.store.mapped.scostore.AbstractCollectionStore acs)
           
protected  void internalRemoveAt(org.datanucleus.StateManager sm, int index, java.lang.String stmt, int size, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Internal method to remove an object at a location in the List.
 int[] internalShift(org.datanucleus.StateManager ownerSM, org.datanucleus.ManagedConnection conn, boolean batched, int oldIndex, int amount, boolean executeNow, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Method to process a "shift" statement, updating the index in the list of the specified index.
protected  void invalidateAddStmt()
          Method to remove any stored statement for addition of an element.
 int lastIndexOf(org.datanucleus.StateManager sm, java.lang.Object element, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
protected  void prepareIndicesOfStmt(org.datanucleus.StateManager sm, java.sql.PreparedStatement ps, java.util.Collection elements, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Method to prepare the indicesOf statement for use.
 boolean removeAll(int currentListSize, int[] indices, java.util.Collection elements, org.datanucleus.StateManager sm, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
 void removeAt(org.datanucleus.StateManager sm, int index, int size, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
 void set(java.lang.Object element, int index, org.datanucleus.StateManager sm, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
 boolean updateEmbeddedElement(org.datanucleus.StateManager sm, java.lang.Object element, int fieldNumber, java.lang.Object value, org.datanucleus.store.mapped.mapping.JavaTypeMapping fieldMapping, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
 
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.mapped.scostore.AbstractListStoreSpecialization
getIndicesOf, indexOf, internalShift, lastIndexOf
 
Methods inherited from interface org.datanucleus.store.mapped.scostore.AbstractCollectionStoreSpecialization
contains, internalRemove, updateEmbeddedElement
 
Methods inherited from interface org.datanucleus.store.mapped.scostore.ElementContainerStoreSpecialization
executeClear, getSize
 

Field Detail

removeAtStmt

protected java.lang.String removeAtStmt

setStmt

protected java.lang.String setStmt

shiftStmt

protected java.lang.String shiftStmt

indexOfStmt

protected java.lang.String indexOfStmt

lastIndexOfStmt

protected java.lang.String lastIndexOfStmt

storeMgr

protected final RDBMSManager storeMgr

sizeStmt

protected java.lang.String sizeStmt
Statement for getting the size of the container.


clearStmt

protected java.lang.String clearStmt
Statement for clearing the container.


addStmt

protected java.lang.String addStmt
Statement for adding an element to the container.


removeStmt

protected java.lang.String removeStmt
Statement for removing an element from the container.


usingDiscriminatorInSizeStmt

protected boolean usingDiscriminatorInSizeStmt
Whether we are using a discriminator in the "size" statement.

Method Detail

getRemoveAllStmt

protected java.lang.String getRemoveAllStmt(java.util.Collection elements,
                                            org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
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.

removeAt

public void removeAt(org.datanucleus.StateManager sm,
                     int index,
                     int size,
                     org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Specified by:
removeAt in interface org.datanucleus.store.mapped.scostore.JoinListStoreSpecialization

removeAll

public boolean removeAll(int currentListSize,
                         int[] indices,
                         java.util.Collection elements,
                         org.datanucleus.StateManager sm,
                         org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Specified by:
removeAll in interface org.datanucleus.store.mapped.scostore.JoinListStoreSpecialization

getSetStmt

protected java.lang.String getSetStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
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

set

public void set(java.lang.Object element,
                int index,
                org.datanucleus.StateManager sm,
                org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Specified by:
set in interface org.datanucleus.store.mapped.scostore.JoinListStoreSpecialization

internalAdd

public boolean internalAdd(org.datanucleus.StateManager sm,
                           org.datanucleus.store.mapped.scostore.ElementContainerStore ecs,
                           int start,
                           boolean atEnd,
                           java.util.Collection c,
                           int currentListSize,
                           int shift)
Specified by:
internalAdd in interface org.datanucleus.store.mapped.scostore.JoinListStoreSpecialization

getIndexOfStmt

protected java.lang.String getIndexOfStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
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
 

Returns:
The Statement for getting the index of an item

getLastIndexOfStmt

protected java.lang.String getLastIndexOfStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
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

getRemoveAtStmt

protected java.lang.String getRemoveAtStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
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(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Generates the statement for shifting items.
 UPDATE LISTTABLE SET INDEXCOL = ?
 WHERE OWNERCOL = ?
 AND INDEXCOL = ?
 [AND DISTINGUISHER=?]
 

Returns:
The Statement for shifting elements

getIndicesOfStmt

protected java.lang.String getIndicesOfStmt(java.util.Collection elements,
                                            org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
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.

prepareIndicesOfStmt

protected void prepareIndicesOfStmt(org.datanucleus.StateManager sm,
                                    java.sql.PreparedStatement ps,
                                    java.util.Collection elements,
                                    org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Method to prepare the indicesOf statement for use. Populates the various parameters. This is required because the query is built dynamically depending on the number of elements to retrieve the indices for.

Parameters:
sm - State Manager of the container.
ps - The Prepared Statement
elements - Collection of elements

internalIndexOf

protected int internalIndexOf(org.datanucleus.StateManager sm,
                              java.lang.Object element,
                              java.lang.String stmt,
                              org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Internal method to find the index of an element.

Parameters:
sm - The state manager.
element - The element
stmt - The statement to find the element.
Returns:
The index of the element in the List.

indexOf

public int indexOf(org.datanucleus.StateManager sm,
                   java.lang.Object element,
                   org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Specified by:
indexOf in interface org.datanucleus.store.mapped.scostore.AbstractListStoreSpecialization

lastIndexOf

public int lastIndexOf(org.datanucleus.StateManager sm,
                       java.lang.Object element,
                       org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Specified by:
lastIndexOf in interface org.datanucleus.store.mapped.scostore.AbstractListStoreSpecialization

getIndicesOf

public int[] getIndicesOf(org.datanucleus.StateManager sm,
                          java.util.Collection elements,
                          org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Specified by:
getIndicesOf in interface org.datanucleus.store.mapped.scostore.AbstractListStoreSpecialization

internalRemoveAt

protected void internalRemoveAt(org.datanucleus.StateManager sm,
                                int index,
                                java.lang.String stmt,
                                int size,
                                org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Internal method to remove an object at a location in the List.

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

internalShift

public int[] internalShift(org.datanucleus.StateManager ownerSM,
                           org.datanucleus.ManagedConnection conn,
                           boolean batched,
                           int oldIndex,
                           int amount,
                           boolean executeNow,
                           org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
                    throws org.datanucleus.store.mapped.exceptions.MappedDatastoreException
Method to process a "shift" statement, updating the index in the list of the specified index.

Specified by:
internalShift in interface org.datanucleus.store.mapped.scostore.AbstractListStoreSpecialization
Parameters:
ownerSM - StateManager of the owner
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

getUpdateEmbeddedElementStmt

protected java.lang.String getUpdateEmbeddedElementStmt(org.datanucleus.store.mapped.mapping.JavaTypeMapping fieldMapping,
                                                        org.datanucleus.store.mapped.scostore.ElementContainerStore acs)
Generate statement for update the field of an embedded element.
 UPDATE SETTABLE
 SET EMBEDDEDFIELD1 = ?
 WHERE OWNERCOL=?
 AND ELEMENTCOL = ?
 

Parameters:
fieldMapping - The mapping for the field within the embedded object to be updated
Returns:
Statement for updating an embedded element in the Set

updateEmbeddedElement

public boolean updateEmbeddedElement(org.datanucleus.StateManager sm,
                                     java.lang.Object element,
                                     int fieldNumber,
                                     java.lang.Object value,
                                     org.datanucleus.store.mapped.mapping.JavaTypeMapping fieldMapping,
                                     org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Specified by:
updateEmbeddedElement in interface org.datanucleus.store.mapped.scostore.AbstractCollectionStoreSpecialization

contains

public boolean contains(org.datanucleus.StateManager sm,
                        java.lang.Object element,
                        org.datanucleus.store.mapped.scostore.AbstractCollectionStore acs)
Specified by:
contains in interface org.datanucleus.store.mapped.scostore.AbstractCollectionStoreSpecialization

internalRemove

public int[] internalRemove(org.datanucleus.StateManager ownerSM,
                            org.datanucleus.ManagedConnection conn,
                            boolean batched,
                            java.lang.Object element,
                            boolean executeNow,
                            org.datanucleus.store.mapped.scostore.AbstractCollectionStore acs)
                     throws org.datanucleus.store.mapped.exceptions.MappedDatastoreException
Specified by:
internalRemove in interface org.datanucleus.store.mapped.scostore.AbstractCollectionStoreSpecialization
Throws:
org.datanucleus.store.mapped.exceptions.MappedDatastoreException

getRemoveStmt

protected java.lang.String getRemoveStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Generate statement for removing an element from the Collection.
 DELETE FROM COLLTABLE WHERE OWNERCOL=? AND ELEMENTCOL = ? [AND DISCRIM = ?]
 

Parameters:
ecs - Element container store
Returns:
Statement for deleting an item from the Collection.

invalidateAddStmt

protected void invalidateAddStmt()
Method to remove any stored statement for addition of an element.


getAddStmt

protected java.lang.String getAddStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Generates the statement for adding items. The EMBEDDEDFIELDX columns are only added for embedded PC elements.
 INSERT INTO COLLTABLE (OWNERCOL,[ELEMENTCOL],[EMBEDDEDFIELD1, EMBEDDEDFIELD2,...],[ORDERCOL]) 
                       VALUES (?,?,?)
 

Returns:
The Statement for adding an item

executeClear

public void executeClear(org.datanucleus.StateManager ownerSM,
                         org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)

getClearStmt

protected java.lang.String getClearStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Generate statement for clearing the container.
 DELETE FROM CONTAINERTABLE WHERE OWNERCOL = ? [AND RELATION_DISCRIM=?]
 
TODO Add a discriminator restriction on this statement so we only clear ones with a valid discriminator value

Returns:
Statement for clearing the container.

getSize

public int getSize(org.datanucleus.StateManager ownerSM,
                   org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)

getSizeStmt

protected java.lang.String getSizeStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Generate statement for getting the size of thecontainer. The order part is only present when an order mapping is used. The discriminator part is only present when the element has a discriminator.
 SELECT COUNT(*) FROM TBL THIS
 [INNER JOIN ELEM_TBL ELEM ON TBL.COL = ELEM.ID] - when no null
 [LEFT OUTER JOIN ELEM_TBL ELEM ON TBL.COL = ELEM.ID] - when allows null
 WHERE THIS.OWNERCOL=?
 [AND THIS.ORDERCOL IS NOT NULL]
 [AND (DISCRIMINATOR=? OR DISCRMINATOR=? OR DISCRIMINATOR=? [OR DISCRIMINATOR IS NULL])]
 [AND RELATION_DISCRIM=?]
 
The discriminator part includes all subclasses of the element type. If the element is in a different table to the container then an INNER JOIN will be present to link the two tables, and table aliases will be present also. TODO Update this to allow for getting the size when more than 1 element table.

Returns:
The Statement returning the size of the container.


Copyright © 2009. All Rights Reserved.