Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.7.2)

E13403-10


oracle.javatools.db.sql
Class AbstractSQLQueryBuilder

java.lang.Object
  extended by oracle.javatools.db.sql.AbstractSQLQueryBuilder

All Implemented Interfaces:
SQLQueryBuilder

public abstract class AbstractSQLQueryBuilder
extends java.lang.Object
implements SQLQueryBuilder

Abstract implementation of SQLQuery that performs functions generic to any builder.

Since:
10.1.3

Nested Class Summary

 

Nested classes/interfaces inherited from interface oracle.javatools.db.sql.SQLQueryBuilder
SQLQueryBuilder.SQLQueryObjectSet

 

Field Summary
protected static SQLFragment[] EMPTY_ARRAY
           
protected  Schema m_defaultSchema
           
protected  DBObjectProvider m_provider
           
protected  AbstractSQLQuery m_query
           

 

Constructor Summary
protected AbstractSQLQueryBuilder(DBObjectProvider provider, Schema defaultSchema)
          Construtor

 

Method Summary
 void addFromObject(FromObject from)
          Adds the given FromObject to the query.
protected  void addFromObjects(FromObject[] froms)
           
 void addGroupByColumn(FromObjectUsage colu)
          Adds the given FromObjectUsage to the end of the GROUP BY clause.
 void addGroupByColumn(int index, FromObjectUsage colu)
          Adds the given FromObjectUsage to the specified index of the GROUP BY clause.
protected  void addJoinObject(FromObject from)
           
 void addOrderByObject(int index, OrderByObject ob)
          Adds the given order by object to the given index in the clause.
 void addOrderByObject(OrderByObject ob)
          Adds the given order by object to the end of the order by clause.
 void addSelectObject(int index, SelectObject select)
          Inserts the given SelectObject to the query at the given index.
 void addSelectObject(SelectObject select)
          Adds the given SelectObject to the query.
protected  void addSelectObjects(SelectObject[] selects)
           
abstract  void buildQuery(SQLQuery query)
          Builds the query based on the given SQLQuery.
 void buildQuery(java.lang.String sql)
          Builds a query object from the given sql expression.
 void buildQuery(java.lang.String sql, SQLQueryOwner parent)
          Builds a query from the given sql expression.
protected abstract  void buildQueryImpl(java.lang.String sql, SQLQueryOwner parent)
          Builds the query based on the given select statement.
 boolean canMergeRelationUsages(RelationUsage baseUsage, RelationUsage mergingUsage)
          Determines whether the two RelationUsages are based on the same table.
 boolean canSetGroupBy()
          Returns true if this query can accept a group by clause.
 void checkUsageQualifications()
          Checks that every FromObjectUsage which isn't qualified is a unique name within the query.
 SQLQueryBuilder.SQLQueryObjectSet constructFKJoin(FKConstraint fk, FromObject left, FromObject right)
          Creates a JOIN in the query's FROM clause to represent the given FKConstraint.
 SQLQueryBuilder.SQLQueryObjectSet constructFKJoins(FKConstraint[] fks, FromObject[] usagesToUse)
          Creates a set of nested JOINs in the query's FROM clause to represent each given FKConstraint.
 SQLQueryBuilder.SQLQueryObjectSet constructFromObject(Relation relation, boolean createSelectObjects, boolean createJoins, FromObject[] includeInJoins)
          Creates a FromObject for the query.
 FromObject constructFromObject(java.lang.String expression, java.lang.String alias)
          Creates a FromObject using the given alias and expression, parsing the expression into an appropriate set of SQLFragments.
 SQLQueryBuilder.SQLQueryObjectSet constructFromObjects(Relation[] baseRelations, boolean createSelectObjects, boolean createJoins, FromObject[] includeInJoins)
          Creates one or more FromObjects for the query.
 SQLQueryBuilder.SQLQueryObjectSet constructSelectObject(Column col, FromObject usageToUse)
          Creates a SelectObject for the query based on the column passed in.
 SelectObject constructSelectObject(java.lang.String expression, java.lang.String alias)
          Creates a SelectObject using the given alias and expression, parsing the expression into an appropriate set of SQLFragments.
 SQLQueryBuilder.SQLQueryObjectSet constructSelectObjects(Column[] baseCols, FromObject[] usagesToUse)
          Creates a set of SelectObjects for the query based on the columns passed in.
protected  FKUsage createFKUsage(DBObjectID fkID, FromObject left, FromObject right)
           
protected  FromObject createFromObject(Relation rel, java.util.List extraNames)
           
protected  JoinCondition createJoinCondition(FKConstraint fk, JoinObject join)
          Constructs a condition to represent the given FK for the given join.
 FromObject createJoinObject(FKConstraint fk, FromObject left, FromObject right)
           
protected  SelectObject createSelectObject(DBObjectID colId, FromObject from, java.lang.String alias)
           
 java.lang.String createUniqueFromAlias(java.lang.String base)
          Takes the given base for an alias and returns an alias that will be unique within this builder's query.
protected  java.lang.String createUniqueFromAlias(java.lang.String base, java.util.List extraNames)
           
 java.lang.String createUniqueSelectAlias(java.lang.String base)
          Takes the given base for an alias and returns an alias that will be unique within this builder's query.
protected  java.lang.String createUniqueSelectAlias(java.lang.String base, java.util.List extraNames)
           
protected  FKUsage doConstructFKUsage(FKConstraint fk, java.util.Map relsIDsToUse, java.util.List newFroms)
           
protected  FromObject doConstructFromObject(Relation relation, java.util.List baseRelIDs, java.util.List relNames, java.util.Map newRels, java.util.List cols, java.util.List fks)
           
protected  FromObject doConstructJoin(FKConstraint fk, java.util.Map relsIDsToUse, java.util.List newFroms, FromObject left, FromObject right)
           
protected  SelectObject doConstructSelectObject(Column col, java.util.Map relsToUse, java.util.Map newRels, java.util.List relNames, java.util.List colNames)
           
protected  DBObjectID ensureID(DBObject s)
          Only call on an object that has been added to the hierarchy - e.g.
protected  void ensureIDs(SQLFragment... frags)
           
protected  FromObjectUsage findColumnInColumnUsage(java.lang.String colName, ColumnUsage colu, FromObject from)
           
protected  FromObjectUsage findColumnInFromExpression(java.lang.String colName, SQLFragment exp, boolean allowDuplicates, FromObject from, SQLFragment creating)
           
protected  FromObjectUsage findColumnInFromObjects(java.lang.String colName, FromObject[] froms, boolean allowDuplicates, boolean enforceInAll, SQLFragment creating)
          Finds a Column of given name amongst the given FromObjects.
protected  FromObjectUsage findColumnInFromObjects(java.lang.String colName, SQLFragment creating, FromObject... extraFroms)
          Finds a Column of given name amongst the RelationUsages in the query.
protected  FromObjectUsage findColumnInJoin(java.lang.String colName, JoinObject join, boolean allowDuplicates, SQLFragment creating)
           
protected  FromObjectUsage findColumnInRelation(java.lang.String colName, Relation rel)
          Warning: The returned ColumnUsage won't have a FromObject set.
protected  FromObjectUsage findColumnInRelation(java.lang.String colName, RelationUsage relU)
           
protected  SelectObjectUsage findColumnInSubQuery(java.lang.String colName, SQLQuery query)
           
 ColumnUsage[] getColumnUsages()
          Returns all the ColumnUsage objects that are present in this query's SELECT and WHERE clauses.
 SQLFragment[] getDependentObjects(FromObject from)
          Gets the objects in the query that are dependent on the given from object.
 SQLFragment[] getDependentObjects(SelectObject select)
          Gets the objects in the query that are dependent on the given select object.
protected  java.lang.String getExternalName(java.lang.String name)
           
 FromObject getFromObject(java.lang.String usableAlias)
          Returns the from object that can be referenced by this alias.
protected  FromObject getFromObject(java.lang.String usableAlias, FromObject extrafrom)
          Gets a FromObject with the given alias.
protected  java.util.List getIDs(DBObject[] objs)
           
protected  java.lang.String getInternalName(java.lang.String name)
           
protected  SchemaObject getObject(java.lang.String type, Schema sch, java.lang.String relation)
           
 RelationUsage[] getRelationUsages()
          Returns the RelationUsages found in the SQLQuery.
protected  java.util.Map getRelIDs(FromObject[] usagesToUse)
           
 SelectObject getSelectObject(java.lang.String usableAlias)
          Returns the select object that can be referenced by this alias.
 AbstractSQLQuery getSQLQuery()
          Returns the query that this builder is working on.
 boolean isUniqueFromAlias(java.lang.String alias)
          Returns true if this alias is unique within the builder's query.
protected  boolean isUniqueFromAlias(java.lang.String alias, java.util.List extraNames)
           
 boolean isUniqueSelectAlias(java.lang.String alias)
          Returns true if this alias is unique within the builder's query.
protected  boolean isUniqueSelectAlias(java.lang.String alias, java.util.List extraNames)
           
protected  boolean isValidName(java.lang.String type, java.lang.String name)
           
 FromObject[] listAllFromObjects()
          Returns all FromObjects in the FROM clause including those nested in JOIN conditions.
 FromObject[] listAllFromObjects(boolean includeJoins)
          Returns all FromObjects in the FROM clause including those nested in JOIN conditions.
 FKUsage[] listAvailableFKs()
          Returns all the FKs that could join the relations used in the view wrapped up in an FKUsage so as to include the appropriate FromObjects.
protected  void loadObject(DBObject frag)
          Load the given object (i.e.
protected  void loadObjects(DBObject[] frags)
           
protected  void loadQuery()
           
 void mergeRelationUsages(RelationUsage baseUsage, RelationUsage mergingUsage)
          Merges two RelationUsages into one.
 SQLFragment parseFromExpression(java.lang.String expression)
          Parses an expression to see if it is a valid expression for a From object.
protected abstract  SQLFragment parseFromExpression(java.lang.String expression, FromObject creating)
           
 SQLFragment parseHavingExpression(java.lang.String expression)
          By default this calls parseWhereExpression().
 SQLFragment parseOrderByExpression(java.lang.String expression)
          By default this calls parseSelectExpression().
 SQLFragment parseSelectExpression(java.lang.String expression)
          Parses an expression to see if it is a valid expression for a Select object.
protected abstract  SQLFragment parseSelectExpression(java.lang.String expression, SelectObject creating)
           
 SQLFragment parseWhereExpression(java.lang.String expression)
          Parses an expression to see if it is a valid expression for a Where object.
abstract  SQLFragment parseWhereExpression(java.lang.String expression, WhereObject creating)
           
 boolean removeFromObject(FromObject obj)
          Removes the given FromObject from the SQLQuery.
 boolean removeGroupByColumn(FromObjectUsage colu)
          Removes the given FromObjectUsage from the GROUP BY clause.
 boolean removeJoinObject(FromObject obj)
          If the expression for the given obj is a JoinObject the join is removed and the two FromObjects that were joined are added to the top level of the query.
 boolean removeOrderByObject(OrderByObject ob)
          Removes the given order by object from the orderby clause.
 boolean removeSelectObject(SelectObject obj)
          Removes the given SelectObject from the SQLQuery.
protected  boolean removeWhereObject(SQLFragment obj)
          Removes a top level WhereObject from the WHERE clause.
 void replaceFromObject(FromObject oldFrom, FromObject newFrom)
          Replaces the existing from object with a new one.
 void replaceOrderByObject(OrderByObject oldOb, OrderByObject newOb)
          Replaces the existing from object with a new one.
 void replaceSelectObject(SelectObject oldSelect, SelectObject newSelect)
          Replaces the existing select object with a new one.
 void setGroupByObject(GroupByObject obj)
          Sets the group by object.
 void setHavingObject(WhereObject having)
          Sets the HAVING clause of the query.
 void setHierarchicalQueryObject(HierarchicalQueryObject obj)
          Sets the CONNECT BY clause of the query.
protected  void setNewFromObject(DBObject frag, FromObject oldFrom, FromObject newFrom)
           
 void setOrderByObjects(OrderByObject[] orderbys)
          Sets the order by objects for the query.
 void setSingleRelation(Relation singleRelation)
           
protected  void setViewColDataType(ViewColumn col)
           
 void setWhereObject(WhereObject obj)
          Sets the WhereObject on the query (whilst caching any appropriate dependencies).
 void syncViewColumns()
          If the query is a View query ( @see isViewQuery() ) this syncs the SelectObjects in the query with the Columns in the View.
protected
<T extends SQLQueryException>
void
throwException(T sqe)
           
protected  void unloadObject(DBObject frag)
           
 void validateQuery()
          Validates a query object to check that its internal structure is correct.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Methods inherited from interface oracle.javatools.db.sql.SQLQueryBuilder
getBuiltInFunctions, parseOnExpression, supportsConnectBy, supportsGroupBy, supportsOrderBy

 

Field Detail

EMPTY_ARRAY

protected static final SQLFragment[] EMPTY_ARRAY

m_query

protected AbstractSQLQuery m_query

m_provider

protected DBObjectProvider m_provider

m_defaultSchema

protected Schema m_defaultSchema

Constructor Detail

AbstractSQLQueryBuilder

protected AbstractSQLQueryBuilder(DBObjectProvider provider,
                                  Schema defaultSchema)
Construtor

Method Detail

buildQuery

public final void buildQuery(java.lang.String sql)
                      throws SQLQueryException
Builds a query object from the given sql expression.
Specified by:
buildQuery in interface SQLQueryBuilder
Throws:
SQLQueryException - if the query cannot be built.

buildQuery

public final void buildQuery(java.lang.String sql,
                             SQLQueryOwner parent)
                      throws SQLQueryException
Builds a query from the given sql expression. The parent is the parent of the query.
Specified by:
buildQuery in interface SQLQueryBuilder
Throws:
SQLQueryException - if the query cannot be built.

buildQueryImpl

protected abstract void buildQueryImpl(java.lang.String sql,
                                       SQLQueryOwner parent)
                                throws SQLQueryException
Builds the query based on the given select statement.
Throws:
SQLQueryException - if the query cannot be built.

buildQuery

public abstract void buildQuery(SQLQuery query)
                         throws SQLQueryException
Builds the query based on the given SQLQuery. If the query is non declarative an attempt will be made to create a declarative one instead.
Specified by:
buildQuery in interface SQLQueryBuilder
Throws:
SQLQueryException - if the query cannot be built.

throwException

protected <T extends SQLQueryException> void throwException(T sqe)
                       throws T extends SQLQueryException
Throws:
T extends SQLQueryException

validateQuery

public void validateQuery()
                   throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Validates a query object to check that its internal structure is correct. This is only structural (first level) validation.
Specified by:
validateQuery in interface SQLQueryBuilder
Throws:
SQLQueryException - if the query fails to validate.

loadQuery

protected final void loadQuery()
                        throws SQLQueryException
Throws:
SQLQueryException

ensureIDs

protected void ensureIDs(SQLFragment... frags)
See Also:
ensureID(DBObject)

ensureID

protected DBObjectID ensureID(DBObject s)
Only call on an object that has been added to the hierarchy - e.g. add a FROM object to the query first, then call ensureID.

loadObjects

protected void loadObjects(DBObject[] frags)

loadObject

protected void loadObject(DBObject frag)
Load the given object (i.e. scan for dependencies).

unloadObject

protected void unloadObject(DBObject frag)

getIDs

protected java.util.List getIDs(DBObject[] objs)
                         throws SQLQueryException
Throws:
SQLQueryException

getRelIDs

protected java.util.Map getRelIDs(FromObject[] usagesToUse)

setNewFromObject

protected void setNewFromObject(DBObject frag,
                                FromObject oldFrom,
                                FromObject newFrom)

getInternalName

protected java.lang.String getInternalName(java.lang.String name)

getExternalName

protected java.lang.String getExternalName(java.lang.String name)

isValidName

protected boolean isValidName(java.lang.String type,
                              java.lang.String name)

getSQLQuery

public AbstractSQLQuery getSQLQuery()
Description copied from interface: SQLQueryBuilder
Returns the query that this builder is working on.
Specified by:
getSQLQuery in interface SQLQueryBuilder

addSelectObject

public void addSelectObject(SelectObject select)
                     throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Adds the given SelectObject to the query.
Specified by:
addSelectObject in interface SQLQueryBuilder
Throws:
SQLQueryException

addSelectObject

public void addSelectObject(int index,
                            SelectObject select)
                     throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Inserts the given SelectObject to the query at the given index.
Specified by:
addSelectObject in interface SQLQueryBuilder
Throws:
SQLQueryException

isUniqueSelectAlias

public boolean isUniqueSelectAlias(java.lang.String alias)
Description copied from interface: SQLQueryBuilder
Returns true if this alias is unique within the builder's query.
Specified by:
isUniqueSelectAlias in interface SQLQueryBuilder

isUniqueSelectAlias

protected boolean isUniqueSelectAlias(java.lang.String alias,
                                      java.util.List extraNames)

createUniqueSelectAlias

public java.lang.String createUniqueSelectAlias(java.lang.String base)
Description copied from interface: SQLQueryBuilder
Takes the given base for an alias and returns an alias that will be unique within this builder's query.
Specified by:
createUniqueSelectAlias in interface SQLQueryBuilder

createUniqueSelectAlias

protected java.lang.String createUniqueSelectAlias(java.lang.String base,
                                                   java.util.List extraNames)

getSelectObject

public SelectObject getSelectObject(java.lang.String usableAlias)
Description copied from interface: SQLQueryBuilder
Returns the select object that can be referenced by this alias. It can be the alias of the object, or if the object doesn't have an alias the expression.
Specified by:
getSelectObject in interface SQLQueryBuilder

constructSelectObject

public SelectObject constructSelectObject(java.lang.String expression,
                                          java.lang.String alias)
                                   throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Creates a SelectObject using the given alias and expression, parsing the expression into an appropriate set of SQLFragments. The SelectObject created is added to the builder's query, and returned from the method.
Specified by:
constructSelectObject in interface SQLQueryBuilder
Parameters:
expression - the sql for the SelectObject
alias - the alias for the SelectObject
Returns:
the SelectObject that's been added to the query as a result of the operation
Throws:
SQLQueryException

constructSelectObject

public SQLQueryBuilder.SQLQueryObjectSet constructSelectObject(Column col,
                                                               FromObject usageToUse)
                                                        throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Creates a SelectObject for the query based on the column passed in. A relevant RelationUsage can be provided in the FromObject passed in. If no relevant RelationUsage exists for a the column, a default RelationUsage is created. RelationUsages that already exist in the view are not reused - unless they are in the candidate array. The objects are automatically added to the query.
Specified by:
constructSelectObject in interface SQLQueryBuilder
Parameters:
col - the column to use as the base of the new SelectObject.
usageToUse - A FromObjects in the query that may be used while creating the SelectObject. If null, then a relation usage will be created by default.
Throws:
SQLQueryException - if the select object cannot be built.

constructSelectObjects

public SQLQueryBuilder.SQLQueryObjectSet constructSelectObjects(Column[] baseCols,
                                                                FromObject[] usagesToUse)
                                                         throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Creates a set of SelectObjects for the query based on the columns passed in. Relevant RelationUsages are taken from the array of candidate usages passed into this method. If no relevant RelationUsage exists for a given column, a default RelationUsage is created. RelationUsages that already exist in the view are not reused - unless they are in the candidate array. The objects are automatically added to the query.
Specified by:
constructSelectObjects in interface SQLQueryBuilder
Parameters:
baseCols - An array of columns to be the base columns of the new SelectObjects.
usagesToUse - An array of FromObjects in the query that may be used while creating the SelectObjects. If null, then relation usages will be created by default.
Throws:
SQLQueryException - if the select objects cannot be built.

doConstructSelectObject

protected SelectObject doConstructSelectObject(Column col,
                                               java.util.Map relsToUse,
                                               java.util.Map newRels,
                                               java.util.List relNames,
                                               java.util.List colNames)
                                        throws SQLQueryException
Throws:
SQLQueryException

createSelectObject

protected SelectObject createSelectObject(DBObjectID colId,
                                          FromObject from,
                                          java.lang.String alias)

addSelectObjects

protected void addSelectObjects(SelectObject[] selects)

removeSelectObject

public boolean removeSelectObject(SelectObject obj)
Description copied from interface: SQLQueryBuilder
Removes the given SelectObject from the SQLQuery. This will cascade to remove all dependent WhereObject fragments.
Specified by:
removeSelectObject in interface SQLQueryBuilder
Parameters:
obj - the SelectObject to remove.
Returns:
true if the remove operation was successful.

replaceSelectObject

public void replaceSelectObject(SelectObject oldSelect,
                                SelectObject newSelect)
                         throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Replaces the existing select object with a new one. Will remove any dependent parts of the WHERE clauses accordingly.
Specified by:
replaceSelectObject in interface SQLQueryBuilder
Throws:
SQLQueryException

isUniqueFromAlias

public boolean isUniqueFromAlias(java.lang.String alias)
Description copied from interface: SQLQueryBuilder
Returns true if this alias is unique within the builder's query.
Specified by:
isUniqueFromAlias in interface SQLQueryBuilder

isUniqueFromAlias

protected boolean isUniqueFromAlias(java.lang.String alias,
                                    java.util.List extraNames)

createUniqueFromAlias

public java.lang.String createUniqueFromAlias(java.lang.String base)
Description copied from interface: SQLQueryBuilder
Takes the given base for an alias and returns an alias that will be unique within this builder's query.
Specified by:
createUniqueFromAlias in interface SQLQueryBuilder

createUniqueFromAlias

protected java.lang.String createUniqueFromAlias(java.lang.String base,
                                                 java.util.List extraNames)

listAllFromObjects

public FromObject[] listAllFromObjects()
Description copied from interface: SQLQueryBuilder
Returns all FromObjects in the FROM clause including those nested in JOIN conditions. This will not return the FromObjects for the JOINS themselves, just those that contain RelationUsages, SQLQuery objects etc.
Specified by:
listAllFromObjects in interface SQLQueryBuilder
Returns:

listAllFromObjects

public FromObject[] listAllFromObjects(boolean includeJoins)
Description copied from interface: SQLQueryBuilder
Returns all FromObjects in the FROM clause including those nested in JOIN conditions. Unless the includeJoins parameter is set to true, this will not return the FromObjects for the JOINS themselves, just those that contain RelationUsages, SQLQuery objects etc.
Specified by:
listAllFromObjects in interface SQLQueryBuilder
Parameters:
includeJoins - if set to true, FromObjects for JOINs will be included in the returned array
Returns:

getFromObject

public FromObject getFromObject(java.lang.String usableAlias)
Description copied from interface: SQLQueryBuilder
Returns the from object that can be referenced by this alias. It can be the alias of the object, or if the object doesn't have an alias the expression.
Specified by:
getFromObject in interface SQLQueryBuilder

getFromObject

protected FromObject getFromObject(java.lang.String usableAlias,
                                   FromObject extrafrom)
Gets a FromObject with the given alias. First looks in the given FromObject which can contain froms in the process of being created.

constructFromObject

public FromObject constructFromObject(java.lang.String expression,
                                      java.lang.String alias)
                               throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Creates a FromObject using the given alias and expression, parsing the expression into an appropriate set of SQLFragments. The FromObject created is added to the builder's query, and returned from the method.
Specified by:
constructFromObject in interface SQLQueryBuilder
Parameters:
expression - the sql for the FromObject
alias - the alias for the FromObject
Returns:
the FromObject that's been added to the query as a result of the operation
Throws:
SQLQueryException

createFromObject

protected FromObject createFromObject(Relation rel,
                                      java.util.List extraNames)
                               throws SQLQueryException
Throws:
SQLQueryException

constructFromObject

public SQLQueryBuilder.SQLQueryObjectSet constructFromObject(Relation relation,
                                                             boolean createSelectObjects,
                                                             boolean createJoins,
                                                             FromObject[] includeInJoins)
                                                      throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Creates a FromObject for the query. Optionally also creates SelectObjects based on the columns of the relation passed in. Optionally creates WHERE clause joins between the new relation usage based on any foreign keys found between tables in the array. The objects are automatically added to the query.
Specified by:
constructFromObject in interface SQLQueryBuilder
Parameters:
relation - A table or view from which to create the new RelationUsage.
createSelectObjects - If true, a SelectObject is created for each column in the base relation.
createJoins - If true, a WhereObject is created for each foreign key between tables in the array of relations.
includeInJoins - Whether or not the createJoins parameter is set to true, any foreign key between the base relation of these FromObjects and a relation in the baseRelations parameter causes the relevant WhereObject to be created. This parameter can be null.
Throws:
SQLQueryException - if the from objects cannot be built.

doConstructFromObject

protected FromObject doConstructFromObject(Relation relation,
                                           java.util.List baseRelIDs,
                                           java.util.List relNames,
                                           java.util.Map newRels,
                                           java.util.List cols,
                                           java.util.List fks)
                                    throws SQLQueryException
Throws:
SQLQueryException

constructFromObjects

public SQLQueryBuilder.SQLQueryObjectSet constructFromObjects(Relation[] baseRelations,
                                                              boolean createSelectObjects,
                                                              boolean createJoins,
                                                              FromObject[] includeInJoins)
                                                       throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Creates one or more FromObjects for the query. Optionally also creates SelectObjects based on the columns of the relations passed in. Optionally creates WHERE clause joins between the new relation usages based on any foreign keys found between tables in the array. The objects are automatically added to the query.
Specified by:
constructFromObjects in interface SQLQueryBuilder
Parameters:
baseRelations - An array of tables and views from which to create the new RelationUsages.
createSelectObjects - If true, a SelectObject is created for each column in the base relation.
createJoins - If true, a WhereObject is created for each foreign key between tables in the array of relations.
includeInJoins - Whether or not the createJoins parameter is set to true, any foreign key between the base relation of these FromObjects and a relation in the baseRelations parameter causes the relevant WhereObject to be created. This parameter can be null.
Throws:
SQLQueryException - if the from objects cannot be built.

addFromObject

public void addFromObject(FromObject from)
                   throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Adds the given FromObject to the query.
Specified by:
addFromObject in interface SQLQueryBuilder
Throws:
SQLQueryException

addFromObjects

protected void addFromObjects(FromObject[] froms)

addJoinObject

protected void addJoinObject(FromObject from)

replaceFromObject

public void replaceFromObject(FromObject oldFrom,
                              FromObject newFrom)
                       throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Replaces the existing from object with a new one. Will remove any dependent parts of the SELECT and WHERE clauses accordingly.
Specified by:
replaceFromObject in interface SQLQueryBuilder
Throws:
SQLQueryException

removeJoinObject

public boolean removeJoinObject(FromObject obj)
Description copied from interface: SQLQueryBuilder
If the expression for the given obj is a JoinObject the join is removed and the two FromObjects that were joined are added to the top level of the query.
Specified by:
removeJoinObject in interface SQLQueryBuilder

removeFromObject

public boolean removeFromObject(FromObject obj)
Description copied from interface: SQLQueryBuilder
Removes the given FromObject from the SQLQuery. This will cascade to remove all SelectObject and WhereObject fragments that were dependent on this FromObject.
Specified by:
removeFromObject in interface SQLQueryBuilder
Parameters:
obj - the FromObject to remove.
Returns:
true if the remove operation was successful.

constructFKJoin

public SQLQueryBuilder.SQLQueryObjectSet constructFKJoin(FKConstraint fk,
                                                         FromObject left,
                                                         FromObject right)
                                                  throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Creates a JOIN in the query's FROM clause to represent the given FKConstraint. By default this is an INNER join with an ON clause. If the left or right expressions are provided they will be used without being checked. Be sure to supply them if and only if you know they are the right expressions to be reused. They will be removed from their current parent when joined.
Specified by:
constructFKJoin in interface SQLQueryBuilder
Parameters:
fk - the foreign key constraint to creat a join for
left - the left hand expression for the join to be created.
right - the right hand expression for the join to be created.
Throws:
SQLQueryException

constructFKJoins

public SQLQueryBuilder.SQLQueryObjectSet constructFKJoins(FKConstraint[] fks,
                                                          FromObject[] usagesToUse)
                                                   throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Creates a set of nested JOINs in the query's FROM clause to represent each given FKConstraint. By default these are an INNER joins. The order of the keys in the array matters - it must reflect the required JOIN heircachy.
Specified by:
constructFKJoins in interface SQLQueryBuilder
Parameters:
fks - the foreign key constraints to creat joins for, in order.
usagesToUse - an array of FromObjects to use for the JOIN. If the relations in question aren't in the array new FromObjects will be created as necessary
Throws:
SQLQueryException

doConstructJoin

protected FromObject doConstructJoin(FKConstraint fk,
                                     java.util.Map relsIDsToUse,
                                     java.util.List newFroms,
                                     FromObject left,
                                     FromObject right)
                              throws SQLQueryException
Throws:
SQLQueryException

createJoinObject

public FromObject createJoinObject(FKConstraint fk,
                                   FromObject left,
                                   FromObject right)
                            throws SQLQueryException
Throws:
SQLQueryException

createJoinCondition

protected JoinCondition createJoinCondition(FKConstraint fk,
                                            JoinObject join)
Constructs a condition to represent the given FK for the given join. If possible a USING condition is created, otherwise ON is used.

doConstructFKUsage

protected FKUsage doConstructFKUsage(FKConstraint fk,
                                     java.util.Map relsIDsToUse,
                                     java.util.List newFroms)
                              throws SQLQueryException
Throws:
SQLQueryException

createFKUsage

protected FKUsage createFKUsage(DBObjectID fkID,
                                FromObject left,
                                FromObject right)

setWhereObject

public void setWhereObject(WhereObject obj)
Description copied from interface: SQLQueryBuilder
Sets the WhereObject on the query (whilst caching any appropriate dependencies).
Specified by:
setWhereObject in interface SQLQueryBuilder
Parameters:
obj - the query's new WhereObject

removeWhereObject

protected boolean removeWhereObject(SQLFragment obj)
Removes a top level WhereObject from the WHERE clause. The obj must either be the clauses WhereObject, or a direct child of that WhereObject.

getRelationUsages

public RelationUsage[] getRelationUsages()
Description copied from interface: SQLQueryBuilder
Returns the RelationUsages found in the SQLQuery.
Specified by:
getRelationUsages in interface SQLQueryBuilder
Returns:
the RelationUsages found in the SQLQuery.

getDependentObjects

public SQLFragment[] getDependentObjects(FromObject from)
Gets the objects in the query that are dependent on the given from object. Does not recurse (i.e. the list could contain more FromObject objects from inside JOINs).
Specified by:
getDependentObjects in interface SQLQueryBuilder
Parameters:
from - the FromObject to get the dependencies for
Returns:
an array of dependent fragments (SelectObject or WhereObject)

getDependentObjects

public SQLFragment[] getDependentObjects(SelectObject select)
Gets the objects in the query that are dependent on the given select object.
Specified by:
getDependentObjects in interface SQLQueryBuilder
Parameters:
select - the object to get the dependencies for
Returns:
an array of dependent fragments.

canMergeRelationUsages

public boolean canMergeRelationUsages(RelationUsage baseUsage,
                                      RelationUsage mergingUsage)
Description copied from interface: SQLQueryBuilder
Determines whether the two RelationUsages are based on the same table. A true result indcates that mergeRelationUsages will be valid.
Specified by:
canMergeRelationUsages in interface SQLQueryBuilder
Parameters:
baseUsage - The RelationUsage that will remain and form the basis of the new usage after the merge
mergingUsage - The RelationUsage which will be removed as part of the merge. Any relevant WhereObjects and SelectObjects will be made to reference the new merged usage.
Returns:
true if the relation usages can be merged

mergeRelationUsages

public void mergeRelationUsages(RelationUsage baseUsage,
                                RelationUsage mergingUsage)
                         throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Merges two RelationUsages into one. The relevant SelectObjects and WhereObjects are updated to use the new alias of the merged RelationUsage. The two usages for the merge must reference the same base relation and be in the same view. The merged RelationUsage is returned and is also added to the query automatically.
Specified by:
mergeRelationUsages in interface SQLQueryBuilder
Parameters:
baseUsage - The RelationUsage that will remain and form the basis of the new usage after the merge
mergingUsage - The RelationUsage which will be removed as part of the merge. Any relevant WhereObjects and SelectObjects will be made to reference the new merged usage.
Throws:
SQLQueryException - if an error occurs merging the relations.

listAvailableFKs

public FKUsage[] listAvailableFKs()
Description copied from interface: SQLQueryBuilder
Returns all the FKs that could join the relations used in the view wrapped up in an FKUsage so as to include the appropriate FromObjects.
Specified by:
listAvailableFKs in interface SQLQueryBuilder

getColumnUsages

public ColumnUsage[] getColumnUsages()
Description copied from interface: SQLQueryBuilder
Returns all the ColumnUsage objects that are present in this query's SELECT and WHERE clauses.
Specified by:
getColumnUsages in interface SQLQueryBuilder

findColumnInFromObjects

protected FromObjectUsage findColumnInFromObjects(java.lang.String colName,
                                                  SQLFragment creating,
                                                  FromObject... extraFroms)
                                           throws SQLQueryException
Finds a Column of given name amongst the RelationUsages in the query. Will throw a SQLQueryException if the column name appears in more than one Relation referred to in the query. Returns an appropriate expression for that Column to use within the query.
Throws:
SQLQueryException

findColumnInFromObjects

protected FromObjectUsage findColumnInFromObjects(java.lang.String colName,
                                                  FromObject[] froms,
                                                  boolean allowDuplicates,
                                                  boolean enforceInAll,
                                                  SQLFragment creating)
                                           throws SQLQueryException
Finds a Column of given name amongst the given FromObjects.
Throws:
SQLQueryException

findColumnInFromExpression

protected FromObjectUsage findColumnInFromExpression(java.lang.String colName,
                                                     SQLFragment exp,
                                                     boolean allowDuplicates,
                                                     FromObject from,
                                                     SQLFragment creating)
                                              throws SQLQueryException
Throws:
SQLQueryException

findColumnInColumnUsage

protected FromObjectUsage findColumnInColumnUsage(java.lang.String colName,
                                                  ColumnUsage colu,
                                                  FromObject from)

findColumnInJoin

protected FromObjectUsage findColumnInJoin(java.lang.String colName,
                                           JoinObject join,
                                           boolean allowDuplicates,
                                           SQLFragment creating)
                                    throws SQLQueryException
Throws:
SQLQueryException

findColumnInRelation

protected FromObjectUsage findColumnInRelation(java.lang.String colName,
                                               RelationUsage relU)
                                        throws SQLQueryException
Throws:
SQLQueryException

findColumnInRelation

protected FromObjectUsage findColumnInRelation(java.lang.String colName,
                                               Relation rel)
                                        throws SQLQueryException
Warning: The returned ColumnUsage won't have a FromObject set.
Throws:
SQLQueryException

findColumnInSubQuery

protected SelectObjectUsage findColumnInSubQuery(java.lang.String colName,
                                                 SQLQuery query)
                                          throws SQLQueryException
Throws:
SQLQueryException

setHierarchicalQueryObject

public void setHierarchicalQueryObject(HierarchicalQueryObject obj)
Description copied from interface: SQLQueryBuilder
Sets the CONNECT BY clause of the query.
Specified by:
setHierarchicalQueryObject in interface SQLQueryBuilder

setGroupByObject

public void setGroupByObject(GroupByObject obj)
Description copied from interface: SQLQueryBuilder
Sets the group by object. This caches any dependent objects against their FromObjects appropriately.
Specified by:
setGroupByObject in interface SQLQueryBuilder

canSetGroupBy

public boolean canSetGroupBy()
Description copied from interface: SQLQueryBuilder
Returns true if this query can accept a group by clause. To have a group by clause there must be a grouping function in the SELECT clause.
Specified by:
canSetGroupBy in interface SQLQueryBuilder

addGroupByColumn

public void addGroupByColumn(FromObjectUsage colu)
Description copied from interface: SQLQueryBuilder
Adds the given FromObjectUsage to the end of the GROUP BY clause. Will create a GroupByObject if necessary.
Specified by:
addGroupByColumn in interface SQLQueryBuilder

addGroupByColumn

public void addGroupByColumn(int index,
                             FromObjectUsage colu)
Description copied from interface: SQLQueryBuilder
Adds the given FromObjectUsage to the specified index of the GROUP BY clause.
Specified by:
addGroupByColumn in interface SQLQueryBuilder

removeGroupByColumn

public boolean removeGroupByColumn(FromObjectUsage colu)
Description copied from interface: SQLQueryBuilder
Removes the given FromObjectUsage from the GROUP BY clause. Will remove the GROUP BY clause if there are no column usages left.
Specified by:
removeGroupByColumn in interface SQLQueryBuilder

parseHavingExpression

public SQLFragment parseHavingExpression(java.lang.String expression)
                                  throws SQLQueryException
By default this calls parseWhereExpression().
Specified by:
parseHavingExpression in interface SQLQueryBuilder
Parameters:
expression - the sql to parse as a HAVING fragment.
Returns:
SQLFragment for the expression.
Throws:
SQLQueryException

parseOrderByExpression

public SQLFragment parseOrderByExpression(java.lang.String expression)
                                   throws SQLQueryException
By default this calls parseSelectExpression().
Specified by:
parseOrderByExpression in interface SQLQueryBuilder
Parameters:
expression - the sql to parse as a ORDER BY fragment.
Returns:
SQLFragment for the expression.
Throws:
SQLQueryException

setHavingObject

public void setHavingObject(WhereObject having)
Description copied from interface: SQLQueryBuilder
Sets the HAVING clause of the query. This is for convinience only as the HAVING object is a child of the GroupByObject. This method assumes that a GroupByObject exists on the SQLQuery. This means a NPE will be thrown if you try and set the HAVING clause and no GroupBy has been set.
Specified by:
setHavingObject in interface SQLQueryBuilder

addOrderByObject

public void addOrderByObject(OrderByObject ob)
Description copied from interface: SQLQueryBuilder
Adds the given order by object to the end of the order by clause.
Specified by:
addOrderByObject in interface SQLQueryBuilder

addOrderByObject

public void addOrderByObject(int index,
                             OrderByObject ob)
Description copied from interface: SQLQueryBuilder
Adds the given order by object to the given index in the clause. If the index is out of bounds the object is added to the end of the clause.
Specified by:
addOrderByObject in interface SQLQueryBuilder

removeOrderByObject

public boolean removeOrderByObject(OrderByObject ob)
Description copied from interface: SQLQueryBuilder
Removes the given order by object from the orderby clause.
Specified by:
removeOrderByObject in interface SQLQueryBuilder

replaceOrderByObject

public void replaceOrderByObject(OrderByObject oldOb,
                                 OrderByObject newOb)
Description copied from interface: SQLQueryBuilder
Replaces the existing from object with a new one. Will recache any dependencies on the FROM clause.
Specified by:
replaceOrderByObject in interface SQLQueryBuilder

setOrderByObjects

public void setOrderByObjects(OrderByObject[] orderbys)
Description copied from interface: SQLQueryBuilder
Sets the order by objects for the query. If there are existing objects they are replaced. Passing null will remove all order by objects.
Specified by:
setOrderByObjects in interface SQLQueryBuilder

syncViewColumns

public void syncViewColumns()
                     throws AliasInUseException
Description copied from interface: SQLQueryBuilder
If the query is a View query ( @see isViewQuery() ) this syncs the SelectObjects in the query with the Columns in the View. Any removed SelectObjects will have their Columns removed and any new SelectObjects will have new Columns created.
Specified by:
syncViewColumns in interface SQLQueryBuilder
Throws:
AliasInUseException

checkUsageQualifications

public void checkUsageQualifications()
Checks that every FromObjectUsage which isn't qualified is a unique name within the query. If it isn't then the column is explicitly qualified.

parseFromExpression

public final SQLFragment parseFromExpression(java.lang.String expression)
                                      throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Parses an expression to see if it is a valid expression for a From object. If the parse is successful a SQLFragment will be returned for the expression. If the parse isn't successful an appropriate Exception will be thrown.
Specified by:
parseFromExpression in interface SQLQueryBuilder
Parameters:
expression - the sql to parse as a FROM fragment.
Returns:
SQLFragment for the expression.
Throws:
SQLQueryException

parseFromExpression

protected abstract SQLFragment parseFromExpression(java.lang.String expression,
                                                   FromObject creating)
                                            throws SQLQueryException
Throws:
SQLQueryException

parseSelectExpression

public final SQLFragment parseSelectExpression(java.lang.String expression)
                                        throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Parses an expression to see if it is a valid expression for a Select object. If the parse is successful a SQLFragment will be returned for the expression. If the parse isn't successful an appropriate Exception will be thrown.
Specified by:
parseSelectExpression in interface SQLQueryBuilder
Parameters:
expression - the sql to parse as a SELECT fragment.
Returns:
SQLFragment for the expression.
Throws:
SQLQueryException

parseSelectExpression

protected abstract SQLFragment parseSelectExpression(java.lang.String expression,
                                                     SelectObject creating)
                                              throws SQLQueryException
Throws:
SQLQueryException

parseWhereExpression

public final SQLFragment parseWhereExpression(java.lang.String expression)
                                       throws SQLQueryException
Description copied from interface: SQLQueryBuilder
Parses an expression to see if it is a valid expression for a Where object. If the parse is successful a SQLFragment will be returned for the expression. If the parse isn't successful an appropriate Exception will be thrown.
Specified by:
parseWhereExpression in interface SQLQueryBuilder
Parameters:
expression - the sql to parse as a WHERE fragment.
Returns:
SQLFragment for the expression.
Throws:
SQLQueryException

parseWhereExpression

public abstract SQLFragment parseWhereExpression(java.lang.String expression,
                                                 WhereObject creating)
                                          throws SQLQueryException
Throws:
SQLQueryException

setViewColDataType

protected void setViewColDataType(ViewColumn col)

setSingleRelation

public void setSingleRelation(Relation singleRelation)

getObject

protected SchemaObject getObject(java.lang.String type,
                                 Schema sch,
                                 java.lang.String relation)
                          throws DBException
Throws:
DBException

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.7.2)

E13403-10


Copyright © 1997, 2013, Oracle. All rights reserved.