public abstract class AbstractSQLQueryBuilder extends DerivedPropertyBuilder<SQLQuery> implements SQLQueryBuilder
Modifier and Type | Class and Description |
---|---|
static class |
AbstractSQLQueryBuilder.QueryColumnInfo |
AbstractDBObjectBuilder.PropertyBuilder
SQLQueryBuilder.SQLQueryObjectSet
Modifier and Type | Field and Description |
---|---|
protected static SQLFragment[] |
EMPTY_ARRAY |
BASE_COMPONENT_KEY
Modifier | Constructor and Description |
---|---|
protected |
AbstractSQLQueryBuilder(DBObjectProvider pro, Schema defaultSchema)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addClauseException(SQLQueryClauseException sce)
Caches a clause exception so that it can be re-thrown after the build has finished.
|
protected void |
addExtraObject(SystemObject obj) |
void |
addFromObject(FromObject from)
Adds the given FromObject to the query.
|
protected void |
addFromObjects(FromObject[] froms) |
void |
addGroupByColumn(int index, SQLFragment colu)
Adds the given FromObjectUsage to the specified index of the GROUP BY clause.
|
void |
addGroupByColumn(SQLFragment colu)
Adds the given FromObjectUsage to the end 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) |
void |
buildDeclarativeProperties(SQLQuery query)
DerivedPropertyBuilder mechanism that directly builds the derived properties on the given SQLQuery.
|
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, SQLQuery query, SQLQueryOwner parent)
Builds the declarative components of the given SQLQuery 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.
|
java.util.Collection<java.lang.String> |
clearDerivedProperties(SQLQuery obj, java.lang.String property, DBObjectChange change)
Clears the properties that are derived from the given property and that need resetting given the new value for the source property.
|
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(SchemaObject 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 abstract boolean |
containsAsterisk() |
protected FKUsage |
createFKUsage(DBObjectID fkID, FromObject left, FromObject right) |
SQLFragment |
createFromFactory(SQLFragment parent, java.lang.String clause, java.lang.Integer offset) |
protected FromObject |
createFromObject(SchemaObject rel, java.util.List<java.lang.String> 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)
Creates a FromObject that joins using a JoinCondition matching the given FK and joins the two from objects.
|
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<java.lang.String> 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<java.lang.String> extraNames) |
protected FKUsage |
doConstructFKUsage(FKConstraint fk, java.util.Map relsIDsToUse, java.util.List<FromObject> newFroms) |
protected FromObject |
doConstructFromObject(SchemaObject relation, java.util.List<DBObjectID> baseRelIDs, java.util.List<java.lang.String> relNames, java.util.Map<DBObjectID,FromObject> newRels, java.util.List<Column> cols, java.util.List<FKConstraint> fks) |
protected FromObject |
doConstructJoin(FKConstraint fk, java.util.Map<DBObjectID,FromObject> relsIDsToUse, java.util.List<FromObject> newFroms, FromObject left, FromObject right) |
protected SelectObject |
doConstructSelectObject(Column col, java.util.Map<DBObjectID,FromObject> relsToUse, java.util.Map<DBObjectID,FromObject> newRels, java.util.List<java.lang.String> relNames, java.util.List<java.lang.String> colNames) |
DBObjectID |
ensureID(DBObject frag)
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, boolean external, ColumnUsage colu, FromObject from)
Finds a column in the given ColumnUsage.
|
FromObjectUsage |
findColumnInFromExpression(java.lang.String colName, boolean external, SQLFragment exp, boolean allowDuplicates, FromObject from, SQLFragment creating)
Finds a Column of given name in the given FromObject's expression.
|
protected FromObjectUsage |
findColumnInFromObjects(java.lang.String colName, boolean external, FromObject[] froms, boolean allowDuplicates, boolean enforceInAll, SQLFragment creating)
Finds a Column of given name amongst the given FromObjects.
|
FromObjectUsage |
findColumnInFromObjects(java.lang.String colName, boolean external, SQLFragment creating, FromObject... extraFroms)
Finds a Column of given name amongst the RelationUsages in the query.
|
protected FromObjectUsage |
findColumnInJoin(java.lang.String colName, boolean external, JoinObject join, boolean allowDuplicates, SQLFragment creating)
Finds a column in the child FromObjects of a given JoinObject.
|
FromObjectUsage |
findColumnInRelation(java.lang.String colName, boolean external, Relation rel)
Finds a Column with the given name in a Relation and returns a FromObjectUsage that references that column.
|
FromObjectUsage |
findColumnInRelation(java.lang.String colName, boolean external, RelationUsage relU)
Finds a Column with the given name in the Relation referred to by the given RelationUsage, and returns a FromObjectUsage that references that column.
|
ColumnUsage |
findColumnInStarSubQuery(java.lang.String colName, boolean external, FromObject from)
The from object is of the form (SELECT * FROM <rel>) <alias>
|
SelectObjectUsage |
findColumnInSubQuery(java.lang.String colName, boolean external, SQLQuery query) |
java.lang.String |
getColumnName(SelectObject sel) |
Column[] |
getColumns()
Retrieves Column objects mapped to the columns in the SQL query that has been built, thereby giving the name and type of each column the query has.
|
ColumnUsage[] |
getColumnUsages()
Deprecated.
|
protected Schema |
getDefaultSchema() |
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 abstract DerivedPropertyBuilder |
getDTUBuilder(int columnIndex)
Sublass implementations to provide a DerivedPropertyBuilder capable of building the DataTypeUsage property for Views/MatViews.
|
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.
|
FromObject |
getFromObject(java.lang.String usableAlias, FromObject extrafrom)
Gets a FromObject with the given alias.
|
protected java.util.List<DBObjectID> |
getIDs(DBObject[] objs) |
protected java.lang.String |
getInternalName(java.lang.String name) |
protected java.util.logging.Logger |
getLogger() |
protected SchemaObject |
getObject(DBObjectCriteria crit) |
protected SchemaObject |
getObject(java.lang.String type, Schema sch, java.lang.String relation) |
protected SQLQuery |
getQuery() |
abstract java.util.List<AbstractSQLQueryBuilder.QueryColumnInfo> |
getQueryColumnInfos()
Obtains information about the select list items for use in building view and materialized view columns without building the query unless absolutely necessary.
|
RelationUsage[] |
getRelationUsages()
Returns the RelationUsages found in the FROM clause of the SQLQuery.
|
protected java.util.Map<DBObjectID,FromObject> |
getRelIDs(FromObject[] usagesToUse) |
SelectObject |
getSelectObject(java.lang.String usableAlias)
Returns the select object that can be referenced by this alias.
|
SQLQuery |
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<java.lang.String> 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<java.lang.String> 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) |
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 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)
Parses an expression to see if it is a valid expression for a Order By object.
|
protected SQLFragment |
parseOrderByExpression(java.lang.String expression, OrderByObject obo) |
SQLFragment |
parseSelectExpression(java.lang.String expression)
Parses an expression to see if it is a valid expression for a Select object.
|
protected 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.
|
SQLFragment |
parseWhereExpression(java.lang.String expression, WhereObject creating) |
protected void |
registerAllSQLFragmentFactories(AbstractSQLQueryBuilder builder) |
void |
registerSQLFragmentFactory(SQLFragmentFactory fac)
Register plugin SQLFragmentFactory to create SQLFragments from the given String if not recognized by the base implementation.
|
boolean |
removeFromObject(FromObject obj)
Removes the given FromObject from the SQLQuery.
|
boolean |
removeGroupByColumn(SQLFragment 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.
|
protected void |
replaceWithAliases(FromObject[] froms)
replace any From Objects in the list that are aliases for a subquery_factoring_clause
|
void |
setExtraObjects(java.util.Collection<? extends SystemObject> objs) |
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 |
setSQLQuery(SQLQuery query)
Sets the query we are building.
|
protected void |
setViewColDataType(Column col, SelectObject so) |
void |
setWhereObject(WhereObject obj)
Sets the WhereObject on the query (whilst caching any appropriate dependencies).
|
void |
syncViewColumns()
Deprecated.
- no longer required
|
<T extends SQLQueryException> |
throwException(T sqe)
Method that takes a SQLQueryException and rethrows it unless it is a SQLQueryClauseException and we are in the middle of a build.
|
protected void |
unloadObject(DBObject frag) |
protected void |
validateAlias(AliasFragment frag, java.lang.String type, java.lang.String alias) |
void |
validateQuery()
Validates a query object to check that its internal structure is correct.
|
canBuildComponents, createObject, registerObject
buildObject, buildObjectComponent, canBuildEditableObject, ensureComponent, fillInObject, fillInObjectComponent, findObjectInProviderCache, findObjectInProviderCache, getBuiltProperties, getDerivedProperties, getObjectType, getProvider, getSchema, isBuildableProperty, markAsBuilt, markAsBuilt, needsBuilding, needsBuilding, newObject, newObject, updateTimestamp, updateTimestamp
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addSetOperatorObject, ensureQueryNonDeclarative, getBuiltInFunctions, matchesProvider, parseOnExpression, supportsConnectBy, supportsGroupBy, supportsOrderBy
protected static final SQLFragment[] EMPTY_ARRAY
protected AbstractSQLQueryBuilder(DBObjectProvider pro, Schema defaultSchema)
protected final java.util.logging.Logger getLogger()
getLogger
in class AbstractDBObjectBuilder<SQLQuery>
protected final Schema getDefaultSchema()
protected final SQLQuery getQuery()
public final void buildQuery(java.lang.String sql) throws SQLQueryException
buildQuery
in interface SQLQueryBuilder
SQLQueryException
- if the query cannot be built.public final void buildQuery(java.lang.String sql, SQLQueryOwner parent) throws SQLQueryException
buildQuery
in interface SQLQueryBuilder
SQLQueryException
- if the query cannot be built.protected final void setSQLQuery(SQLQuery query)
protected abstract void buildQueryImpl(java.lang.String sql, SQLQuery query, SQLQueryOwner parent) throws SQLQueryException
sql
- the query string to buildquery
- the SQLQuery object to build the declarative representation in toparent
- the query's owner (if one exists)SQLQueryException
- if the query cannot be built.public java.util.Collection<java.lang.String> clearDerivedProperties(SQLQuery obj, java.lang.String property, DBObjectChange change)
DerivedPropertyBuilder
clearDerivedProperties
in class DerivedPropertyBuilder<SQLQuery>
obj
- the object the property is being changed onproperty
- the property being changedchange
- the overall change that is occuringpublic final void buildQuery(SQLQuery query) throws SQLQueryException
SQLQueryBuilder
buildQuery
in interface SQLQueryBuilder
SQLQueryException
- if the query cannot be built.public final void buildDeclarativeProperties(SQLQuery query) throws SQLQueryException
query
- the query to build (cannot be null)SQLQueryException
public <T extends SQLQueryException> void throwException(T sqe) throws T extends SQLQueryException
T
- SQLQueryException implementationsqe
- exception to cache or rethrowT
- if sqe is not a clause exception (or we're not building)T extends SQLQueryException
public void addClauseException(SQLQueryClauseException sce)
sce
- the problem with a clause in the query we're building.java.lang.IllegalStateException
- if this method is called and we're not building a query.public void validateQuery() throws SQLQueryException
SQLQueryBuilder
validateQuery
in interface SQLQueryBuilder
SQLQueryException
- if the query fails to validate.protected void ensureIDs(SQLFragment... frags)
ensureID(DBObject)
public DBObjectID ensureID(DBObject frag)
protected void loadObjects(DBObject[] frags)
protected void loadObject(DBObject frag)
protected void unloadObject(DBObject frag)
protected java.util.List<DBObjectID> getIDs(DBObject[] objs) throws SQLQueryException
SQLQueryException
protected java.util.Map<DBObjectID,FromObject> getRelIDs(FromObject[] usagesToUse)
protected void setNewFromObject(DBObject frag, FromObject oldFrom, FromObject newFrom)
protected java.lang.String getInternalName(java.lang.String name)
protected java.lang.String getExternalName(java.lang.String name)
protected boolean isValidName(java.lang.String type, java.lang.String name)
protected void validateAlias(AliasFragment frag, java.lang.String type, java.lang.String alias) throws InvalidAliasException
InvalidAliasException
public SQLQuery getSQLQuery()
SQLQueryBuilder
getSQLQuery
in interface SQLQueryBuilder
public void addSelectObject(SelectObject select) throws SQLQueryException
SQLQueryBuilder
addSelectObject
in interface SQLQueryBuilder
SQLQueryException
public void addSelectObject(int index, SelectObject select) throws SQLQueryException
SQLQueryBuilder
addSelectObject
in interface SQLQueryBuilder
SQLQueryException
public boolean isUniqueSelectAlias(java.lang.String alias)
SQLQueryBuilder
isUniqueSelectAlias
in interface SQLQueryBuilder
protected boolean isUniqueSelectAlias(java.lang.String alias, java.util.List<java.lang.String> extraNames)
public java.lang.String createUniqueSelectAlias(java.lang.String base)
SQLQueryBuilder
createUniqueSelectAlias
in interface SQLQueryBuilder
protected java.lang.String createUniqueSelectAlias(java.lang.String base, java.util.List<java.lang.String> extraNames)
public SelectObject getSelectObject(java.lang.String usableAlias)
SQLQueryBuilder
getSelectObject
in interface SQLQueryBuilder
public SelectObject constructSelectObject(java.lang.String expression, java.lang.String alias) throws SQLQueryException
SQLQueryBuilder
constructSelectObject
in interface SQLQueryBuilder
expression
- the sql for the SelectObjectalias
- the alias for the SelectObjectSQLQueryException
public SQLQueryBuilder.SQLQueryObjectSet constructSelectObject(Column col, FromObject usageToUse) throws SQLQueryException
SQLQueryBuilder
constructSelectObject
in interface SQLQueryBuilder
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.SQLQueryException
- if the select object cannot be built.public SQLQueryBuilder.SQLQueryObjectSet constructSelectObjects(Column[] baseCols, FromObject[] usagesToUse) throws SQLQueryException
SQLQueryBuilder
constructSelectObjects
in interface SQLQueryBuilder
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.SQLQueryException
- if the select objects cannot be built.protected SelectObject doConstructSelectObject(Column col, java.util.Map<DBObjectID,FromObject> relsToUse, java.util.Map<DBObjectID,FromObject> newRels, java.util.List<java.lang.String> relNames, java.util.List<java.lang.String> colNames) throws SQLQueryException
SQLQueryException
protected SelectObject createSelectObject(DBObjectID colId, FromObject from, java.lang.String alias)
protected void addSelectObjects(SelectObject[] selects)
public boolean removeSelectObject(SelectObject obj)
SQLQueryBuilder
removeSelectObject
in interface SQLQueryBuilder
obj
- the SelectObject to remove.public void replaceSelectObject(SelectObject oldSelect, SelectObject newSelect) throws SQLQueryException
SQLQueryBuilder
replaceSelectObject
in interface SQLQueryBuilder
SQLQueryException
public boolean isUniqueFromAlias(java.lang.String alias)
SQLQueryBuilder
isUniqueFromAlias
in interface SQLQueryBuilder
protected boolean isUniqueFromAlias(java.lang.String alias, java.util.List<java.lang.String> extraNames)
public java.lang.String createUniqueFromAlias(java.lang.String base)
SQLQueryBuilder
createUniqueFromAlias
in interface SQLQueryBuilder
protected java.lang.String createUniqueFromAlias(java.lang.String base, java.util.List<java.lang.String> extraNames)
public FromObject[] listAllFromObjects()
SQLQueryBuilder
listAllFromObjects
in interface SQLQueryBuilder
public FromObject[] listAllFromObjects(boolean includeJoins)
SQLQueryBuilder
listAllFromObjects
in interface SQLQueryBuilder
includeJoins
- if set to true, FromObjects for JOINs will be included in the returned arraypublic FromObject getFromObject(java.lang.String usableAlias)
SQLQueryBuilder
getFromObject
in interface SQLQueryBuilder
public FromObject getFromObject(java.lang.String usableAlias, FromObject extrafrom)
public FromObject constructFromObject(java.lang.String expression, java.lang.String alias) throws SQLQueryException
SQLQueryBuilder
constructFromObject
in interface SQLQueryBuilder
expression
- the sql for the FromObjectalias
- the alias for the FromObjectSQLQueryException
protected FromObject createFromObject(SchemaObject rel, java.util.List<java.lang.String> extraNames) throws SQLQueryException
SQLQueryException
public SQLQueryBuilder.SQLQueryObjectSet constructFromObject(SchemaObject relation, boolean createSelectObjects, boolean createJoins, FromObject[] includeInJoins) throws SQLQueryException
SQLQueryBuilder
constructFromObject
in interface SQLQueryBuilder
relation
- a table, view or synonym 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.SQLQueryException
- if the from objects cannot be built.protected FromObject doConstructFromObject(SchemaObject relation, java.util.List<DBObjectID> baseRelIDs, java.util.List<java.lang.String> relNames, java.util.Map<DBObjectID,FromObject> newRels, java.util.List<Column> cols, java.util.List<FKConstraint> fks) throws SQLQueryException
SQLQueryException
public SQLQueryBuilder.SQLQueryObjectSet constructFromObjects(Relation[] baseRelations, boolean createSelectObjects, boolean createJoins, FromObject[] includeInJoins) throws SQLQueryException
SQLQueryBuilder
constructFromObjects
in interface SQLQueryBuilder
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.SQLQueryException
- if the from objects cannot be built.public void addFromObject(FromObject from) throws SQLQueryException
SQLQueryBuilder
addFromObject
in interface SQLQueryBuilder
SQLQueryException
protected void addFromObjects(FromObject[] froms)
protected void addJoinObject(FromObject from)
public void replaceFromObject(FromObject oldFrom, FromObject newFrom) throws SQLQueryException
SQLQueryBuilder
replaceFromObject
in interface SQLQueryBuilder
SQLQueryException
public boolean removeJoinObject(FromObject obj)
SQLQueryBuilder
removeJoinObject
in interface SQLQueryBuilder
public boolean removeFromObject(FromObject obj)
SQLQueryBuilder
removeFromObject
in interface SQLQueryBuilder
obj
- the FromObject to remove.public SQLQueryBuilder.SQLQueryObjectSet constructFKJoin(FKConstraint fk, FromObject left, FromObject right) throws SQLQueryException
SQLQueryBuilder
constructFKJoin
in interface SQLQueryBuilder
fk
- the foreign key constraint to creat a join forleft
- the left hand expression for the join to be created.right
- the right hand expression for the join to be created.SQLQueryException
public SQLQueryBuilder.SQLQueryObjectSet constructFKJoins(FKConstraint[] fks, FromObject[] usagesToUse) throws SQLQueryException
SQLQueryBuilder
constructFKJoins
in interface SQLQueryBuilder
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 necessarySQLQueryException
protected FromObject doConstructJoin(FKConstraint fk, java.util.Map<DBObjectID,FromObject> relsIDsToUse, java.util.List<FromObject> newFroms, FromObject left, FromObject right) throws SQLQueryException
SQLQueryException
public FromObject createJoinObject(FKConstraint fk, FromObject left, FromObject right) throws SQLQueryException
SQLQueryBuilder
createJoinObject
in interface SQLQueryBuilder
fk
- the FKConstraint to use to create the join conditionleft
- the from for the LHS of the joinright
- the from for the RHS of the joinSQLQueryException
protected JoinCondition createJoinCondition(FKConstraint fk, JoinObject join)
protected FKUsage doConstructFKUsage(FKConstraint fk, java.util.Map relsIDsToUse, java.util.List<FromObject> newFroms) throws SQLQueryException
SQLQueryException
protected FKUsage createFKUsage(DBObjectID fkID, FromObject left, FromObject right)
public void setWhereObject(WhereObject obj)
SQLQueryBuilder
setWhereObject
in interface SQLQueryBuilder
obj
- the query's new WhereObjectprotected boolean removeWhereObject(SQLFragment obj)
public RelationUsage[] getRelationUsages()
SQLQueryBuilder
DBUtil.findChildren( builder.getSQLQuery(), RelationUsage.class )
getRelationUsages
in interface SQLQueryBuilder
DBUtil.findChildren(oracle.javatools.db.DBObject, java.lang.Class<T>)
public SQLFragment[] getDependentObjects(FromObject from)
getDependentObjects
in interface SQLQueryBuilder
from
- the FromObject to get the dependencies forpublic SQLFragment[] getDependentObjects(SelectObject select)
getDependentObjects
in interface SQLQueryBuilder
select
- the object to get the dependencies forpublic boolean canMergeRelationUsages(RelationUsage baseUsage, RelationUsage mergingUsage)
SQLQueryBuilder
canMergeRelationUsages
in interface SQLQueryBuilder
baseUsage
- The RelationUsage that will remain and form the basis of the new usage after the mergemergingUsage
- 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.public void mergeRelationUsages(RelationUsage baseUsage, RelationUsage mergingUsage) throws SQLQueryException
SQLQueryBuilder
mergeRelationUsages
in interface SQLQueryBuilder
baseUsage
- The RelationUsage that will remain and form the basis of the new usage after the mergemergingUsage
- 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.SQLQueryException
- if an error occurs merging the relations.public FKUsage[] listAvailableFKs()
SQLQueryBuilder
listAvailableFKs
in interface SQLQueryBuilder
@Deprecated public ColumnUsage[] getColumnUsages()
getColumnUsages
in interface SQLQueryBuilder
DBUtil.findChildren(oracle.javatools.db.DBObject, java.lang.Class<T>)
public FromObjectUsage findColumnInFromObjects(java.lang.String colName, boolean external, SQLFragment creating, FromObject... extraFroms) throws SQLQueryException
colName
- the column name to findexternal
- whether colName is an external (true) or internal (false) name.creating
- the fragment we are in the context of creatingextraFroms
- extra FromObjects to search within for the column (the query's own FromObjects are searched automatically).SQLQueryException
protected void replaceWithAliases(FromObject[] froms)
protected FromObjectUsage findColumnInFromObjects(java.lang.String colName, boolean external, FromObject[] froms, boolean allowDuplicates, boolean enforceInAll, SQLFragment creating) throws SQLQueryException
colName
- the name of the column to findexternal
- whether colName is an external (true) or internal (false) name.froms
- the FromObjects to search inallowDuplicates
- whether to allow duplicate columns to exist ( if false a found duplicate will throw a SQLQueryException)enforceInAll
- whether to enforce that the column must exist in all FromObjects (e.g. when creating a join), if true and the column isn't present in all FROMs a SQLQueryException will be thrown.creating
- the fragment we are in the context of creatingSQLQueryException
public FromObjectUsage findColumnInFromExpression(java.lang.String colName, boolean external, SQLFragment exp, boolean allowDuplicates, FromObject from, SQLFragment creating) throws SQLQueryException
colName
- the name of the column to findexternal
- whether colName is an external (true) or internal (false) name.exp
- the expression to search under (e.g. if this is a RelationUsage we look for a Column on the referenced Relation).allowDuplicates
- whether to allow duplicate columns to exist ( if false a found duplicate will throw a SQLQueryException)from
- the parent of expcreating
- the fragment we are in the context of creatingSQLQueryException
protected FromObjectUsage findColumnInColumnUsage(java.lang.String colName, boolean external, ColumnUsage colu, FromObject from)
colName
- the name of the column to findexternal
- whether colName is an external (true) or internal (false) name.colu
- the ColumnUsage to search underfrom
- the parent of coluprotected FromObjectUsage findColumnInJoin(java.lang.String colName, boolean external, JoinObject join, boolean allowDuplicates, SQLFragment creating) throws SQLQueryException
colName
- the name of the column to findexternal
- whether colName is an external (true) or internal (false) name.join
- the JoinObject to search underneathallowDuplicates
- whether to allow duplicate columns to exist ( if false a found duplicate will throw a SQLQueryException)creating
- the fragment we are in the context of creatingSQLQueryException
public FromObjectUsage findColumnInRelation(java.lang.String colName, boolean external, RelationUsage relU) throws SQLQueryException
colName
- the name of the column to findexternal
- whether colName is an external (true) or internal (false) name.relU
- the relation usage that references the relation to search.SQLQueryException
public FromObjectUsage findColumnInRelation(java.lang.String colName, boolean external, Relation rel) throws SQLQueryException
Warning: The returned ColumnUsage won't have a FromObject set.
colName
- the name of the column to findexternal
- whether colName is an external (true) or internal (false) name.rel
- the relation to search inSQLQueryException
public SelectObjectUsage findColumnInSubQuery(java.lang.String colName, boolean external, SQLQuery query) throws SQLQueryException
SQLQueryException
public ColumnUsage findColumnInStarSubQuery(java.lang.String colName, boolean external, FromObject from) throws SQLQueryException
SQLQueryException
public void setHierarchicalQueryObject(HierarchicalQueryObject obj)
SQLQueryBuilder
setHierarchicalQueryObject
in interface SQLQueryBuilder
public void setGroupByObject(GroupByObject obj)
SQLQueryBuilder
setGroupByObject
in interface SQLQueryBuilder
public boolean canSetGroupBy()
SQLQueryBuilder
canSetGroupBy
in interface SQLQueryBuilder
public void addGroupByColumn(SQLFragment colu)
SQLQueryBuilder
addGroupByColumn
in interface SQLQueryBuilder
public void addGroupByColumn(int index, SQLFragment colu)
SQLQueryBuilder
addGroupByColumn
in interface SQLQueryBuilder
public boolean removeGroupByColumn(SQLFragment colu)
SQLQueryBuilder
removeGroupByColumn
in interface SQLQueryBuilder
public SQLFragment parseHavingExpression(java.lang.String expression) throws SQLQueryException
parseHavingExpression
in interface SQLQueryBuilder
expression
- the sql to parse as a HAVING fragment.SQLQueryException
public final SQLFragment parseOrderByExpression(java.lang.String expression) throws SQLQueryException
SQLQueryBuilder
parseOrderByExpression
in interface SQLQueryBuilder
expression
- the sql to parse as a ORDER BY fragment.SQLQueryException
protected SQLFragment parseOrderByExpression(java.lang.String expression, OrderByObject obo) throws SQLQueryException
SQLQueryException
public void setHavingObject(WhereObject having)
SQLQueryBuilder
setHavingObject
in interface SQLQueryBuilder
public void addOrderByObject(OrderByObject ob)
SQLQueryBuilder
addOrderByObject
in interface SQLQueryBuilder
public void addOrderByObject(int index, OrderByObject ob)
SQLQueryBuilder
addOrderByObject
in interface SQLQueryBuilder
public boolean removeOrderByObject(OrderByObject ob)
SQLQueryBuilder
removeOrderByObject
in interface SQLQueryBuilder
public void replaceOrderByObject(OrderByObject oldOb, OrderByObject newOb)
SQLQueryBuilder
replaceOrderByObject
in interface SQLQueryBuilder
public void setOrderByObjects(OrderByObject[] orderbys)
SQLQueryBuilder
setOrderByObjects
in interface SQLQueryBuilder
@Deprecated public void syncViewColumns() throws AliasInUseException
syncViewColumns
in interface SQLQueryBuilder
AliasInUseException
public java.lang.String getColumnName(SelectObject sel)
public void checkUsageQualifications()
public final SQLFragment parseFromExpression(java.lang.String expression) throws SQLQueryException
SQLQueryBuilder
parseFromExpression
in interface SQLQueryBuilder
expression
- the sql to parse as a FROM fragment.SQLQueryException
protected SQLFragment parseFromExpression(java.lang.String expression, FromObject creating) throws SQLQueryException
SQLQueryException
public final SQLFragment parseSelectExpression(java.lang.String expression) throws SQLQueryException
SQLQueryBuilder
parseSelectExpression
in interface SQLQueryBuilder
expression
- the sql to parse as a SELECT fragment.SQLQueryException
protected SQLFragment parseSelectExpression(java.lang.String expression, SelectObject creating) throws SQLQueryException
SQLQueryException
public final SQLFragment parseWhereExpression(java.lang.String expression) throws SQLQueryException
SQLQueryBuilder
parseWhereExpression
in interface SQLQueryBuilder
expression
- the sql to parse as a WHERE fragment.SQLQueryException
public SQLFragment parseWhereExpression(java.lang.String expression, WhereObject creating) throws SQLQueryException
SQLQueryException
public Column[] getColumns() throws DBException
SQLQueryBuilder
getColumns
in interface SQLQueryBuilder
DBException
- if the query cannot be processedprotected abstract DerivedPropertyBuilder getDTUBuilder(int columnIndex)
protected abstract boolean containsAsterisk() throws SQLQueryException
SQLQueryException
public abstract java.util.List<AbstractSQLQueryBuilder.QueryColumnInfo> getQueryColumnInfos() throws SQLQueryException
SQLQueryException
protected void setViewColDataType(Column col, SelectObject so)
public void setSingleRelation(Relation singleRelation)
public void setExtraObjects(java.util.Collection<? extends SystemObject> objs)
protected void addExtraObject(SystemObject obj)
protected SchemaObject getObject(java.lang.String type, Schema sch, java.lang.String relation) throws DBException
DBException
protected SchemaObject getObject(DBObjectCriteria crit) throws DBException
DBException
public void registerSQLFragmentFactory(SQLFragmentFactory fac)
SQLQueryBuilder
registerSQLFragmentFactory
in interface SQLQueryBuilder
protected void registerAllSQLFragmentFactories(AbstractSQLQueryBuilder builder)
public final SQLFragment createFromFactory(SQLFragment parent, java.lang.String clause, java.lang.Integer offset)