Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 9145 invoked from network); 21 Jul 2006 16:02:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Jul 2006 16:02:59 -0000 Received: (qmail 95403 invoked by uid 500); 21 Jul 2006 16:02:54 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 95362 invoked by uid 500); 21 Jul 2006 16:02:54 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 95263 invoked by uid 99); 21 Jul 2006 16:02:53 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Jul 2006 09:02:53 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Jul 2006 09:02:51 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id CE4071A981A; Fri, 21 Jul 2006 09:02:30 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r424368 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util: BaseJDBCTestCase.java TestConfiguration.java Date: Fri, 21 Jul 2006 16:02:28 -0000 To: derby-commits@db.apache.org From: djd@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060721160230.CE4071A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: djd Date: Fri Jul 21 09:02:27 2006 New Revision: 424368 URL: http://svn.apache.org/viewvc?rev=424368&view=rev Log: DERBY-1555 (partial) Move the code to obtain a default connection into TestConfiuration for the JUnit test setup to allow it to be shared across multiple classes. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java?rev=424368&r1=424367&r2=424368&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java Fri Jul 21 09:02:27 2006 @@ -33,23 +33,6 @@ extends BaseTestCase { /** - * Tell if we are allowed to use DriverManager to create database - * connections. - */ - private static final boolean HAVE_DRIVER; - - static { - // See if java.sql.Driver is available. If it is not, we must use - // DataSource to create connections. - boolean haveDriver = false; - try { - Class.forName("java.sql.Driver"); - haveDriver = true; - } catch (Exception e) {} - HAVE_DRIVER = haveDriver; - } - - /** * Create a test case with the given name. * * @param name of the test case. @@ -67,26 +50,10 @@ */ public static Connection getConnection() throws SQLException { - Connection con = null; - JDBCClient client = CONFIG.getJDBCClient(); - if (HAVE_DRIVER) { - loadJDBCDriver(client.getJDBCDriverName()); - if (!CONFIG.isSingleLegXA()) { - con = DriverManager.getConnection( - CONFIG.getJDBCUrl() + ";create=true", - CONFIG.getUserName(), - CONFIG.getUserPassword()); - } - else { - con = TestDataSourceFactory.getXADataSource().getXAConnection (CONFIG.getUserName(), - CONFIG.getUserPassword()).getConnection(); - } - } else { - //Use DataSource for JSR169 - con = TestDataSourceFactory.getDataSource().getConnection(); - } - return con; + return CONFIG.getDefaultConnection(); } + + /** * Tell if the client is embedded. @@ -244,28 +211,6 @@ */ public static void assertSQLState(String expected, SQLException exception) { assertSQLState("Unexpected SQL state.", expected, exception); - } - - /** - * Load the specified JDBC driver - * - * @param driverClass name of the JDBC driver class. - * @throws SQLException if loading the driver fails. - */ - private static void loadJDBCDriver(String driverClass) - throws SQLException { - try { - Class.forName(driverClass).newInstance(); - } catch (ClassNotFoundException cnfe) { - throw new SQLException("Failed to load JDBC driver '" + - driverClass + "': " + cnfe.getMessage()); - } catch (IllegalAccessException iae) { - throw new SQLException("Failed to load JDBC driver '" + - driverClass + "': " + iae.getMessage()); - } catch (InstantiationException ie) { - throw new SQLException("Failed to load JDBC driver '" + - driverClass + "': " + ie.getMessage()); - } } } // End class BaseJDBCTestCase Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java?rev=424368&r1=424367&r2=424368&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java Fri Jul 21 09:02:27 2006 @@ -20,6 +20,9 @@ package org.apache.derbyTesting.functionTests.util; import java.security.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; import java.util.Properties; import org.apache.derby.iapi.services.info.JVMInfo; @@ -32,10 +35,27 @@ /** * Default Derby test configuration object. */ - public static final TestConfiguration DERBY_TEST_CONFIG = + static final TestConfiguration DERBY_TEST_CONFIG = new TestConfiguration(getSystemProperties()); /** + * Tell if we are allowed to use DriverManager to create database + * connections. + */ + private static final boolean HAVE_DRIVER; + + static { + // See if java.sql.Driver is available. If it is not, we must use + // DataSource to create connections. + boolean haveDriver = false; + try { + Class.forName("java.sql.Driver"); + haveDriver = true; + } catch (Exception e) {} + HAVE_DRIVER = haveDriver; + } + + /** * This constructor creates a TestConfiguration from a Properties object. * * @throws NumberFormatException if the port specification is not an integer. @@ -188,6 +208,36 @@ } /** + * Get connection to the default database. + * If the database does not exist, it will be created. + * A default username and password will be used for the connection. + * + * @return connection to default database. + */ + public Connection getDefaultConnection() + throws SQLException { + Connection con = null; + JDBCClient client =getJDBCClient(); + if (HAVE_DRIVER) { + loadJDBCDriver(client.getJDBCDriverName()); + if (!isSingleLegXA()) { + con = DriverManager.getConnection( + getJDBCUrl() + ";create=true", + getUserName(), + getUserPassword()); + } + else { + con = TestDataSourceFactory.getXADataSource().getXAConnection (getUserName(), + getUserPassword()).getConnection(); + } + } else { + //Use DataSource for JSR169 + con = TestDataSourceFactory.getDataSource().getConnection(); + } + return con; + } + + /** * Set the verbosity, i.e., whether debug statements print. */ public void setVerbosity( boolean isChatty ) { isVerbose = isChatty; } @@ -348,6 +398,28 @@ attrs.setProperty("databaseName", DERBY_TEST_CONFIG.getDatabaseName()); attrs.setProperty("connectionAttributes", "create=true"); return attrs; + } + + /** + * Load the specified JDBC driver + * + * @param driverClass name of the JDBC driver class. + * @throws SQLException if loading the driver fails. + */ + private static void loadJDBCDriver(String driverClass) + throws SQLException { + try { + Class.forName(driverClass).newInstance(); + } catch (ClassNotFoundException cnfe) { + throw new SQLException("Failed to load JDBC driver '" + + driverClass + "': " + cnfe.getMessage()); + } catch (IllegalAccessException iae) { + throw new SQLException("Failed to load JDBC driver '" + + driverClass + "': " + iae.getMessage()); + } catch (InstantiationException ie) { + throw new SQLException("Failed to load JDBC driver '" + + driverClass + "': " + ie.getMessage()); + } } }