org.jpox.store.rdbms.scostore
Class MapEntrySetStore

java.lang.Object
  extended byorg.jpox.store.rdbms.scostore.BaseContainerStore
      extended byorg.jpox.store.rdbms.scostore.MapEntrySetStore
All Implemented Interfaces:
CollectionStore, SetStore, Store

public class MapEntrySetStore
extends org.jpox.store.rdbms.scostore.BaseContainerStore
implements SetStore

Representation of backing store for a MapEntry Set.

Version:
$Revision: 1.36 $

Field Summary
protected  ClassLoaderResolver clr
           
protected  DatastoreAdapter dba
          Datastore adapter in use by this store.
protected  java.lang.String iteratorStmt
           
protected  JavaTypeMapping keyMapping
          Mapping for the key (if not PC(embedded)).
protected  java.lang.String keyType
          The key type.
protected  AbstractClassMetaData kmd
          MetaData for the key class.
protected static Localiser LOCALISER
          Localiser for messages.
protected  MapStore mapStore
          The backing store for the Map.
protected  AbstractPropertyMetaData ownerFieldMetaData
          MetaData for the field in the owner with this container.
protected  JavaTypeMapping ownerMapping
          Mapping to the owner of the container.
protected  DatastoreContainerObject setTable
          Table containing the key and value forming the entry.
protected  java.lang.String sizeStmt
           
protected  StoreManager storeMgr
          Manager for the store.
protected  DatastoreIdentifier thisIdentifier
          Identifier for the container in JDOQL queries.
protected  JavaTypeMapping valueMapping
          Mapping for the value (if not PC(embedded)).
protected  java.lang.String valueType
          The value type
protected  AbstractClassMetaData vmd
          MetaData for the value class.
 
Constructor Summary
MapEntrySetStore(DatastoreContainerObject valueTable, JavaTypeMapping ownerMapping, JavaTypeMapping keyMapping, JavaTypeMapping valueMapping, MapStore mapStore)
          Constructor when using a ForeignKey Map.
MapEntrySetStore(MapTable mapTable, MapStore mapStore, ClassLoaderResolver clr)
          Constructor when using a JoinTable map.
 
Method Summary
 boolean add(StateManager sm, java.lang.Object element)
          Method to add an entry to the Map.
 boolean addAll(StateManager sm, java.util.Collection elements)
          Method to add entries to the Map.
 void clear(StateManager sm)
          Method to clear the Map.
 boolean contains(StateManager sm, java.lang.Object element)
          Method to check if an element exists in the collection.
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.lang.String getElementType()
          Accessor for the element type.
 QueryExpression getExistsSubquery(QueryExpression stmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier collRangeVar)
          Create a subquery for the given query that joins a SetStore element table to the owner table.
 JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
 QueryExpression getSizeSubquery(QueryExpression stmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier collRangeVar)
          Create a subquery for the size() of the collection of entries.
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.
 boolean hasOrderMapping()
          Accessor for whether this store has an order mapping to allow for duplicates, or ordering.
protected  boolean isEmbeddedMapping(JavaTypeMapping mapping)
          Check if the mapping correspond to a non pc object or embedded field
 java.util.Iterator iterator(StateManager sm)
          Accessor for an iterator for the entries of the Map.
 ScalarExpression joinElementsTo(QueryExpression stmt, QueryExpression qs, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier collRangeVar, java.lang.Class filteredElementType, ScalarExpression elmExpr, DatastoreIdentifier elementRangeVar)
          Method used in queries when contains() has been invoked.
 QueryExpression newQueryStatement(StateManager sm, java.lang.String candidateClass)
          Method to return a new QueryStatement.
 Query.ResultObjectFactory newResultObjectFactory(StateManager sm, QueryExpression expr, boolean useFetchPlan)
          Method to return an object factory for processing map entry statements.
 Query.ResultObjectFactory newResultObjectFactory(StateManager sm, QueryExpression stmt, boolean ignoreCache, boolean useFetchPlan)
          Method to return an object factory for processing query statements.
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 remove(StateManager sm, java.lang.Object element)
          Method to remove an entry from the Map.
 boolean removeAll(StateManager sm, java.util.Collection elements)
          Method to remove entries from the Map.
 int size(StateManager sm)
          Accessor for the size of the Map.
 boolean updateEmbeddedElement(StateManager sm, java.lang.Object element, int fieldNumber, java.lang.Object value)
          Method to update an embedded element.
protected  boolean validateElementType(java.lang.Object element)
           
 
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.Store
getStoreManager
 

Field Detail

setTable

protected DatastoreContainerObject setTable
Table containing the key and value forming the entry.


mapStore

protected MapStore mapStore
The backing store for the Map.


keyMapping

protected JavaTypeMapping keyMapping
Mapping for the key (if not PC(embedded)).


valueMapping

protected JavaTypeMapping valueMapping
Mapping for the value (if not PC(embedded)).


keyType

protected java.lang.String keyType
The key type.


valueType

protected java.lang.String valueType
The value type


kmd

protected AbstractClassMetaData kmd
MetaData for the key class.


vmd

protected AbstractClassMetaData vmd
MetaData for the value class.


iteratorStmt

protected java.lang.String iteratorStmt

sizeStmt

protected java.lang.String sizeStmt

clr

protected ClassLoaderResolver clr

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

MapEntrySetStore

public MapEntrySetStore(MapTable mapTable,
                        MapStore mapStore,
                        ClassLoaderResolver clr)
Constructor when using a JoinTable map.

Parameters:
mapTable - Table for the map
mapStore - Store in use by the Map
clr - ClassLoader resolver

MapEntrySetStore

public MapEntrySetStore(DatastoreContainerObject valueTable,
                        JavaTypeMapping ownerMapping,
                        JavaTypeMapping keyMapping,
                        JavaTypeMapping valueMapping,
                        MapStore mapStore)
Constructor when using a ForeignKey Map.

Parameters:
valueTable - Table storing the values
ownerMapping - Mapping to the owner
keyMapping - Mapping to the key
valueMapping - Mapping to the value
mapStore - Store in use by the map.
Method Detail

hasOrderMapping

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

Specified by:
hasOrderMapping in interface CollectionStore
Returns:
Whether it has an order mapping.

updateEmbeddedElement

public boolean updateEmbeddedElement(StateManager sm,
                                     java.lang.Object element,
                                     int fieldNumber,
                                     java.lang.Object value)
Method to update an embedded element.

Specified by:
updateEmbeddedElement in interface CollectionStore
Parameters:
sm - State Manager of the owner
element - The element to update
fieldNumber - The number of the field to update
value - The value
Returns:
Whether the element was modified

getElementType

public java.lang.String getElementType()
Accessor for the element type.

Specified by:
getElementType in interface CollectionStore
Returns:
The element type.

getOwnerMapping

public JavaTypeMapping getOwnerMapping()
Accessor for the owner mapping.

Specified by:
getOwnerMapping in interface Store
Returns:
The owner mapping

validateElementType

protected boolean validateElementType(java.lang.Object element)

iterator

public java.util.Iterator iterator(StateManager sm)
Accessor for an iterator for the entries of the Map.

Specified by:
iterator in interface CollectionStore
Parameters:
sm - State manager for the owner
Returns:
The iterator

size

public int size(StateManager sm)
Accessor for the size of the Map.

Specified by:
size in interface CollectionStore
Parameters:
sm - The state manager
Returns:
The size

contains

public boolean contains(StateManager sm,
                        java.lang.Object element)
Description copied from interface: CollectionStore
Method to check if an element exists in the collection.

Specified by:
contains in interface CollectionStore
Parameters:
sm - State Manager for the collection.
element - Element to check
Returns:
Whether the element exists in the collection.

add

public boolean add(StateManager sm,
                   java.lang.Object element)
Method to add an entry to the Map.

Specified by:
add in interface CollectionStore
Parameters:
sm - State Manager for the owner
element - Entry to add
Returns:
Whether it was added

addAll

public boolean addAll(StateManager sm,
                      java.util.Collection elements)
Method to add entries to the Map.

Specified by:
addAll in interface CollectionStore
Parameters:
sm - State Manager for the owner
elements - Entries to add
Returns:
Whether they were added

remove

public boolean remove(StateManager sm,
                      java.lang.Object element)
Method to remove an entry from the Map.

Specified by:
remove in interface CollectionStore
Parameters:
sm - State Manager for the owner
element - Entry to remove
Returns:
Whether it was removed

removeAll

public boolean removeAll(StateManager sm,
                         java.util.Collection elements)
Method to remove entries from the Map.

Specified by:
removeAll in interface CollectionStore
Parameters:
sm - State Manager for the owner
elements - Entries to remove
Returns:
Whether they were removed

clear

public void clear(StateManager sm)
Method to clear the Map.

Specified by:
clear in interface CollectionStore
Parameters:
sm - State Manager for the owner.

newResultObjectFactory

public Query.ResultObjectFactory newResultObjectFactory(StateManager sm,
                                                        QueryExpression expr,
                                                        boolean useFetchPlan)
Method to return an object factory for processing map entry statements. This type of statement allows both key and value to be extracted.

Parameters:
sm - the StateManager
expr - the QueryExpression
useFetchPlan - whether to use the FetchPlan
Returns:
nothing
Throws:
javax.jdo.JDOUnsupportedOptionException - unsupported method

newQueryStatement

public QueryExpression newQueryStatement(StateManager sm,
                                         java.lang.String candidateClass)
Method to return a new QueryStatement.

Specified by:
newQueryStatement in interface CollectionStore
Parameters:
sm - StateManager for the collection.
candidateClass - The class to query
Returns:
The new QueryStatement.
Throws:
javax.jdo.JDOUnsupportedOptionException - unsupported method

newResultObjectFactory

public Query.ResultObjectFactory newResultObjectFactory(StateManager sm,
                                                        QueryExpression stmt,
                                                        boolean ignoreCache,
                                                        boolean useFetchPlan)
Method to return an object factory for processing query statements.

Specified by:
newResultObjectFactory in interface CollectionStore
Parameters:
sm - State Manager for the collection.
stmt - The Query Statement.
ignoreCache - Whether to ignore the cache.
useFetchPlan - whether to use the fetch plan to retrieve fields in the same query
Returns:
The Persistent object factory.
Throws:
javax.jdo.JDOUnsupportedOptionException - unsupported method

getExistsSubquery

public QueryExpression getExistsSubquery(QueryExpression stmt,
                                         JavaTypeMapping ownerMapping,
                                         LogicSetExpression ownerTe,
                                         DatastoreIdentifier collRangeVar)
Create a subquery for the given query that joins a SetStore element table to the owner table. This subquery can subsequently be used in an EXISTS expression to determine whether a Collection is empty.

Specified by:
getExistsSubquery in interface CollectionStore
Parameters:
stmt - The Query Statement.
ownerMapping - the mapping for the owner.
ownerTe - Table Expression for the owner
collRangeVar - The range variable for the "Collection" table.
Returns:
A subquery for the given query that joins a SetStore element table to the owner table.
Throws:
javax.jdo.JDOUnsupportedOptionException - unsupported method

getSizeSubquery

public QueryExpression getSizeSubquery(QueryExpression stmt,
                                       JavaTypeMapping ownerMapping,
                                       LogicSetExpression ownerTe,
                                       DatastoreIdentifier collRangeVar)
Create a subquery for the size() of the collection of entries.

Specified by:
getSizeSubquery in interface CollectionStore
Parameters:
stmt - The Query Statement.
ownerMapping - the mapping for the owner.
ownerTe - Table Expression for the owner
collRangeVar - The range variable for the "Collection" table.
Returns:
A subquery for the given query that joins a SetStore element table to the owner table.
Throws:
javax.jdo.JDOUnsupportedOptionException - unsupported method

joinElementsTo

public ScalarExpression joinElementsTo(QueryExpression stmt,
                                       QueryExpression qs,
                                       JavaTypeMapping ownerMapping,
                                       LogicSetExpression ownerTe,
                                       DatastoreIdentifier collRangeVar,
                                       java.lang.Class filteredElementType,
                                       ScalarExpression elmExpr,
                                       DatastoreIdentifier elementRangeVar)
Method used in queries when contains() has been invoked.

Specified by:
joinElementsTo in interface CollectionStore
Parameters:
stmt - The Query Statement
ownerMapping - the mapping for the owner.
ownerTe - Table Expression for the owner
collRangeVar - The range variable for the "Collection" table.
filteredElementType - The Class Type for the filtered element
elmExpr - The Expression for the element
elementRangeVar - The SQL alias, or "range variable", to assign to the expression or to the element table.
qs - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
Returns:
expression to the join
Throws:
javax.jdo.JDOUnsupportedOptionException - unsupported method

getStoreManager

public StoreManager getStoreManager()
Accessor for the RDBMSManager.

Returns:
The RDBMSManager.

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 © -2007 . All Rights Reserved.