org.jpox.store.rdbms.scostore
Class AbstractArrayStore

java.lang.Object
  extended by org.jpox.store.rdbms.scostore.ElementContainerStore
      extended by org.jpox.store.rdbms.scostore.AbstractArrayStore
All Implemented Interfaces:
ArrayStore, Store
Direct Known Subclasses:
FKArrayStore, JoinArrayStore

public abstract class AbstractArrayStore
extends ElementContainerStore
implements ArrayStore

Abstract representation of the backing store for an array.

Version:
$Revision: 1.9 $

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
protected  java.lang.String addStmt
          Statement for adding an element to an array.
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 AbstractArrayStore(StoreManager storeMgr, ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 boolean add(StateManager sm, java.lang.Object element, int position)
          Adds one element to the association owner vs elements
 void clear(StateManager ownerSM)
          Clear the association from owner to all elements.
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.
 java.util.List getArray(StateManager ownerSM)
          Method to retrieve the elements of the array.
 QueryExpression getExistsSubquery(QueryExpression qs, JavaTypeMapping mapping, LogicSetExpression ownerTe, DatastoreIdentifier collectionRangeVar)
          JDOQL utility to generate an exists() statement for an element.
protected abstract  QueryExpression getIteratorStatement(StateManager ownerSM)
          Accessor for the statement for the iterator.
 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  boolean isEmbeddedMapping(JavaTypeMapping mapping)
          Check if the mapping correspond to a non pc object or embedded field
 java.util.Iterator iterator(StateManager ownerSM)
          Accessor for an iterator through the array elements.
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 set(StateManager ownerSM, java.lang.Object array)
          Method to set the array for the specified owner to the passed value.
 
Methods inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
getAddStmt, getClearStmt, getElementInformationForClass, getElementType, getSizeStmt, hasOrderMapping, initialiseStatements, 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
 
Methods inherited from interface org.jpox.store.scostore.ArrayStore
getElementType, joinElementsTo, size
 
Methods inherited from interface org.jpox.store.scostore.Store
getOwnerMapping, getStoreManager
 

Field Detail

addStmt

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


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

AbstractArrayStore

protected AbstractArrayStore(StoreManager storeMgr,
                             ClassLoaderResolver clr)
Constructor.

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

getArray

public java.util.List getArray(StateManager ownerSM)
Description copied from interface: ArrayStore
Method to retrieve the elements of the array.

Specified by:
getArray in interface ArrayStore
Parameters:
ownerSM - State Manager of the owner
Returns:
The List of elements in the array (in the same order)

clear

public void clear(StateManager ownerSM)
Clear the association from owner to all elements. Observes the necessary dependent field settings with respect to whether it should delete the element when doing so.

Specified by:
clear in interface ArrayStore
Overrides:
clear in class ElementContainerStore
Parameters:
ownerSM - State Manager for the container.

set

public boolean set(StateManager ownerSM,
                   java.lang.Object array)
Method to set the array for the specified owner to the passed value.

Specified by:
set in interface ArrayStore
Parameters:
ownerSM - State Manager for the owner
array - the array
Returns:
Whether the array was updated successfully

add

public boolean add(StateManager sm,
                   java.lang.Object element,
                   int position)
Adds one element to the association owner vs elements

Parameters:
sm - State Manager for the container
element - The element to add
position - The position to add this element at
Returns:
Whether it was successful

getIteratorStatement

protected abstract QueryExpression getIteratorStatement(StateManager ownerSM)
Accessor for the statement for the iterator.

Parameters:
ownerSM - the owner StateManager
Returns:
The iterator Query Statement.

iterator

public java.util.Iterator iterator(StateManager ownerSM)
Accessor for an iterator through the array elements.

Specified by:
iterator in interface ArrayStore
Specified by:
iterator in class ElementContainerStore
Parameters:
ownerSM - State Manager for the container.
Returns:
The Iterator

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
 

Specified by:
getExistsSubquery in interface ArrayStore
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
 

Specified by:
getSizeSubquery in interface ArrayStore
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 © -2008 . All Rights Reserved.