org.apache.openjpa.jdbc.sql
Class LogicalUnion

java.lang.Object
  extended by org.apache.openjpa.jdbc.sql.LogicalUnion
All Implemented Interfaces:
SelectExecutor, Union

public class LogicalUnion
extends Object
implements Union

A logical union made up of multiple distinct selects whose results are combined in memory.

Author:
Abe White

Nested Class Summary
static interface LogicalUnion.Selector
          A callback used to create the selects in a SQL union.
 class LogicalUnion.UnionSelect
          A select that is part of a logical union.
 
Field Summary
protected  BitSet desc
           
protected  DBDictionary dict
           
protected  ClassMapping[] mappings
           
protected  LogicalUnion.UnionSelect[] sels
           
 
Constructor Summary
  LogicalUnion(JDBCConfiguration conf, int sels)
          Constructor.
protected LogicalUnion(JDBCConfiguration conf, int sels, Select[] seeds)
          Delegate constructor.
  LogicalUnion(JDBCConfiguration conf, Select[] seeds)
          Constructor used to seed the internal selects.
 
Method Summary
 void abortUnion()
          Force the use of a series of standard selects rather than a true UNION.
 Result execute(JDBCStore store, JDBCFetchConfiguration fetch)
          Execute this select in the context of the given store manager.
 Result execute(JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel)
          Execute this select in the context of the given store manager.
 Result execute(JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel, List params)
          Execute this select in the context of the given store manager.
 Result execute(JDBCStore store, JDBCFetchConfiguration fetch, List params)
          Execute this select in the context of the given store manager.
 boolean getAutoDistinct()
          Whether to automatically make results distinct when relational joins would otherwise introduce duplicates.
 JDBCConfiguration getConfiguration()
          Return the select configuration.
 int getCount(JDBCStore store)
          Return the number of instances matching this select.
 DBDictionary getDBDictionary()
           
 int getExpectedResultCount()
          The expected result count for the query.
 int getJoinSyntax()
          The join syntax for this select, as one of the syntax constants from JoinSyntaxes.
 String getOrdering()
          Get the union-level ordering, if any.
 Select[] getSelects()
          Return the selects that make up this union.
 boolean isDistinct()
          Whether this is a SELECT DISTINCT / UNION ALL.
 boolean isLRS()
          Whether the result of this select should be treated as a large result set.
 boolean isUnion()
          Whether this is a true UNION, rather than a logical combination of independent selects.
protected  LogicalUnion.UnionSelect newUnionSelect(SelectImpl seed, int pos)
          Create a new union select with the given delegate and union position.
 void select(Union.Selector selector)
          Select data using the given selector.
 void setAutoDistinct(boolean distinct)
          Whether to automatically make results distinct when relational joins would otherwise introduce duplicates.
 void setDistinct(boolean distinct)
          Whether this is a SELECT DISTINCT / UNION ALL.
 void setExpectedResultCount(int expectedResultCount, boolean force)
          The expected result count for the query.
 void setJoinSyntax(int syntax)
          The join syntax for this select, as one of the syntax constants from JoinSyntaxes.
 void setLRS(boolean lrs)
          Whether the result of this select should be treated as a large result set.
 boolean supportsLocking()
          Whether this select can be executed for update.
 boolean supportsRandomAccess(boolean forUpdate)
          Return whether this select can support a random access result set type.
 SQLBuffer toSelect(boolean forUpdate, JDBCFetchConfiguration fetch)
          Return this select as a SQL statement formatted for the current dictionary.
 SQLBuffer toSelectCount()
          Return this select as a COUNT SQL statement formatted for the current dictionary.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sels

protected final LogicalUnion.UnionSelect[] sels

dict

protected final DBDictionary dict

mappings

protected final ClassMapping[] mappings

desc

protected final BitSet desc
Constructor Detail

LogicalUnion

public LogicalUnion(JDBCConfiguration conf,
                    int sels)
Constructor.

Parameters:
conf - system configuration
sels - the number of SQL selects to union together

LogicalUnion

public LogicalUnion(JDBCConfiguration conf,
                    Select[] seeds)
Constructor used to seed the internal selects.


LogicalUnion

protected LogicalUnion(JDBCConfiguration conf,
                       int sels,
                       Select[] seeds)
Delegate constructor.

Method Detail

newUnionSelect

protected LogicalUnion.UnionSelect newUnionSelect(SelectImpl seed,
                                                  int pos)
Create a new union select with the given delegate and union position.


getSelects

public Select[] getSelects()
Description copied from interface: Union
Return the selects that make up this union.

Specified by:
getSelects in interface Union

isUnion

public boolean isUnion()
Description copied from interface: Union
Whether this is a true UNION, rather than a logical combination of independent selects.

Specified by:
isUnion in interface Union

abortUnion

public void abortUnion()
Description copied from interface: Union
Force the use of a series of standard selects rather than a true UNION.

Specified by:
abortUnion in interface Union

getOrdering

public String getOrdering()
Description copied from interface: Union
Get the union-level ordering, if any.

Specified by:
getOrdering in interface Union

getConfiguration

public JDBCConfiguration getConfiguration()
Description copied from interface: SelectExecutor
Return the select configuration.

Specified by:
getConfiguration in interface SelectExecutor

getDBDictionary

public DBDictionary getDBDictionary()

toSelect

public SQLBuffer toSelect(boolean forUpdate,
                          JDBCFetchConfiguration fetch)
Description copied from interface: SelectExecutor
Return this select as a SQL statement formatted for the current dictionary.

Specified by:
toSelect in interface SelectExecutor

toSelectCount

public SQLBuffer toSelectCount()
Description copied from interface: SelectExecutor
Return this select as a COUNT SQL statement formatted for the current dictionary.

Specified by:
toSelectCount in interface SelectExecutor

getAutoDistinct

public boolean getAutoDistinct()
Description copied from interface: SelectExecutor
Whether to automatically make results distinct when relational joins would otherwise introduce duplicates.

Specified by:
getAutoDistinct in interface SelectExecutor

setAutoDistinct

public void setAutoDistinct(boolean distinct)
Description copied from interface: SelectExecutor
Whether to automatically make results distinct when relational joins would otherwise introduce duplicates.

Specified by:
setAutoDistinct in interface SelectExecutor

isDistinct

public boolean isDistinct()
Description copied from interface: SelectExecutor
Whether this is a SELECT DISTINCT / UNION ALL.

Specified by:
isDistinct in interface SelectExecutor

setDistinct

public void setDistinct(boolean distinct)
Description copied from interface: SelectExecutor
Whether this is a SELECT DISTINCT / UNION ALL.

Specified by:
setDistinct in interface SelectExecutor

isLRS

public boolean isLRS()
Description copied from interface: SelectExecutor
Whether the result of this select should be treated as a large result set.

Specified by:
isLRS in interface SelectExecutor

setLRS

public void setLRS(boolean lrs)
Description copied from interface: SelectExecutor
Whether the result of this select should be treated as a large result set.

Specified by:
setLRS in interface SelectExecutor

getExpectedResultCount

public int getExpectedResultCount()
Description copied from interface: SelectExecutor
The expected result count for the query.

Specified by:
getExpectedResultCount in interface SelectExecutor

setExpectedResultCount

public void setExpectedResultCount(int expectedResultCount,
                                   boolean force)
Description copied from interface: SelectExecutor
The expected result count for the query.

Specified by:
setExpectedResultCount in interface SelectExecutor
force - if false, the count will be discarded if this select has any to-many eager joins that would throw off the result count

getJoinSyntax

public int getJoinSyntax()
Description copied from interface: SelectExecutor
The join syntax for this select, as one of the syntax constants from JoinSyntaxes.

Specified by:
getJoinSyntax in interface SelectExecutor

setJoinSyntax

public void setJoinSyntax(int syntax)
Description copied from interface: SelectExecutor
The join syntax for this select, as one of the syntax constants from JoinSyntaxes.

Specified by:
setJoinSyntax in interface SelectExecutor

supportsRandomAccess

public boolean supportsRandomAccess(boolean forUpdate)
Description copied from interface: SelectExecutor
Return whether this select can support a random access result set type.

Specified by:
supportsRandomAccess in interface SelectExecutor

supportsLocking

public boolean supportsLocking()
Description copied from interface: SelectExecutor
Whether this select can be executed for update.

Specified by:
supportsLocking in interface SelectExecutor

getCount

public int getCount(JDBCStore store)
             throws SQLException
Description copied from interface: SelectExecutor
Return the number of instances matching this select.

Specified by:
getCount in interface SelectExecutor
Throws:
SQLException

execute

public Result execute(JDBCStore store,
                      JDBCFetchConfiguration fetch)
               throws SQLException
Description copied from interface: SelectExecutor
Execute this select in the context of the given store manager.

Specified by:
execute in interface SelectExecutor
Throws:
SQLException

execute

public Result execute(JDBCStore store,
                      JDBCFetchConfiguration fetch,
                      int lockLevel)
               throws SQLException
Description copied from interface: SelectExecutor
Execute this select in the context of the given store manager.

Specified by:
execute in interface SelectExecutor
Throws:
SQLException

execute

public Result execute(JDBCStore store,
                      JDBCFetchConfiguration fetch,
                      List params)
               throws SQLException
Description copied from interface: SelectExecutor
Execute this select in the context of the given store manager.

Specified by:
execute in interface SelectExecutor
Throws:
SQLException

execute

public Result execute(JDBCStore store,
                      JDBCFetchConfiguration fetch,
                      int lockLevel,
                      List params)
               throws SQLException
Description copied from interface: SelectExecutor
Execute this select in the context of the given store manager.

Specified by:
execute in interface SelectExecutor
Throws:
SQLException

select

public void select(Union.Selector selector)
Description copied from interface: Union
Select data using the given selector.

Specified by:
select in interface Union

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.