public abstract class JaninoQuery extends JaninoScript implements ParametersCallback
This class exposes a simplified query API. The concept of this API is the following:
set(String, Object)
for each virtual column.
next()
is called to process this row by nested scripting elements.
helper method
exists to make iterating even simpler.
Virtual rows may also be constructed
from Map
or Properties
.
Public members of this class are available in Janino scripting elements.
Examples:
The following query produces two virtual rows:
id | name | age |
---|---|---|
123 | John | 20 |
200 | Mary |
<query>
set("id", "123"); //set row column
set("name", "John");
set("age", new Integer(20));
next();//sends a virtual row for processing
set("id", "200");
set("name", "Mary");
next();
</query>
The same effect may achieved using the following code:
<query>
String[] names = new String[] {"id", "name", "age"};
next(names, new Object[] {"123", "John", new Integer(20)};
next(names, new Object[] {"200", "Mary", null)};
</query>
Assume you have a map(or Properties) with the following mapping:
id->123, name->John, age->20
A virtual row is produced using this code:
<query>
//fill a map or load properties file
next(map};
</query>
Constructor and Description |
---|
JaninoQuery() |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getParameter(java.lang.String name)
Returns the value of parameter specified by name.
|
QueryCallback |
getQueryCallback() |
void |
next()
Moves to the next virtual row.
|
void |
next(java.util.Map<java.lang.String,?> parametersMap)
Produces a virtual row based on the specified columns.
|
void |
next(java.lang.String[] parameterNames,
java.lang.Object[] values)
Produces a virtual row based on the specified columns.
|
void |
set(java.util.Map<java.lang.String,?> parametersMap)
Fills the virtual row using parameters from specified map.
|
void |
set(java.lang.String name,
java.lang.Object value)
Sets a value for specified parameter name.
|
java.lang.String |
toString() |
execute, get, getParametersCallback
public final QueryCallback getQueryCallback()
public final java.lang.Object getParameter(java.lang.String name)
ParametersCallback
The callback internally delegates a call to parent callbacks if the parameter cannot be found.
getParameter
in interface ParametersCallback
name
- parameter name. Providers are allowed (but not required) to ignore a case of the name parameter
to comply with their internal model. For example JDBC drivers are case-insensitive to column names.public final void set(java.lang.String name, java.lang.Object value)
This parameter becomes visible to nested scripting elements
after next()
method is called.
This method is available inside Janino <query> element.
name
- parameter namevalue
- parameter value.public final void set(java.util.Map<java.lang.String,?> parametersMap)
This method is available inside Janino <query> element.
parametersMap
- map of parameters, where key is a variable namepublic final void next()
Nested scripting elements are evaluated and
the parameters set by set(String, Object)
method are available to them.
Note: The values of all parameters set via set(String, Object)
method are
cleared(or restored).
This method is available inside Janino <query> element.
public final void next(java.lang.String[] parameterNames, java.lang.Object[] values)
A serie of parameter setters
is performed.
After parameters for the current row have been set, next()
method is invoked.
This method is available inside Janino <query> element.
parameterNames
- array of parameter names.values
- array of parameter values, i.e. value[i] specifies a value for parameter[i].public final void next(java.util.Map<java.lang.String,?> parametersMap)
Parameters are set via set(java.util.Map)
method.
After parameters for the current row have been set, next()
method is invoked.
This method is available inside Janino <query> element.
parametersMap
- map of parameters.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © Copyright 2006-2019 The Scriptella Project Team.