Class DBSupport

java.lang.Object
com.sun.ts.tests.common.ejb.dba.DBSupport
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CompoundDBSupport, FloatDBSupport, IntegerDBSupport, LongDBSupport, StringDBSupport

public class DBSupport extends Object implements Serializable
Provide basic DB support for TS deployment tests, using The Datasource referenced as 'jdbc/DB1' in the component environment. This class is not intended to be used "as is", but rather to be sub-classed by other DB support classes focusing on a particular DB schema (and in particular on a type of primary key).
See Also:
  • Field Details

    • prefix

      protected static final String prefix
      Prefix used for JNDI lookups
      See Also:
    • DBLookupName

      protected static final String DBLookupName
      JNDI name used to lookup the DataSource
      See Also:
    • tablePrefix

      protected String tablePrefix
      DB table prefix. Used to get the appropriate SQL properties
    • ds

      protected DataSource ds
    • dbConnection

      protected transient Connection dbConnection
    • nctx

      protected TSNamingContext nctx
    • cofID

      protected int cofID
    • cofName

      protected String cofName
    • cofPrice

      protected float cofPrice
  • Constructor Details

    • DBSupport

      public DBSupport(String tablePrefix) throws Exception
      Create a new DBSupport object. If called from an EJB or a Web component, you must make sure to call TestUtil.init() before creating a new DBSupport object (so that you can safely use TestUtil.getProperty).
      Parameters:
      tablePrefix - Prefix to use for SQL properties lookups.
      Throws:
      Exception
  • Method Details

    • initTable

      public static void initTable(String tablePrefix, Properties props) throws Exception
      Initialize DB table (remove all existing rows). Method is static so that it can be easily called from the Application Client setup method.
      Throws:
      Exception
    • getDBConnection

      public void getDBConnection() throws SQLException
      Make sure we have a valid DB connection handy
      Throws:
      SQLException
    • closeDBConnection

      public void closeDBConnection() throws SQLException
      Close current DB connection, if applicable
      Throws:
      SQLException
    • getStmt

      public PreparedStatement getStmt(String suffix) throws SQLException
      Generic method to get a SQL statement for current table. We get the SQL code associated with the DEPLOY__ TS property.
      Throws:
      SQLException
    • closeStmt

      public void closeStmt(PreparedStatement pStmt, ResultSet result)
      Close the ResultSet and the PreparedStatement in a safely manner and ignoring any SQLException that could be thrown. This method is designed to be called from a finally block to ensure the release of associated resources.