org.jpox.store.rdbms.scostore
Class AbstractCollectionStore

java.lang.Object
  extended by org.jpox.store.rdbms.scostore.ElementContainerStore
      extended by org.jpox.store.rdbms.scostore.AbstractCollectionStore
Direct Known Subclasses:
FKListStore, FKSetStore, JoinListStore, JoinSetStore, MapKeySetStore, MapValueSetStore

public abstract class AbstractCollectionStore
extends ElementContainerStore

Abstract representation of a store of a Collection. Contains all common parts of storing Sets and Lists.

Version:
$Revision: 1.44 $

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
protected  java.lang.String containsStmt
          Statement for getting whether an element is contained in the collection.
protected  DatastoreAdapter dba
          Datastore adapter in use by this store.
protected static Localiser LOCALISER
          Localiser for messages.
protected  AbstractPropertyMetaData ownerFieldMetaData
          MetaData for the field in the owner with this container.
protected  JavaTypeMapping ownerMapping
          Mapping to the owner of the container.
protected  StoreManager storeMgr
          Manager for the store.
protected  DatastoreIdentifier thisIdentifier
          Identifier for the container in JDOQL queries.
 
Fields inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
clearStmt, clr, containerTable, elementInfo, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, elmIdentifier, emd, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, sizeStmt
 
Constructor Summary
protected AbstractCollectionStore(StoreManager storeMgr, ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 boolean contains(StateManager sm, java.lang.Object element)
          Method to verify if the association owner vs elements contains a specific element in the association
protected  java.sql.ResultSet executeQuery(java.lang.String stmt, java.sql.PreparedStatement ps)
          Method to execute a PreparedStatement query, and return the ResultSet.
protected  int executeUpdate(java.lang.String stmt, java.sql.PreparedStatement ps)
          Method to execute a PreparedStatement.
protected  java.lang.String getContainsStmt()
          Generate statement for retrieving the contents of the Collection.
 QueryExpression getExistsSubquery(QueryExpression qs, JavaTypeMapping mapping, LogicSetExpression ownerTe, DatastoreIdentifier collectionRangeVar)
          JDOQL utility to generate an exists() statement for an element.
 JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
 QueryExpression getSizeSubquery(QueryExpression qs, JavaTypeMapping mapping, LogicSetExpression ownerTe, DatastoreIdentifier collectionRangeVar)
          JDOQL utility to generate a subquery for the size() of the collection.
protected  StateManager getStateManagerForEmbeddedPCObject(StateManager sm, java.lang.Object obj, JoinTable table)
          Method to return the StateManager for an embedded PC object (element, key, value).
 StoreManager getStoreManager()
          Accessor for the RDBMSManager.
protected  java.lang.String getUpdateEmbeddedElementStmt(JavaTypeMapping fieldMapping)
          Generate statement for update the field of an embedded element.
protected  void initialiseStatements()
          Method to initialise the statements being used.
protected  boolean isEmbeddedMapping(JavaTypeMapping mapping)
          Check if the mapping correspond to a non pc object or embedded field
protected  int populateOwnerInStatement(StateManager sm, PersistenceManager pm, java.sql.PreparedStatement ps, int jdbcPosition)
          Convenience method to populate the passed PreparedStatement with the value from the owner.
 boolean updateEmbeddedElement(StateManager sm, java.lang.Object element, int fieldNumber, java.lang.Object value)
          Method to update a field of an embedded element.
 
Methods inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
clear, getAddStmt, getClearStmt, getElementInformationForClass, getElementType, getSizeStmt, hasOrderMapping, iterator, newResultObjectFactory, populateElementDiscriminatorInStatement, populateElementInStatement, populateEmbeddedElementFieldsInStatement, populateOrderInStatement, populateRelationDiscriminatorInStatement, size, validateElementForReading, validateElementForWriting, validateElementType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

containsStmt

protected java.lang.String containsStmt
Statement for getting whether an element is contained in the collection.


LOCALISER

protected static final Localiser LOCALISER
Localiser for messages.


storeMgr

protected StoreManager storeMgr
Manager for the store.


dba

protected DatastoreAdapter dba
Datastore adapter in use by this store.


ownerMapping

protected JavaTypeMapping ownerMapping
Mapping to the owner of the container.


ownerFieldMetaData

protected AbstractPropertyMetaData ownerFieldMetaData
MetaData for the field in the owner with this container.


thisIdentifier

protected final DatastoreIdentifier thisIdentifier
Identifier for the container in JDOQL queries.

Constructor Detail

AbstractCollectionStore

protected AbstractCollectionStore(StoreManager storeMgr,
                                  ClassLoaderResolver clr)
Constructor.

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

initialiseStatements

protected void initialiseStatements()
Method to initialise the statements being used.

Overrides:
initialiseStatements in class ElementContainerStore

getUpdateEmbeddedElementStmt

protected java.lang.String getUpdateEmbeddedElementStmt(JavaTypeMapping fieldMapping)
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(StateManager sm,
                                     java.lang.Object element,
                                     int fieldNumber,
                                     java.lang.Object value)
Method to update a field of an embedded element.

Parameters:
sm - State Manager of the owner
element - The element to update
fieldNumber - The number of the field to update
value - The value
Returns:
true if the datastore was updated

getContainsStmt

protected java.lang.String getContainsStmt()
Generate statement for retrieving the contents of the Collection. The discriminator part is only present when the element type has inheritance strategy of "superclass-table" and is Inverse.
 SELECT OWNERCOL FROM COLLECTIONTABLE 
 WHERE OWNERCOL=?
 AND ELEMENTCOL=?
 [AND DISCRIMINATOR=?]
 [AND RELATION_DISCRIM=?]
 

Returns:
Statement for retrieving the contents of the Collection.

contains

public boolean contains(StateManager sm,
                        java.lang.Object element)
Method to verify if the association owner vs elements contains a specific element in the association

Parameters:
sm - The StateManager
element - The element
Returns:
Whether it contains the element

getExistsSubquery

public QueryExpression getExistsSubquery(QueryExpression qs,
                                         JavaTypeMapping mapping,
                                         LogicSetExpression ownerTe,
                                         DatastoreIdentifier collectionRangeVar)
JDOQL utility to generate an exists() statement for an element. The generated query will be of the form
 SELECT 1 FROM JOINTABLE THIS_JOIN WHERE THIS_JOIN.OWNER_ID_OID = THIS.OWNER_ID
 

Parameters:
qs - The JDOQL query statement
mapping - mapping of the field
ownerTe - Expression for the table
collectionRangeVar - range variable for the collection
Returns:
The JDOQL query statement

getSizeSubquery

public QueryExpression getSizeSubquery(QueryExpression qs,
                                       JavaTypeMapping mapping,
                                       LogicSetExpression ownerTe,
                                       DatastoreIdentifier collectionRangeVar)
JDOQL utility to generate a subquery for the size() of the collection. The generated query will be of the form
 SELECT COUNT(*) FROM JOINTABLE THIS_JOIN WHERE THIS_JOIN.OWNER_ID_OID = THIS.OWNER_ID
 

Parameters:
qs - The JDOQL query statement
mapping - mapping of the field
ownerTe - Expression for the table
collectionRangeVar - range variable for the collection
Returns:
The JDOQL query statement

getStoreManager

public StoreManager getStoreManager()
Accessor for the RDBMSManager.

Returns:
The RDBMSManager.

getOwnerMapping

public JavaTypeMapping getOwnerMapping()
Accessor for the owner mapping.

Returns:
Owner mapping.

executeUpdate

protected int executeUpdate(java.lang.String stmt,
                            java.sql.PreparedStatement ps)
                     throws java.sql.SQLException
Method to execute a PreparedStatement. Prints logging information about timings.

Parameters:
stmt - The statement text
ps - The Prepared Statement
Returns:
The numer of rows affected (as per PreparedStatement.executeUpdate)
Throws:
java.sql.SQLException - Thrown if an error occurs

executeQuery

protected java.sql.ResultSet executeQuery(java.lang.String stmt,
                                          java.sql.PreparedStatement ps)
                                   throws java.sql.SQLException
Method to execute a PreparedStatement query, and return the ResultSet. Prints logging information about timings.

Parameters:
stmt - The statement text
ps - The Prepared Statement
Returns:
The ResultSet from the query
Throws:
java.sql.SQLException - Thrown if an error occurs

isEmbeddedMapping

protected boolean isEmbeddedMapping(JavaTypeMapping mapping)
Check if the mapping correspond to a non pc object or embedded field

Parameters:
mapping - the mapping
Returns:
true if the field is embedded into one column

populateOwnerInStatement

protected int populateOwnerInStatement(StateManager sm,
                                       PersistenceManager pm,
                                       java.sql.PreparedStatement ps,
                                       int jdbcPosition)
Convenience method to populate the passed PreparedStatement with the value from the owner.

Parameters:
sm - State Manager
pm - Persistence Manager
ps - The PreparedStatement
jdbcPosition - Position in JDBC statement to populate
Returns:
The next position in the JDBC statement

getStateManagerForEmbeddedPCObject

protected StateManager getStateManagerForEmbeddedPCObject(StateManager sm,
                                                          java.lang.Object obj,
                                                          JoinTable table)
Method to return the StateManager for an embedded PC object (element, key, value). It creates one if the element is not currently managed.

Parameters:
sm - State Manager of the owner
obj - The embedded PC object
table - Join table where the objects are stored
Returns:
The state manager


Copyright © -2011 . All Rights Reserved.