Class MapSQLStatement


public class MapSQLStatement
extends java.lang.Object

Handle SQL statements. It is similar to CallableStatement but convert result set to HierarchicalMap. It also accepts parameters in HierarchicalMap format.
Start instantiating this class passing Connection. Then set a statement, or a callable statement like "{ call procedure(?, ?, ?) }". Create a HierarchicalMap containing input parameters. When parameter is output or inout, it must be wrapped using either OutParameter or InOutParameter classes.
This class is not thread safe. Be aware when sharing the same connection among several MapSQLStatement.

Nested Class Summary
static class MapSQLStatement.InOutParameter
          Static class to flag a node to be registered as in/out parameter.
static class MapSQLStatement.OutParameter
          Static class to flag a node to be registered as out parameter.
static class MapSQLStatement.OutResultSet
          Static class to flag a node to be registered as out ResultSet.
static class MapSQLStatement.Parameter
          A parent class for Parameters.
Field Summary
static MapSQLStatement.OutResultSet ResultSet
Constructor Summary
MapSQLStatement(java.sql.Connection con)
          Constructor receiving a connection to be used for further SQL statement execution.
Method Summary
 void close()
          Closes the current connection.
 HierarchicalMap execute()
          Executes the statement without parameter.
 HierarchicalMap execute(HierarchicalMap param)
          Executes the statement using HierarchiclMap as parameter.
 java.lang.String getResultSetName()
          Retrieves the current resultsetname.
 java.sql.CallableStatement getStatement()
          Retrieve the statement object.
 void setResultSetName(java.lang.String resultsetname)
          Defines the prefix for key used to map resultsets.
 void setStatement(java.lang.String sql)
          Prepares a callable statement object to be used during execution.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static final MapSQLStatement.OutResultSet ResultSet
Constructor Detail


public MapSQLStatement(java.sql.Connection con)
Constructor receiving a connection to be used for further SQL statement execution. The session must be established before execution.

con - a java.sql.Connection object.
Method Detail


public void setStatement(java.lang.String sql)
Prepares a callable statement object to be used during execution.

sql - an SQL statement that may contain several '?' as in or out parameter placeholders.


public java.sql.CallableStatement getStatement()
Retrieve the statement object. Null if it is not defined yet.

prepared statement.


public HierarchicalMap execute()
Executes the statement without parameter. If the statement returns a resultset, it is converted to HierarchicalMap mapping to key named "resultsetn" (where n should be 1 for first resultset 2 for second and so on).

a HierarchicalMap containing the returning results.


public HierarchicalMap execute(HierarchicalMap param)
Executes the statement using HierarchiclMap as parameter. Before execution, each node of parameter are mapped to corresponding placeholders in the statement. So the order of nodes within HierarchicalMap is crucial. Each node can be any Object for in parameter. The standard mapping between java Objects and SQL Objects specified by JDBC specification is applied (it is done calling java.sql.PreparedStatement.setObject() method). For out parameter, the Object must be wrapped using OutParameter or InOutParameter. The key associated to out parameter will be used to map the returning value on returning HierarchicalMap.

param - HierarchicalMap containing parameters.
HierarchicalMap with values returned from database.


public void setResultSetName(java.lang.String resultsetname)
Defines the prefix for key used to map resultsets.

resultsetname - to be used for further execution.


public java.lang.String getResultSetName()
Retrieves the current resultsetname.

current resultsetname.


public void close()
Closes the current connection.