|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand
Abstract superclass for all JAWS Commands that use JDBC directly. Provides a Template Method for jdbcExecute(), default implementations for some of the methods called by this template, and a bunch of utility methods that database commands may need to call.
Field Summary | |
static boolean |
debug
Gives compile-time control of tracing. |
protected JDBCCommandFactory |
factory
|
protected JawsEntityMetaData |
jawsEntity
|
protected Logger |
log
|
protected java.lang.String |
name
|
Constructor Summary | |
protected |
JDBCCommand(JDBCCommandFactory factory,
java.lang.String name)
Construct a JDBCCommand with given factory and name. |
Method Summary | |
protected abstract java.lang.Object |
executeStatementAndHandleResult(java.sql.PreparedStatement stmt,
java.lang.Object argOrArgs)
Executes the PreparedStatement and handles result of successful execution. |
protected java.lang.Object |
getCMPFieldValue(java.lang.Object instance,
CMPFieldMetaData fieldMetaData)
|
protected java.sql.Connection |
getConnection()
Get a database connection |
protected int |
getJawsCMPFieldJDBCType(CMPFieldMetaData fieldMetaData)
|
protected int |
getJDBCType(java.lang.String name)
Gets the integer JDBC type code corresponding to the given name. |
protected java.lang.String |
getJDBCTypeName(int jdbcType)
Gets the JDBC type name corresponding to the given type code. |
protected java.lang.String |
getPkColumnList()
Returns the comma-delimited list of primary key column names for this entity. |
protected java.lang.String |
getPkColumnWhereList()
Returns the string to go in a WHERE clause based on the entity's primary key. |
protected java.lang.Object |
getPkFieldValue(java.lang.Object pk,
PkFieldMetaData pkFieldMetaData)
|
protected java.lang.Object |
getResultObject(java.sql.ResultSet rs,
int idx,
java.lang.Class destination)
Used for all retrieval of results from ResultSet s. |
protected java.lang.Object |
getResultObject(java.sql.ResultSet rs,
int idx,
CMPFieldMetaData cmpField)
Wrapper around getResultObject(ResultSet rs, int idx, Class destination). |
protected java.lang.String |
getSQL(java.lang.Object argOrArgs)
Gets the SQL to be used in the PreparedStatement. |
protected java.lang.Object[] |
getState(EntityEnterpriseContext ctx)
|
protected boolean |
isBinaryType(int jdbcType)
Returns true if the JDBC type should be (de-)serialized as a binary stream and false otherwise. |
protected java.lang.Object |
jdbcExecute(java.lang.Object argOrArgs)
Template method handling the mundane business of opening a database connection, preparing a statement, setting its parameters, executing the prepared statement, handling the result, and cleaning up. |
protected void |
setCMPFieldValue(java.lang.Object instance,
CMPFieldMetaData fieldMetaData,
java.lang.Object value)
|
protected void |
setParameter(java.sql.PreparedStatement stmt,
int idx,
int jdbcType,
java.lang.Object value)
Sets a parameter in this Command's PreparedStatement. |
protected void |
setParameters(java.sql.PreparedStatement stmt,
java.lang.Object argOrArgs)
Default implementation does nothing. |
protected int |
setPrimaryKeyParameters(java.sql.PreparedStatement stmt,
int parameterIndex,
java.lang.Object id)
Sets the PreparedStatement parameters for a primary key in a WHERE clause. |
protected void |
setSQL(java.lang.String sql)
Used to set static SQL in subclass constructors. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected JDBCCommandFactory factory
protected JawsEntityMetaData jawsEntity
protected Logger log
protected java.lang.String name
public static boolean debug
Constructor Detail |
protected JDBCCommand(JDBCCommandFactory factory, java.lang.String name)
factory
- the factory which was used to create this JDBCCommand,
which is also used as a common repository, shared by all an
entity's Commands.name
- the name to be used when tracing execution.Method Detail |
protected java.lang.Object jdbcExecute(java.lang.Object argOrArgs) throws java.lang.Exception
argOrArgs
- argument or array of arguments passed in from
subclass execute method, and passed on to 'hook' methods for
getting SQL and for setting parameters.java.lang.Exception
- if connection fails, or if any 'hook' method
throws an exception.protected void setSQL(java.lang.String sql)
sql
- the static SQL to be used by this Command.protected java.lang.String getSQL(java.lang.Object argOrArgs) throws java.lang.Exception
sql
field value.
This is appropriate in all cases where static SQL can be
constructed in the Command constructor.
Override if dynamically-generated SQL, based on the arguments
given to execute(), is needed.argOrArgs
- argument or array of arguments passed in from
subclass execute method.java.lang.Exception
- if an attempt to generate dynamic SQL results in
an Exception.protected void setParameters(java.sql.PreparedStatement stmt, java.lang.Object argOrArgs) throws java.lang.Exception
stmt
- the PreparedStatement which will be executed by this Command.argOrArgs
- argument or array of arguments passed in from
subclass execute method.java.lang.Exception
- if parameter setting fails.protected abstract java.lang.Object executeStatementAndHandleResult(java.sql.PreparedStatement stmt, java.lang.Object argOrArgs) throws java.lang.Exception
stmt
- the PreparedStatement to execute.argOrArgs
- argument or array of arguments passed in from
subclass execute method.java.lang.Exception
- if execution or result handling fails.protected void setParameter(java.sql.PreparedStatement stmt, int idx, int jdbcType, java.lang.Object value) throws java.sql.SQLException
stmt
- the PreparedStatement whose parameter needs to be set.idx
- the index (1-based) of the parameter to be set.jdbcType
- the JDBC type of the parameter.value
- the value which the parameter is to be set to.java.sql.SQLException
- if parameter setting fails.protected int setPrimaryKeyParameters(java.sql.PreparedStatement stmt, int parameterIndex, java.lang.Object id) throws java.lang.IllegalAccessException, java.sql.SQLException
stmt
- the PreparedStatementparameterIndex
- the index (1-based) of the first parameter to set
in the PreparedStatementid
- the entity's IDjava.sql.SQLException
- if parameter setting failsjava.lang.IllegalAccessException
- if accessing a field in the PK class failsprotected java.lang.Object getResultObject(java.sql.ResultSet rs, int idx, java.lang.Class destination) throws java.sql.SQLException
ResultSet
s.
Implements tracing, and allows some tweaking of returned types.rs
- the ResultSet
from which a result is being retrieved.idx
- index of the result column.destination
- The class of the variable this is going intoprotected java.lang.Object getResultObject(java.sql.ResultSet rs, int idx, CMPFieldMetaData cmpField) throws java.sql.SQLException
protected final int getJDBCType(java.lang.String name)
name
- the JDBC type name.Types
protected final java.lang.String getJDBCTypeName(int jdbcType)
jdbcType
- the integer JDBC type code.Types
protected final boolean isBinaryType(int jdbcType)
jdbcType
- the JDBC typeprotected final java.lang.String getPkColumnList()
protected final java.lang.String getPkColumnWhereList()
pkCol1Name=? AND pkCol2Name=?
protected java.lang.Object[] getState(EntityEnterpriseContext ctx)
protected java.lang.Object getCMPFieldValue(java.lang.Object instance, CMPFieldMetaData fieldMetaData) throws java.lang.IllegalAccessException
protected void setCMPFieldValue(java.lang.Object instance, CMPFieldMetaData fieldMetaData, java.lang.Object value) throws java.lang.IllegalAccessException
protected java.lang.Object getPkFieldValue(java.lang.Object pk, PkFieldMetaData pkFieldMetaData) throws java.lang.IllegalAccessException
protected int getJawsCMPFieldJDBCType(CMPFieldMetaData fieldMetaData)
protected java.sql.Connection getConnection() throws java.sql.SQLException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |