com.triactive.jdo.store
Class ManyToManySetStore

java.lang.Object
  extended bycom.triactive.jdo.store.AbstractSetStore
      extended bycom.triactive.jdo.store.ManyToManySetStore
All Implemented Interfaces:
CollectionStore, SetStore

public class ManyToManySetStore
extends com.triactive.jdo.store.AbstractSetStore

The backing store for a many-to-many set defined over a join table.

The join table has (at least) two columns, designated the "owner" and "element" columns. Each {owner,element} pair represents the presence of that element in the the owner's Set. The owner column must be an OID column. The element column may or may not be an OID.

The base PersistenceCapable type of the owning objects in question must be known (their ClassBaseTable must be provided).

If the elements are PersistenceCapable then queries and iterations over the set will execute with a single SQL statement that includes all the default-fetch-group fields.

Author:
Mike Martin

Field Summary
protected  DatabaseAdapter dba
          The database adapter for this set store.
 
Method Summary
 boolean allowsNulls()
          Indicates whether or not null elements are allowed to be stored.
 void clearAll(java.util.Collection owners)
          Clears the sets associated with an entire group of objects.
 boolean equals(java.lang.Object obj)
           
 java.lang.Class getElementType()
          Returns the type of elements stored in the collection.
static SetStore getInstance(ClassBaseTable ownerTable, Table joinTable, ColumnMapping ownerMapping, ColumnMapping elementMapping)
          Returns a many-to-many set store.
 int hashCode()
           
protected  com.triactive.jdo.store.AbstractSetStore intern()
           
 boolean isEmbeddedElement()
          Indicates whether or not elements are "embedded" in the store. An embedded object is stored by value (SCO), otherwise an OID reference is stored (FCO).
 PersistentSet newSetInstance(StateManager owner)
          Returns a new persistent set representing the set associated with the given object.

Iterators returned by the persistent set support the remove() method.

 QueryStatement.QueryColumn[] newSubqueryStatement(QueryStatement qs, CorrelationName setRangeVar)
          Creates a subquery of the given query that selects all the relationships in the collection. No columns have been selected yet in the new subquery.
 QueryStatement.QueryColumn[] newSubqueryStatement(QueryStatement qs, CorrelationName setRangeVar, CorrelationName elementRangeVar, java.lang.Class elementSubtype)
          Creates a subquery of the given query that selects all the relationships in the collection to elements of a specific type. No columns have been selected yet in the new subquery.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dba

protected final DatabaseAdapter dba
The database adapter for this set store.

Method Detail

getInstance

public static SetStore getInstance(ClassBaseTable ownerTable,
                                   Table joinTable,
                                   ColumnMapping ownerMapping,
                                   ColumnMapping elementMapping)
Returns a many-to-many set store. Returns either a newly-constructed set store object, or an equivalent existing object from an internally-maintained pool.

Parameters:
ownerTable - The backing table of the owner objects.
joinTable - The table joining owners to elements.
ownerMapping - The mapping for the owner column in the join table.
elementMapping - The mapping for the element column in the join table.

getElementType

public java.lang.Class getElementType()
Returns the type of elements stored in the collection.


isEmbeddedElement

public boolean isEmbeddedElement()
Indicates whether or not elements are "embedded" in the store. An embedded object is stored by value (SCO), otherwise an OID reference is stored (FCO).


allowsNulls

public boolean allowsNulls()
Indicates whether or not null elements are allowed to be stored.


newSubqueryStatement

public QueryStatement.QueryColumn[] newSubqueryStatement(QueryStatement qs,
                                                         CorrelationName setRangeVar)
Creates a subquery of the given query that selects all the relationships in the collection. No columns have been selected yet in the new subquery.

Parameters:
qs - The surrounding query statement.
setRangeVar - The range variable to be used for the "Set" table in the subquery.
Returns:
An array of two QueryColumns representing the owner ID column and the element or element ID column, respectively, in the subquery.

newSubqueryStatement

public QueryStatement.QueryColumn[] newSubqueryStatement(QueryStatement qs,
                                                         CorrelationName setRangeVar,
                                                         CorrelationName elementRangeVar,
                                                         java.lang.Class elementSubtype)
Creates a subquery of the given query that selects all the relationships in the collection to elements of a specific type. No columns have been selected yet in the new subquery.

Parameters:
qs - The surrounding query statement.
setRangeVar - The range variable to be used for the "Set" table in the subquery.
elementRangeVar - The range variable to be used for the "Element" table in the subquery, if necessary.
elementSubtype - Attempts to query only over elements of this type.
Returns:
An array of two QueryColumns representing the owner ID column and the element or element ID column, respectively, in the subquery.

newSetInstance

public PersistentSet newSetInstance(StateManager owner)
Returns a new persistent set representing the set associated with the given object.

Iterators returned by the persistent set support the remove() method.

Parameters:
owner - The StateManager of the object whose set is to be returned.
Returns:
the new persistent set

hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object obj)

intern

protected com.triactive.jdo.store.AbstractSetStore intern()

clearAll

public void clearAll(java.util.Collection owners)
Clears the sets associated with an entire group of objects.

The implementation in this class simply iterates over the owners, and calls newSetInstance(o).clear() on each one. There are opportunities for further optimization here. Subclasses might benefit from implementing this method in some way more specific to the type of SetStore.

For many-to-many sets, the clearing of the rows in the join table could be made quicker by a series of DELETE ... WHERE OWNER IN (?,...)

For one-to-many sets, if the owner column is nullable a series of UPDATE ... SET OWNER = NULL WHERE OWNER IN (?,...) might be faster. If it's not nullable then the deletions might be made quicker with a new method like ClassBaseTable.deleteWhereIn().

Another day ...

Specified by:
clearAll in interface SetStore
Parameters:
owners - The StateManagers of all the objects whose set is to be cleared.


Copyright 2001-2007 The TJDO Project All Rights Reserved.