org.jpox.store.rdbms.scostore
Class JoinSetStore

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.JoinSetStore
All Implemented Interfaces:
CollectionStore, SetStore, Store

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

Representation of a Normal Set as part of a relationship. This class is used where you have a 1-N and the tables are joined via a link table. That is one table is the owner, and it has a link table to another table, with the link table having 2 columns - the ids of the 2 tables. This is in contrast to InverseSetStore which represents 1-N relationships without using a link table (using an id in the other table).

For sets of primitive types (eg Date,String etc), the NormalSetStore is used, but the 'link' table contains the id of the owner and the field(s) representing the primitive type.

Version:
$Revision: 1.6 $

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 locateStmt
          Statement to check the existence of an owner-element relation.
protected  boolean m2n
          Whether this relation is one end of an M-N relation.
protected  java.lang.String maxOrderColumnIdStmt
          Statement to get the maximum order column id so we can set the next insert value.
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
JoinSetStore(AbstractPropertyMetaData fmd, CollectionTable joinTable, ClassLoaderResolver clr)
          Constructor for the relationship representation.
 
Method Summary
 boolean add(StateManager sm, java.lang.Object element)
          Adds one element to the association owner vs elements.
 boolean addAll(StateManager sm, java.util.Collection elements)
          Adds all elements from a collection to the association container.
protected  QueryExpression getIteratorStatement(StateManager ownerSM)
          Accessor for the statement for the iterator.
protected  java.lang.String getRemoveAllStmt(StateManager ownerSm, java.util.Collection elements)
          Generate statement for removing a collection of items from the Set.
protected  java.lang.String getRemoveStmt()
          Generate statement for deleting items from the Set.
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.
 boolean locate(StateManager sm, java.lang.Object element)
          Method to check for the existence in the datastore of an owner-element relation.
 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)
          Removes the association to one 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
clear, executeQuery, executeUpdate, getAddStmt, getClearStmt, getElementInformationForClass, getElementType, getOwnerMapping, getSizeStmt, getStateManagerForEmbeddedPCObject, getStoreManager, hasOrderMapping, isEmbeddedMapping, newResultObjectFactory, populateElementDiscriminatorInStatement, populateElementInStatement, populateEmbeddedElementFieldsInStatement, populateOrderInStatement, populateOwnerInStatement, 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
clear, contains, getElementType, getExistsSubquery, getSizeSubquery, hasOrderMapping, newResultObjectFactory, size, updateEmbeddedElement
 
Methods inherited from interface org.jpox.store.scostore.Store
getOwnerMapping, getStoreManager
 

Field Detail

locateStmt

protected final java.lang.String locateStmt
Statement to check the existence of an owner-element relation.


maxOrderColumnIdStmt

protected final java.lang.String maxOrderColumnIdStmt
Statement to get the maximum order column id so we can set the next insert value.


m2n

protected final boolean m2n
Whether this relation is one end of an M-N relation.


setName

protected java.lang.String setName

addStmt

protected java.lang.String addStmt

removeStmt

protected java.lang.String removeStmt
Constructor Detail

JoinSetStore

public JoinSetStore(AbstractPropertyMetaData fmd,
                    CollectionTable joinTable,
                    ClassLoaderResolver clr)
Constructor for the relationship representation.

Parameters:
joinTable - The table for the link
clr - The ClassLoaderResolver
Method Detail

getRemoveStmt

protected java.lang.String getRemoveStmt()
Generate statement for deleting items from the Set. The EMBEDDEDFIELDX is only present when the elements are PC(embedded).
 DELETE FROM SETTABLE 
 WHERE OWNERCOL=?
 AND ELEMENTCOL = ?
 [AND EMBEDDEDFIELD1 = ? AND EMBEDDEDFIELD2 = ? AND EMBEDDEDFIELD3 = ?]
 [AND RELATION_DISCRIM = ?]
 

Returns:
Statement for deleting items from the Set.

getRemoveAllStmt

protected java.lang.String getRemoveAllStmt(StateManager ownerSm,
                                            java.util.Collection elements)
Generate statement for removing a collection of items from the Set.
 DELETE FROM SETTABLE 
 WHERE (OWNERCOL=? AND ELEMENTCOL=?) OR
      (OWNERCOL=? AND ELEMENTCOL=?) OR
      (OWNERCOL=? AND ELEMENTCOL=?)
 

Parameters:
ownerSm - The owner StateManager
elements - Collection of elements to remove
Returns:
Statement for deleting items from the Set.

removeAll

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

Parameters:
sm - State Manager for the container
elements - Collection of elements to remove
Returns:
Whether the database was updated

locate

public boolean locate(StateManager sm,
                      java.lang.Object element)
Method to check for the existence in the datastore of an owner-element relation.

Parameters:
sm - State Manager for the owner
element - The element
Returns:
Whether the relation exists in the datastore

add

public boolean add(StateManager sm,
                   java.lang.Object element)
Adds one element to the association owner vs elements.

Parameters:
sm - State Manager for the container.
element - Element to add
Returns:
Whether it was successful

addAll

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

Parameters:
sm - State Manager for the container.
elements - Collection of elements to add
Returns:
Whether it was successful

getIteratorStatement

protected QueryExpression getIteratorStatement(StateManager ownerSM)
Accessor for the statement for the iterator.

Parameters:
ownerSM - the owner StateManager
Returns:
The iterator Query Statement.

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.

remove

public boolean remove(StateManager sm,
                      java.lang.Object element)
Removes the association to one element

Specified by:
remove in interface CollectionStore
Parameters:
sm - State Manager for the container
element - Element to remove
Returns:
Whether it was successful


Copyright © -2007 . All Rights Reserved.