atg.adapter.gsa
Class SQLProcessor

java.lang.Object
  extended by atg.adapter.gsa.SQLProcessor

public class SQLProcessor
extends java.lang.Object

A generic class to execute SQL actions against a database. Parts copied from atg.service.idgen.?? by mgk

Version:
1.0
Author:
mf

Constructor Summary
SQLProcessor(javax.transaction.TransactionManager pTxManager, javax.sql.DataSource pDataSource)
          Construct with specified DataSource
SQLProcessor(javax.transaction.TransactionManager pTxManager, java.lang.String pUsername, java.lang.String pPassword, java.lang.String pDriver, java.lang.String pURL)
          Constructor with specified user/password/driver/URL.
 
Method Summary
static javax.sql.DataSource createBasicDataSource(java.lang.String pUsername, java.lang.String pPassword, java.lang.String pDriver, java.lang.String pURL)
          creates and returns a DataSource based on the user/pwd/driver/url info supplied.
 void dropTables(java.util.Collection<java.lang.String> pNames, boolean pCascadeConstraints, boolean pPreview)
          Method that iteratively attempts to drop tables.
 java.util.List<?> executeQuery(java.lang.String pQuery, java.lang.String pColumnName)
          executes the specified query and returns a List of values for the specified column name.
 void executeSQL(java.lang.String pSQL)
          Perform the specified SQL statement in a new transaction which is commited.
 java.lang.String getCreateTableBeginDelimiter()
           
 java.lang.String getCreateTableEndDelimiter()
           
 javax.sql.DataSource getDataSource()
          returns the DataSource from which db connections are obtained
 java.lang.String getDetermineTableExistsSQL()
          returns String executed to determine whether a table exists.
 java.lang.String getDropTableSQL()
          returns String executed to drop a table.
 atg.nucleus.GenericService getLoggingManager()
           
 javax.transaction.TransactionManager getTransactionManager()
          returns the TransactionManager that should be used to monitor transaction
 boolean isSetAutoCommit()
          returns true if autoCommit should be set to true on all connections used to execute SQL.
 void setAutoCommit(boolean pCommit)
          if set to true, then autoCommit will be set to true on all connections used to execute SQL.
 void setCreateTableBeginDelimiter(java.lang.String pStr)
           
 void setCreateTableEndDelimiter(java.lang.String pStr)
           
 void setDataSource(javax.sql.DataSource pDataSource)
          sets the DataSource from which to get DB connections
 void setDetermineTableExistsSQL(java.lang.String pStr)
          sets String executed to determine whether a table exists.
 void setDropTableSQL(java.lang.String pStr)
          sets String executed to drop a table.
 void setLoggingManager(atg.nucleus.GenericService pLogger)
           
 void setTransactionManager(javax.transaction.TransactionManager pManager)
          sets the TransactionManager that should be used to monitor transactions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLProcessor

public SQLProcessor(javax.transaction.TransactionManager pTxManager,
                    javax.sql.DataSource pDataSource)
Construct with specified DataSource

Parameters:
TransactionManager - manager - the TransactionManager to use to monitor transactions
DataSource - dataSource - the DataSource to use for db connections

SQLProcessor

public SQLProcessor(javax.transaction.TransactionManager pTxManager,
                    java.lang.String pUsername,
                    java.lang.String pPassword,
                    java.lang.String pDriver,
                    java.lang.String pURL)
             throws java.sql.SQLException
Constructor with specified user/password/driver/URL. specified parameters are used to create a DataSource connection to the database.

Parameters:
TransactionManager - manager - the TransactionManager to use to monitor transactions
String - username - name of user to connect to db
String - password - pwd to connectc to db
String - driver - driver specification to connect to db
String - url - url to connect to db
Throws:
java.sql.SQLException - if an error occurs creating the DataSource
Method Detail

setDataSource

public void setDataSource(javax.sql.DataSource pDataSource)
sets the DataSource from which to get DB connections


getDataSource

public javax.sql.DataSource getDataSource()
returns the DataSource from which db connections are obtained


setTransactionManager

public void setTransactionManager(javax.transaction.TransactionManager pManager)
sets the TransactionManager that should be used to monitor transactions


getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()
returns the TransactionManager that should be used to monitor transaction


setDetermineTableExistsSQL

public void setDetermineTableExistsSQL(java.lang.String pStr)
sets String executed to determine whether a table exists. The table name is appended to the end of the string before execution occurs.


getDetermineTableExistsSQL

public java.lang.String getDetermineTableExistsSQL()
returns String executed to determine whether a table exists. The table name is appended to the end of the string before execution occurs.


setDropTableSQL

public void setDropTableSQL(java.lang.String pStr)
sets String executed to drop a table. The table name is appended to the end of the string before execution


getDropTableSQL

public java.lang.String getDropTableSQL()
returns String executed to drop a table. The table name is appended to the end of the string before execution


setCreateTableBeginDelimiter

public void setCreateTableBeginDelimiter(java.lang.String pStr)

getCreateTableBeginDelimiter

public java.lang.String getCreateTableBeginDelimiter()

setCreateTableEndDelimiter

public void setCreateTableEndDelimiter(java.lang.String pStr)

getCreateTableEndDelimiter

public java.lang.String getCreateTableEndDelimiter()

setLoggingManager

public void setLoggingManager(atg.nucleus.GenericService pLogger)

getLoggingManager

public atg.nucleus.GenericService getLoggingManager()

setAutoCommit

public void setAutoCommit(boolean pCommit)
if set to true, then autoCommit will be set to true on all connections used to execute SQL. otherwise, autoCommit will not be altered from what is set by the DataSource.


isSetAutoCommit

public boolean isSetAutoCommit()
returns true if autoCommit should be set to true on all connections used to execute SQL.


createBasicDataSource

public static javax.sql.DataSource createBasicDataSource(java.lang.String pUsername,
                                                         java.lang.String pPassword,
                                                         java.lang.String pDriver,
                                                         java.lang.String pURL)
creates and returns a DataSource based on the user/pwd/driver/url info supplied.


executeSQL

public void executeSQL(java.lang.String pSQL)
                throws java.sql.SQLException,
                       atg.dtm.TransactionDemarcationException
Perform the specified SQL statement in a new transaction which is commited. Autocommit on the connection is set to true if isSetAutoCommit() is true.

Parameters:
pSQL - SQL to execute
Throws:
java.sql.SQLException - if there is DB problem
atg.dtm.TransactionDemarcationException - if there is a tx problem

executeQuery

public java.util.List<?> executeQuery(java.lang.String pQuery,
                                      java.lang.String pColumnName)
                               throws java.sql.SQLException,
                                      atg.dtm.TransactionDemarcationException
executes the specified query and returns a List of values for the specified column name. for example, executeQuery( "select * from user", "first_name" ) would return a List of the first names of all entries in the user table.

Returns:
List of Object values
Throws:
java.sql.SQLException - if a sql error occurs
atg.dtm.TransactionDemarcationException - if a tx error occurs

dropTables

public void dropTables(java.util.Collection<java.lang.String> pNames,
                       boolean pCascadeConstraints,
                       boolean pPreview)
                throws java.sql.SQLException,
                       atg.dtm.TransactionDemarcationException
Method that iteratively attempts to drop tables. An iterative effort is utilized in case references exist between tables. ASSUMPTION: references only exist between tables specified in the List. If references exist from tables outside the List, then some tables may not be able to be dropped and this method will throw a SQLException

Parameters:
Collection - of names of tables to be dropped
boolean - cascadeConstraints. true if 'CASCADE CONSTRAINTS' should be used in drop statement.
boolean - preview. if true then iterative behavior is disabled and method simply prints one drop statement that would be executed for each table. iterative behavior has to be disabled since it doesn't make sense if drops are not being executed.
Throws:
java.sql.SQLException - thrown if all tables can not be dropped
atg.dtm.TransactionDemarcationException


Copyright © 2009. All Rights Reserved.