org.datanucleus.store.rdbms.scostore
Class RDBMSJoinArrayStoreSpecialization

java.lang.Object
  extended by org.datanucleus.store.mapped.scostore.BaseElementContainerStoreSpecialization
      extended by org.datanucleus.store.rdbms.scostore.RDBMSJoinArrayStoreSpecialization
All Implemented Interfaces:
org.datanucleus.store.mapped.scostore.AbstractArrayStoreSpecialization, org.datanucleus.store.mapped.scostore.AbstractCollectionStoreSpecialization, org.datanucleus.store.mapped.scostore.ElementContainerStoreSpecialization, org.datanucleus.store.mapped.scostore.JoinArrayStoreSpecialization

public class RDBMSJoinArrayStoreSpecialization
extends org.datanucleus.store.mapped.scostore.BaseElementContainerStoreSpecialization
implements org.datanucleus.store.mapped.scostore.JoinArrayStoreSpecialization

RDBMS-specific implementation of a JoinArrayStoreSpecialization.


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 removeStmt
          Statement for removing an element from the container.
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
 void clear(org.datanucleus.StateManager ownerSM, org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
           
 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 getRemoveStmt(org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
          Generate statement for removing an element from the Collection.
 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[] internalAdd(org.datanucleus.StateManager sm, org.datanucleus.store.mapped.scostore.AbstractArrayStore aas, java.lang.Object element, org.datanucleus.ManagedConnection conn, boolean batched, int orderId, boolean executeNow)
          Internal method to add a row to the join table.
 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 invalidateAddStmt()
          Method to remove any stored statement for addition of an element.
 void processBatchedWrites(org.datanucleus.ManagedConnection mconn)
           
 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.AbstractArrayStoreSpecialization
clear, internalAdd, processBatchedWrites
 
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

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

clear

public void clear(org.datanucleus.StateManager ownerSM,
                  org.datanucleus.store.mapped.scostore.ElementContainerStore ecs)
Specified by:
clear in interface org.datanucleus.store.mapped.scostore.AbstractArrayStoreSpecialization

internalAdd

public int[] internalAdd(org.datanucleus.StateManager sm,
                         org.datanucleus.store.mapped.scostore.AbstractArrayStore aas,
                         java.lang.Object element,
                         org.datanucleus.ManagedConnection conn,
                         boolean batched,
                         int orderId,
                         boolean executeNow)
                  throws org.datanucleus.store.mapped.exceptions.MappedDatastoreException
Internal method to add a row to the join table. Used by add() and set() to add a row to the join table.

Specified by:
internalAdd in interface org.datanucleus.store.mapped.scostore.AbstractArrayStoreSpecialization
Parameters:
sm - StateManager for the owner of the collection
element - The element to add the relation to
conn - The connection
batched - Whether we are batching
orderId - The order id to use for this element relation
executeNow - Whether to execute the statement now (and not wait for any batch)
Returns:
Whether a row was inserted
Throws:
java.sql.SQLException - Thrown if an error occurs
org.datanucleus.store.mapped.exceptions.MappedDatastoreException

processBatchedWrites

public void processBatchedWrites(org.datanucleus.ManagedConnection mconn)
                          throws org.datanucleus.store.mapped.exceptions.MappedDatastoreException
Specified by:
processBatchedWrites in interface org.datanucleus.store.mapped.scostore.AbstractArrayStoreSpecialization
Throws:
org.datanucleus.store.mapped.exceptions.MappedDatastoreException

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.