net.sf.saffron.oj.stmt
Class OJStatement

java.lang.Object
  |
  +--net.sf.saffron.oj.stmt.OJStatement

public class OJStatement
extends Object

An OJStatement is used to execute a saffron (or regular Java) expression dynamically.


Nested Class Summary
static class OJStatement.Argument
          An Argument supplies a name/value pair to a statement.
(package private) static interface OJStatement.Binder
           
 
Field Summary
private  SaffronConnection connection
           
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  CallingConvention resultCallingConvention
          CallingConvention via which results should be returned by execution.
 
Constructor Summary
OJStatement(SaffronConnection connection)
          Creates a statement
 
Method Summary
private  void addDecl(Statement statement, ExpressionList exprList)
           
private  BoundMethod compile(ClassDeclaration decl, Environment env, ParseTree parseTree, OJStatement.Argument[] arguments)
           
private  BoundMethod compile(String packageName, String className, String s, Class[] parameterTypes, String[] parameterNames)
           
private  BoundMethod compileAndBind(ClassDeclaration decl, ParseTree parseTree, OJStatement.Argument[] arguments)
           
private static JavaCompiler createCompiler()
           
 Object evaluate(ClassDeclaration decl, ParseTree parseTree, OJStatement.Argument[] arguments)
          Evaluates an expression represented by a parse tree.
 Object execute(String queryString, OJStatement.Argument[] arguments)
          Executes a query string, passing in a set of arguments, and returns the result.
 ResultSet executeSql(String queryString)
           
protected static String getClassRoot()
           
private static String getCompilerClassName()
           
 Environment getEnvironment()
           
protected static String getJavaRoot()
           
protected  SqlToRelConverter getSqlToRelConverter(SqlValidator validator, SaffronConnection connection)
          Protected method to allow subclasses to override construction of SqlToRelConverter.
protected  String getTempClassName()
           
protected  String getTempMethodName()
           
protected  String getTempPackageName()
           
 ClassDeclaration init(OJStatement.Argument[] arguments)
           
 Expression parse(String queryString)
           
 PreparedResult prepareSql(SqlNode sqlQuery, Class runtimeContextClass, SqlValidator validator)
          Prepares a statement for execution, starting from a parse tree and using a user-supplied validator.
 PreparedResult prepareSql(String queryString)
          Prepares a statement for execution, starting from a SQL string and using the standard validator.
 void setResultCallingConvention(CallingConvention resultCallingConvention)
           
 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)
          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

connectionVariable

public static final String connectionVariable
See Also:
Constant Field Values

env

Environment env

executionCount

int executionCount

resultCallingConvention

private CallingConvention resultCallingConvention
CallingConvention via which results should be returned by execution.


javaCompiler

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


connection

private final SaffronConnection connection
Constructor Detail

OJStatement

public OJStatement(SaffronConnection connection)
Creates a statement

Parameters:
connection - Connection statement belongs to; may be null, but only if this statement implements SaffronConnection
Pre-condition:
connection != null || this instanceof SaffronConnection
Method Detail

getEnvironment

public Environment getEnvironment()

setResultCallingConvention

public void setResultCallingConvention(CallingConvention resultCallingConvention)

evaluate

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


compileAndBind

private BoundMethod compileAndBind(ClassDeclaration decl,
                                   ParseTree parseTree,
                                   OJStatement.Argument[] arguments)

execute

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

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)});

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

executeSql

public ResultSet executeSql(String queryString)

init

public ClassDeclaration init(OJStatement.Argument[] arguments)

parse

public Expression parse(String queryString)

prepareSql

public PreparedResult prepareSql(String queryString)
Prepares a statement for execution, starting from a SQL string and using the standard validator.


prepareSql

public PreparedResult prepareSql(SqlNode sqlQuery,
                                 Class runtimeContextClass,
                                 SqlValidator validator)
Prepares a statement for execution, starting from a parse tree and using a user-supplied validator.


getSqlToRelConverter

protected SqlToRelConverter getSqlToRelConverter(SqlValidator validator,
                                                 SaffronConnection connection)
Protected method to allow subclasses to override construction of SqlToRelConverter.


validate

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


getClassRoot

protected static String getClassRoot()

getCompilerClassName

private static String getCompilerClassName()

getJavaRoot

protected static String getJavaRoot()

getTempPackageName

protected String getTempPackageName()

getTempMethodName

protected String getTempMethodName()

getTempClassName

protected String getTempClassName()

createCompiler

private static JavaCompiler createCompiler()

visibleBaseClass

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


addDecl

private void addDecl(Statement statement,
                     ExpressionList exprList)

compile

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

compile

private BoundMethod compile(String packageName,
                            String className,
                            String s,
                            Class[] parameterTypes,
                            String[] parameterNames)

SourceForge.net_Logo