org.jpox.store.rdbms.scostore
Class MapEntrySetStore

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

public class MapEntrySetStore
extends java.lang.Object
implements org.jpox.store.scostore.SetStore

Representation of backing store for a MapEntry Set.

Version:
$Revision: 1.54 $

Field Summary
protected  boolean allowsNull
          Whether the container allows null elements/values.
protected  org.jpox.ClassLoaderResolver clr
           
protected  org.jpox.store.mapped.DatastoreAdapter dba
          Datastore adapter in use by this store.
protected  java.lang.String iteratorStmt
           
protected  org.jpox.store.mapped.mapping.JavaTypeMapping keyMapping
          Mapping for the key (if not PC(embedded)).
protected  java.lang.String keyType
          The key type.
protected  org.jpox.metadata.AbstractClassMetaData kmd
          MetaData for the key class.
protected static org.jpox.util.Localiser LOCALISER
          Localiser for messages.
protected  org.jpox.store.scostore.MapStore mapStore
          The backing store for the Map.
protected  org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping
          Mapping to the owner of the container.
protected  org.jpox.metadata.AbstractMemberMetaData ownerMemberMetaData
          MetaData for the field/property in the owner with this container.
protected  org.jpox.store.mapped.DatastoreContainerObject setTable
          Table containing the key and value forming the entry.
protected  java.lang.String sizeStmt
           
protected  RDBMSManager storeMgr
          Manager for the store.
protected  org.jpox.store.mapped.mapping.JavaTypeMapping valueMapping
          Mapping for the value (if not PC(embedded)).
protected  java.lang.String valueType
          The value type
protected  org.jpox.metadata.AbstractClassMetaData vmd
          MetaData for the value class.
 
Constructor Summary
MapEntrySetStore(org.jpox.store.mapped.DatastoreContainerObject valueTable, org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping, org.jpox.store.mapped.mapping.JavaTypeMapping keyMapping, org.jpox.store.mapped.mapping.JavaTypeMapping valueMapping, org.jpox.store.scostore.MapStore mapStore)
          Constructor when using a ForeignKey Map.
MapEntrySetStore(MapTable mapTable, org.jpox.store.scostore.MapStore mapStore, org.jpox.ClassLoaderResolver clr)
          Constructor when using a JoinTable map.
 
Method Summary
 boolean add(org.jpox.StateManager sm, java.lang.Object element, int size)
          Method to add an entry to the Map.
 boolean addAll(org.jpox.StateManager sm, java.util.Collection elements, int size)
          Method to add entries to the Map.
protected  boolean allowsBatching()
          Convenience method to return if the RDBMS supports batching and the user wants batching.
 void clear(org.jpox.StateManager sm)
          Method to clear the Map.
 boolean contains(org.jpox.StateManager sm, java.lang.Object element)
           
 java.lang.String getElementType()
          Accessor for the element type.
 org.jpox.store.mapped.expression.QueryExpression getExistsSubquery(org.jpox.store.mapped.expression.QueryExpression stmt, org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping, org.jpox.store.mapped.expression.LogicSetExpression ownerTe, org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias)
          Create a subquery for the given query that joins a SetStore element table to the owner table.
 org.jpox.store.mapped.mapping.JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
 org.jpox.store.mapped.expression.QueryExpression getSizeSubquery(org.jpox.store.mapped.expression.QueryExpression stmt, org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping, org.jpox.store.mapped.expression.LogicSetExpression ownerTe, org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias)
          Create a subquery for the size() of the collection of entries.
protected  org.jpox.StateManager getStateManagerForEmbeddedPCObject(org.jpox.StateManager sm, java.lang.Object obj, JoinTable table)
          Method to return the StateManager for an embedded PC object (element, key, value).
 org.jpox.store.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(org.jpox.store.mapped.mapping.JavaTypeMapping mapping)
          Check if the mapping correspond to a non pc object or embedded field
 java.util.Iterator iterator(org.jpox.StateManager sm)
          Accessor for an iterator for the entries of the Map.
 org.jpox.store.mapped.expression.ScalarExpression joinElementsTo(org.jpox.store.mapped.expression.QueryExpression stmt, org.jpox.store.mapped.expression.QueryExpression qs, org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping, org.jpox.store.mapped.expression.LogicSetExpression ownerTe, org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias, java.lang.Class filteredElementType, org.jpox.store.mapped.expression.ScalarExpression elmExpr, org.jpox.store.mapped.DatastoreIdentifier elementTableAlias, boolean existsQuery)
          Method used in queries when contains() has been invoked.
 org.jpox.store.mapped.expression.QueryExpression newQueryStatement(org.jpox.StateManager sm, java.lang.String candidateClass, org.jpox.store.mapped.DatastoreIdentifier candidateAlias)
          Method to return a new QueryStatement.
 org.jpox.store.query.ResultObjectFactory newResultObjectFactory(org.jpox.StateManager sm, org.jpox.store.mapped.expression.QueryExpression expr, boolean useFetchPlan)
          Method to return an object factory for processing map entry statements.
 org.jpox.store.query.ResultObjectFactory newResultObjectFactory(org.jpox.StateManager sm, org.jpox.store.mapped.expression.QueryExpression stmt, boolean ignoreCache, boolean useFetchPlan)
          Method to return an object factory for processing query statements.
protected  int populateOwnerInStatement(org.jpox.StateManager sm, org.jpox.ObjectManager om, java.sql.PreparedStatement ps, int jdbcPosition)
          Convenience method to populate the passed PreparedStatement with the value from the owner.
 boolean remove(org.jpox.StateManager sm, java.lang.Object element, int size, boolean allowDependentField)
          Method to remove an entry from the Map.
 boolean removeAll(org.jpox.StateManager sm, java.util.Collection elements, int size)
          Method to remove entries from the Map.
protected  void setOwnerMemberMetaData(org.jpox.metadata.AbstractMemberMetaData mmd)
          Method to set the owner field/property MetaData and sets whether null elements/values are allowed.
 int size(org.jpox.StateManager sm)
          Accessor for the size of the Map.
 boolean updateEmbeddedElement(org.jpox.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 org.jpox.store.mapped.DatastoreContainerObject setTable
Table containing the key and value forming the entry.


mapStore

protected org.jpox.store.scostore.MapStore mapStore
The backing store for the Map.


keyMapping

protected org.jpox.store.mapped.mapping.JavaTypeMapping keyMapping
Mapping for the key (if not PC(embedded)).


valueMapping

protected org.jpox.store.mapped.mapping.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 org.jpox.metadata.AbstractClassMetaData kmd
MetaData for the key class.


vmd

protected org.jpox.metadata.AbstractClassMetaData vmd
MetaData for the value class.


iteratorStmt

protected java.lang.String iteratorStmt

sizeStmt

protected java.lang.String sizeStmt

clr

protected org.jpox.ClassLoaderResolver clr

LOCALISER

protected static final org.jpox.util.Localiser LOCALISER
Localiser for messages.


storeMgr

protected RDBMSManager storeMgr
Manager for the store.


dba

protected org.jpox.store.mapped.DatastoreAdapter dba
Datastore adapter in use by this store.


ownerMapping

protected org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping
Mapping to the owner of the container.


ownerMemberMetaData

protected org.jpox.metadata.AbstractMemberMetaData ownerMemberMetaData
MetaData for the field/property in the owner with this container.


allowsNull

protected boolean allowsNull
Whether the container allows null elements/values.

Constructor Detail

MapEntrySetStore

public MapEntrySetStore(MapTable mapTable,
                        org.jpox.store.scostore.MapStore mapStore,
                        org.jpox.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(org.jpox.store.mapped.DatastoreContainerObject valueTable,
                        org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping,
                        org.jpox.store.mapped.mapping.JavaTypeMapping keyMapping,
                        org.jpox.store.mapped.mapping.JavaTypeMapping valueMapping,
                        org.jpox.store.scostore.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 org.jpox.store.scostore.CollectionStore
Returns:
Whether it has an order mapping.

updateEmbeddedElement

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

Specified by:
updateEmbeddedElement in interface org.jpox.store.scostore.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 org.jpox.store.scostore.CollectionStore
Returns:
The element type.

getOwnerMapping

public org.jpox.store.mapped.mapping.JavaTypeMapping getOwnerMapping()
Accessor for the owner mapping.

Returns:
The owner mapping

validateElementType

protected boolean validateElementType(java.lang.Object element)

iterator

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

Specified by:
iterator in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - State manager for the owner
Returns:
The iterator

size

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

Specified by:
size in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - The state manager
Returns:
The size

contains

public boolean contains(org.jpox.StateManager sm,
                        java.lang.Object element)
Specified by:
contains in interface org.jpox.store.scostore.CollectionStore

add

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

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

addAll

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

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

remove

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

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

removeAll

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

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

clear

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

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

newResultObjectFactory

public org.jpox.store.query.ResultObjectFactory newResultObjectFactory(org.jpox.StateManager sm,
                                                                       org.jpox.store.mapped.expression.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:
org.jpox.exceptions.JPOXUserException - unsupported method

newQueryStatement

public org.jpox.store.mapped.expression.QueryExpression newQueryStatement(org.jpox.StateManager sm,
                                                                          java.lang.String candidateClass,
                                                                          org.jpox.store.mapped.DatastoreIdentifier candidateAlias)
Method to return a new QueryStatement.

Parameters:
sm - StateManager for the collection.
candidateClass - The class to query
candidateAlias - Alias for the candidate
Returns:
The new QueryStatement.
Throws:
org.jpox.exceptions.JPOXUserException - unsupported method

newResultObjectFactory

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

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:
org.jpox.exceptions.JPOXUserException - unsupported method

getExistsSubquery

public org.jpox.store.mapped.expression.QueryExpression getExistsSubquery(org.jpox.store.mapped.expression.QueryExpression stmt,
                                                                          org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping,
                                                                          org.jpox.store.mapped.expression.LogicSetExpression ownerTe,
                                                                          org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias)
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.

Parameters:
stmt - The Query Statement.
ownerMapping - the mapping for the owner.
ownerTe - Table Expression for the owner
collectionTableAlias - Alias for the "Collection" table.
Returns:
A subquery for the given query that joins a SetStore element table to the owner table.
Throws:
org.jpox.exceptions.JPOXUserException - unsupported method

getSizeSubquery

public org.jpox.store.mapped.expression.QueryExpression getSizeSubquery(org.jpox.store.mapped.expression.QueryExpression stmt,
                                                                        org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping,
                                                                        org.jpox.store.mapped.expression.LogicSetExpression ownerTe,
                                                                        org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias)
Create a subquery for the size() of the collection of entries.

Parameters:
stmt - The Query Statement.
ownerMapping - the mapping for the owner.
ownerTe - Table Expression for the owner
collectionTableAlias - Alias for the "Collection" table.
Returns:
A subquery for the given query that joins a SetStore element table to the owner table.
Throws:
org.jpox.exceptions.JPOXUserException - unsupported method

joinElementsTo

public org.jpox.store.mapped.expression.ScalarExpression joinElementsTo(org.jpox.store.mapped.expression.QueryExpression stmt,
                                                                        org.jpox.store.mapped.expression.QueryExpression qs,
                                                                        org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping,
                                                                        org.jpox.store.mapped.expression.LogicSetExpression ownerTe,
                                                                        org.jpox.store.mapped.DatastoreIdentifier collectionTableAlias,
                                                                        java.lang.Class filteredElementType,
                                                                        org.jpox.store.mapped.expression.ScalarExpression elmExpr,
                                                                        org.jpox.store.mapped.DatastoreIdentifier elementTableAlias,
                                                                        boolean existsQuery)
Method used in queries when contains() has been invoked.

Parameters:
stmt - The Query Statement
ownerMapping - the mapping for the owner.
ownerTe - Table Expression for the owner
collectionTableAlias - Alias for the "Collection" table.
filteredElementType - The Class Type for the filtered element
elmExpr - The Expression for the element
elementTableAlias - The SQL alias to assign to the expression or to the element table.
Returns:
expression to the join
Throws:
org.jpox.exceptions.JPOXUserException - unsupported method

setOwnerMemberMetaData

protected void setOwnerMemberMetaData(org.jpox.metadata.AbstractMemberMetaData mmd)
Method to set the owner field/property MetaData and sets whether null elements/values are allowed.

Parameters:
mmd - MetaData for the field/property owning this backing store.

getStoreManager

public org.jpox.store.StoreManager getStoreManager()
Accessor for the RDBMSManager.

Returns:
The RDBMSManager.

isEmbeddedMapping

protected boolean isEmbeddedMapping(org.jpox.store.mapped.mapping.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(org.jpox.StateManager sm,
                                       org.jpox.ObjectManager om,
                                       java.sql.PreparedStatement ps,
                                       int jdbcPosition)
Convenience method to populate the passed PreparedStatement with the value from the owner.

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

getStateManagerForEmbeddedPCObject

protected org.jpox.StateManager getStateManagerForEmbeddedPCObject(org.jpox.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

allowsBatching

protected boolean allowsBatching()
Convenience method to return if the RDBMS supports batching and the user wants batching.

Returns:
If batching of statements is permissible


Copyright © -2008 . All Rights Reserved.