saffron
Class Statement

java.lang.Object
  |
  +--saffron.Statement

public class Statement
extends Object

A Statement is used to execute a saffron (or regular Java) expression dynamically.


Nested Class Summary
static class Statement.Argument
          An Argument supplies a name/value pair to a statement.
(package private) static interface Statement.Binder
           
(package private) static class Statement.Thunk
           
 
Field Summary
static String connectionVariable
           
(package private)  Environment env
           
(package private)  int executionCount
           
private  JavaCompiler javaCompiler
          Share the same compiler between multiple statements because DynamicJava has a class loader which caches class definitions.
private  Class resultClass
          Class which should be returned by execution.
 
Constructor Summary
Statement()
           
 
Method Summary
private  void addDecl(Statement statement, ExpressionList exprList)
           
private  ParseTree addResultCast(Expression expression)
           
private  Statement.Thunk compile(ClassDeclaration decl, Environment env, ParseTree parseTree, Statement.Argument[] arguments)
           
private  Statement.Thunk compile(String packageName, String className, String s, Class[] parameterTypes, String[] parameterNames)
           
private static JavaCompiler createCompiler()
           
 Object evaluate(ClassDeclaration decl, ParseTree parseTree, Statement.Argument[] arguments)
          Evaluates an expression represented by a parse tree.
 Object execute(String queryString, Statement.Argument[] arguments)
          Executes a query string, passing in a set of arguments, and returns the result.
 ResultSet executeSql(String queryString, Connection connection)
           
private static String getClassRoot()
           
private static String getCompilerClassName()
           
 Environment getEnvironment()
           
private static String getJavaRoot()
           
private static String getTempPackageName()
           
 ClassDeclaration init(Statement.Argument[] arguments)
           
 Expression parse(String queryString)
           
private  PreparedResult prepareExplanation(ParseTree parseTree)
           
 PreparedResult prepareSql(String queryString, Connection connection)
           
 void setResultClass(Class resultClass)
           
private  Expression toExpression(SqlNode sqlNode, Connection connection)
           
 ParseTree validate(ParseTree parseTree, QueryExpander queryExpander)
          Validates and transforms an expression: expands schemas, validates, and possibly expands queries.
private static Class visibleBaseClass(Class clazz, String fromPackageName, String fromClassName)
          Returns the lowest ancestor of clazz which is visible from fromPackage.fromClazz.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

env

Environment env

executionCount

int executionCount

javaCompiler

private JavaCompiler javaCompiler
Share the same compiler between multiple statements because DynamicJava has a class loader which caches class definitions.


resultClass

private Class resultClass
Class which should be returned by execution.


connectionVariable

public static final String connectionVariable
See Also:
Constant Field Values
Constructor Detail

Statement

public Statement()
Method Detail

getEnvironment

public Environment getEnvironment()

setResultClass

public void setResultClass(Class resultClass)

execute

public Object execute(String queryString,
                      Statement.Argument[] arguments)
Executes a query string, passing in a set of arguments, and returns the result.

Parameters:
queryString - expression to execute. (Although this method is intended to allow execution of relational expressions, queryString can actually be any valid Java expression, for example 1 + 2.)
arguments - a set of name/value pairs to pass to the expression.
Returns:
the result of evaluating the expression. If the expression is relational, the return is a Enumeration

Example:

Sales sales = new Sales("jdbc:odbc:Northwind");
 int maxSalary = 10000;
 Statement statement = new Statement();
 statement.execute(
     "select * from sales.emp where emp.sal > maxSalary",
     this.class,
     new Argument[] {
         new Argument("sales", sales),
         new Argument("maxSalary", maxSalary)});

parse

public Expression parse(String queryString)

validate

public ParseTree validate(ParseTree parseTree,
                          QueryExpander queryExpander)
Validates and transforms an expression: expands schemas, validates, and possibly expands queries.


init

public ClassDeclaration init(Statement.Argument[] arguments)

visibleBaseClass

private static Class visibleBaseClass(Class clazz,
                                      String fromPackageName,
                                      String fromClassName)
Returns the lowest ancestor of clazz which is visible from fromPackage.fromClazz.


getTempPackageName

private static String getTempPackageName()

getJavaRoot

private static String getJavaRoot()

getClassRoot

private static String getClassRoot()

getCompilerClassName

private static String getCompilerClassName()

createCompiler

private static JavaCompiler createCompiler()

evaluate

public Object evaluate(ClassDeclaration decl,
                       ParseTree parseTree,
                       Statement.Argument[] arguments)
Evaluates an expression represented by a parse tree. The parse tree must not contain any non-standard java syntax.


compile

private Statement.Thunk compile(ClassDeclaration decl,
                                Environment env,
                                ParseTree parseTree,
                                Statement.Argument[] arguments)

compile

private Statement.Thunk compile(String packageName,
                                String className,
                                String s,
                                Class[] parameterTypes,
                                String[] parameterNames)

addDecl

private void addDecl(Statement statement,
                     ExpressionList exprList)

executeSql

public ResultSet executeSql(String queryString,
                            Connection connection)

prepareSql

public PreparedResult prepareSql(String queryString,
                                 Connection connection)

prepareExplanation

private PreparedResult prepareExplanation(ParseTree parseTree)

toExpression

private Expression toExpression(SqlNode sqlNode,
                                Connection connection)

addResultCast

private ParseTree addResultCast(Expression expression)

SourceForge.net_Logo