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:
org.jpox.store.mapped.scostore.CollectionStoreQueryable, org.jpox.store.scostore.CollectionStore, org.jpox.store.scostore.SetStore, org.jpox.store.scostore.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.55 $

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
protected  boolean allowsNull
          Whether the container allows null elements/values.
protected  org.jpox.store.mapped.DatastoreAdapter dba
          Datastore adapter in use by this store.
protected static org.jpox.util.Localiser LOCALISER
          Localiser for messages.
protected static int MAP_TYPE_JOIN
          Indicator for a map that is managed by a join table.
protected static int MAP_TYPE_KEY_IN_VALUE
          Indicator for a map that is managed by storing the key as a field in the value.
protected static int MAP_TYPE_VALUE_IN_KEY
          Indicator for a map that is managed by storing the value as a field in the key.
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  java.lang.String setName
           
protected  RDBMSManager storeMgr
          Manager for the store.
 
Fields inherited from class org.jpox.store.rdbms.scostore.AbstractCollectionStore
containsStmt
 
Fields inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
addStmt, clearStmt, clr, containerTable, elementInfo, elementIsPersistentInterface, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, elmIdentifier, emd, iterateUsingDiscriminator, orderMapping, relationDiscriminatorMapping, relationDiscriminatorValue, removeStmt, usingDiscriminatorInSizeStmt
 
Constructor Summary
MapKeySetStore(org.jpox.store.mapped.DatastoreContainerObject valueTable, org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping, org.jpox.store.mapped.mapping.JavaTypeMapping keyMapping, org.jpox.ClassLoaderResolver clr, org.jpox.metadata.AbstractMemberMetaData fmd)
          Constructor where either the key is stored in the value table or the value is stored in the key table.
MapKeySetStore(MapTable mapTable, org.jpox.ClassLoaderResolver clr)
          Constructor where a join table is used to store the map relation.
 
Method Summary
 boolean add(org.jpox.StateManager sm, java.lang.Object element, int size)
          Method to add an element.
 boolean addAll(org.jpox.StateManager sm, java.util.Collection elements, int size)
          Method to add a collection of elements.
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 collection.
protected  org.jpox.store.mapped.expression.QueryExpression getIteratorStatement(org.jpox.StateManager ownerSM)
          Method to create an iterator for the map keys.
 org.jpox.store.mapped.mapping.JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
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.
protected  int[] internalAdd(org.jpox.StateManager ownerSM, org.jpox.ManagedConnection conn, boolean batched, java.lang.Object element, boolean processNow)
          Method to process an "add" statement.
protected  int[] internalRemove(org.jpox.StateManager ownerSM, org.jpox.ManagedConnection conn, boolean batched, java.lang.Object element, boolean executeNow)
          Method to process a "remove" statement.
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 ownerSM)
          Accessor for an iterator for the set.
 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 te, org.jpox.store.mapped.DatastoreIdentifier setTableAlias, java.lang.Class filteredElementType, org.jpox.store.mapped.expression.ScalarExpression elmExpr, org.jpox.store.mapped.DatastoreIdentifier elementTableAlias, boolean existsQuery)
           
 org.jpox.store.mapped.expression.QueryExpression newQueryStatement(org.jpox.StateManager sm, java.lang.String candidateClass, org.jpox.store.mapped.DatastoreIdentifier candidateAlias)
           
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 element.
 boolean removeAll(org.jpox.StateManager sm, java.util.Collection elements, int size)
          Method to remove a collection of elements.
protected  void setOwnerMemberMetaData(org.jpox.metadata.AbstractMemberMetaData mmd)
          Method to set the owner field/property MetaData and sets whether null elements/values are allowed.
 
Methods inherited from class org.jpox.store.rdbms.scostore.AbstractCollectionStore
contains, getContainsStmt, getExistsSubquery, getRemoveStmt, 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, hasOrderMapping, size, updateEmbeddedElement
 
Methods inherited from interface org.jpox.store.scostore.Store
getStoreManager
 
Methods inherited from interface org.jpox.store.mapped.scostore.CollectionStoreQueryable
newResultObjectFactory
 

Field Detail

MAP_TYPE_JOIN

protected static final int MAP_TYPE_JOIN
Indicator for a map that is managed by a join table.

See Also:
Constant Field Values

MAP_TYPE_KEY_IN_VALUE

protected static final int MAP_TYPE_KEY_IN_VALUE
Indicator for a map that is managed by storing the key as a field in the value.

See Also:
Constant Field Values

MAP_TYPE_VALUE_IN_KEY

protected static final int MAP_TYPE_VALUE_IN_KEY
Indicator for a map that is managed by storing the value as a field in the key.

See Also:
Constant Field Values

setName

protected java.lang.String setName

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

MapKeySetStore

public MapKeySetStore(MapTable mapTable,
                      org.jpox.ClassLoaderResolver clr)
Constructor where a join table is used to store the map relation.

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

MapKeySetStore

public MapKeySetStore(org.jpox.store.mapped.DatastoreContainerObject valueTable,
                      org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping,
                      org.jpox.store.mapped.mapping.JavaTypeMapping keyMapping,
                      org.jpox.ClassLoaderResolver clr,
                      org.jpox.metadata.AbstractMemberMetaData fmd)
Constructor where either the key is stored in the value table or the value is stored in the key table.

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/column
clr - The ClassLoaderResolver
fmd - FieldMetaData for the owning "map" field
Method Detail

getIteratorStatement

protected org.jpox.store.mapped.expression.QueryExpression getIteratorStatement(org.jpox.StateManager ownerSM)
Method to create an iterator for the map keys.

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

add

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

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

addAll

public boolean addAll(org.jpox.StateManager sm,
                      java.util.Collection elements,
                      int size)
Method to add a collection of elements. Overridden because we want to prevent it.

Specified by:
addAll in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - State Manager of collection.
elements - Elements to add.
size - Current size of set (if known). Not used by sets
Returns:
Whether it was successful

remove

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

Specified by:
remove in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - State Manager of collection.
element - Element to remove.
size - Current size
allowDependentField - Whether to allow any cascade deletes caused by this removal
Returns:
Whether it was successful

removeAll

public boolean removeAll(org.jpox.StateManager sm,
                         java.util.Collection elements,
                         int size)
Method to remove a collection of elements. Overridden because we want to prevent it.

Specified by:
removeAll in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - State Manager of collection.
elements - Elements to remove.
Returns:
Whether it was successful

clear

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

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

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 te,
                                                                        org.jpox.store.mapped.DatastoreIdentifier setTableAlias,
                                                                        java.lang.Class filteredElementType,
                                                                        org.jpox.store.mapped.expression.ScalarExpression elmExpr,
                                                                        org.jpox.store.mapped.DatastoreIdentifier elementTableAlias,
                                                                        boolean existsQuery)

newQueryStatement

public org.jpox.store.mapped.expression.QueryExpression newQueryStatement(org.jpox.StateManager sm,
                                                                          java.lang.String candidateClass,
                                                                          org.jpox.store.mapped.DatastoreIdentifier candidateAlias)

iterator

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

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

internalAdd

protected int[] internalAdd(org.jpox.StateManager ownerSM,
                            org.jpox.ManagedConnection conn,
                            boolean batched,
                            java.lang.Object element,
                            boolean processNow)
                     throws java.sql.SQLException
Method to process an "add" statement.

Parameters:
ownerSM - StateManager for the owner
conn - The connection
batched - Whether we are batching it
element - The element
Returns:
Number of datastore records changed (always 0 if batch since nothing yet changed)
Throws:
java.sql.SQLException - Thrown if an error occurs

internalRemove

protected int[] internalRemove(org.jpox.StateManager ownerSM,
                               org.jpox.ManagedConnection conn,
                               boolean batched,
                               java.lang.Object element,
                               boolean executeNow)
                        throws java.sql.SQLException
Method to process a "remove" statement.

Overrides:
internalRemove in class AbstractCollectionStore
Parameters:
ownerSM - StateManager for the owner
conn - The connection
batched - Whether we are batching it
element - The element
executeNow - Whether to execute the statement rather than allow batching til later
Returns:
Number of records changed (0 if batch since nothing yet changed)
Throws:
java.sql.SQLException - Thrown if an error occurs

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.

getOwnerMapping

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

Returns:
Owner mapping.

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.