org.datanucleus.store.rdbms.scostore
Class ElementContainerStore

java.lang.Object
  extended by org.datanucleus.store.rdbms.scostore.BaseContainerStore
      extended by org.datanucleus.store.rdbms.scostore.ElementContainerStore
Direct Known Subclasses:
AbstractArrayStore, AbstractCollectionStore

public abstract class ElementContainerStore
extends BaseContainerStore

Representation of the store of an element-based container. This is used to represent either a collection or an array. There are the following types of situation that we try to cater for with respect to elements.


Nested Class Summary
static class ElementContainerStore.ElementInfo
          Inner class wrapping the information required for a valid element type.
 
Field Summary
protected  String addStmt
          Statement for adding an element to the container.
protected  String clearStmt
          Statement for clearing the container.
protected  org.datanucleus.ClassLoaderResolver clr
          ClassLoader resolver.
protected  org.datanucleus.store.mapped.DatastoreContainerObject containerTable
          Table containing the link between owner and element.
protected  ElementContainerStore.ElementInfo[] elementInfo
          Information for the elements of this container.
protected  boolean elementIsPersistentInterface
          Whether the element is of a persistent-interface (defined using "") type.
protected  org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping
          Mapping for the element.
protected  boolean elementsAreEmbedded
          Whether the elements are embedded.
protected  boolean elementsAreSerialised
          Whether the elements are serialised.
protected  String elementType
          Type of the element.
protected  org.datanucleus.metadata.AbstractClassMetaData emd
          MetaData for the "element-type" class.
protected  boolean iterateUsingDiscriminator
          Flag to set whether the iterator statement will use a discriminator or not.
protected  org.datanucleus.store.mapped.mapping.JavaTypeMapping orderMapping
          Mapping for an ordering column to allow for duplicates in the container.
protected  org.datanucleus.store.mapped.mapping.JavaTypeMapping relationDiscriminatorMapping
          Optional mapping to distinguish elements of one collection from another when sharing the join table.
protected  String relationDiscriminatorValue
          Value to use to discriminate between elements of this collection from others using the same join table.
protected  String removeStmt
          Statement for removing an element from the container.
protected  String sizeStmt
          Statement for getting the size of the container.
protected  boolean usingDiscriminatorInSizeStmt
          Whether we are using a discriminator in the "size" statement.
 
Fields inherited from class org.datanucleus.store.rdbms.scostore.BaseContainerStore
allowNulls, dba, LOCALISER, ownerMapping, ownerMemberMetaData, relationType, storeMgr
 
Constructor Summary
protected ElementContainerStore(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 void clear(org.datanucleus.store.ObjectProvider ownerSM)
          Clear the association from owner to all elements.
 void executeClear(org.datanucleus.store.ObjectProvider ownerSM)
           
protected  String getAddStmt()
          Generates the statement for adding items.
protected  String getClearStmt()
          Generate statement for clearing the container.
 org.datanucleus.store.mapped.DatastoreContainerObject getContainerTable()
           
 ElementContainerStore.ElementInfo[] getElementInfo()
           
protected  ElementContainerStore.ElementInfo[] getElementInformationForClass()
          Convenience method to find the element information relating to the element type.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getElementMapping()
           
 org.datanucleus.metadata.AbstractClassMetaData getEmd()
           
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getOrderMapping()
           
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getRelationDiscriminatorMapping()
           
 String getRelationDiscriminatorValue()
           
 int getSize(org.datanucleus.store.ObjectProvider ownerSM)
           
protected  String getSizeStmt()
          Generate statement for getting the size of thecontainer.
 boolean hasOrderMapping()
          Accessor for whether the store has an order mapping, to allow for duplicates or ordering.
protected  void invalidateAddStmt()
          Method to remove any stored statement for addition of an element.
 boolean isElementsAreEmbedded()
           
 boolean isElementsAreSerialised()
           
abstract  Iterator iterator(org.datanucleus.store.ObjectProvider ownerSM)
          Accessor for an iterator through the container elements.
 int size(org.datanucleus.store.ObjectProvider sm)
          Method to return the size of the container.
protected  boolean validateElementForReading(org.datanucleus.store.ObjectProvider sm, Object element)
          Method to check if an element is already persistent or is persistent but managed by a different persistence manager.
protected  boolean validateElementForWriting(org.datanucleus.store.ExecutionContext ec, Object element, org.datanucleus.store.FieldValues fieldValues)
          Method to check if an element is already persistent, or is managed by a different Persistencemanager.
protected  boolean validateElementType(org.datanucleus.ClassLoaderResolver clr, Object element)
          Method to validate an element against the accepted type.
 
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
 

Field Detail

iterateUsingDiscriminator

protected boolean iterateUsingDiscriminator
Flag to set whether the iterator statement will use a discriminator or not.


sizeStmt

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


clearStmt

protected String clearStmt
Statement for clearing the container.


addStmt

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


removeStmt

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


usingDiscriminatorInSizeStmt

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


elementInfo

protected ElementContainerStore.ElementInfo[] elementInfo
Information for the elements of this container. When the "element-type" table is new-table, or superclass-table then there is 1 value here. When the "element-type" table uses subclass-table, or when it is a reference type then there can be multiple.


emd

protected org.datanucleus.metadata.AbstractClassMetaData emd
MetaData for the "element-type" class. Not used for reference types since no metadata is present for the declared type.


containerTable

protected org.datanucleus.store.mapped.DatastoreContainerObject containerTable
Table containing the link between owner and element. Not set when using FK relations.


elementMapping

protected org.datanucleus.store.mapped.mapping.JavaTypeMapping elementMapping
Mapping for the element.


elementType

protected String elementType
Type of the element.


elementsAreEmbedded

protected boolean elementsAreEmbedded
Whether the elements are embedded.


elementsAreSerialised

protected boolean elementsAreSerialised
Whether the elements are serialised.


elementIsPersistentInterface

protected boolean elementIsPersistentInterface
Whether the element is of a persistent-interface (defined using "") type.


orderMapping

protected org.datanucleus.store.mapped.mapping.JavaTypeMapping orderMapping
Mapping for an ordering column to allow for duplicates in the container. Can also be used for ordering elements in a List/array. Can also be used where we have an embedded object and so need to form the PK with something.


relationDiscriminatorMapping

protected org.datanucleus.store.mapped.mapping.JavaTypeMapping relationDiscriminatorMapping
Optional mapping to distinguish elements of one collection from another when sharing the join table.


relationDiscriminatorValue

protected String relationDiscriminatorValue
Value to use to discriminate between elements of this collection from others using the same join table.


clr

protected org.datanucleus.ClassLoaderResolver clr
ClassLoader resolver.

Constructor Detail

ElementContainerStore

protected ElementContainerStore(RDBMSStoreManager storeMgr,
                                org.datanucleus.ClassLoaderResolver clr)
Constructor.

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

getElementInfo

public ElementContainerStore.ElementInfo[] getElementInfo()

getElementMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getElementMapping()

getOrderMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getOrderMapping()

getRelationDiscriminatorMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getRelationDiscriminatorMapping()

getRelationDiscriminatorValue

public String getRelationDiscriminatorValue()

getContainerTable

public org.datanucleus.store.mapped.DatastoreContainerObject getContainerTable()

getEmd

public org.datanucleus.metadata.AbstractClassMetaData getEmd()

isElementsAreSerialised

public boolean isElementsAreSerialised()

isElementsAreEmbedded

public boolean isElementsAreEmbedded()

getElementInformationForClass

protected ElementContainerStore.ElementInfo[] getElementInformationForClass()
Convenience method to find the element information relating to the element type. Used specifically for the "element-type" of a collection/array to find the elements which have table information. Not used for reference types.

Returns:
Element information relating to the element type

hasOrderMapping

public boolean hasOrderMapping()
Accessor for whether the store has an order mapping, to allow for duplicates or ordering.

Returns:
Whether an order mapping is present.

validateElementType

protected boolean validateElementType(org.datanucleus.ClassLoaderResolver clr,
                                      Object element)
Method to validate an element against the accepted type.

Parameters:
clr - The ClassLoaderResolver
element - The element to validate
Returns:
Whether it is valid.

validateElementForReading

protected boolean validateElementForReading(org.datanucleus.store.ObjectProvider sm,
                                            Object element)
Method to check if an element is already persistent or is persistent but managed by a different persistence manager.

Parameters:
sm - The state manager of this owner
element - The element
Returns:
Whether it is valid for reading.

validateElementForWriting

protected boolean validateElementForWriting(org.datanucleus.store.ExecutionContext ec,
                                            Object element,
                                            org.datanucleus.store.FieldValues fieldValues)
Method to check if an element is already persistent, or is managed by a different Persistencemanager. If not persistent, this will persist it.

Parameters:
ec - execution context
element - The element
fieldValues - any initial field values to use if persisting the element
Returns:
Whether the element was persisted during this call

iterator

public abstract Iterator iterator(org.datanucleus.store.ObjectProvider ownerSM)
Accessor for an iterator through the container elements.

Parameters:
ownerSM - State Manager for the container.
Returns:
The Iterator

clear

public void clear(org.datanucleus.store.ObjectProvider ownerSM)
Clear the association from owner to all elements. Provides cascade-delete when the elements being deleted are PC types.

Parameters:
ownerSM - State Manager for the container.

size

public int size(org.datanucleus.store.ObjectProvider sm)
Method to return the size of the container.

Parameters:
sm - The state manager.
Returns:
The size.

invalidateAddStmt

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


getAddStmt

protected String getAddStmt()
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.store.ObjectProvider ownerSM)

getClearStmt

protected String getClearStmt()
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.store.ObjectProvider ownerSM)

getSizeStmt

protected String getSizeStmt()
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 © 2012. All Rights Reserved.