nl.gx.webmanager.handler.forms.foundation
Class FormHandlerBase

java.lang.Object
  extended by nl.gx.webmanager.handler.forms.foundation.FormHandlerBase
All Implemented Interfaces:
FormComponent
Direct Known Subclasses:
ConfirmationHandler, CopyFileHandler, CountDbValidator, DatabaseUpdateHandler, DBDeleteHandler, DBInsertHandler, DBUpdateHandler, DigiDHandler, FlowLoggingHandler, MailHandler, OgoneRouter, PollHandler, ProfileHandler, QueryToSessionHandler, StoredProcedureHandler, SubscriptionHandler, XslQueryArgumentsHandler

public abstract class FormHandlerBase
extends java.lang.Object
implements FormComponent

Convenient base class for handlers. FIXME: add a generic insert with identity method that uses the oracle & mssql specific methods. FIXME: move database methods to a separate database utility class, update all handlers and provide deprecated stubs in this class. Database class may be useful for api as well.


Field Summary
static int DEFAULT_STATEMENT_TIMEOUT
           
protected  java.util.logging.Logger log
           
protected static java.util.logging.Logger staticlog
           
 
Constructor Summary
FormHandlerBase()
           
 
Method Summary
static void close(java.sql.ResultSet rs, java.sql.Connection con)
          Utility method to close a resultset and a connection safely.
static void close(java.sql.ResultSet rs, java.sql.Statement statement, java.sql.Connection con)
          Utility method to close a resultset, statement and connection safely.
static void close(java.sql.Statement statement, java.sql.Connection con)
          Utility method to close a statement and a connection safely.
protected static java.lang.String executeInsertWithIdentityMSSQLMYSQL(javax.sql.DataSource datasource, java.lang.String statement)
          Insert a row into a mssql or mysql table and return the incremented id of the row.
protected static java.lang.String executeInsertWithIdentityOracle(javax.sql.DataSource datasource, java.lang.String statement, java.lang.String tablename, java.lang.String identityfield)
          For oracle we first increment a sequence and then use new id in the insert statement.
static java.lang.Integer executeIntegerQuery(javax.sql.DataSource datasource, java.lang.String statement, java.lang.Class[] types, java.lang.Object[] arguments)
          Execute a query that returns an integer (for example a select will return the number of records.
static java.lang.Integer executeIntegerQuery(javax.sql.DataSource datasource, java.lang.String statement, java.lang.Object[] arguments)
          Execute a query that returns an integer (for example a select will return the number of records.
static java.lang.Integer[] executeIntegersQuery(javax.sql.DataSource datasource, java.lang.String statement, java.lang.Class[] types, java.lang.Object[] arguments)
          Execute a query that returns integers.
static java.lang.Integer[] executeIntegersQuery(javax.sql.DataSource datasource, java.lang.String statement, java.lang.Object[] arguments)
          Execute a query that returns integers.
protected static java.lang.Object[][] executeQuery(javax.sql.DataSource datasource, java.lang.String statement, java.lang.Object[] arguments)
          Executes a select statement on a datasource.
protected static java.lang.String[] executeStringQuery(javax.sql.DataSource datasource, java.lang.String statement, java.lang.Object[] arguments)
           
protected static int executeUpdate(javax.sql.DataSource datasource, java.lang.String statement, java.lang.Object[] arguments, java.lang.Class[] classes)
           
static void fillValues(FormPart[] webUserParts, SessionFormFlow formValues, java.lang.Class[] classes, java.lang.Object[] args)
          Fill the class and args parameter for use in a query (for example executeIntegerQuery).
static javax.sql.DataSource getDataSource(java.lang.String connectionName)
           
protected static void setArguments(java.sql.PreparedStatement stmt, java.lang.Object[] objects, java.lang.Class[] classes)
           
protected static void setArguments(java.sql.PreparedStatement stmt, java.lang.Object[] objects, int[] types)
          Set the parameters of a query to the values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface nl.gx.webmanager.handler.forms.FormComponent
init
 

Field Detail

staticlog

protected static final java.util.logging.Logger staticlog

log

protected java.util.logging.Logger log

DEFAULT_STATEMENT_TIMEOUT

public static final int DEFAULT_STATEMENT_TIMEOUT
See Also:
Constant Field Values
Constructor Detail

FormHandlerBase

public FormHandlerBase()
Method Detail

getDataSource

public static javax.sql.DataSource getDataSource(java.lang.String connectionName)
                                          throws java.sql.SQLException
Throws:
java.sql.SQLException

setArguments

protected static void setArguments(java.sql.PreparedStatement stmt,
                                   java.lang.Object[] objects,
                                   int[] types)
                            throws java.sql.SQLException
Set the parameters of a query to the values.

Parameters:
stmt - the statement to set the values on
objects - an array with the values
types - an array with the java.sql.Types
Throws:
java.sql.SQLException

setArguments

protected static void setArguments(java.sql.PreparedStatement stmt,
                                   java.lang.Object[] objects,
                                   java.lang.Class[] classes)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

executeUpdate

protected static int executeUpdate(javax.sql.DataSource datasource,
                                   java.lang.String statement,
                                   java.lang.Object[] arguments,
                                   java.lang.Class[] classes)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

executeQuery

protected static java.lang.Object[][] executeQuery(javax.sql.DataSource datasource,
                                                   java.lang.String statement,
                                                   java.lang.Object[] arguments)
                                            throws java.sql.SQLException
Executes a select statement on a datasource.

Parameters:
datasource - The datasource for the statement
statement - The select statement that should be executed
arguments - The arguments for the prepared statement.
Returns:
The results of the first tuple of the resultset, or null if there are no tuples available.
Throws:
java.sql.SQLException - If the statement couldn't be executed

executeIntegerQuery

public static java.lang.Integer executeIntegerQuery(javax.sql.DataSource datasource,
                                                    java.lang.String statement,
                                                    java.lang.Object[] arguments)
                                             throws java.sql.SQLException
Execute a query that returns an integer (for example a select will return the number of records. in the resultset)

Parameters:
datasource -
statement -
arguments -
Returns:
the integer returned by executing the query
Throws:
java.sql.SQLException

executeIntegerQuery

public static java.lang.Integer executeIntegerQuery(javax.sql.DataSource datasource,
                                                    java.lang.String statement,
                                                    java.lang.Class[] types,
                                                    java.lang.Object[] arguments)
                                             throws java.sql.SQLException
Execute a query that returns an integer (for example a select will return the number of records. in the resultset)

Parameters:
datasource -
statement -
types -
arguments -
Returns:
the integer returned by executing the query
Throws:
java.sql.SQLException

executeIntegersQuery

public static java.lang.Integer[] executeIntegersQuery(javax.sql.DataSource datasource,
                                                       java.lang.String statement,
                                                       java.lang.Object[] arguments)
                                                throws java.sql.SQLException
Execute a query that returns integers.

Parameters:
datasource -
statement -
arguments -
Returns:
array of integers
Throws:
java.sql.SQLException

executeIntegersQuery

public static java.lang.Integer[] executeIntegersQuery(javax.sql.DataSource datasource,
                                                       java.lang.String statement,
                                                       java.lang.Class[] types,
                                                       java.lang.Object[] arguments)
                                                throws java.sql.SQLException
Execute a query that returns integers.

Parameters:
datasource -
statement -
types -
arguments -
Returns:
array of integers
Throws:
java.sql.SQLException

executeStringQuery

protected static java.lang.String[] executeStringQuery(javax.sql.DataSource datasource,
                                                       java.lang.String statement,
                                                       java.lang.Object[] arguments)
                                                throws java.sql.SQLException
Throws:
java.sql.SQLException

executeInsertWithIdentityOracle

protected static java.lang.String executeInsertWithIdentityOracle(javax.sql.DataSource datasource,
                                                                  java.lang.String statement,
                                                                  java.lang.String tablename,
                                                                  java.lang.String identityfield)
                                                           throws java.sql.SQLException
For oracle we first increment a sequence and then use new id in the insert statement. TODO: test whether this actually works

Parameters:
datasource -
statement -
tablename -
identityfield -
Returns:
identity
Throws:
java.sql.SQLException

executeInsertWithIdentityMSSQLMYSQL

protected static java.lang.String executeInsertWithIdentityMSSQLMYSQL(javax.sql.DataSource datasource,
                                                                      java.lang.String statement)
                                                               throws java.sql.SQLException
Insert a row into a mssql or mysql table and return the incremented id of the row. This method will throw an exception if the database is not mssql or mysql.

Parameters:
datasource -
statement -
Returns:
identity
Throws:
java.sql.SQLException

close

public static void close(java.sql.ResultSet rs,
                         java.sql.Statement statement,
                         java.sql.Connection con)
                  throws java.sql.SQLException
Utility method to close a resultset, statement and connection safely.

Parameters:
rs -
statement -
con -
Throws:
java.sql.SQLException

close

public static void close(java.sql.Statement statement,
                         java.sql.Connection con)
                  throws java.sql.SQLException
Utility method to close a statement and a connection safely.

Parameters:
statement -
con -
Throws:
java.sql.SQLException

close

public static void close(java.sql.ResultSet rs,
                         java.sql.Connection con)
                  throws java.sql.SQLException
Utility method to close a resultset and a connection safely.

Parameters:
rs -
con -
Throws:
java.sql.SQLException

fillValues

public static void fillValues(FormPart[] webUserParts,
                              SessionFormFlow formValues,
                              java.lang.Class[] classes,
                              java.lang.Object[] args)
Fill the class and args parameter for use in a query (for example executeIntegerQuery).

Parameters:
webUserParts - formparts with values
formValues - the formflow with the form values
classes - this array will be filled with the types of the formvalues
args - this array will be filled with instances of the types with the appropriate values


Copyright © 2007-2011 GX Software BV. All Rights Reserved.