站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 3.2.7 server API Documentation 英文版文档

JDBCCommand (JBoss Server API) - JBoss 3.2.7 server API Documentation 英文版文档


org.jboss.ejb.plugins.jaws.jdbc
Class JDBCCommand

java.lang.Object
  extended byorg.jboss.ejb.plugins.jaws.jdbc.JDBCCommand
Direct Known Subclasses:
JDBCQueryCommand, JDBCUpdateCommand

public abstract class JDBCCommand
extends Object

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.

Version:
$Revision: 1.43.2.3 $

Revisions:

20010621 danch:

  • add getter for name

20010621 (ref 1.25) danch:

  • improve logging: an exception execing SQL is an error!

20010812 vincent.harcq@hubmethods.com:

  • Get Rid of debug flag, use log4j instead
Author:
Justin Forder, Dirk Zimmermann, danch (Dan Christopherson

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 ResultSets.
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

factory

protected JDBCCommandFactory factory

jawsEntity

protected JawsEntityMetaData jawsEntity

name

protected String name
Constructor Detail

JDBCCommand

protected JDBCCommand(JDBCCommandFactory factory,
                      String name)
Construct a JDBCCommand with given factory and name.

Parameters:
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

getName

public String getName()
return the name of this command


jdbcExecute

protected Object jdbcExecute(Object argOrArgs)
                      throws Exception
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.

Parameters:
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.
Returns:
any result produced by the handling of the result of executing the prepared statement.
Throws:
Exception - if connection fails, or if any 'hook' method throws an exception.

setSQL

protected void setSQL(String sql)
Used to set static SQL in subclass constructors.

Parameters:
sql - the static SQL to be used by this Command.

getSQL

protected String getSQL(Object argOrArgs)
                 throws Exception
Gets the SQL to be used in the PreparedStatement. The default implementation returns the 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.

Parameters:
argOrArgs - argument or array of arguments passed in from subclass execute method.
Returns:
the SQL to use in the PreparedStatement.
Throws:
Exception - if an attempt to generate dynamic SQL results in an Exception.

setParameters

protected void setParameters(PreparedStatement stmt,
                             Object argOrArgs)
                      throws Exception
Default implementation does nothing. Override if parameters need to be set.

Parameters:
stmt - the PreparedStatement which will be executed by this Command.
argOrArgs - argument or array of arguments passed in from subclass execute method.
Throws:
Exception - if parameter setting fails.

executeStatementAndHandleResult

protected abstract Object executeStatementAndHandleResult(PreparedStatement stmt,
                                                          Object argOrArgs)
                                                   throws Exception
Executes the PreparedStatement and handles result of successful execution. This is implemented in subclasses for queries and updates.

Parameters:
stmt - the PreparedStatement to execute.
argOrArgs - argument or array of arguments passed in from subclass execute method.
Returns:
any result produced by the handling of the result of executing the prepared statement.
Throws:
Exception - if execution or result handling fails.

setParameter

protected void setParameter(PreparedStatement stmt,
                            int idx,
                            int jdbcType,
                            Object value)
                     throws SQLException
Sets a parameter in this Command's PreparedStatement. Handles null values, and provides tracing.

Parameters:
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.
Throws:
SQLException - if parameter setting fails.

setPrimaryKeyParameters

protected int setPrimaryKeyParameters(PreparedStatement stmt,
                                      int parameterIndex,
                                      Object id)
                               throws IllegalAccessException,
                                      SQLException
Sets the PreparedStatement parameters for a primary key in a WHERE clause.

Parameters:
stmt - the PreparedStatement
parameterIndex - the index (1-based) of the first parameter to set in the PreparedStatement
id - the entity's ID
Returns:
the index of the next unset parameter
Throws:
SQLException - if parameter setting fails
IllegalAccessException - if accessing a field in the PK class fails

getResultObject

protected Object getResultObject(ResultSet rs,
                                 int idx,
                                 Class destination)
                          throws SQLException
Used for all retrieval of results from ResultSets. Implements tracing, and allows some tweaking of returned types.

Parameters:
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
Throws:
SQLException

getResultObject

protected Object getResultObject(ResultSet rs,
                                 int idx,
                                 CMPFieldMetaData cmpField)
                          throws SQLException
Wrapper around getResultObject(ResultSet rs, int idx, Class destination).

Throws:
SQLException

getJDBCType

protected final int getJDBCType(String name)
Gets the integer JDBC type code corresponding to the given name.

Parameters:
name - the JDBC type name.
Returns:
the JDBC type code.
See Also:
Types

getJDBCTypeName

protected final String getJDBCTypeName(int jdbcType)
Gets the JDBC type name corresponding to the given type code.

Parameters:
jdbcType - the integer JDBC type code.
Returns:
the JDBC type name.
See Also:
Types

isBinaryType

protected final boolean isBinaryType(int jdbcType)
Returns true if the JDBC type should be (de-)serialized as a binary stream and false otherwise.

Parameters:
jdbcType - the JDBC type
Returns:
true if binary type, false otherwise

getPkColumnList

protected final String getPkColumnList()
Returns the comma-delimited list of primary key column names for this entity.

Returns:
comma-delimited list of primary key column names.

getPkColumnWhereList

protected final String getPkColumnWhereList()
Returns the string to go in a WHERE clause based on the entity's primary key.

Returns:
WHERE clause content, in the form pkCol1Name=? AND pkCol2Name=?

getState

protected Object[] getState(EntityEnterpriseContext ctx)

getCMPFieldValue

protected Object getCMPFieldValue(Object instance,
                                  CMPFieldMetaData fieldMetaData)
                           throws IllegalAccessException
Throws:
IllegalAccessException

setCMPFieldValue

protected void setCMPFieldValue(Object instance,
                                CMPFieldMetaData fieldMetaData,
                                Object value)
                         throws IllegalAccessException
Throws:
IllegalAccessException

getPkFieldValue

protected Object getPkFieldValue(Object pk,
                                 PkFieldMetaData pkFieldMetaData)
                          throws IllegalAccessException
Throws:
IllegalAccessException

getJawsCMPFieldJDBCType

protected int getJawsCMPFieldJDBCType(CMPFieldMetaData fieldMetaData)

getConnection

protected Connection getConnection()
                            throws SQLException
Get a database connection

Throws:
SQLException


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.