Class JaninoQuery
- All Implemented Interfaces:
ParametersCallback
This class exposes a simplified query API. The concept of this API is the following:
- A virtual row is produced by calling
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>
- Version:
- 1.0
- Author:
- Fyodor Kupolov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal ObjectgetParameter(String name) Returns the value of parameter specified by name.final QueryCallbackfinal voidnext()Moves to the next virtual row.final voidProduces a virtual row based on the specified columns.final voidProduces a virtual row based on the specified columns.final voidSets a value for specified parameter name.final voidFills the virtual row using parameters from specified map.toString()Methods inherited from class scriptella.driver.janino.JaninoScript
execute, get, getParametersCallback
-
Constructor Details
-
JaninoQuery
public JaninoQuery()
-
-
Method Details
-
getQueryCallback
-
getParameter
Description copied from interface:ParametersCallbackReturns the value of parameter specified by name.The callback internally delegates a call to parent callbacks if the parameter cannot be found.
- Specified by:
getParameterin interfaceParametersCallback- Parameters:
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.- Returns:
- parameter value or null if parameter doesn't exist.
-
set
Sets a value for specified parameter name.This parameter becomes visible to nested scripting elements after
next()method is called.This method is available inside Janino <query> element.
- Parameters:
name- parameter namevalue- parameter value.
-
set
Fills the virtual row using parameters from specified map.This method is available inside Janino <query> element.
- Parameters:
parametersMap- map of parameters, where key is a variable name
-
next
public final void next()Moves to the next virtual row.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.
-
next
Produces a virtual row based on the specified columns.A serie of
parameter settersis performed. After parameters for the current row have been set,next()method is invoked.This method is available inside Janino <query> element.
- Parameters:
parameterNames- array of parameter names.values- array of parameter values, i.e. value[i] specifies a value for parameter[i].
-
next
Produces a virtual row based on the specified columns.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.
- Parameters:
parametersMap- map of parameters.
-
toString
-