|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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.
Revisions:
20010621 danch:
20010621 (ref 1.25) danch:
20010812 vincent.harcq@hubmethods.com:
Field Summary | |
protected JDBCCommandFactory |
factory
|
protected JawsEntityMetaData |
jawsEntity
|
protected String |
name
|
Constructor Summary | |
protected |
JDBCCommand(JDBCCommandFactory factory,
String name)
Construct a JDBCCommand with given factory and name. |
Method Summary | |
protected abstract Object |
executeStatementAndHandleResult(PreparedStatement stmt,
Object argOrArgs)
Executes the PreparedStatement and handles result of successful execution. |
protected Object |
getCMPFieldValue(Object instance,
CMPFieldMetaData fieldMetaData)
|
protected Connection |
getConnection()
Get a database connection |
protected int |
getJawsCMPFieldJDBCType(CMPFieldMetaData fieldMetaData)
|
protected int |
getJDBCType(String name)
Gets the integer JDBC type code corresponding to the given name. |
protected String |
getJDBCTypeName(int jdbcType)
Gets the JDBC type name corresponding to the given type code. |
String |
getName()
return the name of this command |
protected String |
getPkColumnList()
Returns the comma-delimited list of primary key column names for this entity. |
protected String |
getPkColumnWhereList()
Returns the string to go in a WHERE clause based on the entity's primary key. |
protected Object |
getPkFieldValue(Object pk,
PkFieldMetaData pkFieldMetaData)
|
protected Object |
getResultObject(ResultSet rs,
int idx,
Class destination)
Used for all retrieval of results from ResultSet s. |
protected Object |
getResultObject(ResultSet rs,
int idx,
CMPFieldMetaData cmpField)
Wrapper around getResultObject(ResultSet rs, int idx, Class destination). |
protected String |
getSQL(Object argOrArgs)
Gets the SQL to be used in the PreparedStatement. |
protected 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 Object |
jdbcExecute(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(Object instance,
CMPFieldMetaData fieldMetaData,
Object value)
|
protected void |
setParameter(PreparedStatement stmt,
int idx,
int jdbcType,
Object value)
Sets a parameter in this Command's PreparedStatement. |
protected void |
setParameters(PreparedStatement stmt,
Object argOrArgs)
Default implementation does nothing. |
protected int |
setPrimaryKeyParameters(PreparedStatement stmt,
int parameterIndex,
Object id)
Sets the PreparedStatement parameters for a primary key in a WHERE clause. |
protected void |
setSQL(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 String name
Constructor Detail |
protected JDBCCommand(JDBCCommandFactory factory, 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 |
public String getName()
protected Object jdbcExecute(Object argOrArgs) throws 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.
Exception
- if connection fails, or if any 'hook' method
throws an exception.protected void setSQL(String sql)
sql
- the static SQL to be used by this Command.protected String getSQL(Object argOrArgs) throws 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.
Exception
- if an attempt to generate dynamic SQL results in
an Exception.protected void setParameters(PreparedStatement stmt, Object argOrArgs) throws Exception
stmt
- the PreparedStatement which will be executed by this Command.argOrArgs
- argument or array of arguments passed in from
subclass execute method.
Exception
- if parameter setting fails.protected abstract Object executeStatementAndHandleResult(PreparedStatement stmt, Object argOrArgs) throws Exception
stmt
- the PreparedStatement to execute.argOrArgs
- argument or array of arguments passed in from
subclass execute method.
Exception
- if execution or result handling fails.protected void setParameter(PreparedStatement stmt, int idx, int jdbcType, Object value) throws 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.
SQLException
- if parameter setting fails.protected int setPrimaryKeyParameters(PreparedStatement stmt, int parameterIndex, Object id) throws IllegalAccessException, SQLException
stmt
- the PreparedStatementparameterIndex
- the index (1-based) of the first parameter to set
in the PreparedStatementid
- the entity's ID
SQLException
- if parameter setting fails
IllegalAccessException
- if accessing a field in the PK class failsprotected Object getResultObject(ResultSet rs, int idx, Class destination) throws 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 into
SQLException
protected Object getResultObject(ResultSet rs, int idx, CMPFieldMetaData cmpField) throws SQLException
SQLException
protected final int getJDBCType(String name)
name
- the JDBC type name.
Types
protected final String getJDBCTypeName(int jdbcType)
jdbcType
- the integer JDBC type code.
Types
protected final boolean isBinaryType(int jdbcType)
jdbcType
- the JDBC type
protected final String getPkColumnList()
protected final String getPkColumnWhereList()
pkCol1Name=? AND pkCol2Name=?
protected Object[] getState(EntityEnterpriseContext ctx)
protected Object getCMPFieldValue(Object instance, CMPFieldMetaData fieldMetaData) throws IllegalAccessException
IllegalAccessException
protected void setCMPFieldValue(Object instance, CMPFieldMetaData fieldMetaData, Object value) throws IllegalAccessException
IllegalAccessException
protected Object getPkFieldValue(Object pk, PkFieldMetaData pkFieldMetaData) throws IllegalAccessException
IllegalAccessException
protected int getJawsCMPFieldJDBCType(CMPFieldMetaData fieldMetaData)
protected Connection getConnection() throws SQLException
SQLException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |