org.jpox.store.rdbms.scostore
Class FKSetStore

java.lang.Object
  extended byorg.jpox.store.rdbms.scostore.BaseContainerStore
      extended byorg.jpox.store.rdbms.scostore.ElementContainerStore
          extended byorg.jpox.store.rdbms.scostore.AbstractCollectionStore
              extended byorg.jpox.store.rdbms.scostore.AbstractSetStore
                  extended byorg.jpox.store.rdbms.scostore.FKSetStore
All Implemented Interfaces:
CollectionStore, SetStore, Store

public class FKSetStore
extends org.jpox.store.rdbms.scostore.AbstractSetStore

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.5 $

Nested Class Summary
 
Nested classes inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
ElementContainerStore.ElementInfo
 
Field Summary
protected  java.lang.String addStmt
           
protected  java.lang.String removeStmt
           
protected  java.lang.String setName
           
 
Fields inherited from class org.jpox.store.rdbms.scostore.AbstractCollectionStore
containsStmt
 
Fields inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
clearStmt, clr, containerTable, dba, elementInfo, elementMapping, elementsAreEmbedded, elementsAreSerialised, elementType, elmIdentifier, emd, iterateUsingDiscriminator, LOCALISER, orderMapping, ownerFieldMetaData, ownerMapping, relationDiscriminatorMapping, relationDiscriminatorValue, sizeStmt, storeMgr, thisIdentifier
 
Constructor Summary
FKSetStore(AbstractPropertyMetaData fmd, RDBMSManager storeMgr, ClassLoaderResolver clr)
          Constructor for the relationship representation.
 
Method Summary
 boolean add(StateManager sm, java.lang.Object element)
          Method to add an object to the relationship at the collection end.
 boolean addAll(StateManager sm, java.util.Collection elements)
          Method to add a collection of object to the relationship at the collection end.
 void clear(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  QueryExpression getIteratorStatement(StateManager ownerSM)
          Accessor for a QueryStatement to retrieve the elements of the set.
protected  int getOwnerFieldOwner(StateManager sm)
           
protected  java.lang.String getRemoveStmt()
          Generate statement for deleting an item from the Set.
protected  java.lang.String getSizeStmt()
          Generate statement for getting the size of the container.
protected  void initialiseStatements()
          Method to initialise the statements being used.
 java.util.Iterator iterator(StateManager ownerSM)
          Accessor for an iterator for the set.
 ScalarExpression joinElementsTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier setRangeVar, java.lang.Class filteredElementType, ScalarExpression elmExpr, DatastoreIdentifier elementRangeVar)
          Utility for use in building a query, joining the element table and the owner table.
 QueryExpression newQueryStatement(StateManager sm, java.lang.String candidateClass)
          Utility method to return a new QueryStatement for retrieval of the elements of this Set.
 boolean remove(StateManager sm, java.lang.Object element)
          Method to remove the link to the collection object specified.
 boolean removeAll(StateManager sm, java.util.Collection elements)
          Method to remove the links to a collection of elements specified.
protected  void validateElementForWriting(StateManager sm, java.lang.Object element)
          Method to check if an element is already persistent, or is managed by a different Persistencemanager.
 
Methods inherited from class org.jpox.store.rdbms.scostore.AbstractCollectionStore
contains, getExistsSubquery, getSizeSubquery, getUpdateEmbeddedElementStmt, updateEmbeddedElement
 
Methods inherited from class org.jpox.store.rdbms.scostore.ElementContainerStore
executeQuery, executeUpdate, getAddStmt, getClearStmt, getElementInformationForClass, getElementType, getOwnerMapping, getStateManagerForEmbeddedPCObject, getStoreManager, hasOrderMapping, isEmbeddedMapping, newResultObjectFactory, populateElementDiscriminatorInStatement, populateElementInStatement, populateEmbeddedElementFieldsInStatement, populateOrderInStatement, populateOwnerInStatement, populateRelationDiscriminatorInStatement, size, validateElementForReading, 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
Constructor Detail

FKSetStore

public FKSetStore(AbstractPropertyMetaData fmd,
                  RDBMSManager storeMgr,
                  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.

validateElementForWriting

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

Overrides:
validateElementForWriting in class ElementContainerStore
Parameters:
sm - The state manager of this collection
element - The element

getOwnerFieldOwner

protected int getOwnerFieldOwner(StateManager sm)

add

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

Parameters:
sm - StateManager of the owner of the Set
element - Element to be added
Returns:
Success indicator

addAll

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

Parameters:
sm - StateManager of the Set
elements - Elements to be added
Returns:
Success indicator

remove

public boolean remove(StateManager sm,
                      java.lang.Object element)
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).

Parameters:
sm - The StateManager of the Set
element - The element of the collection to be deleted.
Returns:
A success indicator.

removeAll

public boolean removeAll(StateManager sm,
                         java.util.Collection elements)
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.

Parameters:
sm - The StateManager of the Set
elements - The elements of the collection to be deleted.
Returns:
A success indicator.

clear

public void clear(StateManager ownerSM)
Method to allow the Set relationship to be cleared out. This is called by the Collection.clear() method and also when the container object is being deleted and the elements are to be removed (maybe for dependent field).

Specified by:
clear in interface CollectionStore
Overrides:
clear in class ElementContainerStore
Parameters:
ownerSM - StateManager of the Set

getIteratorStatement

protected QueryExpression getIteratorStatement(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 QueryExpression newQueryStatement(StateManager sm,
                                         java.lang.String candidateClass)
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.
Returns:
The QueryStatement

joinElementsTo

public ScalarExpression joinElementsTo(QueryExpression stmt,
                                       QueryExpression parentStmt,
                                       JavaTypeMapping ownerMapping,
                                       LogicSetExpression ownerTe,
                                       DatastoreIdentifier setRangeVar,
                                       java.lang.Class filteredElementType,
                                       ScalarExpression elmExpr,
                                       DatastoreIdentifier elementRangeVar)
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
setRangeVar - The range variable for the "Set" 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:
A subquery for the provided query that joins the element table to the owner table.

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.

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.


Copyright © -2007 . All Rights Reserved.