org.datanucleus.store.rdbms
Class RDBMSFetchStatement

java.lang.Object
  extended by org.datanucleus.store.rdbms.RDBMSFetchStatement
All Implemented Interfaces:
org.datanucleus.store.mapped.FetchStatement

public class RDBMSFetchStatement
extends java.lang.Object
implements org.datanucleus.store.mapped.FetchStatement

Representation of a Fetch statement for RDBMS datastores.

Provides a simplification over QueryStatement which is totally general. Fetch statements only provide select of columns, (inner) joins to superclass tables/secondary tables, and (left outer) joins to related table columns.

Takes the traditional SQL form of "SELECT .... FROM ... WHERE ... " and can have an optional locking on the selected rows where required. Can operate using ANSI92 SQL JOIN syntax, or custom JOIN syntax where the DatabaseAdapter doesnt support ANSI (e.g Oracle 8).


Field Summary
protected  java.lang.StringBuffer conditionList
          Any WHERE conditions specified.
protected  java.util.Map innerTableMappings
          Map of mappings to inner join to (from the id of the main table), keyed by the table alias
protected static org.datanucleus.util.Localiser LOCALISER
          Localiser of messages.
protected  org.datanucleus.store.mapped.DatastoreContainerObject mainTable
          The primary table, which will have an alias of "THIS".
protected  java.util.Map outerTableMappings
          Map of mappings to left outer join to (from the id of the main table), keyed by the table alias
protected  java.util.ArrayList selected
          The selected columns.
 
Constructor Summary
RDBMSFetchStatement(org.datanucleus.store.mapped.DatastoreContainerObject mainTable)
          Constructor.
 
Method Summary
 void andCondition(java.lang.String condition)
          Method to add an extra condition to the WHERE clause.
 java.lang.String referenceDatastoreField(org.datanucleus.store.mapped.DatastoreField col)
          Method to specify a column to be referenced.
 int select(org.datanucleus.store.mapped.DatastoreField col)
          Add a column to the SELECT clause.
 int select(java.lang.String expr)
          Adds an expression to the SELECT clause.
 int[] selectOuterJoin(org.datanucleus.store.mapped.mapping.JavaTypeMapping refMapping, org.datanucleus.store.mapped.mapping.JavaTypeMapping selectMapping, org.datanucleus.store.mapped.mapping.JavaTypeMapping refTypeMapping)
          Add column(s) to the SELECT clause using a LEFT OUTER JOIN to join to a related table.
 int[] selectOuterJoin(org.datanucleus.store.mapped.mapping.JavaTypeMapping refMapping, org.datanucleus.store.mapped.mapping.JavaTypeMapping selectMapping, org.datanucleus.store.mapped.mapping.JavaTypeMapping refDiscrimMapping, java.lang.Object[] discrimValues, boolean useExistingJoinIfPossible)
          Add column(s) to the SELECT clause using a LEFT OUTER JOIN to join to a related table.
 java.lang.String toString()
          Method to return the statement assuming no locking of rows.
 java.lang.String toString(boolean lock)
          Method to return the statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER
Localiser of messages.


mainTable

protected final org.datanucleus.store.mapped.DatastoreContainerObject mainTable
The primary table, which will have an alias of "THIS".


selected

protected final java.util.ArrayList selected
The selected columns.


conditionList

protected java.lang.StringBuffer conditionList
Any WHERE conditions specified.


innerTableMappings

protected final java.util.Map innerTableMappings
Map of mappings to inner join to (from the id of the main table), keyed by the table alias


outerTableMappings

protected final java.util.Map outerTableMappings
Map of mappings to left outer join to (from the id of the main table), keyed by the table alias

Constructor Detail

RDBMSFetchStatement

public RDBMSFetchStatement(org.datanucleus.store.mapped.DatastoreContainerObject mainTable)
Constructor.

Parameters:
mainTable - The table to select from
Method Detail

selectOuterJoin

public int[] selectOuterJoin(org.datanucleus.store.mapped.mapping.JavaTypeMapping refMapping,
                             org.datanucleus.store.mapped.mapping.JavaTypeMapping selectMapping,
                             org.datanucleus.store.mapped.mapping.JavaTypeMapping refDiscrimMapping,
                             java.lang.Object[] discrimValues,
                             boolean useExistingJoinIfPossible)
Add column(s) to the SELECT clause using a LEFT OUTER JOIN to join to a related table. Used in 3 situations :- The discriminator part is optional and allows for a case where the referenced table has a discriminator so that we can select the correct referenced object type (where the subclasses of the referenced type use the same table as the referenced type).

Specified by:
selectOuterJoin in interface org.datanucleus.store.mapped.FetchStatement
Parameters:
refMapping - The reference mapping in the other table that we join to our id
selectMapping - The mapping of the field in the referenced table to select in the fetch
refDiscrimMapping - Mapping for discriminator in the related table
discrimValues - Possible values to accept for the discriminator in the related table
useExistingJoinIfPossible - WHether to reuse an existing join to the same table where possible
Returns:
The parameter position(s) of the column(s) in the statement.

selectOuterJoin

public int[] selectOuterJoin(org.datanucleus.store.mapped.mapping.JavaTypeMapping refMapping,
                             org.datanucleus.store.mapped.mapping.JavaTypeMapping selectMapping,
                             org.datanucleus.store.mapped.mapping.JavaTypeMapping refTypeMapping)
Add column(s) to the SELECT clause using a LEFT OUTER JOIN to join to a related table. Used in 2 situations :- The reference type mapping is optional and allows for the case where we have subclasses of the referenced type so that we can join to the correct subclass type (where the subclasses of the referenced type have their own tables).

Specified by:
selectOuterJoin in interface org.datanucleus.store.mapped.FetchStatement
Parameters:
refMapping - The reference mapping in the other table that we join to our id
selectMapping - The mapping of the field to select in the fetch
refTypeMapping - Mapping to the type of the referenced table (subclass table)
Returns:
The parameter position(s) of the column(s) in the statement.

select

public int select(org.datanucleus.store.mapped.DatastoreField col)
Add a column to the SELECT clause.

Specified by:
select in interface org.datanucleus.store.mapped.FetchStatement
Parameters:
col - The column to add
Returns:
The parameter position of this column in the statement.

select

public int select(java.lang.String expr)
Adds an expression to the SELECT clause.

Specified by:
select in interface org.datanucleus.store.mapped.FetchStatement
Parameters:
expr - the expr to add to the select clause
Returns:
The parameter position of this expression in the statement.

referenceDatastoreField

public java.lang.String referenceDatastoreField(org.datanucleus.store.mapped.DatastoreField col)
Method to specify a column to be referenced. The column is either in the main table or is assumed to be in the table of a superclass of the main class.

Specified by:
referenceDatastoreField in interface org.datanucleus.store.mapped.FetchStatement
Parameters:
col - The column
Returns:
The column statement text

andCondition

public void andCondition(java.lang.String condition)
Method to add an extra condition to the WHERE clause.

Specified by:
andCondition in interface org.datanucleus.store.mapped.FetchStatement
Parameters:
condition - The condition

toString

public java.lang.String toString()
Method to return the statement assuming no locking of rows.

Specified by:
toString in interface org.datanucleus.store.mapped.FetchStatement
Overrides:
toString in class java.lang.Object
Returns:
The statement

toString

public java.lang.String toString(boolean lock)
Method to return the statement.

Specified by:
toString in interface org.datanucleus.store.mapped.FetchStatement
Parameters:
lock - Whether to lock the rows found by this SELECT
Returns:
The statement


Copyright © 2009. All Rights Reserved.