Package com.mckoi.database.interpret
Class TableExpressionFromSet
- java.lang.Object
-
- com.mckoi.database.interpret.TableExpressionFromSet
-
class TableExpressionFromSet extends java.lang.ObjectA set of tables and function references that make up the resources made available by a table expression. When a SelectQueriable is prepared this object is created and is used to dereference names to sources. It also has the ability to chain to another TableExpressionFromSet and resolve references over a complex sub-query hierarchy.
-
-
Field Summary
Fields Modifier and Type Field Description private booleancase_insensitiveSet to true if this should do case insensitive resolutions.private java.util.ArrayListexposed_variablesThe list of Variable references in this set that are exposed to the outside, including function aliases.private java.util.ArrayListfunction_resourcesThe list of function expression resources.private TableExpressionFromSetparentThe parent TableExpressionFromSet if one exists.private java.util.ArrayListtable_resourcesThe list of table resources in this set.
-
Constructor Summary
Constructors Constructor Description TableExpressionFromSet(DatabaseConnection connection)Constructs the object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFunctionRef(java.lang.String name, Expression expression)Adds a function resource to the set.voidaddTable(FromTableInterface table_resource)Adds a table resource to the set.(package private) ExpressiondereferenceAssignment(Variable v)Dereferences a fully qualified reference that is within this set.voidexposeAllColumns()Exposes all the columns in all the child tables.voidexposeAllColumnsFromSource(FromTableInterface table)Exposes all the columns from the given FromTableInterface.voidexposeAllColumnsFromSource(TableName tn)Exposes all the columns from the given table name.voidexposeVariable(Variable v)Adds a variable in this from set that is exposed to the outside.(package private) ExpressionPreparerexpressionQualifier()Returns an ExpressionPreparer that qualifies all variables in an expression to either a qualified Variable or a CorrelatedVariable object.(package private) FromTableInterfacefindTable(java.lang.String schema, java.lang.String name)Returns the first FromTableInterface object that matches the given schema, table reference.Variable[]generateResolvedVariableList()Returns a Variable[] array for each variable that is exposed in this from set.TableExpressionFromSetgetParent()Returns the parent of this set.(package private) FromTableInterfacegetTable(int i)Returns the FromTableInterface object at the given index position in this set.(package private) CorrelatedVariableglobalResolveReference(int level, Variable v)Resolves the given Variable reference within the chained list of TableExpressionFromSet objects to a CorrelatedVariable.(package private) java.lang.ObjectqualifyVariable(Variable v_in)Attempts to qualify the given Variable object to a value found either in this from set, or a value in the parent from set.private VariableresolveAssignmentReference(Variable v)Resolves the given Variable object to an assignment if it's possible to do so within the context of this set.(package private) VariableresolveReference(Variable v)Resolves the given Variable object to a fully resolved Variable within the context of this table expression.(package private) VariableresolveTableColumnReference(Variable v)Resolves the given Variable against the table columns in this from set.voidsetCaseInsensitive(boolean status)Toggle the case sensitivity flag.(package private) intsetCount()Returns the number of FromTableInterface objects in this set.voidsetParent(TableExpressionFromSet parent)Sets the parent of this expression.(package private) booleanstringCompare(java.lang.String str1, java.lang.String str2)
-
-
-
Field Detail
-
table_resources
private java.util.ArrayList table_resources
The list of table resources in this set. (FromTableInterface).
-
function_resources
private java.util.ArrayList function_resources
The list of function expression resources. For example, one table expression may expose a function as 'SELECT (a + b) AS c, ....' in which case we have a virtual assignment of c = (a + b) in this set.
-
exposed_variables
private java.util.ArrayList exposed_variables
The list of Variable references in this set that are exposed to the outside, including function aliases. For example, SELECT a, b, c, (a + 1) d FROM ABCTable Would be exposing variables 'a', 'b', 'c' and 'd'.
-
case_insensitive
private boolean case_insensitive
Set to true if this should do case insensitive resolutions.
-
parent
private TableExpressionFromSet parent
The parent TableExpressionFromSet if one exists. This is used for chaining a set of table sets together. When chained the 'globalResolveVariable' method can be used to resolve a reference in the chain.
-
-
Constructor Detail
-
TableExpressionFromSet
public TableExpressionFromSet(DatabaseConnection connection)
Constructs the object.
-
-
Method Detail
-
setParent
public void setParent(TableExpressionFromSet parent)
Sets the parent of this expression. parent can be set to null.
-
getParent
public TableExpressionFromSet getParent()
Returns the parent of this set. If it has no parent it returns null.
-
setCaseInsensitive
public void setCaseInsensitive(boolean status)
Toggle the case sensitivity flag.
-
stringCompare
boolean stringCompare(java.lang.String str1, java.lang.String str2)
-
addTable
public void addTable(FromTableInterface table_resource)
Adds a table resource to the set.
-
addFunctionRef
public void addFunctionRef(java.lang.String name, Expression expression)Adds a function resource to the set. Note that is possible for there to be references in the 'expression' that do not reference resources in this set. For example, a correlated reference.
-
exposeVariable
public void exposeVariable(Variable v)
Adds a variable in this from set that is exposed to the outside. This list should contain all references from the SELECT ... part of the query. For example, SELECT a, b, (a + 1) d exposes variables a, b and d.
-
exposeAllColumnsFromSource
public void exposeAllColumnsFromSource(FromTableInterface table)
Exposes all the columns from the given FromTableInterface.
-
exposeAllColumns
public void exposeAllColumns()
Exposes all the columns in all the child tables.
-
exposeAllColumnsFromSource
public void exposeAllColumnsFromSource(TableName tn)
Exposes all the columns from the given table name.
-
generateResolvedVariableList
public Variable[] generateResolvedVariableList()
Returns a Variable[] array for each variable that is exposed in this from set. This is a list of fully qualified variables that are referencable from the final result of the table expression.
-
findTable
FromTableInterface findTable(java.lang.String schema, java.lang.String name)
Returns the first FromTableInterface object that matches the given schema, table reference. Returns null if no objects with the given schema/name reference match.
-
setCount
int setCount()
Returns the number of FromTableInterface objects in this set.
-
getTable
FromTableInterface getTable(int i)
Returns the FromTableInterface object at the given index position in this set.
-
dereferenceAssignment
Expression dereferenceAssignment(Variable v)
Dereferences a fully qualified reference that is within this set. For example, SELECT ( a + b ) AS z given 'z' would return the expression (a + b).Returns null if unable to dereference assignment because it does not exist.
-
resolveAssignmentReference
private Variable resolveAssignmentReference(Variable v)
Resolves the given Variable object to an assignment if it's possible to do so within the context of this set. If the variable can not be unambiguously resolved to a function or aliased column, a StatementException is thrown. If the variable isn't assigned to any function or aliased column, 'null' is returned.
-
resolveTableColumnReference
Variable resolveTableColumnReference(Variable v)
Resolves the given Variable against the table columns in this from set. If the variable does not resolve to anything 'null' is returned. If the variable is ambiguous, a StatementException is thrown.Note that the given variable does not have to be fully qualified but the returned expressions are fully qualified.
-
resolveReference
Variable resolveReference(Variable v)
Resolves the given Variable object to a fully resolved Variable within the context of this table expression. If the variable does not resolve to anything 'null' is returned. If the variable is ambiguous, a StatementException is thrown.If the variable name references a table column, an expression with a single Variable element is returned. If the variable name references a function, an expression of the function is returned.
Note that the given variable does not have to be fully qualified but the returned expressions are fully qualified.
-
globalResolveReference
CorrelatedVariable globalResolveReference(int level, Variable v)
Resolves the given Variable reference within the chained list of TableExpressionFromSet objects to a CorrelatedVariable. If the reference is not found in this set the method recurses to the parent set. The first unambiguous reference is returned.If resolution is ambiguous within a set, a StatementException is thrown.
Returns null if the reference could not be resolved.
-
qualifyVariable
java.lang.Object qualifyVariable(Variable v_in)
Attempts to qualify the given Variable object to a value found either in this from set, or a value in the parent from set. A variable that is qualified by the parent is called a correlated variable. Any correlated variables that are successfully qualified are returned as CorrelatedVariable objects.
-
expressionQualifier
ExpressionPreparer expressionQualifier()
Returns an ExpressionPreparer that qualifies all variables in an expression to either a qualified Variable or a CorrelatedVariable object.
-
-