scriptella.driver.janino
Class JaninoQuery

java.lang.Object
  extended by scriptella.driver.janino.JaninoScript
      extended by scriptella.driver.janino.JaninoQuery
All Implemented Interfaces:
scriptella.spi.ParametersCallback

public abstract class JaninoQuery
extends JaninoScript
implements scriptella.spi.ParametersCallback

A base class for Janino <query> elements.

This class exposes a simplified query API. The concept of this API is the following:

Additionally a 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:

idnameage
123John20
200Mary
 <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
JaninoQuery()
           
 
Method Summary
 java.lang.Object getParameter(java.lang.String name)
           
 scriptella.spi.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()
           
 
Methods inherited from class scriptella.driver.janino.JaninoScript
execute, get, getParametersCallback
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JaninoQuery

public JaninoQuery()
Method Detail

getQueryCallback

public final scriptella.spi.QueryCallback getQueryCallback()

getParameter

public final java.lang.Object getParameter(java.lang.String name)
Specified by:
getParameter in interface scriptella.spi.ParametersCallback

set

public final void set(java.lang.String name,
                      java.lang.Object value)
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 name
value - parameter value.

set

public final void set(java.util.Map<java.lang.String,?> parametersMap)
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

public final void next(java.lang.String[] parameterNames,
                       java.lang.Object[] values)
Produces a virtual row based on the specified columns.

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.

Parameters:
parameterNames - array of parameter names.
values - array of parameter values, i.e. value[i] specifies a value for parameter[i].

next

public final void next(java.util.Map<java.lang.String,?> parametersMap)
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

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © Copyright 2006-2009 The Scriptella Project Team.