Class Statement
- java.lang.Object
-
- com.mckoi.database.interpret.Statement
-
- Direct Known Subclasses:
AlterTable
,Call
,Compact
,CompleteTransaction
,CreateTable
,CreateTrigger
,Delete
,DropTable
,DropTrigger
,Function
,Insert
,Misc
,NoOp
,PrivManager
,Schema
,Select
,Sequence
,Set
,Show
,UpdateTable
,UserManager
,ViewManager
public abstract class Statement extends java.lang.Object
Provides a set of useful utility functions to use by all the interpretted statements.
-
-
Field Summary
Fields Modifier and Type Field Description protected StatementTree
cmd
The StatementTree object that is the container for the query.protected DatabaseConnection
database
The Database context.protected SQLQuery
query
The SQLQuery object that was used to produce this statement.protected java.util.Vector
table_list
The list of all FromTableInterface objects of resources referenced in this query.protected User
user
The user context.
-
Constructor Summary
Constructors Constructor Description Statement()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addTable(FromTableInterface table)
Add an FromTableInterface that is used within this query.DebugLogger
Debug()
Returns a DebugLogger object used to log debug commands.abstract Table
evaluate()
Evaluates the statement and returns a table that represents the result set.(package private) boolean
existsTableWithColumn(Variable column_name)
Given a fully resolved table name ( eg.(package private) FromTableInterface
findTableInQuery(java.lang.String schema, java.lang.String name)
Returns the first FromTableInterface object that matches the given schema, table reference.(package private) FromTableInterface
findTableWithColumn(Variable column_name)
Given a fully resolved table name ( eg.void
init(DatabaseConnection db, StatementTree stree, SQLQuery query)
Sets up internal variables for this statement for derived classes to use.abstract void
prepare()
Prepares the statement with the given Database object.(package private) void
reset()
Resets this statement so it may be re-prepared and evaluated again.(package private) java.util.ArrayList
resolveAgainstAliases(Variable alias_name)
Overwrite this method if your statement has some sort of column aliasing capability (such as a select statement).(package private) Variable
resolveColumn(Variable v)
Attempts to resolve an ambiguous column name such as 'id' into a Variable from the tables in this statement.(package private) void
resolveExpression(Expression exp)
Given an Expression, this will run through the expression and resolve any variable names via the 'resolveVariableName' method here.(package private) TableName
resolveTableName(java.lang.String name, DatabaseConnection db)
Resolves a TableName string (eg.void
resolveTree()
Performs initial preparation on the contents of the StatementTree by resolving all sub queries and mapping functions to their executable forms.Variable
resolveVariableName(Variable v)
Given a Variable object, this will resolve the name into a column name the database understands (substitutes aliases, etc).
-
-
-
Field Detail
-
database
protected DatabaseConnection database
The Database context.
-
user
protected User user
The user context.
-
cmd
protected StatementTree cmd
The StatementTree object that is the container for the query.
-
query
protected SQLQuery query
The SQLQuery object that was used to produce this statement.
-
table_list
protected java.util.Vector table_list
The list of all FromTableInterface objects of resources referenced in this query. (FromTableInterface)
-
-
Method Detail
-
Debug
public final DebugLogger Debug()
Returns a DebugLogger object used to log debug commands.
-
reset
void reset()
Resets this statement so it may be re-prepared and evaluated again. Useful for repeating a query multiple times.
-
resolveTree
public final void resolveTree() throws DatabaseException
Performs initial preparation on the contents of the StatementTree by resolving all sub queries and mapping functions to their executable forms.Given a StatementTree and a Database context, this method will convert all sub-queries found in the StatementTree to a Queriable object. In other words, all StatementTree are converted to Select objects. The given 'database' object is used as the session to prepare the sub-queries against.
This is called after 'init' and before 'prepare'.
- Throws:
DatabaseException
-
findTableWithColumn
FromTableInterface findTableWithColumn(Variable column_name)
Given a fully resolved table name ( eg. Part.id ) this method will attempt to find the Table object that the column is in.
-
existsTableWithColumn
boolean existsTableWithColumn(Variable column_name)
Given a fully resolved table name ( eg. Part.id ) this returns true if there is a table with the given column name, otherwise false.NOTE: Intended to be overwritten...
-
resolveAgainstAliases
java.util.ArrayList resolveAgainstAliases(Variable alias_name)
Overwrite this method if your statement has some sort of column aliasing capability (such as a select statement). Returns a list of all fully qualified Variables that match the alias name, or an empty list if no matches found.By default, returns an empty list.
-
resolveTableName
TableName resolveTableName(java.lang.String name, DatabaseConnection db)
Resolves a TableName string (eg. 'Customer' 'APP.Customer' ) to a TableName object. If the schema part of the table name is not present then it is set to the current schema of the database connection. If the database is ignoring the case then this will correctly resolve the table to the cased version of the table name.
-
findTableInQuery
FromTableInterface findTableInQuery(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.
-
resolveColumn
Variable resolveColumn(Variable v)
Attempts to resolve an ambiguous column name such as 'id' into a Variable from the tables in this statement.
-
resolveVariableName
public Variable resolveVariableName(Variable v)
Given a Variable object, this will resolve the name into a column name the database understands (substitutes aliases, etc).
-
resolveExpression
void resolveExpression(Expression exp)
Given an Expression, this will run through the expression and resolve any variable names via the 'resolveVariableName' method here.
-
addTable
protected void addTable(FromTableInterface table)
Add an FromTableInterface that is used within this query. These tables are used when we try to resolve a column name.
-
init
public final void init(DatabaseConnection db, StatementTree stree, SQLQuery query)
Sets up internal variables for this statement for derived classes to use. This is called before 'prepare' and 'isExclusive' is called.It is assumed that any ? style parameters in the StatementTree will have been resolved previous to a call to this method.
- Parameters:
db
- the DatabaseConnection that will execute this statement.stree
- the StatementTree that contains the parsed content of the statement being executed.
-
prepare
public abstract void prepare() throws DatabaseException
Prepares the statement with the given Database object. This is called before the statement is evaluated. The prepare statement queries the database and resolves information about the statement (for example, it resolves column names and aliases and determines the tables that are touched by this statement so we can lock the appropriate tables before we evaluate).NOTE: Care must be taken to ensure that all methods called here are safe in as far as modifications to the data occuring. The rules for safety should be as follows. If the database is in EXCLUSIVE mode, then we need to wait until it's switched back to SHARED mode before this method is called. All collection of information done here should not involve any table state info. except for column count, column names, column types, etc. Queries such as obtaining the row count, selectable scheme information, and certainly 'getCellContents' must never be called during prepare. When prepare finishes, the affected tables are locked and the query is safe to 'evaluate' at which time table state is safe to inspect.
- Throws:
DatabaseException
-
evaluate
public abstract Table evaluate() throws DatabaseException, TransactionException
Evaluates the statement and returns a table that represents the result set. This is called after 'prepare'.
-
-