Package org.apache.openjpa.jdbc.sql
Class LogicalUnion
- java.lang.Object
-
- org.apache.openjpa.jdbc.sql.LogicalUnion
-
- All Implemented Interfaces:
SelectExecutor
,Union
public class LogicalUnion extends java.lang.Object implements Union
A logical union made up of multiple distinct selects whose results are combined in memory.- Author:
- Abe White
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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
Fields Modifier and Type Field Description protected java.util.BitSet
desc
protected DBDictionary
dict
protected ClassMapping[]
mappings
protected LogicalUnion.UnionSelect[]
sels
-
Constructor Summary
Constructors Modifier Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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 fromJoinSyntaxes
.java.lang.String
getOrdering()
Get the union-level ordering, if any.Select[]
getSelects()
Return the selects that make up this union.SQLBuffer
getSQL()
Get the buffer if it has been computed by a previous call toSelectExecutor.toSelect(boolean, JDBCFetchConfiguration)
, if any.boolean
hasMultipleSelects()
Affirm if this receiver requires more than one selects to fetch its data.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 fromJoinSyntaxes
.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.java.lang.String
toString()
-
-
-
Field Detail
-
sels
protected final LogicalUnion.UnionSelect[] sels
-
dict
protected final DBDictionary dict
-
mappings
protected final ClassMapping[] mappings
-
desc
protected final java.util.BitSet desc
-
-
Constructor Detail
-
LogicalUnion
public LogicalUnion(JDBCConfiguration conf, int sels)
Constructor.- Parameters:
conf
- system configurationsels
- 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 interfaceUnion
-
isUnion
public boolean isUnion()
Description copied from interface:Union
Whether this is a true UNION, rather than a logical combination of independent selects.
-
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 interfaceUnion
-
getOrdering
public java.lang.String getOrdering()
Description copied from interface:Union
Get the union-level ordering, if any.- Specified by:
getOrdering
in interfaceUnion
-
getConfiguration
public JDBCConfiguration getConfiguration()
Description copied from interface:SelectExecutor
Return the select configuration.- Specified by:
getConfiguration
in interfaceSelectExecutor
-
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 interfaceSelectExecutor
-
getSQL
public SQLBuffer getSQL()
Description copied from interface:SelectExecutor
Get the buffer if it has been computed by a previous call toSelectExecutor.toSelect(boolean, JDBCFetchConfiguration)
, if any.- Specified by:
getSQL
in interfaceSelectExecutor
-
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 interfaceSelectExecutor
-
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 interfaceSelectExecutor
-
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 interfaceSelectExecutor
-
isDistinct
public boolean isDistinct()
Description copied from interface:SelectExecutor
Whether this is a SELECT DISTINCT / UNION ALL.- Specified by:
isDistinct
in interfaceSelectExecutor
-
setDistinct
public void setDistinct(boolean distinct)
Description copied from interface:SelectExecutor
Whether this is a SELECT DISTINCT / UNION ALL.- Specified by:
setDistinct
in interfaceSelectExecutor
-
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 interfaceSelectExecutor
-
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 interfaceSelectExecutor
-
getExpectedResultCount
public int getExpectedResultCount()
Description copied from interface:SelectExecutor
The expected result count for the query.- Specified by:
getExpectedResultCount
in interfaceSelectExecutor
-
setExpectedResultCount
public void setExpectedResultCount(int expectedResultCount, boolean force)
Description copied from interface:SelectExecutor
The expected result count for the query.- Specified by:
setExpectedResultCount
in interfaceSelectExecutor
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 fromJoinSyntaxes
.- Specified by:
getJoinSyntax
in interfaceSelectExecutor
-
setJoinSyntax
public void setJoinSyntax(int syntax)
Description copied from interface:SelectExecutor
The join syntax for this select, as one of the syntax constants fromJoinSyntaxes
.- Specified by:
setJoinSyntax
in interfaceSelectExecutor
-
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 interfaceSelectExecutor
-
supportsLocking
public boolean supportsLocking()
Description copied from interface:SelectExecutor
Whether this select can be executed for update.- Specified by:
supportsLocking
in interfaceSelectExecutor
-
hasMultipleSelects
public boolean hasMultipleSelects()
Description copied from interface:SelectExecutor
Affirm if this receiver requires more than one selects to fetch its data.- Specified by:
hasMultipleSelects
in interfaceSelectExecutor
-
getCount
public int getCount(JDBCStore store) throws java.sql.SQLException
Description copied from interface:SelectExecutor
Return the number of instances matching this select.- Specified by:
getCount
in interfaceSelectExecutor
- Throws:
java.sql.SQLException
-
execute
public Result execute(JDBCStore store, JDBCFetchConfiguration fetch) throws java.sql.SQLException
Description copied from interface:SelectExecutor
Execute this select in the context of the given store manager.- Specified by:
execute
in interfaceSelectExecutor
- Throws:
java.sql.SQLException
-
execute
public Result execute(JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel) throws java.sql.SQLException
Description copied from interface:SelectExecutor
Execute this select in the context of the given store manager.- Specified by:
execute
in interfaceSelectExecutor
- Throws:
java.sql.SQLException
-
select
public void select(Union.Selector selector)
Description copied from interface:Union
Select data using the given selector.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-