org.jpox.store.query
Class DiscriminatorIteratorStatement

java.lang.Object
  extended byorg.jpox.store.query.AbstractIteratorStatement
      extended byorg.jpox.store.query.DiscriminatorIteratorStatement

public class DiscriminatorIteratorStatement
extends AbstractIteratorStatement

Class to generate a QueryStatement that can be used for iterating through instances in a single table using a discriminator to distinguish between the classes. There are two modes of operation supported :-

Generated statement - candidate type

Let's assume that we have class A which is the candidate and this has subclasses A1, A2 that are stored in the same table (with different values of the discriminator). We want to find all objects of the candidate type and optionally its subclasses and we want information about what type the object is (A or A1 or A2). The query will be of the form
 SELECT [THIS.DISCRIMINATOR] 
 FROM A THIS
 [WHERE (THIS.DISCRIMINATOR = value1 || THIS.DISCRIMINATOR = value2 || THIS_DISCRIMINATOR = value3)]
 
The SELECT of the discriminator column is optional. The WHERE clause is added where we don't want to include all possible classes that are stored in that table. You can omit the WHERE clause by specifying restrictDiscriminator as false.

Generated statement - candidate type with select table

Let's assume that we have a 1-N relation with a join table, and we want to find all elements of the candidate type (B) and optionally its subclasses (B1, B2). We need to select the join table, yet have a different candidate type. The query will be of the form
 SELECT [`ELEMENT`.DISCRIMINATOR]
 FROM SELECTTABLE THIS INNER JOIN B `ELEMENT` ON `ELEMENT`.B_ID = THIS.B_ID_EID 
 [WHERE (`ELEMENT`.DISCRIMINATOR = value1 OR `ELEMENT`.DISCRIMINATOR = value2 || `ELEMENT`.DISCRIMINATOR = value3)]
 
The SELECT of the discriminator column is optional. The WHERE clause is added where we don't want to include all possible classes that are stored in that table. You can omit the WHERE clause by specifying restrictDiscriminator as false.

Selecting columns

It should be noted that the "SELECT" columns are not added here (with the exception of THIS.DISCRIMINATOR, which is an optional addition). They are added after creating this statement. This statement simply creates the basic form of the select statement.

Version:
$Revision: 1.22 $

Field Summary
 
Fields inherited from class org.jpox.store.query.AbstractIteratorStatement
candidateFullClassName, candidateTable, clr, dba, includeSubclasses, LOCALISER, storeMgr
 
Constructor Summary
DiscriminatorIteratorStatement(ClassLoaderResolver clr, java.lang.Class[] candidateTypes, boolean includeSubclasses, StoreManager storeMgr, boolean selectDiscriminator)
          Constructor, for a candidate type select.
DiscriminatorIteratorStatement(ClassLoaderResolver clr, java.lang.Class[] candidateType, boolean includeSubclasses, StoreManager storeMgr, boolean selectDiscriminator, DatastoreContainerObject selectTable, JavaTypeMapping selectCandidateMapping, DatastoreIdentifier candidateTableIdentifier)
          Constructor, for a candidate type with a select table.
 
Method Summary
 QueryExpression getQueryStatement()
          Accessor for the Query Statement.
 void setRestrictDiscriminator(boolean restrict)
          Mutator for whether to restrict the discriminator values in the query to just those of the candidate class (and subclasses where specified).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiscriminatorIteratorStatement

public DiscriminatorIteratorStatement(ClassLoaderResolver clr,
                                      java.lang.Class[] candidateTypes,
                                      boolean includeSubclasses,
                                      StoreManager storeMgr,
                                      boolean selectDiscriminator)
Constructor, for a candidate type select.

Parameters:
clr - The ClassLoaderResolver
candidateTypes - Base object types that we are looking for
includeSubclasses - Should we include subclasses of this candidate?
storeMgr - Manager for the store
selectDiscriminator - Whether to select the discriminator

DiscriminatorIteratorStatement

public DiscriminatorIteratorStatement(ClassLoaderResolver clr,
                                      java.lang.Class[] candidateType,
                                      boolean includeSubclasses,
                                      StoreManager storeMgr,
                                      boolean selectDiscriminator,
                                      DatastoreContainerObject selectTable,
                                      JavaTypeMapping selectCandidateMapping,
                                      DatastoreIdentifier candidateTableIdentifier)
Constructor, for a candidate type with a select table.

Parameters:
clr - The ClassLoaderResolver
candidateType - Base object type that we are looking for
includeSubclasses - Should we include subclasses of this candidate?
storeMgr - Manager for the store
selectDiscriminator - Whether to select the discriminator
selectTable - Table to select
selectCandidateMapping - Mapping in the select table to join with the id of the candidate table
candidateTableIdentifier - Identifier to use for the candidate table when using a select table
Method Detail

setRestrictDiscriminator

public void setRestrictDiscriminator(boolean restrict)
Mutator for whether to restrict the discriminator values in the query to just those of the candidate class (and subclasses where specified). By default the values of the discriminator will be restricted in the query. Must be set before calling getQueryStatement() if it is required

Parameters:
restrict - the valid discrim values in the query.

getQueryStatement

public QueryExpression getQueryStatement()
Accessor for the Query Statement.

Specified by:
getQueryStatement in class AbstractIteratorStatement
Returns:
The Query Statement for iterating through objects with a discriminator column


Copyright © -2007 . All Rights Reserved.