atg.test.util
Class DBUtils

java.lang.Object
  extended by atg.test.util.DBUtils

public class DBUtils
extends java.lang.Object

Utility code for getting a connection to a database. The most common method is getHSQLDBInMemoryDBConnection. This returns a connection to an in-memory HSQL database.

Author:
adamb

Field Summary
 java.sql.Connection conn
           
 java.lang.String mDatabaseType
           
 
Constructor Summary
DBUtils(java.util.Properties pProps)
          Creates a new DBUtils given a Properties object containing connection info Expected keys: URL
driver
user
password

DBUtils(java.lang.String pURL, java.lang.String pJDBCDriver, java.lang.String pUser, java.lang.String pPassword)
           
 
Method Summary
 java.io.File createFakeXADataSource(java.io.File pRoot)
           
 java.io.File createFakeXADataSource(java.io.File pRoot, java.lang.String pName)
           
static java.io.File createJTDataSource(java.io.File pRoot)
           
static java.io.File createJTDataSource(java.io.File pRoot, java.lang.String pName, java.lang.String pFakeXAName)
          Creates a new JTDataSource component.
 void dump(java.sql.ResultSet rs)
           
 void executeCreateIdGenerator()
           
 void executeSQLFile(java.io.File pFile)
           
static java.util.Properties getDB2DBConnection(java.lang.String pHostName, java.lang.String pPort, java.lang.String pDBName, java.lang.String pUser, java.lang.String pPassword)
           
static java.util.Properties getHSQLDBFileDBConnection(java.lang.String pPath)
          Returns a Properties object preconfigured to create an HSQLDB in memory database connecting with user "sa" password ""
static java.util.Properties getHSQLDBInMemoryDBConnection()
          Returns a Properties object preconfigured to create an HSQLDB in memory database connecting with user "sa" password ""
static java.util.Properties getHSQLDBInMemoryDBConnection(java.lang.String pTestDBName)
          Returns a Properties object preconfigured to create an HSQLDB in memory database connecting with user "sa" password ""
static java.util.Properties getHSQLDBRegularDBConnection(java.lang.String pTestDBName, java.lang.String pHostName, java.lang.Object pUser, java.lang.Object pPassword)
          Returns a Properties object preconfigured to create an HSQLDB in memory database connecting with user "sa" password ""
static java.util.Properties getMSSQLDBConnection(java.lang.String pHostName, java.lang.String pPort, java.lang.String pDBName, java.lang.String pUser, java.lang.String pPassword)
          Returns connection properties for MSSQL
static java.util.Properties getMySQLDBConnection(java.lang.String pHostName, java.lang.String pPort, java.lang.String pDBName, java.lang.String pUser, java.lang.String pPassword)
          Returns connection properties for mysql
static java.util.Properties getOracleDBConnection(java.lang.String pHostName, java.lang.String pPort, java.lang.String pDBName, java.lang.String pUser, java.lang.String pPassword)
          Returns connection properties for MSSQL
 int getRowCount(java.lang.String pTable)
           
static java.util.Properties getSolidDBConnection(java.lang.String pHostName, java.lang.String pPort, java.lang.String pUser, java.lang.String pPassword)
          Returns connection properties for MSSQL
static java.util.Properties getSybaseDBConnection(java.lang.String pHostName, java.lang.String pPort, java.lang.String pDBName, java.lang.String pUser, java.lang.String pPassword)
          Returns connection properties for MSSQL
 boolean isDB2()
           
static boolean isDB2(java.util.Properties pProps)
           
 boolean isMSSQLServer()
           
static boolean isMSSQLServer(java.util.Properties pProps)
           
 boolean isOracle()
           
static boolean isOracle(java.util.Properties pProps)
           
 boolean isSybase()
           
static boolean isSybase(java.util.Properties pProps)
           
 void query(java.lang.String expression)
           
 void shutdown()
           
 void update(java.lang.String expression)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conn

public java.sql.Connection conn

mDatabaseType

public java.lang.String mDatabaseType
Constructor Detail

DBUtils

public DBUtils(java.util.Properties pProps)
        throws java.lang.Exception
Creates a new DBUtils given a Properties object containing connection info Expected keys: URL
driver
user
password

Parameters:
pProps -
Throws:
java.lang.Exception

DBUtils

public DBUtils(java.lang.String pURL,
               java.lang.String pJDBCDriver,
               java.lang.String pUser,
               java.lang.String pPassword)
        throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

getHSQLDBInMemoryDBConnection

public static java.util.Properties getHSQLDBInMemoryDBConnection(java.lang.String pTestDBName)
Returns a Properties object preconfigured to create an HSQLDB in memory database connecting with user "sa" password ""

Parameters:
pTestDBName -

getHSQLDBRegularDBConnection

public static java.util.Properties getHSQLDBRegularDBConnection(java.lang.String pTestDBName,
                                                                java.lang.String pHostName,
                                                                java.lang.Object pUser,
                                                                java.lang.Object pPassword)
Returns a Properties object preconfigured to create an HSQLDB in memory database connecting with user "sa" password ""

Parameters:
pTestDBName -

getHSQLDBFileDBConnection

public static java.util.Properties getHSQLDBFileDBConnection(java.lang.String pPath)
Returns a Properties object preconfigured to create an HSQLDB in memory database connecting with user "sa" password ""

Parameters:
pTestDBName -

getMSSQLDBConnection

public static java.util.Properties getMSSQLDBConnection(java.lang.String pHostName,
                                                        java.lang.String pPort,
                                                        java.lang.String pDBName,
                                                        java.lang.String pUser,
                                                        java.lang.String pPassword)
Returns connection properties for MSSQL

Parameters:
pHostName - host name of db server
pPort - port number of db
pDBName - database name
pUser - database username
pPassword - database user's password
Returns:

getMySQLDBConnection

public static java.util.Properties getMySQLDBConnection(java.lang.String pHostName,
                                                        java.lang.String pPort,
                                                        java.lang.String pDBName,
                                                        java.lang.String pUser,
                                                        java.lang.String pPassword)
Returns connection properties for mysql

Parameters:
pHostName - host name of db server
pPort - port number of db
pDBName - database name
pUser - database username
pPassword - database user's password
Returns:

getDB2DBConnection

public static java.util.Properties getDB2DBConnection(java.lang.String pHostName,
                                                      java.lang.String pPort,
                                                      java.lang.String pDBName,
                                                      java.lang.String pUser,
                                                      java.lang.String pPassword)
Parameters:
pString -
pString2 -
pString3 -
pString4 -
pString5 -
Returns:

getOracleDBConnection

public static java.util.Properties getOracleDBConnection(java.lang.String pHostName,
                                                         java.lang.String pPort,
                                                         java.lang.String pDBName,
                                                         java.lang.String pUser,
                                                         java.lang.String pPassword)
Returns connection properties for MSSQL

Parameters:
pHostName - host name of db server
pPort - port number of db
pDBName - database name
pUser - database username
pPassword - database user's password
Returns:

getSolidDBConnection

public static java.util.Properties getSolidDBConnection(java.lang.String pHostName,
                                                        java.lang.String pPort,
                                                        java.lang.String pUser,
                                                        java.lang.String pPassword)
Returns connection properties for MSSQL

Parameters:
pHostName - host name of db server
pPort - port number of db
pDBName - database name
pUser - database username
pPassword - database user's password
Returns:

getSybaseDBConnection

public static java.util.Properties getSybaseDBConnection(java.lang.String pHostName,
                                                         java.lang.String pPort,
                                                         java.lang.String pDBName,
                                                         java.lang.String pUser,
                                                         java.lang.String pPassword)
Returns connection properties for MSSQL

Parameters:
pHostName - host name of db server
pPort - port number of db
pDBName - database name
pUser - database username
pPassword - database user's password
Returns:

getHSQLDBInMemoryDBConnection

public static java.util.Properties getHSQLDBInMemoryDBConnection()
Returns a Properties object preconfigured to create an HSQLDB in memory database connecting with user "sa" password ""

Parameters:
pTestDBName -

shutdown

public void shutdown()
              throws java.sql.SQLException
Throws:
java.sql.SQLException

getRowCount

public int getRowCount(java.lang.String pTable)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

query

public void query(java.lang.String expression)
           throws java.sql.SQLException
Throws:
java.sql.SQLException

update

public void update(java.lang.String expression)
            throws java.sql.SQLException
Throws:
java.sql.SQLException

dump

public void dump(java.sql.ResultSet rs)
          throws java.sql.SQLException
Throws:
java.sql.SQLException

executeCreateIdGenerator

public void executeCreateIdGenerator()
                              throws java.sql.SQLException
Parameters:
db -
Throws:
java.sql.SQLException

executeSQLFile

public void executeSQLFile(java.io.File pFile)

createFakeXADataSource

public java.io.File createFakeXADataSource(java.io.File pRoot)
                                    throws java.io.IOException
Throws:
java.io.IOException

createFakeXADataSource

public java.io.File createFakeXADataSource(java.io.File pRoot,
                                           java.lang.String pName)
                                    throws java.io.IOException
Throws:
java.io.IOException

createJTDataSource

public static java.io.File createJTDataSource(java.io.File pRoot)
                                       throws java.io.IOException
Parameters:
pRoot -
Throws:
java.io.IOException

createJTDataSource

public static java.io.File createJTDataSource(java.io.File pRoot,
                                              java.lang.String pName,
                                              java.lang.String pFakeXAName)
                                       throws java.io.IOException
Creates a new JTDataSource component. The name of the component may be specified by passing in a non null value for pName. Also the name of the FakeXADataSource may be specified by passing in a non null name. Otherwise the defaults are JTDataSource and FakeXADataSource.

Parameters:
pRoot -
pName -
pFakeXAName -
Returns:
Throws:
java.io.IOException

isOracle

public static boolean isOracle(java.util.Properties pProps)
Parameters:
pProps -
Returns:

isSybase

public static boolean isSybase(java.util.Properties pProps)
Parameters:
pProps -
Returns:

isMSSQLServer

public static boolean isMSSQLServer(java.util.Properties pProps)
Parameters:
pProps -
Returns:

isDB2

public static boolean isDB2(java.util.Properties pProps)
Parameters:
pProps -
Returns:

isOracle

public boolean isOracle()
Parameters:
pProps -
Returns:

isSybase

public boolean isSybase()
Parameters:
pProps -
Returns:

isMSSQLServer

public boolean isMSSQLServer()
Parameters:
pProps -
Returns:

isDB2

public boolean isDB2()
Parameters:
pProps -
Returns:


Copyright © 2009. All Rights Reserved.