org.jpox.store.rdbms.scostore
Class FKMapStore

java.lang.Object
  extended byorg.jpox.store.rdbms.scostore.BaseContainerStore
      extended byorg.jpox.store.rdbms.scostore.AbstractMapStore
          extended byorg.jpox.store.rdbms.scostore.FKMapStore
All Implemented Interfaces:
MapStore, Store

public class FKMapStore
extends org.jpox.store.rdbms.scostore.AbstractMapStore

Representation of an "inverse" (FK) backing for a Map. This class is used where you have a 1-N and the tables are not joined via a link table. There are 2 possible uses here

In both cases the value class will have a field that represents the key, and so the user must specify a 'key mapped-by="..."' attribute to denote which field is the key. TODO Allow for 'value mapped-by="..."' where the key is a PC, and the value is a field in the key. This will need keyTable adding, and the various selects using keyTable instead of valueTable etc (i.e reverse what is there now).

Version:
$Revision: 1.4 $

Field Summary
protected  java.lang.String containsValueStmt
           
protected  DatastoreAdapter dba
          Datastore adapter in use by this store.
protected  DatastoreIdentifier elmIdentifier
          Identifier for elements in JDOQL queries.
protected  boolean iterateUsingDiscriminator
          Flag to set whether the iterator statement will use a discriminator or not.
protected  JavaTypeMapping keyMapping
          Mapping to the key.
protected  boolean keysAreEmbedded
          Whether the keys are embedded.
protected  boolean keysAreSerialised
          Whether the keys are serialised.
protected  java.lang.String keyType
          Type of the key.
protected  AbstractClassMetaData kmd
           
protected static Localiser LOCALISER
          Localiser for messages.
protected  DatastoreContainerObject mapTable
           
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.
protected  JavaTypeMapping valueMapping
          Mapping to the value.
protected  boolean valuesAreEmbedded
          Whether the values are embedded.
protected  boolean valuesAreSerialised
          Whether the values are serialised.
protected  DatastoreClass valueTable
           
protected  java.lang.String valueType
          Type of the value.
protected  AbstractClassMetaData vmd
           
 
Constructor Summary
FKMapStore(AbstractPropertyMetaData fmd, RDBMSManager storeMgr, ClassLoaderResolver clr)
          Constructor for an Inverse Map.
 
Method Summary
 void clear(StateManager sm)
          Method to clear the map of all values.
 void clearKeyOfValue(StateManager sm, java.lang.Object key, java.lang.Object oldValue)
          Utility to clear the key of a value from the Map.
 boolean containsKey(StateManager sm, java.lang.Object key)
          Method to check if a key exists in the Map.
 boolean containsValue(StateManager sm, java.lang.Object value)
          Method to check if a value exists in the Map.
 SetStore entrySetStore()
          Accessor for the map entries in the Map.
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.Object get(StateManager sm, java.lang.Object key)
          Method to return the value for a key.
 QueryExpression getExistsSubquery(QueryExpression qs, JavaTypeMapping mapping, LogicSetExpression ownerTe, DatastoreIdentifier mapRangeVar)
          Method used where a Query uses map.isEmpty().
protected  QueryExpression getGetStatement(StateManager ownerSm, java.lang.Object key)
          Accessor for the Get statement to retrieve a value from the Map.
 java.lang.String getKeyType()
          Accessor for the key type for storing in this Map.
 JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
 QueryExpression getSizeSubquery(QueryExpression qs, JavaTypeMapping mapping, LogicSetExpression ownerTe, DatastoreIdentifier mapRangeVar)
          JDOQL utility to generate a subquery for the size() of the map.
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 getUpdateEmbeddedKeyStmt(JavaTypeMapping fieldMapping)
          Generate statement for update the field of an embedded key.
protected  java.lang.String getUpdateEmbeddedValueStmt(JavaTypeMapping fieldMapping)
          Generate statement for update the field of an embedded value.
protected  java.lang.Object getValue(StateManager sm, java.lang.Object key)
          Method to retrieve a value from the Map given the key.
 java.lang.String getValueType()
          Accessor for the value type for storing in this Map.
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
 ScalarExpression joinKeysTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression te, DatastoreIdentifier mapRangeVar, java.lang.Class filteredKeyType, ScalarExpression kExpr, DatastoreIdentifier keyRangeVar)
          Utility to create a join for keys to be used in a containsKey() query.
 ScalarExpression[] joinKeysToGet(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression te, DatastoreIdentifier mapRangeVar, java.lang.Class filteredKeyType, DatastoreIdentifier keyRangeVar, DatastoreIdentifier valueRangeVar)
          Used as part of the Querying of Maps where a get(Key) is used.
 ScalarExpression[] joinKeysValuesTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier mapRangeVar, java.lang.Class filteredKeyType, java.lang.Class filteredValueType, ScalarExpression keyExpr, ScalarExpression valExpr, DatastoreIdentifier keyRangeVar, DatastoreIdentifier valueRangeVar)
          Utility to create a join for keys and values to be used in ai containsEntry() query.
 ScalarExpression joinValuesTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier mapRangeVar, java.lang.Class filteredValueType, ScalarExpression valExpr, DatastoreIdentifier valueRangeVar)
          Used as part of the Querying of Maps where a containsValue() is used.
 boolean keysAreEmbedded()
          Accessor for whether the keys are embedded or not.
 boolean keysAreSerialised()
          Accessor for whether the keys are serialised or not.
 SetStore keySetStore(ClassLoaderResolver clr)
          Accessor for the keys in the Map.
 QueryExpression newQueryStatement(StateManager sm, java.lang.String candidateClass)
          Utility method to return a new QueryStatement for retrieval of the elements of this Map.
 Query.ResultObjectFactory newResultObjectFactory(StateManager sm, QueryExpression stmt, boolean ignoreCache, boolean useFetchPlan)
          Method to create a Result Object factory for extracting objects from a ResultSet.
protected  int populateEmbeddedKeyFieldsInStatement(StateManager sm, java.lang.Object key, java.sql.PreparedStatement ps, int jdbcPosition, JoinTable joinTable)
          Convenience method to populate the passed PreparedStatement with the field values from the embedded key starting at the specified jdbc position.
protected  int populateEmbeddedValueFieldsInStatement(StateManager sm, java.lang.Object value, java.sql.PreparedStatement ps, int jdbcPosition, JoinTable joinTable)
          Convenience method to populate the passed PreparedStatement with the field values from the embedded value starting at the specified jdbc position.
protected  int populateKeyInStatement(PersistenceManager pm, java.sql.PreparedStatement ps, java.lang.Object key, int jdbcPosition)
          Convenience method to populate the passed PreparedStatement with the value for the key.
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.
protected  int populateValueInStatement(PersistenceManager pm, java.sql.PreparedStatement ps, java.lang.Object value, int jdbcPosition)
          Convenience method to populate the passed PreparedStatement with the value for the value.
 java.lang.Object put(StateManager sm, java.lang.Object newKey, java.lang.Object newValue)
          Method to put an item in the Map.
 void putAll(StateManager sm, java.util.Map m)
          Method to put all elements from a Map into our Map.
 java.lang.Object remove(StateManager sm, java.lang.Object key)
          Method to remove an item from the map.
 boolean updateEmbeddedKey(StateManager sm, java.lang.Object key, int fieldNumber, java.lang.Object newValue)
          Method to update a field of an embedded key.
 boolean updateEmbeddedValue(StateManager sm, java.lang.Object value, int fieldNumber, java.lang.Object newValue)
          Method to update a field of an embedded key.
protected  boolean validateKeyForReading(StateManager sm, java.lang.Object key)
          Utility to validate a key is ok for reading.
protected  void validateKeyForWriting(StateManager sm, java.lang.Object key)
          Method to check if an key is already persistent, or is managed by a different Persistencemanager.
protected  void validateKeyType(ClassLoaderResolver clr, java.lang.Object key)
          Utility to validate the type of a key for storing in the Map.
protected  boolean validateValueForReading(StateManager sm, java.lang.Object value)
          Utility to validate a value is ok for reading.
protected  void validateValueForWriting(StateManager sm, java.lang.Object value)
          Method to check if an value is already persistent, or is managed by a different Persistencemanager.
protected  void validateValueType(ClassLoaderResolver clr, java.lang.Object value)
          Utility to validate the type of a value for storing in the Map.
 boolean valuesAreEmbedded()
          Accessor for whether the values are embedded or not.
 boolean valuesAreSerialised()
          Accessor for whether the values are serialised or not.
 SetStore valueSetStore(ClassLoaderResolver clr)
          Accessor for the values in the Map.
 
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
getOwnerMapping, getStoreManager
 

Field Detail

iterateUsingDiscriminator

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


mapTable

protected DatastoreContainerObject mapTable

valueTable

protected DatastoreClass valueTable

kmd

protected AbstractClassMetaData kmd

vmd

protected AbstractClassMetaData vmd

keyMapping

protected JavaTypeMapping keyMapping
Mapping to the key.


valueMapping

protected JavaTypeMapping valueMapping
Mapping to the value.


keyType

protected java.lang.String keyType
Type of the key.


valueType

protected java.lang.String valueType
Type of the value.


keysAreEmbedded

protected boolean keysAreEmbedded
Whether the keys are embedded.


keysAreSerialised

protected boolean keysAreSerialised
Whether the keys are serialised.


valuesAreEmbedded

protected boolean valuesAreEmbedded
Whether the values are embedded.


valuesAreSerialised

protected boolean valuesAreSerialised
Whether the values are serialised.


containsValueStmt

protected java.lang.String containsValueStmt

elmIdentifier

protected final DatastoreIdentifier elmIdentifier
Identifier for elements in JDOQL queries.


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

FKMapStore

public FKMapStore(AbstractPropertyMetaData fmd,
                  RDBMSManager storeMgr,
                  ClassLoaderResolver clr)
Constructor for an Inverse Map.

Parameters:
fmd - Field Meta-Data for the Map field.
storeMgr - The Store Manager we are using.
clr - The ClassLoaderResolver
Method Detail

getGetStatement

protected QueryExpression getGetStatement(StateManager ownerSm,
                                          java.lang.Object key)
Accessor for the Get statement to retrieve a value from the Map.

Parameters:
ownerSm - The owner StateManager
key - The search key
Returns:
The QueryStatement.

validateValueType

protected void validateValueType(ClassLoaderResolver clr,
                                 java.lang.Object value)
Utility to validate the type of a value for storing in the Map.

Parameters:
value - The value to check.
clr - The ClassLoaderResolver

validateValueForWriting

protected void validateValueForWriting(StateManager sm,
                                       java.lang.Object value)
Method to check if an value is already persistent, or is managed by a different Persistencemanager. If not persistent, this will persist it.

Parameters:
sm - The state manager of this collection
value - The value

validateKeyForWriting

protected void validateKeyForWriting(StateManager sm,
                                     java.lang.Object key)
Method to check if an key is already persistent, or is managed by a different Persistencemanager. If not persistent, this will persist it.

Parameters:
sm - The state manager of this collection
key - The key

put

public java.lang.Object put(StateManager sm,
                            java.lang.Object newKey,
                            java.lang.Object newValue)
Method to put an item in the Map.

Parameters:
sm - State Manager for the map.
newKey - The key to store the value against
newValue - The value to store.
Returns:
The value stored.

remove

public java.lang.Object remove(StateManager sm,
                               java.lang.Object key)
Method to remove an item from the map.

Parameters:
sm - State Manager for the map.
key - Key of the item to remove.
Returns:
The value that was removed.

clear

public void clear(StateManager sm)
Method to clear the map of all values.

Parameters:
sm - State Manager for the map.

clearKeyOfValue

public void clearKeyOfValue(StateManager sm,
                            java.lang.Object key,
                            java.lang.Object oldValue)
Utility to clear the key of a value from the Map. If the key is non nullable, delete the value.

Parameters:
sm - State Manager for the map.
key - Key of the object
oldValue - Value to remove

keySetStore

public SetStore keySetStore(ClassLoaderResolver clr)
Accessor for the keys in the Map.

Parameters:
clr - The ClassLoaderResolver
Returns:
The keys

valueSetStore

public SetStore valueSetStore(ClassLoaderResolver clr)
Accessor for the values in the Map.

Parameters:
clr - The ClassLoaderResolver
Returns:
The values.

entrySetStore

public SetStore entrySetStore()
Accessor for the map entries in the Map.

Returns:
The map entries.

newQueryStatement

public QueryExpression newQueryStatement(StateManager sm,
                                         java.lang.String candidateClass)
Utility method to return a new QueryStatement for retrieval of the elements of this Map.

Parameters:
sm - StateManager for this object
candidateClass - Class for the value end of the link.
Returns:
The QueryStatement

joinKeysTo

public ScalarExpression joinKeysTo(QueryExpression stmt,
                                   QueryExpression parentStmt,
                                   JavaTypeMapping ownerMapping,
                                   LogicSetExpression te,
                                   DatastoreIdentifier mapRangeVar,
                                   java.lang.Class filteredKeyType,
                                   ScalarExpression kExpr,
                                   DatastoreIdentifier keyRangeVar)
Utility to create a join for keys to be used in a containsKey() query.

Parameters:
stmt - The Query Statement
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - Mapping for the owner
te - Table Expression for the owner
mapRangeVar - The range variable for the "Map" table.
filteredKeyType - The Class Type for the filtered key
keyRangeVar - The SQL alias, or "range variable", to assign to the expression or to the key table.
kExpr - the expression to the key field
Returns:
QueryColumnList with the columns from the key mapping

joinValuesTo

public ScalarExpression joinValuesTo(QueryExpression stmt,
                                     QueryExpression parentStmt,
                                     JavaTypeMapping ownerMapping,
                                     LogicSetExpression ownerTe,
                                     DatastoreIdentifier mapRangeVar,
                                     java.lang.Class filteredValueType,
                                     ScalarExpression valExpr,
                                     DatastoreIdentifier valueRangeVar)
Used as part of the Querying of Maps where a containsValue() is used.

Parameters:
stmt - The Query Statement
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - Mapping for the owner
ownerTe - Table Expression for the owner
mapRangeVar - The range variable for the "Map" table.
filteredValueType - The Class Type for the filtered value
valExpr - Table Expression for the value
valueRangeVar - The SQL alias, or "range variable", to assign to the expression or to the value table.
Returns:
QueryColumnList with the columns from the value mapping

joinKeysValuesTo

public ScalarExpression[] joinKeysValuesTo(QueryExpression stmt,
                                           QueryExpression parentStmt,
                                           JavaTypeMapping ownerMapping,
                                           LogicSetExpression ownerTe,
                                           DatastoreIdentifier mapRangeVar,
                                           java.lang.Class filteredKeyType,
                                           java.lang.Class filteredValueType,
                                           ScalarExpression keyExpr,
                                           ScalarExpression valExpr,
                                           DatastoreIdentifier keyRangeVar,
                                           DatastoreIdentifier valueRangeVar)
Utility to create a join for keys and values to be used in ai containsEntry() query.

Parameters:
stmt - The Query Statement to apply the join
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - Mapping for the owner
ownerTe - Table Expression for the owner
mapRangeVar - The SQL alias, or "range variable", to assign to the expression or to the main table.
filteredKeyType - The Class Type for the filtered key
filteredValueType - The Class Type for the filtered value
keyExpr - the expression to the key field
valExpr - Table Expression for the value
keyRangeVar - The SQL alias, or "range variable", to assign to the expression or to the key table.
valueRangeVar - The SQL alias, or "range variable", to assign to the expression or to the value table.
Returns:
an array with 2 elements of QueryColumnList. The first element contains the columns from the key mapping and the second element the columns from the value mapping

initialiseStatements

protected void initialiseStatements()
Method to initialise the statements being used. Subclasses should override the getXXXStmt() if they want to use an alternative statement.


keysAreEmbedded

public boolean keysAreEmbedded()
Accessor for whether the keys are embedded or not. If they are PC instances then returns false;

Specified by:
keysAreEmbedded in interface MapStore
Returns:
Whether the keys are embedded

keysAreSerialised

public boolean keysAreSerialised()
Accessor for whether the keys are serialised or not. If they are PC instances then returns false;

Specified by:
keysAreSerialised in interface MapStore
Returns:
Whether the keys are serialised

valuesAreEmbedded

public boolean valuesAreEmbedded()
Accessor for whether the values are embedded or not. If they are PC instances then returns false;

Specified by:
valuesAreEmbedded in interface MapStore
Returns:
Whether the values are embedded

valuesAreSerialised

public boolean valuesAreSerialised()
Accessor for whether the values are serialised or not. If they are PC instances then returns false;

Specified by:
valuesAreSerialised in interface MapStore
Returns:
Whether the values are serialised

getKeyType

public java.lang.String getKeyType()
Accessor for the key type for storing in this Map.

Specified by:
getKeyType in interface MapStore
Returns:
The type of the key

getValueType

public java.lang.String getValueType()
Accessor for the value type for storing in this Map. Types inherited from this (base) type can also be stored as values.

Specified by:
getValueType in interface MapStore
Returns:
The type of the value (base class).

containsKey

public boolean containsKey(StateManager sm,
                           java.lang.Object key)
Method to check if a key exists in the Map.

Specified by:
containsKey in interface MapStore
Parameters:
sm - State Manager for the map
key - The key to check for.
Returns:
Whether the key exists in the Map.

containsValue

public boolean containsValue(StateManager sm,
                             java.lang.Object value)
Method to check if a value exists in the Map.

Specified by:
containsValue in interface MapStore
Parameters:
sm - State Manager for the map
value - The value to check for.
Returns:
Whether the value exists in the Map.

get

public java.lang.Object get(StateManager sm,
                            java.lang.Object key)
Method to return the value for a key.

Specified by:
get in interface MapStore
Parameters:
sm - State Manager for the Map.
key - The key of the object to retrieve.
Returns:
The value for this key.

putAll

public void putAll(StateManager sm,
                   java.util.Map m)
Method to put all elements from a Map into our Map.

Specified by:
putAll in interface MapStore
Parameters:
sm - State Manager for the Map
m - The Map to add

validateKeyType

protected void validateKeyType(ClassLoaderResolver clr,
                               java.lang.Object key)
Utility to validate the type of a key for storing in the Map.

Parameters:
clr - The ClassLoaderResolver
key - The key to check.

validateKeyForReading

protected boolean validateKeyForReading(StateManager sm,
                                        java.lang.Object key)
Utility to validate a key is ok for reading.

Parameters:
sm - State Manager for the map.
key - The key to check.
Returns:
Whether it is validated.

validateValueForReading

protected boolean validateValueForReading(StateManager sm,
                                          java.lang.Object value)
Utility to validate a value is ok for reading.

Parameters:
sm - State Manager for the map.
value - The value to check.
Returns:
Whether it is validated.

getValue

protected java.lang.Object getValue(StateManager sm,
                                    java.lang.Object key)
                             throws java.util.NoSuchElementException
Method to retrieve a value from the Map given the key.

Parameters:
sm - State Manager for the map.
key - The key to retrieve the value for.
Returns:
The value for this key
Throws:
java.util.NoSuchElementException - if the value for the key was not found

populateKeyInStatement

protected int populateKeyInStatement(PersistenceManager pm,
                                     java.sql.PreparedStatement ps,
                                     java.lang.Object key,
                                     int jdbcPosition)
Convenience method to populate the passed PreparedStatement with the value for the key. Not used with embedded PC elements.

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

populateValueInStatement

protected int populateValueInStatement(PersistenceManager pm,
                                       java.sql.PreparedStatement ps,
                                       java.lang.Object value,
                                       int jdbcPosition)
Convenience method to populate the passed PreparedStatement with the value for the value. Not used with embedded PC elements.

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

populateEmbeddedKeyFieldsInStatement

protected int populateEmbeddedKeyFieldsInStatement(StateManager sm,
                                                   java.lang.Object key,
                                                   java.sql.PreparedStatement ps,
                                                   int jdbcPosition,
                                                   JoinTable joinTable)
Convenience method to populate the passed PreparedStatement with the field values from the embedded key starting at the specified jdbc position.

Parameters:
sm - State Manager of the owning container
key - The embedded key
ps - The PreparedStatement
jdbcPosition - JDBC position in the statement to start at
joinTable - The Join table where the values are embedded
Returns:
The next JDBC position

populateEmbeddedValueFieldsInStatement

protected int populateEmbeddedValueFieldsInStatement(StateManager sm,
                                                     java.lang.Object value,
                                                     java.sql.PreparedStatement ps,
                                                     int jdbcPosition,
                                                     JoinTable joinTable)
Convenience method to populate the passed PreparedStatement with the field values from the embedded value starting at the specified jdbc position.

Parameters:
sm - State Manager of the owning container
value - The embedded value
ps - The PreparedStatement
jdbcPosition - JDBC position in the statement to start at
joinTable - The Join table where the values are embedded
Returns:
The next JDBC position

updateEmbeddedKey

public boolean updateEmbeddedKey(StateManager sm,
                                 java.lang.Object key,
                                 int fieldNumber,
                                 java.lang.Object newValue)
Method to update a field of an embedded key.

Specified by:
updateEmbeddedKey in interface MapStore
Parameters:
sm - State Manager of the owner
key - The key to update
fieldNumber - The number of the field to update
newValue - The new value
Returns:
Whether the element was modified

updateEmbeddedValue

public boolean updateEmbeddedValue(StateManager sm,
                                   java.lang.Object value,
                                   int fieldNumber,
                                   java.lang.Object newValue)
Method to update a field of an embedded key.

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

getUpdateEmbeddedKeyStmt

protected java.lang.String getUpdateEmbeddedKeyStmt(JavaTypeMapping fieldMapping)
Generate statement for update the field of an embedded key.
 UPDATE MAPTABLE
 SET EMBEDDEDKEYCOL1 = ?
 WHERE OWNERCOL=?
 AND EMBEDDEDKEYCOL1 = ?
 AND EMBEDDEDKEYCOL2 = ? ...
 

Parameters:
fieldMapping - The mapping for the field to be updated
Returns:
Statement for updating an embedded key in the Set

getUpdateEmbeddedValueStmt

protected java.lang.String getUpdateEmbeddedValueStmt(JavaTypeMapping fieldMapping)
Generate statement for update the field of an embedded value.
 UPDATE MAPTABLE
 SET EMBEDDEDVALUECOL1 = ?
 WHERE OWNERCOL=?
 AND EMBEDDEDVALUECOL1 = ?
 AND EMBEDDEDVALUECOL2 = ? ...
 

Parameters:
fieldMapping - The mapping for the field to be updated
Returns:
Statement for updating an embedded value in the Set

newResultObjectFactory

public Query.ResultObjectFactory newResultObjectFactory(StateManager sm,
                                                        QueryExpression stmt,
                                                        boolean ignoreCache,
                                                        boolean useFetchPlan)
Method to create a Result Object factory for extracting objects from a ResultSet.

Specified by:
newResultObjectFactory in interface MapStore
Parameters:
sm - State Manager of owner field
stmt - The Query statement
ignoreCache - Whether to ignore the cache
useFetchPlan - Whether to retrieve the fetch plan fields or DFG
Returns:
The Result Object factory

getExistsSubquery

public QueryExpression getExistsSubquery(QueryExpression qs,
                                         JavaTypeMapping mapping,
                                         LogicSetExpression ownerTe,
                                         DatastoreIdentifier mapRangeVar)
Method used where a Query uses map.isEmpty().

Specified by:
getExistsSubquery in interface MapStore
Parameters:
qs - The QueryStatement
mapping - The mapping of the java type
ownerTe - The owner table expression
mapRangeVar - The range variable for the "Map" table.
Returns:
A subquery

getSizeSubquery

public QueryExpression getSizeSubquery(QueryExpression qs,
                                       JavaTypeMapping mapping,
                                       LogicSetExpression ownerTe,
                                       DatastoreIdentifier mapRangeVar)
JDOQL utility to generate a subquery for the size() of the map.

Specified by:
getSizeSubquery in interface MapStore
Parameters:
qs - The JDOQL query statement
mapping - mapping of the field
ownerTe - Expression for the table
mapRangeVar - range variable for the map
Returns:
The JDOQL query statement

joinKeysToGet

public ScalarExpression[] joinKeysToGet(QueryExpression stmt,
                                        QueryExpression parentStmt,
                                        JavaTypeMapping ownerMapping,
                                        LogicSetExpression te,
                                        DatastoreIdentifier mapRangeVar,
                                        java.lang.Class filteredKeyType,
                                        DatastoreIdentifier keyRangeVar,
                                        DatastoreIdentifier valueRangeVar)
Used as part of the Querying of Maps where a get(Key) is used.

Specified by:
joinKeysToGet in interface MapStore
Parameters:
stmt - The Query Statement to apply the join
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - Mapping for the owner.
te - Table Expression for the owner
mapRangeVar - The SQL alias, or "range variable", to assign to the expression or to the main table.
filteredKeyType - The Class Type for the filtered key
keyRangeVar - The SQL alias, or "range variable", to assign to the expression or to the key table.
valueRangeVar - The SQL alias, or "range variable", to assign to the expression or to the value table.
Returns:
an array with 2 elements of QueryColumnList. The first element contains the columns from the key mapping and the second element the columns from the value mapping

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