com.onewebsql.util.jdbc
Class JdbcUtil

java.lang.Object
  extended by com.onewebsql.util.jdbc.JdbcUtil

public class JdbcUtil
extends Object

Utility class to access JDBC layer. It manages the connection (opens, closes, handles exceptions) and wraps JDBC results into Java™ objects.


Constructor Summary
JdbcUtil()
          Creates a new JdbcUtil object.
JdbcUtil(DataSource dataSource)
          Constructor.
 
Method Summary
<PH> List<Integer>
batchUpdate(String query, Collection<PH> parameters, ParameterHandler<PH> parameterHandler)
          Shorthand to invoke a batch update.
<T,IP,OP> T
call(String query, IP inputParameters, OP outputParameters, CallableStatementParameterHandler<IP,OP> callableStatementParameterHandler, CallableStatementHandler<T> callableStatementHandler)
          Shorthand to invoke a stored procedure.
<PH,RH> List<RH>
query(String query, PH parameters, ParameterHandler<PH> parameterHandler, RowHandler<RH> rowHandler)
          Shorthand to invoke a SELECT query.
<PH> Integer
update(String query, PH parameters, ParameterHandler<PH> parameterHandler)
          Shorthand to invoke an UPDATE query.
<T> T
withDataSourceConnection(ConnectionOp<T> operation)
          Invokes an operation which uses JDBC connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcUtil

public JdbcUtil()
Creates a new JdbcUtil object.


JdbcUtil

public JdbcUtil(DataSource dataSource)
Constructor.

Parameters:
dataSource - data source used in the operations
Method Detail

withDataSourceConnection

public <T> T withDataSourceConnection(ConnectionOp<T> operation)
Invokes an operation which uses JDBC connection. The method gets a connection from the data source and then it invokes the specified operation. The method closes the connection in the right way regardless of whether an exception was thrown.

Parameters:
operation - operation to invoke
Returns:
result of the operation

query

public <PH,RH> List<RH> query(String query,
                              PH parameters,
                              ParameterHandler<PH> parameterHandler,
                              RowHandler<RH> rowHandler)
Shorthand to invoke a SELECT query.

Parameters:
query - select query
parameters - SQL parameters
parameterHandler - object which converts between Java™ objects and database PreparedStatement parameters.
rowHandler - object which converts ResultSet object into a Java object
Returns:
list of objects create from the SQL result

update

public <PH> Integer update(String query,
                           PH parameters,
                           ParameterHandler<PH> parameterHandler)
Shorthand to invoke an UPDATE query.

Parameters:
query - SQL statement
parameters - SQL parameters
parameterHandler - object which converts between Java™ objects and database PreparedStatement parameters.
Returns:
number of modified rows

batchUpdate

public <PH> List<Integer> batchUpdate(String query,
                                      Collection<PH> parameters,
                                      ParameterHandler<PH> parameterHandler)
Shorthand to invoke a batch update.

Parameters:
query - SQL statement
parameters - SQL parameters
parameterHandler - object which converts between Java™ objects and database PreparedStatement parameters.
Returns:
list containing number of rows modified by consecutive statements

call

public <T,IP,OP> T call(String query,
                        IP inputParameters,
                        OP outputParameters,
                        CallableStatementParameterHandler<IP,OP> callableStatementParameterHandler,
                        CallableStatementHandler<T> callableStatementHandler)
Shorthand to invoke a stored procedure.

Parameters:
ds - data source
query - wywołanie procedury składowanej.
inputParameters - input parameters
outputParameters - output parameters
callableStatementParameterHandler - object which binds input ('IN') and output ('OUT') parameters to the specified CallableStatement.
callableStatementHandler - object which returns out parameters to Java object
Returns:
result of the callable statement


Copyright © 2011-2013 e-point SA. All Rights Reserved.