org.jpox.store.rdbms.scostore
Class MapKeySetStore

java.lang.Object
  extended by org.jpox.store.rdbms.scostore.ElementContainerStore
      extended by org.jpox.store.rdbms.scostore.AbstractCollectionStore
          extended by org.jpox.store.rdbms.scostore.MapKeySetStore
All Implemented Interfaces:
CollectionStore, SetStore, Store

public class MapKeySetStore
extends AbstractCollectionStore

Representation of the backing store for a MapKey Set. This is used where the user calls Map.keySet() and then wants to perform some operation on the resulting Collection. The keys for a Map can be stored in several ways. There are four possibilities

TODO Cater for embedded keys

Version:
$Revision: 1.38 $

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
protected  java.lang.String addStmt
           
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  java.lang.String removeStmt
           
protected  java.lang.String setName
           
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.AbstractCollectionStore
containsStmt
 
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
MapKeySetStore(DatastoreContainerObject valueTable, JavaTypeMapping ownerMapping, JavaTypeMapping keyMapping, ClassLoaderResolver clr)
          Constructor.
MapKeySetStore(MapTable mapTable, ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 boolean add(StateManager sm, java.lang.Object element)
          Method to add an element.
 boolean addAll(StateManager sm, java.util.Collection elements)
          Adds all elements from a collection to the association owner vs elements
 void clear(StateManager sm)
          Method to clear 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.
protected  QueryExpression getIteratorStatement(StateManager ownerSM)
          Method to create an iterator for the map keys.
 JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
protected  java.lang.String getRemoveStmt()
          Generate statement for deleting an item from the Set.
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  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
 java.util.Iterator iterator(StateManager ownerSM)
          Accessor for an iterator for the set.
 ScalarExpression joinElementsTo(QueryExpression stmt, QueryExpression qs, JavaTypeMapping ownerMapping, LogicSetExpression te, DatastoreIdentifier setRangeVar, 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 Query Statement containing the candidate class.
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 element.
 boolean removeAll(StateManager sm, java.util.Collection elements)
          Remove all elements from a collection from the association owner vs elements.
 
Methods inherited from class org.jpox.store.rdbms.scostore.AbstractCollectionStore
contains, getContainsStmt, getExistsSubquery, getSizeSubquery, getUpdateEmbeddedElementStmt, updateEmbeddedElement
 
Methods inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
getAddStmt, getClearStmt, getElementInformationForClass, getElementType, getSizeStmt, hasOrderMapping, 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.CollectionStore
contains, getElementType, getExistsSubquery, getSizeSubquery, hasOrderMapping, newResultObjectFactory, size, updateEmbeddedElement
 
Methods inherited from interface org.jpox.store.scostore.Store
getOwnerMapping, getStoreManager
 

Field Detail

setName

protected java.lang.String setName

addStmt

protected java.lang.String addStmt

removeStmt

protected java.lang.String removeStmt

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

MapKeySetStore

public MapKeySetStore(MapTable mapTable,
                      ClassLoaderResolver clr)
Constructor.

Parameters:
mapTable - The table for the map (join table)
clr - The ClassLoaderResolver

MapKeySetStore

public MapKeySetStore(DatastoreContainerObject valueTable,
                      JavaTypeMapping ownerMapping,
                      JavaTypeMapping keyMapping,
                      ClassLoaderResolver clr)
Constructor.

Parameters:
valueTable - The table for the "value" of the map
ownerMapping - The mapping for this table to the owner table
keyMapping - The mapping for this table to the key table
clr - The ClassLoaderResolver
Method Detail

getIteratorStatement

protected QueryExpression getIteratorStatement(StateManager ownerSM)
Method to create an iterator for the map keys.

Parameters:
ownerSM - StateManager for the map
Returns:
the QueryStatement

add

public boolean add(StateManager sm,
                   java.lang.Object element)
Method to add an element. Overridden because we want to prevent it.

Specified by:
add in interface CollectionStore
Parameters:
sm - State Manager of collection.
element - Element to add.
Returns:
Whether it was successful

remove

public boolean remove(StateManager sm,
                      java.lang.Object element)
Method to remove an element. Overridden because we want to prevent it.

Specified by:
remove in interface CollectionStore
Parameters:
sm - State Manager of collection.
element - Element to remove.
Returns:
Whether it was successful

clear

public void clear(StateManager sm)
Method to clear the collection. Overridden because we want to prevent it.

Specified by:
clear in interface CollectionStore
Overrides:
clear in class ElementContainerStore
Parameters:
sm - State Manager of collection.

joinElementsTo

public ScalarExpression joinElementsTo(QueryExpression stmt,
                                       QueryExpression qs,
                                       JavaTypeMapping ownerMapping,
                                       LogicSetExpression te,
                                       DatastoreIdentifier setRangeVar,
                                       java.lang.Class filteredElementType,
                                       ScalarExpression elmExpr,
                                       DatastoreIdentifier elementRangeVar)
Description copied from interface: CollectionStore
Method used in queries when contains() has been invoked.

Parameters:
stmt - The Query Statement
qs - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - the mapping for the owner.
te - Table Expression for the owner
setRangeVar - 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.
Returns:
expression to the join

newQueryStatement

public QueryExpression newQueryStatement(StateManager sm,
                                         java.lang.String candidateClass)
Description copied from interface: CollectionStore
Method to return a new Query Statement containing the candidate class.

Parameters:
sm - State Manager for the collection.
candidateClass - Class of the elements.
Returns:
The Query Statement.

initialiseStatements

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

Overrides:
initialiseStatements in class AbstractCollectionStore

iterator

public java.util.Iterator iterator(StateManager ownerSM)
Accessor for an iterator for the set.

Specified by:
iterator in interface CollectionStore
Specified by:
iterator in class ElementContainerStore
Parameters:
ownerSM - State Manager for the set.
Returns:
Iterator for the set.

addAll

public boolean addAll(StateManager sm,
                      java.util.Collection elements)
Adds all elements from a collection to the association owner vs elements

Specified by:
addAll in interface CollectionStore
Parameters:
sm - State Manager for the container
elements - The elements to add
Returns:
Whether it was successful

removeAll

public boolean removeAll(StateManager sm,
                         java.util.Collection elements)
Remove all elements from a collection from the association owner vs elements. This implementation iterates around the remove() method doing each element 1 at a time. Please refer to the NormalSetStore and InverseSetStore for the variations used there.

Specified by:
removeAll in interface CollectionStore
Parameters:
sm - State Manager for the container
elements - Collection of elements to remove
Returns:
Whether the database was updated

getRemoveStmt

protected java.lang.String getRemoveStmt()
Generate statement for deleting an item from the Set.
 DELETE FROM SETTABLE 
 WHERE OWNERCOL=?
 AND ELEMENTCOL = ?
 [AND DISCRIM = ?]
 

Returns:
Statement for deleting an item from the Set.

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