org.jpox.store.rdbms.scostore
Class FKSetStore

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.FKSetStore
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 FKSetStore
extends AbstractCollectionStore

Representation of an Inverse Set as part of a relationship. This class is used where you have a 1-N and the tables are not joined via a link table. That is there is an owner table, and a collection table, and the collection table has a column being the id of the owner table. This is in contrast to NormalSetStore which represents 1-N relationships using a link table. There are 2 possible uses here

Version:
$Revision: 1.64 $

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  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
FKSetStore(org.jpox.metadata.AbstractMemberMetaData fmd, RDBMSManager storeMgr, org.jpox.ClassLoaderResolver clr)
          Constructor for the relationship representation.
 
Method Summary
 boolean add(org.jpox.StateManager sm, java.lang.Object element, int size)
          Method to add an object to the relationship at the collection end.
 boolean addAll(org.jpox.StateManager sm, java.util.Collection elements, int size)
          Method to add a collection of object to the relationship at the collection end.
protected  boolean allowsBatching()
          Convenience method to return if the RDBMS supports batching and the user wants batching.
 void clear(org.jpox.StateManager ownerSM)
          Method to allow the Set relationship to be cleared out.
protected  java.lang.String getClearNullifyStmt()
          Generates the statement for clearing items by nulling the owner link out.
protected  java.lang.String getContainsStmt()
          Generate statement for retrieving the contents of the Collection.
protected  int getFieldNumberInElementForBidirectional(org.jpox.StateManager sm)
          This seems to return the field number in the element of the relation when it is a bidirectional relation.
protected  org.jpox.store.mapped.expression.QueryExpression getIteratorStatement(org.jpox.StateManager ownerSM)
          Accessor for a QueryStatement to retrieve the elements of the set.
 org.jpox.store.mapped.mapping.JavaTypeMapping getOwnerMapping()
          Accessor for the owner mapping.
protected  java.lang.String getSizeStmt()
          Generate statement for getting the size of the container.
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 parentStmt, org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping, org.jpox.store.mapped.expression.LogicSetExpression ownerTe, org.jpox.store.mapped.DatastoreIdentifier setTableAlias, java.lang.Class filteredElementType, org.jpox.store.mapped.expression.ScalarExpression elementExpr, org.jpox.store.mapped.DatastoreIdentifier elementTableAlias, boolean existsQuery)
          Utility for use in building a query, joining the element table and the owner table.
 org.jpox.store.mapped.expression.QueryExpression newQueryStatement(org.jpox.StateManager sm, java.lang.String candidateClass, org.jpox.store.mapped.DatastoreIdentifier candidateAlias)
          Utility method to return a new QueryStatement for retrieval of the elements of this Set.
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 the link to the collection object specified.
 boolean removeAll(org.jpox.StateManager sm, java.util.Collection elements, int size)
          Method to remove the links to a collection of elements specified.
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, getExistsSubquery, getRemoveStmt, getSizeSubquery, getUpdateEmbeddedElementStmt, updateEmbeddedElement
 
Methods inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
getAddStmt, getClearStmt, getElementInformationForClass, getElementType, 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

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

FKSetStore

public FKSetStore(org.jpox.metadata.AbstractMemberMetaData fmd,
                  RDBMSManager storeMgr,
                  org.jpox.ClassLoaderResolver clr)
Constructor for the relationship representation.

Parameters:
fmd - The MetaData for the field that this represents
storeMgr - The RDBMSManager managing the associated datastore.
clr - The ClassLoaderResolver
Method Detail

getSizeStmt

protected java.lang.String getSizeStmt()
Generate statement for getting the size of the container. The order part is only present when an order mapping is used. The discriminator part is only present when the element type has inheritance strategy of "superclass-table" and is Inverse.
 SELECT COUNT(*) FROM CONTAINERTABLE
 WHERE OWNERCOL=?
 [AND ORDERCOL IS NOT NULL]
 [AND (DISCRIMINATOR=? OR DISCRMINATOR=? OR DISCRIMINATOR=?)]
 
The discriminator part includes all subclasses of the element type

Overrides:
getSizeStmt in class ElementContainerStore
Returns:
The Statement returning the size of the container.

getContainsStmt

protected java.lang.String getContainsStmt()
Generate statement for retrieving the contents of the Collection. The discriminator part is only present when the element type has inheritance strategy of "superclass-table" and is Inverse.
 
 SELECT OWNERCOL FROM COLLECTIONTABLE 
 WHERE OWNERCOL=?
 AND ELEMENTCOL = ?
 [AND DISCRIMINATOR = ?]
 

Overrides:
getContainsStmt in class AbstractCollectionStore
Returns:
Statement for retrieving the contents of the Collection.

getClearNullifyStmt

protected java.lang.String getClearNullifyStmt()
Generates the statement for clearing items by nulling the owner link out. The statement will be
 UPDATE LISTTABLE SET OWNERCOL=NULL [,DISTINGUISHER=NULL]
 WHERE OWNERCOL=?
 
when there is only one element table, and will be
 UPDATE ? SET OWNERCOL=NULL [,DISTINGUISHER=NULL]
 WHERE OWNERCOL=?
 
when there is more than 1 element table.

Returns:
The Statement for clearing items for the owner.

getFieldNumberInElementForBidirectional

protected int getFieldNumberInElementForBidirectional(org.jpox.StateManager sm)
This seems to return the field number in the element of the relation when it is a bidirectional relation.

Parameters:
sm - StateManager of the owner
Returns:
The field number in the element for this relation

add

public boolean add(org.jpox.StateManager sm,
                   java.lang.Object element,
                   int size)
Method to add an object to the relationship at the collection end.

Specified by:
add in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - StateManager of the owner of the Set
element - Element to be added
Returns:
Success indicator

addAll

public boolean addAll(org.jpox.StateManager sm,
                      java.util.Collection elements,
                      int size)
Method to add a collection of object to the relationship at the collection end.

Specified by:
addAll in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - StateManager of the Set
elements - Elements to be added
size - Current size of set (if known). Not used by sets
Returns:
Success indicator

remove

public boolean remove(org.jpox.StateManager sm,
                      java.lang.Object element,
                      int size,
                      boolean allowDependentField)
Method to remove the link to the collection object specified. Depending on the column characteristics in the collection table, the id of the owner field may be NULLed, or the record may be deleted completely (as per cascade-delete in EJB).

Specified by:
remove in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - The StateManager of the Set
element - The element of the collection to be deleted.
allowDependentField - Whether to allow any cascade deletes caused by this removal
size - Current size
Returns:
A success indicator.

removeAll

public boolean removeAll(org.jpox.StateManager sm,
                         java.util.Collection elements,
                         int size)
Method to remove the links to a collection of elements specified. Depending on the column characteristics in the collection table, the id of the owner fields may be NULLed, or the records may be deleted completely.

Specified by:
removeAll in interface org.jpox.store.scostore.CollectionStore
Parameters:
sm - The StateManager of the Set
elements - The elements of the collection to be deleted.
Returns:
A success indicator.

clear

public void clear(org.jpox.StateManager ownerSM)
Method to allow the Set relationship to be cleared out. This is called by the List.clear() method, or when the container object is being deleted and the elements are to be removed (maybe for dependent field), or also when updating a Collection and removing all existing prior to adding all new.

Specified by:
clear in interface org.jpox.store.scostore.CollectionStore
Overrides:
clear in class ElementContainerStore
Parameters:
ownerSM - StateManager of the Set

getIteratorStatement

protected org.jpox.store.mapped.expression.QueryExpression getIteratorStatement(org.jpox.StateManager ownerSM)
Accessor for a QueryStatement to retrieve the elements of the set.

Parameters:
ownerSM - the owner StateManager
Returns:
The QueryStatement to retrieve the elements

newQueryStatement

public org.jpox.store.mapped.expression.QueryExpression newQueryStatement(org.jpox.StateManager sm,
                                                                          java.lang.String candidateClass,
                                                                          org.jpox.store.mapped.DatastoreIdentifier candidateAlias)
Utility method to return a new QueryStatement for retrieval of the elements of this Set.

Parameters:
sm - StateManager for this object
candidateClass - Class for the element end of the link.
candidateAlias - Alias for the candidate
Returns:
The QueryStatement

joinElementsTo

public org.jpox.store.mapped.expression.ScalarExpression joinElementsTo(org.jpox.store.mapped.expression.QueryExpression stmt,
                                                                        org.jpox.store.mapped.expression.QueryExpression parentStmt,
                                                                        org.jpox.store.mapped.mapping.JavaTypeMapping ownerMapping,
                                                                        org.jpox.store.mapped.expression.LogicSetExpression ownerTe,
                                                                        org.jpox.store.mapped.DatastoreIdentifier setTableAlias,
                                                                        java.lang.Class filteredElementType,
                                                                        org.jpox.store.mapped.expression.ScalarExpression elementExpr,
                                                                        org.jpox.store.mapped.DatastoreIdentifier elementTableAlias,
                                                                        boolean existsQuery)
Utility for use in building a query, joining the element table and the owner table.

Parameters:
stmt - The Query Statement
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - the mapping for the owner.
ownerTe - Table Expression for the owner
filteredElementType - The Class Type for the filtered element
elementExpr - The Expression for the element
elementTableAlias - The SQL alias to assign to the expression or to the element table.
setTableAlias - The alias for the "Set" table
existsQuery - Whether this is joining for an EXISTS query
Returns:
Expression for the id of the elements table

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.