com.syrtsov.ddao.factory
Class DefaultStatementFactory
java.lang.Object
com.syrtsov.ddao.factory.DefaultStatementFactory
- All Implemented Interfaces:
- StatementFactory
public class DefaultStatementFactory
- extends java.lang.Object
- implements StatementFactory
DefaultStatementFactory creates new prepared statment using simplified IBATIS like query syntax:
value reference can be put using number that reflect 0 based method argument number
that will be used as simle value
(and as such can not be java bean or any other non trivial object)
or it can be name of java bean property or Map object that is 1st argument in the
list of method arguments.
Query paramter can be added as inline value by enclosing it in '$' or
it can be added as bound value by enclosing it in '#'. Inline value will be injected in
query text before query will be passed to JDBC connection. Bound value will be bound to
prepared statement before it's execution.
Created by Pavel Syrtsov
Date: Nov 3, 2007
Time: 9:24:44 PM
Method Summary |
void |
addInlineParameter(java.lang.reflect.Method method,
java.lang.String name)
|
void |
addRefParameter(java.lang.reflect.Method method,
java.lang.String name)
|
java.sql.PreparedStatement |
createStatement(java.sql.Connection connection,
java.lang.Object[] args)
Creates new PreparedStatement according to definition given in setup. |
void |
init(java.lang.String sql,
java.lang.reflect.Method method)
Initializes factory object with query data |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DefaultStatementFactory
public DefaultStatementFactory()
init
public void init(java.lang.String sql,
java.lang.reflect.Method method)
throws StatementFactoryException
- Description copied from interface:
StatementFactory
- Initializes factory object with query data
- Specified by:
init
in interface StatementFactory
- Parameters:
sql
- - query textmethod
- - method that quey will be attached to
- Throws:
StatementFactoryException
- - throws excpetion if fails to parse query
addRefParameter
public void addRefParameter(java.lang.reflect.Method method,
java.lang.String name)
throws StatementParameterException
- Throws:
StatementParameterException
addInlineParameter
public void addInlineParameter(java.lang.reflect.Method method,
java.lang.String name)
throws StatementParameterException
- Throws:
StatementParameterException
createStatement
public java.sql.PreparedStatement createStatement(java.sql.Connection connection,
java.lang.Object[] args)
throws StatementFactoryException
- Description copied from interface:
StatementFactory
- Creates new PreparedStatement according to definition given in setup.
This method implementation has to be thread safe.
- Specified by:
createStatement
in interface StatementFactory
- Parameters:
connection
- - JDBC connection to be used to create new statementargs
- - parameters values to bind to prepared statement
- Returns:
- PreparedStatement instance ready to be executed
- Throws:
StatementFactoryException
- if it fails to create
and initialize prepared statement