Package org.apache.openjpa.jdbc.sql
Class SelectImpl
- java.lang.Object
-
- org.apache.openjpa.jdbc.sql.SelectImpl
-
- All Implemented Interfaces:
Joins,Select,SelectExecutor
public class SelectImpl extends java.lang.Object implements Select
StandardSelectimplementation. Usage note: though this class implementsJoins, it should not be used for joining directly. Instead, use the return value ofnewJoins().- Author:
- Abe White
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSelectImpl.SelectResultAResultimplementation wrapped around this select.protected static classSelectImpl.SelectsHelper class to track selected columns, with fast contains method.
-
Field Summary
Fields Modifier and Type Field Description protected SelectImpl_outerprotected SelectImpl.Selects_selects-
Fields inherited from interface org.apache.openjpa.jdbc.sql.Select
EAGER_INNER, EAGER_OUTER, EAGER_PARALLEL, FROM_SELECT_ALIAS, SUBS_ANY_JOINABLE, SUBS_EXACT, SUBS_JOINABLE, SUBS_NONE, TYPE_JOINLESS, TYPE_TWO_PART
-
-
Constructor Summary
Constructors Constructor Description SelectImpl(JDBCConfiguration conf)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddJoinClassConditions()Apply class conditions from relation joins.Joinsand(Joins joins1, Joins joins2)AND the given joins together.voidappend(SQLBuffer buf, Joins joins)Append the given joins to the given buffer.voidclearOrdering()Clear odering conditions.voidclearPlaceholderSelects()Clear selected placeholders, and return removed select indexes.voidclearSelects()Clear the existing column selects.SelectImplclone(Context ctx)JoinscrossJoin(Table localTable, Table foreignTable)Perform a cross join on the given tables.Contextctx()Return the JPQL query context of this selectSelectExecutoreagerClone(FieldMapping key, int eagerType, boolean toMany, int sels)Return a select that will be eagerly executed with this one, or null if the select cannot be created for the given key and join type.Resultexecute(JDBCStore store, JDBCFetchConfiguration fetch)Execute this select in the context of the given store manager.Resultexecute(JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel)Execute this select in the context of the given store manager.protected Resultexecute(StoreContext ctx, JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel)Execute this select in the context of the given store manager.java.sql.ResultSetexecuteQuery(java.sql.Connection conn, java.sql.PreparedStatement stmnt, java.lang.String sql, JDBCStore store, java.lang.Object[] params, Column[] cols)This method is to provide override for non-JDBC or JDBC-like implementation of executing query.protected java.sql.ResultSetexecuteQuery(java.sql.Connection conn, java.sql.PreparedStatement stmnt, SQLBuffer sql, boolean isLRS, JDBCStore store)This method is to provide override for non-JDBC or JDBC-like implementation of executing query.SelectExecutorfullClone(int sels)Return a SELECT that is a complete clone of this one.java.util.MapgetAliases()booleangetAutoDistinct()Whether to automatically make results distinct when relational joins would otherwise introduce duplicates.java.lang.StringgetColumnAlias(java.lang.String col, Table table)Return the alias for the given column.java.lang.StringgetColumnAlias(java.lang.String col, Table table, Joins joins)Return the alias for the given column.java.lang.StringgetColumnAlias(Column col)Return the alias for the given column.java.lang.StringgetColumnAlias(Column col, java.lang.Object path)Return the alias for the give columnjava.lang.StringgetColumnAlias(Column col, Joins joins)Return the alias for the given column.JDBCConfigurationgetConfiguration()Return the select configuration.java.lang.StringgetCorrelatedVariable()Return correlated variable nameprotected intgetCount(java.sql.ResultSet rs)This method is to provide override for non-JDBC or JDBC-like implementation of getting count from the result set.intgetCount(JDBCStore store)Return the number of instances matching this select.DBDictionarygetDictionary()SelectExecutorgetEager(FieldMapping key)Return the eager select for the given key.java.util.MapgetEagerMap()Return view of eager selects.ResultgetEagerResult(java.sql.Connection conn, java.sql.PreparedStatement stmnt, java.sql.ResultSet rs, JDBCStore store, JDBCFetchConfiguration fetch, boolean forUpdate, SQLBuffer sql)This method is to provide override for non-JDBC or JDBC-like implementation of executing eager selects.longgetEndIndex()The result end index.java.util.ListgetExcludedJoinedTableClassMeta()get joined table metadatas excluded for polymorphic queriesintgetExpectedResultCount()The expected result count for the query.SelectgetFromSelect()Another select instance that creates a temporary table from which this select pulls data.SQLBuffergetGrouping()Return the grouping SQL for this select.booleangetHasSubselect()Return the flag to indicate whether this Select has internally generated subselectSQLBuffergetHaving()Return the HAVING clause, or null if none.java.util.ListgetIdentifierAliases()Get the aliases for identifier columns that can be used in COUNT selects to find the number of matches.java.util.ListgetJoinedTableClassMeta()get joined table metadatas for polymorphic queriesjava.util.IteratorgetJoinIterator()Return the top-levelJoinelements for this select.JoinsgetJoins()Return the top-level joins for this select.intgetJoinSyntax()The join syntax for this select, as one of the syntax constants fromJoinSyntaxes.SQLBuffergetOrdering()Return the ordering SQL for this select.SelectgetParent()Return the parent of this select, if it is a subselect.java.lang.StringgetPathStr()SelectgetSelect()java.util.ListgetSelectAliases()Return the aliases of all selected columns and all selected buffers, in the order they were selected.java.util.ListgetSelects()Return the actualVals andColumns that were selected, in the order that they were selected.SQLBuffergetSQL()Get the buffer if it has been computed by a previous call toSelectExecutor.toSelect(boolean, JDBCFetchConfiguration), if any.longgetStartIndex()The result start index.java.lang.StringgetSubselectPath()Return the subselect path for this select, if it is a subselect.java.util.ListgetSubselects()Return this select's subselects, or empty collection if none.java.util.CollectiongetTableAliases()Return the set of all used table aliases.ClassMappinggetTablePerClassMeta()get table-per-class metadata for polymorphic queriesjava.util.MapgetTables()SQLBuffergetWhere()Return the WHERE clause, minus any necessary end joins.voidgroupBy(java.lang.String sql)Add a GROUP BY clause.voidgroupBy(java.lang.String sql, Joins joins)Add a GROUP BY clause.voidgroupBy(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch)Group by the columns of the given mapping, possibly including subclasses.voidgroupBy(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, Joins joins)Group by the columns of the given mapping, possibly including subclasses.voidgroupBy(Column col)Group by the given column.voidgroupBy(Column[] cols)Group by the given columns.voidgroupBy(Column[] cols, Joins joins)Group by the given columns.voidgroupBy(Column col, Joins joins)Group by the given column.voidgroupBy(SQLBuffer sql)Add a GROUP BY clause.voidgroupBy(SQLBuffer sql, Joins joins)Add a GROUP BY clause.booleanhasEagerJoin(boolean toMany)Whether this select has an eager join of the specified type.booleanhasJoin(boolean toMany)Whether this select has a join of the specified type.booleanhasMultipleSelects()Affirm if this receiver requires more than one selects to fetch its data.voidhaving(java.lang.String sql)Add the given having conditions.voidhaving(java.lang.String sql, Joins joins)Add the given having conditions.voidhaving(SQLBuffer sql)Add the given having conditions.voidhaving(SQLBuffer sql, Joins joins)Add the given having conditions.intindexOf()The index of this select within the UNION, or 0.voidinsertPlaceholder(java.lang.String sql, int pos)Insert a placeholder at the given index; use a negative index to count from the back of the select list.booleanisAggregate()Return true if this is an aggregate select.booleanisDirty()booleanisDistinct()Whether this is a SELECT DISTINCT / UNION ALL.booleanisEmpty()Whether we have any joins.booleanisLob()Return true if this select includes a LOB.booleanisLRS()Whether the result of this select should be treated as a large result set.booleanisOuter()Whether this joins path results in outer joins.booleanisSelected(Table table)Return whether the given table is being used in this select.Joinsjoin(ForeignKey fk, boolean inverse, boolean toMany)Join the columns of the given foreign key.intjoinCount()JoinsjoinRelation(java.lang.String name, ForeignKey fk, ClassMapping target, int subs, boolean inverse, boolean toMany)Join the columns of the given foreign key, which represents a relation via the given field name.org.apache.openjpa.jdbc.sql.JoinSetjoins()voidlogEagerRelations()Extended trace that logs eager relationsvoidmoveJoinsToParent()Move joins that belong to subquery's parentJoinsnewJoins()Return a new instance to use for joining.JoinsnewOuterJoins()Return a new instance to use for outer joining.protected SelectImpl.SelectsnewSelects()voidnullJoins()Joinsor(Joins joins1, Joins joins2)OR the given joins together.booleanorderBy(java.lang.String sql, boolean asc, boolean sel)Add an ORDER BY clause.booleanorderBy(java.lang.String sql, boolean asc, Joins joins, boolean sel)Add an ORDER BY clause.intorderBy(Column[] cols, boolean asc, boolean sel)Order by the given columns.intorderBy(Column[] cols, boolean asc, Joins joins, boolean sel)Order by the given columns.booleanorderBy(Column col, boolean asc, boolean sel)Order by the given column.booleanorderBy(Column col, boolean asc, Joins joins, boolean sel)Order by the given column.booleanorderBy(SQLBuffer sql, boolean asc, boolean sel, Value selAs)Add an ORDER BY clause.booleanorderBy(SQLBuffer sql, boolean asc, Joins joins, boolean sel, Value selAs)Add an ORDER BY clause.intorderByPrimaryKey(ClassMapping mapping, boolean asc, boolean sel)Order on the primary key columns of the given mapping, joining to superclasses as necessary to get all columns needed to construct an object id.intorderByPrimaryKey(ClassMapping mapping, boolean asc, Joins joins, boolean sel)Select and order on the primary key columns of the given mapping, joining to superclasses as necessary to get all columns needed to construct an object id.intorderByPrimaryKey(ClassMapping mapping, boolean asc, Joins joins, boolean sel, boolean aliasOrder)Allow unions to set aliases on order columns.Joinsouter(Joins joins)Return a join set making the given joins outer joins.JoinsouterJoin(ForeignKey fk, boolean inverse, boolean toMany)Join the columns of the given foreign key.JoinsouterJoinRelation(java.lang.String name, ForeignKey fk, ClassMapping target, int subs, boolean inverse, boolean toMany)Join the columns of the given foreign key, which represents a relation via the given field name.java.lang.StringBuilderpath()java.sql.PreparedStatementprepareStatement(java.sql.Connection conn, java.lang.String sql)This method is to provide override for non-JDBC or JDBC-like implementation of preparing statement.protected java.sql.PreparedStatementprepareStatement(java.sql.Connection conn, SQLBuffer sql, JDBCFetchConfiguration fetch, int rsType, int rsConcur, boolean isLRS)This method is to provide override for non-JDBC or JDBC-like implementation of preparing statement.voidremoveAlias(java.lang.Object key)voidremoveTable(java.lang.Object key)booleanselect(java.lang.String sql, java.lang.Object id)Select the given SQL; the given id object is an identifier to use when retrieving the corresponding value from aResult.booleanselect(java.lang.String sql, java.lang.Object id, Joins joins)Select the given SQL; the given id object is an identifier to use when retrieving the corresponding value from aResult.voidselect(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, int eager)Select the columns of the given mapping, possibly including subclasses.voidselect(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, int eager, Joins joins)Select the columns of the given mapping, possibly including subclasses.booleanselect(Column col)Select the given column.intselect(Column[] cols)Select the given columns.intselect(Column[] cols, Joins joins)Select the given columns.booleanselect(Column col, Joins joins)Select the given column.booleanselect(SQLBuffer sql, java.lang.Object id)Select the given SQL; the given id object is an identifier to use when retrieving the corresponding value from aResult.booleanselect(SQLBuffer sql, java.lang.Object id, Joins joins)Select the given SQL; the given id object is an identifier to use when retrieving the corresponding value from aResult.voidselectIdentifier(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, int eager)Select the columns of the given mapping, possibly including subclasses.voidselectIdentifier(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, int eager, Joins joins)Select the columns of the given mapping, possibly including subclasses.booleanselectIdentifier(Column col)Select the given column as one that can be used to get a count of distinct matches.intselectIdentifier(Column[] cols)Select the given columns as ones that can be used to get a count of distinct matches.intselectIdentifier(Column[] cols, Joins joins)Select the given columns as ones that can be used to get a count of distinct matches.booleanselectIdentifier(Column col, Joins joins)Select the given column as one that can be used to get a count of distinct matches.voidselectPlaceholder(java.lang.String sql)Select the given SQL as a placeholder for a UNION element.intselectPrimaryKey(ClassMapping mapping)Select the primary key columns of the given mapping, joining to superclasses as necessary to get all columns needed to construct an object id.intselectPrimaryKey(ClassMapping mapping, Joins joins)Select the primary key columns of the given mapping, joining to superclasses as necessary to get all columns needed to construct an object id.voidsetAggregate(boolean agg)Set to true for aggregate selects.voidsetAutoDistinct(boolean val)Whether to automatically make results distinct when relational joins would otherwise introduce duplicates.voidsetContext(Context context)Set JPQL query context for this selectJoinssetCorrelatedVariable(java.lang.String var)Set the correlated variable name being traversed into with the next join.voidsetDistinct(boolean distinct)Whether this is a SELECT DISTINCT / UNION ALL.voidsetExcludedJoinedTableClassMeta(java.util.List meta)Set joined table metadatas excluded for polymorphic queriesvoidsetExpectedResultCount(int expectedResultCount, boolean force)The expected result count for the query.voidsetFromSelect(Select sel)Another select instance that creates a temporary table from which this select pulls data.voidsetHasSubselect(boolean hasSub)Set the flag to indicate whether this Select has internally generated subselectJoinssetJoinContext(Context ctx)Set subquery context when traversing into the next join is in transition from parent context to subquery.voidsetJoinedTableClassMeta(java.util.List meta)Set joined table metadatas for polymorphic queriesvoidsetJoinSyntax(int joinSyntax)The join syntax for this select, as one of the syntax constants fromJoinSyntaxes.voidsetLob(boolean lob)Set to true for selects that include LOB columns.voidsetLRS(boolean lrs)Whether the result of this select should be treated as a large result set.org.apache.openjpa.jdbc.sql.PathJoinssetOuter(boolean outer)voidsetParent(Select parent, java.lang.String path)Turn this select into a subselect of the given instance.voidsetRange(long start, long end)Set the result range for this select.voidsetSchemaAlias(java.lang.String schemaAlias)Record the initial schemaAlias of a join pathJoinssetSubselect(java.lang.String alias)Set the subquery alias.voidsetTablePerClassMeta(ClassMapping meta)Set table-per-class metadata for polymorphic queriesJoinssetVariable(java.lang.String var)Set the variable name being traversed into with the next join.booleansupportsLocking()Whether this select can be executed for update.booleansupportsRandomAccess(boolean forUpdate)Return whether this select can support a random access result set type.static java.lang.StringtoOrderAlias(int index)Helper method to return the proper order alias for the given order column index.SQLBuffertoSelect(boolean forUpdate, JDBCFetchConfiguration fetch)Return this select as a SQL statement formatted for the current dictionary.SQLBuffertoSelectCount()Return this select as a COUNT SQL statement formatted for the current dictionary.java.lang.StringtoString()Implement toString to generate SQL string for profiling/debuggging.voidwhere(java.lang.String sql)Add the given where conditions.voidwhere(java.lang.String sql, Joins joins)Add the given where conditions.voidwhere(Joins joins)Add the given where conditions.voidwhere(SQLBuffer sql)Add the given where conditions.voidwhere(SQLBuffer sql, Joins joins)Add the given where conditions.SelectExecutorwhereClone(int sels)Return a SELECT with the same joins and where conditions as this one.voidwhereForeignKey(ForeignKey fk, java.lang.Object oid, ClassMapping mapping, JDBCStore store)Add where conditions setting the given foreign key to the given oid values.voidwherePrimaryKey(java.lang.Object oid, ClassMapping mapping, JDBCStore store)Add where conditions setting the mapping's primary key to the given oid values.
-
-
-
Field Detail
-
_selects
protected final SelectImpl.Selects _selects
-
_outer
protected SelectImpl _outer
-
-
Constructor Detail
-
SelectImpl
public SelectImpl(JDBCConfiguration conf)
Constructor. Supply configuration.
-
-
Method Detail
-
getTablePerClassMeta
public ClassMapping getTablePerClassMeta()
Description copied from interface:Selectget table-per-class metadata for polymorphic queries- Specified by:
getTablePerClassMetain interfaceSelect
-
setTablePerClassMeta
public void setTablePerClassMeta(ClassMapping meta)
Description copied from interface:SelectSet table-per-class metadata for polymorphic queries- Specified by:
setTablePerClassMetain interfaceSelect
-
setJoinedTableClassMeta
public void setJoinedTableClassMeta(java.util.List meta)
Description copied from interface:SelectSet joined table metadatas for polymorphic queries- Specified by:
setJoinedTableClassMetain interfaceSelect
-
getJoinedTableClassMeta
public java.util.List getJoinedTableClassMeta()
Description copied from interface:Selectget joined table metadatas for polymorphic queries- Specified by:
getJoinedTableClassMetain interfaceSelect
-
setExcludedJoinedTableClassMeta
public void setExcludedJoinedTableClassMeta(java.util.List meta)
Description copied from interface:SelectSet joined table metadatas excluded for polymorphic queries- Specified by:
setExcludedJoinedTableClassMetain interfaceSelect
-
getExcludedJoinedTableClassMeta
public java.util.List getExcludedJoinedTableClassMeta()
Description copied from interface:Selectget joined table metadatas excluded for polymorphic queries- Specified by:
getExcludedJoinedTableClassMetain interfaceSelect
-
toOrderAlias
public static java.lang.String toOrderAlias(int index)
Helper method to return the proper order alias for the given order column index.
-
setContext
public void setContext(Context context)
Description copied from interface:SelectSet JPQL query context for this select- Specified by:
setContextin interfaceSelect
-
ctx
public Context ctx()
Description copied from interface:SelectReturn the JPQL query context of this select
-
setSchemaAlias
public void setSchemaAlias(java.lang.String schemaAlias)
Description copied from interface:SelectRecord the initial schemaAlias of a join path- Specified by:
setSchemaAliasin interfaceSelect
-
getConfiguration
public JDBCConfiguration getConfiguration()
Description copied from interface:SelectExecutorReturn the select configuration.- Specified by:
getConfigurationin interfaceSelectExecutor
-
toSelect
public SQLBuffer toSelect(boolean forUpdate, JDBCFetchConfiguration fetch)
Description copied from interface:SelectExecutorReturn this select as a SQL statement formatted for the current dictionary.- Specified by:
toSelectin interfaceSelectExecutor
-
getSQL
public SQLBuffer getSQL()
Description copied from interface:SelectExecutorGet the buffer if it has been computed by a previous call toSelectExecutor.toSelect(boolean, JDBCFetchConfiguration), if any.- Specified by:
getSQLin interfaceSelectExecutor
-
toSelectCount
public SQLBuffer toSelectCount()
Description copied from interface:SelectExecutorReturn this select as a COUNT SQL statement formatted for the current dictionary.- Specified by:
toSelectCountin interfaceSelectExecutor
-
getAutoDistinct
public boolean getAutoDistinct()
Description copied from interface:SelectExecutorWhether to automatically make results distinct when relational joins would otherwise introduce duplicates.- Specified by:
getAutoDistinctin interfaceSelectExecutor
-
setAutoDistinct
public void setAutoDistinct(boolean val)
Description copied from interface:SelectExecutorWhether to automatically make results distinct when relational joins would otherwise introduce duplicates.- Specified by:
setAutoDistinctin interfaceSelectExecutor
-
isDistinct
public boolean isDistinct()
Description copied from interface:SelectExecutorWhether this is a SELECT DISTINCT / UNION ALL.- Specified by:
isDistinctin interfaceSelectExecutor
-
setDistinct
public void setDistinct(boolean distinct)
Description copied from interface:SelectExecutorWhether this is a SELECT DISTINCT / UNION ALL.- Specified by:
setDistinctin interfaceSelectExecutor
-
isLRS
public boolean isLRS()
Description copied from interface:SelectExecutorWhether the result of this select should be treated as a large result set.- Specified by:
isLRSin interfaceSelectExecutor
-
setLRS
public void setLRS(boolean lrs)
Description copied from interface:SelectExecutorWhether the result of this select should be treated as a large result set.- Specified by:
setLRSin interfaceSelectExecutor
-
getExpectedResultCount
public int getExpectedResultCount()
Description copied from interface:SelectExecutorThe expected result count for the query.- Specified by:
getExpectedResultCountin interfaceSelectExecutor
-
setExpectedResultCount
public void setExpectedResultCount(int expectedResultCount, boolean force)Description copied from interface:SelectExecutorThe expected result count for the query.- Specified by:
setExpectedResultCountin interfaceSelectExecutorforce- 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:SelectExecutorThe join syntax for this select, as one of the syntax constants fromJoinSyntaxes.- Specified by:
getJoinSyntaxin interfaceSelectExecutor
-
setJoinSyntax
public void setJoinSyntax(int joinSyntax)
Description copied from interface:SelectExecutorThe join syntax for this select, as one of the syntax constants fromJoinSyntaxes.- Specified by:
setJoinSyntaxin interfaceSelectExecutor
-
supportsRandomAccess
public boolean supportsRandomAccess(boolean forUpdate)
Description copied from interface:SelectExecutorReturn whether this select can support a random access result set type.- Specified by:
supportsRandomAccessin interfaceSelectExecutor
-
supportsLocking
public boolean supportsLocking()
Description copied from interface:SelectExecutorWhether this select can be executed for update.- Specified by:
supportsLockingin interfaceSelectExecutor
-
hasMultipleSelects
public boolean hasMultipleSelects()
Description copied from interface:SelectExecutorAffirm if this receiver requires more than one selects to fetch its data.- Specified by:
hasMultipleSelectsin interfaceSelectExecutor
-
getCount
public int getCount(JDBCStore store) throws java.sql.SQLException
Description copied from interface:SelectExecutorReturn the number of instances matching this select.- Specified by:
getCountin interfaceSelectExecutor- Throws:
java.sql.SQLException
-
execute
public Result execute(JDBCStore store, JDBCFetchConfiguration fetch) throws java.sql.SQLException
Description copied from interface:SelectExecutorExecute this select in the context of the given store manager.- Specified by:
executein interfaceSelectExecutor- Throws:
java.sql.SQLException
-
execute
public Result execute(JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel) throws java.sql.SQLException
Description copied from interface:SelectExecutorExecute this select in the context of the given store manager.- Specified by:
executein interfaceSelectExecutor- Throws:
java.sql.SQLException
-
execute
protected Result execute(StoreContext ctx, JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel) throws java.sql.SQLException
Execute this select in the context of the given store manager. The context is passed in separately for profiling purposes.- Throws:
java.sql.SQLException
-
prepareStatement
protected java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, SQLBuffer sql, JDBCFetchConfiguration fetch, int rsType, int rsConcur, boolean isLRS) throws java.sql.SQLExceptionThis method is to provide override for non-JDBC or JDBC-like implementation of preparing statement.- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, java.lang.String sql) throws java.sql.SQLExceptionThis method is to provide override for non-JDBC or JDBC-like implementation of preparing statement.- Throws:
java.sql.SQLException
-
executeQuery
protected java.sql.ResultSet executeQuery(java.sql.Connection conn, java.sql.PreparedStatement stmnt, SQLBuffer sql, boolean isLRS, JDBCStore store) throws java.sql.SQLExceptionThis method is to provide override for non-JDBC or JDBC-like implementation of executing query.- Throws:
java.sql.SQLException
-
executeQuery
public java.sql.ResultSet executeQuery(java.sql.Connection conn, java.sql.PreparedStatement stmnt, java.lang.String sql, JDBCStore store, java.lang.Object[] params, Column[] cols) throws java.sql.SQLExceptionThis method is to provide override for non-JDBC or JDBC-like implementation of executing query.- Throws:
java.sql.SQLException
-
getCount
protected int getCount(java.sql.ResultSet rs) throws java.sql.SQLExceptionThis method is to provide override for non-JDBC or JDBC-like implementation of getting count from the result set.- Throws:
java.sql.SQLException
-
getEagerResult
public Result getEagerResult(java.sql.Connection conn, java.sql.PreparedStatement stmnt, java.sql.ResultSet rs, JDBCStore store, JDBCFetchConfiguration fetch, boolean forUpdate, SQLBuffer sql) throws java.sql.SQLException
This method is to provide override for non-JDBC or JDBC-like implementation of executing eager selects.- Throws:
java.sql.SQLException
-
indexOf
public int indexOf()
Description copied from interface:SelectThe index of this select within the UNION, or 0.
-
getSubselects
public java.util.List getSubselects()
Description copied from interface:SelectReturn this select's subselects, or empty collection if none.- Specified by:
getSubselectsin interfaceSelect
-
getParent
public Select getParent()
Description copied from interface:SelectReturn the parent of this select, if it is a subselect.
-
getSubselectPath
public java.lang.String getSubselectPath()
Description copied from interface:SelectReturn the subselect path for this select, if it is a subselect.- Specified by:
getSubselectPathin interfaceSelect
-
setParent
public void setParent(Select parent, java.lang.String path)
Description copied from interface:SelectTurn this select into a subselect of the given instance.
-
setHasSubselect
public void setHasSubselect(boolean hasSub)
Description copied from interface:SelectSet the flag to indicate whether this Select has internally generated subselect- Specified by:
setHasSubselectin interfaceSelect
-
getHasSubselect
public boolean getHasSubselect()
Description copied from interface:SelectReturn the flag to indicate whether this Select has internally generated subselect- Specified by:
getHasSubselectin interfaceSelect
-
getAliases
public java.util.Map getAliases()
-
removeAlias
public void removeAlias(java.lang.Object key)
-
getTables
public java.util.Map getTables()
-
removeTable
public void removeTable(java.lang.Object key)
-
getFromSelect
public Select getFromSelect()
Description copied from interface:SelectAnother select instance that creates a temporary table from which this select pulls data.- Specified by:
getFromSelectin interfaceSelect
-
setFromSelect
public void setFromSelect(Select sel)
Description copied from interface:SelectAnother select instance that creates a temporary table from which this select pulls data.- Specified by:
setFromSelectin interfaceSelect
-
hasEagerJoin
public boolean hasEagerJoin(boolean toMany)
Description copied from interface:SelectWhether this select has an eager join of the specified type.- Specified by:
hasEagerJoinin interfaceSelect
-
hasJoin
public boolean hasJoin(boolean toMany)
Description copied from interface:SelectWhether this select has a join of the specified type.
-
isSelected
public boolean isSelected(Table table)
Description copied from interface:SelectReturn whether the given table is being used in this select.- Specified by:
isSelectedin interfaceSelect
-
getTableAliases
public java.util.Collection getTableAliases()
Description copied from interface:SelectReturn the set of all used table aliases.- Specified by:
getTableAliasesin interfaceSelect
-
getSelects
public java.util.List getSelects()
Description copied from interface:SelectReturn the actualVals andColumns that were selected, in the order that they were selected.- Specified by:
getSelectsin interfaceSelect
-
getSelectAliases
public java.util.List getSelectAliases()
Description copied from interface:SelectReturn the aliases of all selected columns and all selected buffers, in the order they were selected. Each alias may be either a string or aSQLBuffer.- Specified by:
getSelectAliasesin interfaceSelect
-
getIdentifierAliases
public java.util.List getIdentifierAliases()
Description copied from interface:SelectGet the aliases for identifier columns that can be used in COUNT selects to find the number of matches. Each alias will be a string. If no identifier columns have been nominated, then all column alises are returned.- Specified by:
getIdentifierAliasesin interfaceSelect
-
getOrdering
public SQLBuffer getOrdering()
Description copied from interface:SelectReturn the ordering SQL for this select.- Specified by:
getOrderingin interfaceSelect
-
getGrouping
public SQLBuffer getGrouping()
Description copied from interface:SelectReturn the grouping SQL for this select.- Specified by:
getGroupingin interfaceSelect
-
getWhere
public SQLBuffer getWhere()
Description copied from interface:SelectReturn the WHERE clause, minus any necessary end joins.
-
getHaving
public SQLBuffer getHaving()
Description copied from interface:SelectReturn the HAVING clause, or null if none.
-
addJoinClassConditions
public void addJoinClassConditions()
Description copied from interface:SelectApply class conditions from relation joins. This may affect the return values ofSelect.getJoins(),Select.getJoinIterator(), andSelect.getWhere().- Specified by:
addJoinClassConditionsin interfaceSelect
-
getJoins
public Joins getJoins()
Description copied from interface:SelectReturn the top-level joins for this select.
-
getJoinIterator
public java.util.Iterator getJoinIterator()
Description copied from interface:SelectReturn the top-levelJoinelements for this select.- Specified by:
getJoinIteratorin interfaceSelect
-
getStartIndex
public long getStartIndex()
Description copied from interface:SelectThe result start index.- Specified by:
getStartIndexin interfaceSelect
-
getEndIndex
public long getEndIndex()
Description copied from interface:SelectThe result end index.- Specified by:
getEndIndexin interfaceSelect
-
setRange
public void setRange(long start, long end)Description copied from interface:SelectSet the result range for this select.
-
getColumnAlias
public java.lang.String getColumnAlias(Column col)
Description copied from interface:SelectReturn the alias for the given column.- Specified by:
getColumnAliasin interfaceSelect
-
getColumnAlias
public java.lang.String getColumnAlias(Column col, Joins joins)
Description copied from interface:SelectReturn the alias for the given column.- Specified by:
getColumnAliasin interfaceSelect
-
getColumnAlias
public java.lang.String getColumnAlias(java.lang.String col, Table table)Description copied from interface:SelectReturn the alias for the given column.- Specified by:
getColumnAliasin interfaceSelect
-
getColumnAlias
public java.lang.String getColumnAlias(java.lang.String col, Table table, Joins joins)Description copied from interface:SelectReturn the alias for the given column.- Specified by:
getColumnAliasin interfaceSelect
-
getColumnAlias
public java.lang.String getColumnAlias(Column col, java.lang.Object path)
Return the alias for the give column- Specified by:
getColumnAliasin interfaceSelect
-
isAggregate
public boolean isAggregate()
Description copied from interface:SelectReturn true if this is an aggregate select.- Specified by:
isAggregatein interfaceSelect
-
setAggregate
public void setAggregate(boolean agg)
Description copied from interface:SelectSet to true for aggregate selects.- Specified by:
setAggregatein interfaceSelect
-
isLob
public boolean isLob()
Description copied from interface:SelectReturn true if this select includes a LOB.
-
setLob
public void setLob(boolean lob)
Description copied from interface:SelectSet to true for selects that include LOB columns.
-
clearSelects
public void clearSelects()
Description copied from interface:SelectClear the existing column selects.- Specified by:
clearSelectsin interfaceSelect
-
select
public boolean select(SQLBuffer sql, java.lang.Object id)
Description copied from interface:SelectSelect the given SQL; the given id object is an identifier to use when retrieving the corresponding value from aResult.
-
select
public boolean select(SQLBuffer sql, java.lang.Object id, Joins joins)
Description copied from interface:SelectSelect the given SQL; the given id object is an identifier to use when retrieving the corresponding value from aResult.
-
select
public boolean select(java.lang.String sql, java.lang.Object id)Description copied from interface:SelectSelect the given SQL; the given id object is an identifier to use when retrieving the corresponding value from aResult.
-
select
public boolean select(java.lang.String sql, java.lang.Object id, Joins joins)Description copied from interface:SelectSelect the given SQL; the given id object is an identifier to use when retrieving the corresponding value from aResult.
-
selectPlaceholder
public void selectPlaceholder(java.lang.String sql)
Description copied from interface:SelectSelect the given SQL as a placeholder for a UNION element.- Specified by:
selectPlaceholderin interfaceSelect
-
insertPlaceholder
public void insertPlaceholder(java.lang.String sql, int pos)Insert a placeholder at the given index; use a negative index to count from the back of the select list.
-
clearPlaceholderSelects
public void clearPlaceholderSelects()
Clear selected placeholders, and return removed select indexes.
-
select
public boolean select(Column col)
Description copied from interface:SelectSelect the given column.
-
select
public boolean select(Column col, Joins joins)
Description copied from interface:SelectSelect the given column.
-
select
public int select(Column[] cols)
Description copied from interface:SelectSelect the given columns.
-
select
public int select(Column[] cols, Joins joins)
Description copied from interface:SelectSelect the given columns.
-
select
public void select(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, int eager)
Description copied from interface:SelectSelect the columns of the given mapping, possibly including subclasses. This method should be called after all where conditions are added in case the given mapping batches other selects.
-
select
public void select(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, int eager, Joins joins)
Description copied from interface:SelectSelect the columns of the given mapping, possibly including subclasses. This method should be called after all where conditions are added in case the given mapping batches other selects.
-
selectIdentifier
public boolean selectIdentifier(Column col)
Description copied from interface:SelectSelect the given column as one that can be used to get a count of distinct matches. It is not necessary to designate distinct identifiers when eagerly traversing the entire result of the select or when not using an LRSSize setting ofcount.- Specified by:
selectIdentifierin interfaceSelect- Returns:
- true if selected
-
selectIdentifier
public boolean selectIdentifier(Column col, Joins joins)
Description copied from interface:SelectSelect the given column as one that can be used to get a count of distinct matches. It is not necessary to designate distinct identifiers when eagerly traversing the entire result of the select or when not using an LRSSize setting ofcount.- Specified by:
selectIdentifierin interfaceSelect- Returns:
- true if selected
-
selectIdentifier
public int selectIdentifier(Column[] cols)
Description copied from interface:SelectSelect the given columns as ones that can be used to get a count of distinct matches. It is not necessary to designate distinct identifiers when eagerly traversing the entire result of the select or when not using an LRSSize setting ofcount.- Specified by:
selectIdentifierin interfaceSelect- Returns:
- bit set of indexes of columns that were selected
-
selectIdentifier
public int selectIdentifier(Column[] cols, Joins joins)
Description copied from interface:SelectSelect the given columns as ones that can be used to get a count of distinct matches. It is not necessary to designate distinct identifiers when eagerly traversing the entire result of the select or when not using an LRSSize setting ofcount.- Specified by:
selectIdentifierin interfaceSelect- Returns:
- bit set of indexes of columns that were selected
-
selectIdentifier
public void selectIdentifier(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, int eager)
Description copied from interface:SelectSelect the columns of the given mapping, possibly including subclasses. This method should be called after all where conditions are added in case the given mapping batches other selects. The primary key columns of the mapping can be used to get a count of distinct matches. It is not necessary to designate distinct identifiers when eagerly traversing the entire result of the select or when not using an LRSSize setting ofcount.- Specified by:
selectIdentifierin interfaceSelect
-
selectIdentifier
public void selectIdentifier(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, int eager, Joins joins)
Description copied from interface:SelectSelect the columns of the given mapping, possibly including subclasses. This method should be called after all where conditions are added in case the given mapping batches other selects. The primary key columns of the mapping can be used to get a count of distinct matches. It is not necessary to designate distinct identifiers when eagerly traversing the entire result of the select or when not using an LRSSize setting ofcount.- Specified by:
selectIdentifierin interfaceSelect
-
selectPrimaryKey
public int selectPrimaryKey(ClassMapping mapping)
Description copied from interface:SelectSelect the primary key columns of the given mapping, joining to superclasses as necessary to get all columns needed to construct an object id.- Specified by:
selectPrimaryKeyin interfaceSelect- Returns:
- bit set of indexes of pk columns that were selected
-
selectPrimaryKey
public int selectPrimaryKey(ClassMapping mapping, Joins joins)
Description copied from interface:SelectSelect the primary key columns of the given mapping, joining to superclasses as necessary to get all columns needed to construct an object id.- Specified by:
selectPrimaryKeyin interfaceSelect- Returns:
- bit set of indexes of pk columns that were selected
-
orderByPrimaryKey
public int orderByPrimaryKey(ClassMapping mapping, boolean asc, boolean sel)
Description copied from interface:SelectOrder on the primary key columns of the given mapping, joining to superclasses as necessary to get all columns needed to construct an object id. Optionally selects ordering data if not already selected.- Specified by:
orderByPrimaryKeyin interfaceSelect
-
orderByPrimaryKey
public int orderByPrimaryKey(ClassMapping mapping, boolean asc, Joins joins, boolean sel)
Description copied from interface:SelectSelect and order on the primary key columns of the given mapping, joining to superclasses as necessary to get all columns needed to construct an object id. Optionally selects ordering data if not already selected.- Specified by:
orderByPrimaryKeyin interfaceSelect
-
orderByPrimaryKey
public int orderByPrimaryKey(ClassMapping mapping, boolean asc, Joins joins, boolean sel, boolean aliasOrder)
Allow unions to set aliases on order columns.
-
orderBy
public boolean orderBy(Column col, boolean asc, boolean sel)
Description copied from interface:SelectOrder by the given column. Optionally selects ordering data if not already selected.
-
orderBy
public boolean orderBy(Column col, boolean asc, Joins joins, boolean sel)
Description copied from interface:SelectOrder by the given column. Optionally selects ordering data if not already selected.
-
orderBy
public int orderBy(Column[] cols, boolean asc, boolean sel)
Description copied from interface:SelectOrder by the given columns. Optionally selects ordering data if not already selected.
-
orderBy
public int orderBy(Column[] cols, boolean asc, Joins joins, boolean sel)
Description copied from interface:SelectOrder by the given columns. Optionally selects ordering data if not already selected.
-
orderBy
public boolean orderBy(SQLBuffer sql, boolean asc, boolean sel, Value selAs)
Description copied from interface:SelectAdd an ORDER BY clause. Optionally selects ordering data if not already selected.
-
orderBy
public boolean orderBy(SQLBuffer sql, boolean asc, Joins joins, boolean sel, Value selAs)
Description copied from interface:SelectAdd an ORDER BY clause. Optionally selects ordering data if not already selected.
-
orderBy
public boolean orderBy(java.lang.String sql, boolean asc, boolean sel)Description copied from interface:SelectAdd an ORDER BY clause. Optionally selects ordering data if not already selected.
-
orderBy
public boolean orderBy(java.lang.String sql, boolean asc, Joins joins, boolean sel)Description copied from interface:SelectAdd an ORDER BY clause. Optionally selects ordering data if not already selected.
-
clearOrdering
public void clearOrdering()
Description copied from interface:SelectClear odering conditions.- Specified by:
clearOrderingin interfaceSelect
-
wherePrimaryKey
public void wherePrimaryKey(java.lang.Object oid, ClassMapping mapping, JDBCStore store)Description copied from interface:SelectAdd where conditions setting the mapping's primary key to the given oid values. If the given mapping does not use oid values for its primary key, we will recursively join to its superclass until we find an ancestor that does.- Specified by:
wherePrimaryKeyin interfaceSelect
-
whereForeignKey
public void whereForeignKey(ForeignKey fk, java.lang.Object oid, ClassMapping mapping, JDBCStore store)
Description copied from interface:SelectAdd where conditions setting the given foreign key to the given oid values.- Specified by:
whereForeignKeyin interfaceSelect- See Also:
Select.wherePrimaryKey(java.lang.Object, org.apache.openjpa.jdbc.meta.ClassMapping, org.apache.openjpa.jdbc.kernel.JDBCStore)
-
where
public void where(Joins joins)
Description copied from interface:SelectAdd the given where conditions.
-
where
public void where(SQLBuffer sql)
Description copied from interface:SelectAdd the given where conditions.
-
where
public void where(SQLBuffer sql, Joins joins)
Description copied from interface:SelectAdd the given where conditions.
-
where
public void where(java.lang.String sql)
Description copied from interface:SelectAdd the given where conditions.
-
where
public void where(java.lang.String sql, Joins joins)Description copied from interface:SelectAdd the given where conditions.
-
having
public void having(SQLBuffer sql)
Description copied from interface:SelectAdd the given having conditions.
-
having
public void having(SQLBuffer sql, Joins joins)
Description copied from interface:SelectAdd the given having conditions.
-
having
public void having(java.lang.String sql)
Description copied from interface:SelectAdd the given having conditions.
-
having
public void having(java.lang.String sql, Joins joins)Description copied from interface:SelectAdd the given having conditions.
-
groupBy
public void groupBy(SQLBuffer sql)
Description copied from interface:SelectAdd a GROUP BY clause.
-
groupBy
public void groupBy(SQLBuffer sql, Joins joins)
Description copied from interface:SelectAdd a GROUP BY clause.
-
groupBy
public void groupBy(java.lang.String sql)
Description copied from interface:SelectAdd a GROUP BY clause.
-
groupBy
public void groupBy(java.lang.String sql, Joins joins)Description copied from interface:SelectAdd a GROUP BY clause.
-
groupBy
public void groupBy(Column col)
Description copied from interface:SelectGroup by the given column.
-
groupBy
public void groupBy(Column col, Joins joins)
Description copied from interface:SelectGroup by the given column.
-
groupBy
public void groupBy(Column[] cols)
Description copied from interface:SelectGroup by the given columns.
-
groupBy
public void groupBy(Column[] cols, Joins joins)
Description copied from interface:SelectGroup by the given columns.
-
groupBy
public void groupBy(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch)
Description copied from interface:SelectGroup by the columns of the given mapping, possibly including subclasses. Assumes EAGER_NONE.
-
groupBy
public void groupBy(ClassMapping mapping, int subclasses, JDBCStore store, JDBCFetchConfiguration fetch, Joins joins)
Description copied from interface:SelectGroup by the columns of the given mapping, possibly including subclasses. Assumes EAGER_NONE.
-
whereClone
public SelectExecutor whereClone(int sels)
Description copied from interface:SelectReturn a SELECT with the same joins and where conditions as this one.- Specified by:
whereClonein interfaceSelect- Parameters:
sels- number of selects to UNION together; ignored if <= 1
-
fullClone
public SelectExecutor fullClone(int sels)
Description copied from interface:SelectReturn a SELECT that is a complete clone of this one.
-
eagerClone
public SelectExecutor eagerClone(FieldMapping key, int eagerType, boolean toMany, int sels)
Description copied from interface:SelectReturn a select that will be eagerly executed with this one, or null if the select cannot be created for the given key and join type. If the join type is inner or outer, then this select instance will be returned. Otherwise, the returned select will have a clone of this select's where conditions and joins but will be independent.- Specified by:
eagerClonein interfaceSelect- Parameters:
key- the key for the eager selecteagerType- one of the EAGER_* constantstoMany- whether the eager join is to-manysels- number of selects to UNION together; ignored if <= 1
-
getEagerMap
public java.util.Map getEagerMap()
Return view of eager selects. May be null.
-
logEagerRelations
public void logEagerRelations()
Description copied from interface:SelectExtended trace that logs eager relations- Specified by:
logEagerRelationsin interfaceSelect
-
getEager
public SelectExecutor getEager(FieldMapping key)
Description copied from interface:SelectReturn the eager select for the given key.
-
newJoins
public Joins newJoins()
Description copied from interface:SelectReturn a new instance to use for joining.
-
newOuterJoins
public Joins newOuterJoins()
Description copied from interface:SelectReturn a new instance to use for outer joining.- Specified by:
newOuterJoinsin interfaceSelect
-
append
public void append(SQLBuffer buf, Joins joins)
Description copied from interface:SelectAppend the given joins to the given buffer.
-
and
public Joins and(Joins joins1, Joins joins2)
Description copied from interface:SelectAND the given joins together. The given joins will be hollowed in the process.
-
getSelect
public Select getSelect()
-
or
public Joins or(Joins joins1, Joins joins2)
Description copied from interface:SelectOR the given joins together. The common joins will be removed in the process.
-
outer
public Joins outer(Joins joins)
Description copied from interface:SelectReturn a join set making the given joins outer joins.
-
toString
public java.lang.String toString()
Description copied from interface:SelectImplement toString to generate SQL string for profiling/debuggging.
-
isOuter
public boolean isOuter()
Description copied from interface:JoinsWhether this joins path results in outer joins.
-
setOuter
public org.apache.openjpa.jdbc.sql.PathJoins setOuter(boolean outer)
-
isDirty
public boolean isDirty()
-
path
public java.lang.StringBuilder path()
-
getPathStr
public java.lang.String getPathStr()
-
joins
public org.apache.openjpa.jdbc.sql.JoinSet joins()
-
joinCount
public int joinCount()
-
nullJoins
public void nullJoins()
-
isEmpty
public boolean isEmpty()
Description copied from interface:JoinsWhether we have any joins.
-
crossJoin
public Joins crossJoin(Table localTable, Table foreignTable)
Description copied from interface:JoinsPerform a cross join on the given tables.
-
join
public Joins join(ForeignKey fk, boolean inverse, boolean toMany)
Description copied from interface:JoinsJoin the columns of the given foreign key.
-
outerJoin
public Joins outerJoin(ForeignKey fk, boolean inverse, boolean toMany)
Description copied from interface:JoinsJoin the columns of the given foreign key.
-
joinRelation
public Joins joinRelation(java.lang.String name, ForeignKey fk, ClassMapping target, int subs, boolean inverse, boolean toMany)
Description copied from interface:JoinsJoin the columns of the given foreign key, which represents a relation via the given field name.- Specified by:
joinRelationin interfaceJoins
-
outerJoinRelation
public Joins outerJoinRelation(java.lang.String name, ForeignKey fk, ClassMapping target, int subs, boolean inverse, boolean toMany)
Description copied from interface:JoinsJoin the columns of the given foreign key, which represents a relation via the given field name.- Specified by:
outerJoinRelationin interfaceJoins
-
setVariable
public Joins setVariable(java.lang.String var)
Description copied from interface:JoinsSet the variable name being traversed into with the next join.- Specified by:
setVariablein interfaceJoins
-
setSubselect
public Joins setSubselect(java.lang.String alias)
Description copied from interface:JoinsSet the subquery alias.- Specified by:
setSubselectin interfaceJoins
-
clone
public SelectImpl clone(Context ctx)
-
newSelects
protected SelectImpl.Selects newSelects()
-
getDictionary
public DBDictionary getDictionary()
- Specified by:
getDictionaryin interfaceSelect
-
setCorrelatedVariable
public Joins setCorrelatedVariable(java.lang.String var)
Description copied from interface:JoinsSet the correlated variable name being traversed into with the next join.- Specified by:
setCorrelatedVariablein interfaceJoins
-
setJoinContext
public Joins setJoinContext(Context ctx)
Description copied from interface:JoinsSet subquery context when traversing into the next join is in transition from parent context to subquery.- Specified by:
setJoinContextin interfaceJoins
-
getCorrelatedVariable
public java.lang.String getCorrelatedVariable()
Description copied from interface:JoinsReturn correlated variable name- Specified by:
getCorrelatedVariablein interfaceJoins
-
moveJoinsToParent
public void moveJoinsToParent()
Description copied from interface:JoinsMove joins that belong to subquery's parent- Specified by:
moveJoinsToParentin interfaceJoins
-
-