You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2006/07/14 00:22:27 UTC
svn commit: r421717 - in /db/derby/code/trunk: ./
java/engine/org/apache/derby/jdbc/ java/engine/org/apache/derby/loc/
java/shared/org/apache/derby/shared/common/reference/
java/testing/org/apache/derbyTesting/functionTests/suites/
java/testing/org/apa...
Author: rhillegas
Date: Thu Jul 13 15:22:25 2006
New Revision: 421717
URL: http://svn.apache.org/viewvc?rev=421717&view=rev
Log:
DERBY-1459: Commit bug1459_v04.diff. This introduces a dummy jdbc driver so that JDBC4 driver autoloading will play well with the engine booting which happens when the public embedded driver classloads.
Added:
db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java (with props)
Modified:
db/derby/code/trunk/build.xml
db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java
db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java
db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDriver.java
db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java
db/derby/code/trunk/java/engine/org/apache/derby/jdbc/build.xml
db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Thu Jul 13 15:22:25 2006
@@ -964,7 +964,7 @@
<!-- declare the embedded driver for autoloading by the JDBC 4 DriverManager -->
<antcall target="declare-autoloadable-driver">
- <param name="driver.name" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+ <param name="driver.name" value="org.apache.derby.jdbc.AutoloadedDriver"/>
</antcall>
<!-- the next two targets are orthogonal. Only one will be executed, -->
Added: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java?rev=421717&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java Thu Jul 13 15:22:25 2006
@@ -0,0 +1,221 @@
+/*
+
+ Derby - Class org.apache.derby.jdbc.AutoloadedDriver
+
+ Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+
+package org.apache.derby.jdbc;
+
+import java.sql.DriverManager;
+import java.sql.Driver;
+import java.sql.Connection;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+
+import java.io.PrintStream;
+import java.util.Properties;
+
+import org.apache.derby.iapi.reference.MessageId;
+import org.apache.derby.iapi.reference.Attribute;
+import org.apache.derby.iapi.services.i18n.MessageService;
+import org.apache.derby.iapi.jdbc.JDBCBoot;
+
+
+/**
+ This is the dummy driver which is autoloaded under JDBC4 and registered with
+ the DriverManager. Loading this class will NOT automatically boot the Derby engine.
+ Instead, the engine boots lazily when you ask for a
+ Connection. Alternatively, you can force the engine to boot as follows:
+
+ <PRE>
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+
+ // or
+
+ new org.apache.derby.jdbc.EmbeddedDriver();
+
+
+ </PRE>
+*/
+public class AutoloadedDriver implements Driver
+{
+ // This flag is set if the engine is forcibly brought down.
+ private static boolean _engineForcedDown = false;
+
+ //
+ // This is the driver that's specific to the JDBC level we're running at.
+ // It's the module which boots the whole Derby engine.
+ //
+ private static Driver _driverModule;
+
+ static
+ {
+ try {
+ DriverManager.registerDriver( new AutoloadedDriver() );
+ }
+ catch (SQLException se)
+ {
+ String message = MessageService.getTextMessage
+ (MessageId.JDBC_DRIVER_REGISTER_ERROR, se.getMessage() );
+
+ throw new IllegalStateException( message );
+ }
+ }
+
+ /*
+ ** Methods from java.sql.Driver.
+ */
+ /**
+ Accept anything that starts with <CODE>jdbc:derby:</CODE>.
+ @exception SQLException if a database-access error occurs.
+ @see java.sql.Driver
+ */
+ public boolean acceptsURL(String url) throws SQLException {
+
+ //
+ // We don't want to accidentally boot the engine just because
+ // the application is looking for a connection from some other
+ // driver.
+ //
+ return ( isBooted() && InternalDriver.embeddedDriverAcceptsURL(url) );
+ }
+
+
+ /**
+ Connect to the URL if possible
+ @exception SQLException illegal url or problem with connectiong
+ @see java.sql.Driver
+ */
+ public Connection connect(String url, Properties info)
+ throws SQLException
+ {
+ //
+ // This pretty piece of logic compensates for the following behavior
+ // of the DriverManager: When asked to get a Connection, the
+ // DriverManager cycles through all of its autoloaded drivers, looking
+ // for one which will return a Connection. Without this pretty logic,
+ // the embedded driver module will be booted by any request for
+ // a connection which cannot be satisfied by drivers ahead of us
+ // in the list.
+ if (!InternalDriver.embeddedDriverAcceptsURL(url)) { return null; }
+
+ return getDriverModule().connect(url, info);
+ }
+
+ /**
+ * Returns an array of DriverPropertyInfo objects describing possible properties.
+ @exception SQLException if a database-access error occurs.
+ @see java.sql.Driver
+ */
+ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
+ throws SQLException
+ {
+ return getDriverModule().getPropertyInfo(url, info);
+ }
+
+ /**
+ * Returns the driver's major version number.
+ @see java.sql.Driver
+ */
+ public int getMajorVersion() {
+ try {
+ return (getDriverModule().getMajorVersion());
+ }
+ catch (SQLException se) {
+ return 0;
+ }
+ }
+ /**
+ * Returns the driver's minor version number.
+ @see java.sql.Driver
+ */
+ public int getMinorVersion() {
+ try {
+ return (getDriverModule().getMinorVersion());
+ }
+ catch (SQLException se) {
+ return 0;
+ }
+ }
+
+ /**
+ * Report whether the Driver is a genuine JDBC COMPLIANT (tm) driver.
+ @see java.sql.Driver
+ */
+ public boolean jdbcCompliant() {
+ try {
+ return (getDriverModule().jdbcCompliant());
+ }
+ catch (SQLException se) {
+ return false;
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Support for booting and shutting down the engine.
+ //
+ ///////////////////////////////////////////////////////////////////////
+
+ /*
+ ** Retrieve the driver which is specific to our JDBC level.
+ ** We defer real work to this specific driver.
+ */
+ public static Driver getDriverModule() throws SQLException {
+
+ if ( _engineForcedDown )
+ {
+ // Driver not registered
+ throw new SQLException
+ (MessageService.getTextMessage(MessageId.CORE_JDBC_DRIVER_UNREGISTERED));
+ }
+
+ if ( !isBooted() ) { EmbeddedDriver.boot(); }
+
+ return _driverModule;
+ }
+
+ /*
+ ** Record which driver module actually booted.
+ */
+ protected static void registerDriverModule( Driver driver )
+ {
+ _driverModule = driver;
+ _engineForcedDown = false;
+ }
+
+ /*
+ ** Unregister the driver. This happens when the engine is
+ ** forcibly shut down.
+ */
+ protected static void unregisterDriverModule()
+ {
+ _driverModule = null;
+ _engineForcedDown = true;
+ }
+
+
+ /*
+ ** Return true if the engine has been booted.
+ */
+ private static boolean isBooted()
+ {
+ return ( _driverModule != null );
+ }
+
+}
+
Propchange: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java Thu Jul 13 15:22:25 2006
@@ -68,27 +68,18 @@
super.boot(create, properties);
// Register with the driver manager
- try {
- DriverManager.registerDriver(this);
+ AutoloadedDriver.registerDriverModule( this );
- // hold onto the driver manager to avoid it being garbage collected.
- // make sure the class is loaded by using .class
- antiGCDriverManager = java.sql.DriverManager.class;
-
- } catch (SQLException e) {
- throw StandardException.newException(SQLState.JDBC_DRIVER_REGISTER, e);
- }
+ // hold onto the driver manager to avoid its being garbage collected.
+ // make sure the class is loaded by using .class
+ antiGCDriverManager = java.sql.DriverManager.class;
}
public void stop() {
super.stop();
- try {
- DriverManager.deregisterDriver(this);
- } catch (SQLException sqle) {
- // just do nothing
- }
+ AutoloadedDriver.unregisterDriverModule();
}
/**
Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java Thu Jul 13 15:22:25 2006
@@ -503,7 +503,9 @@
// If we know the driver, we loaded it. Otherwise only
// work if DriverManager has already loaded it.
- driver = (InternalDriver) DriverManager.getDriver(url);
+ AutoloadedDriver autoloadedDriver =
+ (AutoloadedDriver) DriverManager.getDriver(url);
+ driver = (InternalDriver) autoloadedDriver.getDriverModule();
// DriverManager will throw an exception if it cannot find the driver
}
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDriver.java?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDriver.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDriver.java Thu Jul 13 15:22:25 2006
@@ -83,13 +83,15 @@
@see java.sql.SQLException
*/
-public class EmbeddedDriver implements Driver {
+public class EmbeddedDriver implements Driver {
static {
EmbeddedDriver.boot();
}
+ private AutoloadedDriver _autoloadedDriver;
+
// Boot from the constructor as well to ensure that
// Class.forName(...).newInstance() reboots Derby
// after a shutdown inside the same JVM.
@@ -106,7 +108,7 @@
@see java.sql.Driver
*/
public boolean acceptsURL(String url) throws SQLException {
- return getRegisteredDriver().acceptsURL(url);
+ return getDriverModule().acceptsURL(url);
}
/**
@@ -117,7 +119,7 @@
public Connection connect(String url, Properties info)
throws SQLException
{
- return getRegisteredDriver().connect(url, info);
+ return getDriverModule().connect(url, info);
}
/**
@@ -128,7 +130,7 @@
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
throws SQLException
{
- return getRegisteredDriver().getPropertyInfo(url, info);
+ return getDriverModule().getPropertyInfo(url, info);
}
/**
@@ -137,19 +139,20 @@
*/
public int getMajorVersion() {
try {
- return (getRegisteredDriver().getMajorVersion());
+ return (getDriverModule().getMajorVersion());
}
catch (SQLException se) {
return 0;
}
}
+
/**
* Returns the driver's minor version number.
@see java.sql.Driver
*/
public int getMinorVersion() {
try {
- return (getRegisteredDriver().getMinorVersion());
+ return (getDriverModule().getMinorVersion());
}
catch (SQLException se) {
return 0;
@@ -162,14 +165,28 @@
*/
public boolean jdbcCompliant() {
try {
- return (getRegisteredDriver().jdbcCompliant());
+ return (getDriverModule().jdbcCompliant());
}
catch (SQLException se) {
return false;
}
}
- private static void boot() {
+ /**
+ * Lookup the booted driver module appropriate to our JDBC level.
+ */
+ private Driver getDriverModule()
+ throws SQLException
+ {
+ return AutoloadedDriver.getDriverModule();
+ }
+
+
+ /*
+ ** Find the appropriate driver for our JDBC level and boot it.
+ * This is package protected so that AutoloadedDriver can call it.
+ */
+ static void boot() {
PrintStream ps = DriverManager.getLogStream();
if (ps == null)
@@ -178,18 +195,6 @@
new JDBCBoot().boot(Attribute.PROTOCOL, ps);
}
- /*
- ** Retrieve the actual Registered Driver,
- ** probe the DriverManager in order to get it.
- */
- private Driver getRegisteredDriver() throws SQLException {
- try {
- return DriverManager.getDriver(Attribute.PROTOCOL);
- }
- catch (SQLException se) {
- // Driver not registered
- throw new SQLException(MessageService.getTextMessage(MessageId.CORE_JDBC_DRIVER_UNREGISTERED));
- }
- }
+
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java Thu Jul 13 15:22:25 2006
@@ -104,7 +104,16 @@
** Methods from java.sql.Driver
*/
public boolean acceptsURL(String url) {
- return active &&
+ return active && embeddedDriverAcceptsURL( url );
+ }
+
+ /*
+ ** This method can be called by AutoloadedDriver so that we
+ ** don't accidentally boot Derby while answering the question "Can
+ ** you handle this URL?"
+ */
+ public static boolean embeddedDriverAcceptsURL(String url) {
+ return
// need to reject network driver's URL's
!url.startsWith(Attribute.JCC_PROTOCOL) && !url.startsWith(Attribute.DNC_PROTOCOL) &&
(url.startsWith(Attribute.PROTOCOL) || url.equals(Attribute.SQLJ_NESTED));
Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/build.xml?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/build.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/build.xml Thu Jul 13 15:22:25 2006
@@ -119,6 +119,7 @@
<classpath>
<pathelement path="${java13compile.classpath}"/>
</classpath>
+ <include name="${derby.dir}/jdbc/AutoloadedDriver.java"/>
<include name="${derby.dir}/jdbc/EmbeddedDriver.java"/>
<include name="${derby.dir}/jdbc/ReferenceableDataSource.java"/>
<include name="${derby.dir}/jdbc/EmbeddedDataSource.java"/>
Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties Thu Jul 13 15:22:25 2006
@@ -1467,6 +1467,7 @@
I015=org.apache.derby.jdbc.EmbeddedDriver is not registered with the JDBC driver manager
I024=Database not available
I025=JDBC Driver not available
+I026=JDBC Driver registration with java.sql.DriverManager failed: {0}
# Import/Export
XIE01.S=Connection was null.
Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java (original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java Thu Jul 13 15:22:25 2006
@@ -161,9 +161,12 @@
String CORE_JDBC_DRIVER_UNREGISTERED= "I015"; // JDBCDriver is not registered with the JDBC driver manager
String CORE_DATABASE_NOT_AVAILABLE = "I024"; // Database not available
String CORE_DRIVER_NOT_AVAILABLE = "I025"; // JDBC Driver not available
+ String JDBC_DRIVER_REGISTER_ERROR = "I026"; // Error while registering driver
/*
* Monitor
*/
String SERVICE_PROPERTIES_DONT_EDIT = "M001"; // Tell user not to edit service.properties
+
+
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude Thu Jul 13 15:22:25 2006
@@ -23,3 +23,8 @@
largedata/LobLimits.java
jdbc4/TestDbMetaData.java
jdbc4/TestJDBC40Exception.java
+#
+# This test brings the network server up and down by itself
+# and so should not be run with a competing server.
+#
+jdbc4/AutoloadBooting.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall Thu Jul 13 15:22:25 2006
@@ -7,6 +7,7 @@
jdbc4/TestResultSetMethods.java
# JUnit tests
+jdbc4/AutoloadBooting.junit
jdbc4/AutoloadTest.junit
jdbc4/BlobTest.junit
jdbc4/CallableStatementTest.junit
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java?rev=421717&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java Thu Jul 13 15:22:25 2006
@@ -0,0 +1,389 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.AutoloadBooting
+
+ Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+/**
+ * <p>
+ * This JUnit test verifies driver autoloading does not boot the engine.
+ * This test is only run embedded because we manually bring the server up and down.
+ * </p>
+ *
+ * @author Rick
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbc4;
+
+import java.sql.*;
+import java.util.*;
+import junit.framework.*;
+
+import org.apache.derby.iapi.services.monitor.Monitor;
+import org.apache.derby.drda.NetworkServerControl;
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+
+public class AutoloadBooting extends BaseJDBCTestCase
+{
+ /////////////////////////////////////////////////////////////
+ //
+ // CONSTANTS
+ //
+ /////////////////////////////////////////////////////////////
+
+ private static final String HEADER_LINE = "-------------------------------------";
+ private static final String SPACER_LINE = "-- ";
+ private static final String DRIVER_FACTORY = "org.apache.derby.jdbc.InternalDriver";
+ private static final String DRIVER_SERVICE = "jdbc";
+ private static final String NONEXISTENT_DATABASE = "nonexistentDatabase";
+ private static final String CLIENT_DRIVER_NAME = "org.apache.derby.jdbc.ClientDriver";
+ private static final int SERVER_PORT = 1527;
+ private static final long SLEEP_TIME_MILLIS = 5000L;
+ private static final int PING_COUNT = 6;
+
+
+ /////////////////////////////////////////////////////////////
+ //
+ // STATE
+ //
+ /////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////
+ //
+ // CONSTRUCTOR
+ //
+ /////////////////////////////////////////////////////////////
+
+ public AutoloadBooting( String name ) { super( name ); }
+
+ /////////////////////////////////////////////////////////////
+ //
+ // ENTRY POINT
+ //
+ /////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////
+ //
+ // JUnit BEHAVIOR
+ //
+ /////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////
+ //
+ // TEST ENTRY POINTS
+ //
+ /////////////////////////////////////////////////////////////
+
+ /**
+ * <p>
+ * Tests that the JDBC driver module is not booted by the autoloading
+ * of drivers.
+ * </p>
+ */
+ public void testBooting()
+ throws Exception
+ {
+ //
+ // Uncomment this line if you want to the test to describe
+ // its progress.
+ //
+ //CONFIG.setVerbosity( true );
+
+ //
+ // Only run embedded.
+ //
+ if ( !usingEmbedded() )
+ {
+ println( "Not running in the embedded framework. Exitting..." );
+ return;
+ }
+
+ vetInitialization();
+ scenario1_3();
+ scenario2();
+ }
+
+ /**
+ * <p>
+ * Make sure that things look right at initialization.
+ * </p>
+ */
+ private void vetInitialization()
+ throws Exception
+ {
+ printBanner( "Initialization" );
+
+ //
+ // The engine should not be up when we start.
+ //
+ embeddedEngineIsUp( "In the beginning...", false );
+ }
+
+ /**
+ * <p>
+ * Scenarios (1) and (3) from the problem cases attached to DERBY-1459:
+ * http://issues.apache.org/jira/secure/attachment/12336017/autoloading_scenarios.html.
+ * </p>
+ *
+ * <p>
+ * In scenario (1), we verify that the embedded engine does not boot when
+ * you request a connection from some driver other than the embedded driver.
+ * In scenario (3), we verify that the network server also does not
+ * accidentally come up if you request a connection from some driver
+ * other than the embedded driver.
+ * </p>
+ */
+ private void scenario1_3()
+ throws Exception
+ {
+ printBanner( "Scenarios 1 and 3" );
+
+ embeddedEngineIsUp( "Before loading client driver...", false );
+
+ //
+ // Request the network server to come up if the engine boots.
+ //
+ requestNetworkServerBoot();
+
+ //
+ // The engine should not come up when we load the network client driver.
+ //
+ loadNetworkClientDriver();
+ embeddedEngineIsUp( "After loading network client...", false );
+
+ //
+ // The network server should not be up.
+ //
+ ping( false );
+ }
+
+ /**
+ * <p>
+ * Scenario (2) from the problem cases attached to DERBY-1459:
+ * http://issues.apache.org/jira/secure/attachment/12336017/autoloading_scenarios.html.
+ * </p>
+ *
+ * <p>
+ * In this scenario, we verify that the engine boots when we instantiate the
+ * embedded driver. We also test that the network server comes up if
+ * we set the appropriate system property.
+ * </p>
+ */
+ private void scenario2()
+ throws Exception
+ {
+ printBanner( "Scenario 2" );
+
+ embeddedEngineIsUp( "Before instantiating embedded driver...", false );
+
+ //
+ // Request the network server to come up.
+ //
+ requestNetworkServerBoot();
+
+ //
+ // The engine should come up when we manually instantiate the EmbeddedDriver.
+ //
+ instantiateEmbeddedDriver();
+ embeddedEngineIsUp( "After instantiating EmbeddedDriver...", true );
+
+ //
+ // The network server should also be booted because we set the
+ // requesting system property.
+ //
+ ping( true );
+
+ //
+ // Now bring down the server and the engine.
+ //
+ bringDownServer();
+ shutdownDerby();
+ embeddedEngineIsUp( "After bringing down server...", false );
+ }
+
+ /////////////////////////////////////////////////////////////
+ //
+ // MINIONS
+ //
+ /////////////////////////////////////////////////////////////
+
+ /**
+ * <p>
+ * Verify whether the network server came up.
+ * </p>
+ */
+ private void ping( boolean shouldBeUp )
+ throws Exception
+ {
+ NetworkServerControl controller = new NetworkServerControl();
+ Exception finalException = null;
+ boolean isUp = false;
+
+ for ( int i = 0; i < PING_COUNT; i++ )
+ {
+ try {
+ controller.ping();
+ isUp = true;
+ println( "Network server came up!" );
+
+ break;
+ }
+ catch (Exception e)
+ {
+ finalException = e;
+ println( "Network server still down!" );
+ }
+
+ Thread.sleep( SLEEP_TIME_MILLIS );
+ }
+
+ assertEquals( "Network Server status", shouldBeUp, isUp );
+ }
+
+ /**
+ * <p>
+ * Tear down the network server.
+ * </p>
+ */
+ private void bringDownServer()
+ throws Exception
+ {
+ NetworkServerControl controller = new NetworkServerControl();
+
+ controller.shutdown();
+ }
+
+ /**
+ * <p>
+ * Set the system property which requests the network server to boot.
+ * </p>
+ */
+ private void requestNetworkServerBoot()
+ throws Exception
+ {
+ setSystemProperty( "derby.drda.startNetworkServer", "true" );
+ }
+
+ /**
+ * <p>
+ * Bring down the engine.
+ * </p>
+ */
+ private void shutdownDerby()
+ throws Exception
+ {
+ // swallow the shutdown exception
+ try{
+ DriverManager.getConnection("jdbc:derby:;shutdown=true");
+ } catch (SQLException e) {}
+ }
+
+ /**
+ * <p>
+ * Print out the banner for a test scenario.
+ * </p>
+ */
+ private void printBanner( String bannerText )
+ {
+ println( HEADER_LINE );
+ println( SPACER_LINE );
+ println( SPACER_LINE + bannerText );
+ println( SPACER_LINE );
+ println( HEADER_LINE );
+ }
+
+ /**
+ * <p>
+ * Verify whether the embedded JDBC driver (and engine) has booted.
+ * </p>
+ */
+ private void embeddedEngineIsUp( String banner, boolean isUp )
+ {
+ Object service = null;
+
+ // We get an NPE if the service doesn't exist
+ try {
+ service = Monitor.findService( DRIVER_FACTORY, DRIVER_SERVICE );
+ }
+ catch (NullPointerException npe) {}
+
+ boolean actualState = (service != null);
+
+ println( banner + " Engine's booted status should be " + isUp + ", and is " + actualState );
+
+ assertEquals( "JDBC driver status", isUp, actualState );
+ }
+
+ /**
+ * <p>
+ * Load the embedded driver.
+ * </p>
+ */
+ private void instantiateEmbeddedDriver()
+ throws Exception
+ {
+ Class.forName( "org.apache.derby.jdbc.EmbeddedDriver" ).newInstance();
+ }
+
+
+ /**
+ * <p>
+ * Load the network client.
+ * </p>
+ */
+ private void loadNetworkClientDriver()
+ throws Exception
+ {
+ boolean isAutoloading = !CONFIG.autoloading();
+
+ //
+ // Forcibly load the network client if we are not autoloading it.
+ //
+ if ( isAutoloading )
+ {
+ println( "Not autoloading, so forcibly faulting in the client driver." );
+
+ Class.forName( CLIENT_DRIVER_NAME );
+ }
+
+ //
+ // We should fail to get a connection to the nonexistent database.
+ // However, this call should force the client driver to register itself.
+ //
+ String clientURL = "jdbc:derby://localhost:" + SERVER_PORT + "/" + NONEXISTENT_DATABASE;
+
+ try {
+ DriverManager.getConnection( clientURL );
+
+ fail( "Should not have connected to " + clientURL );
+ }
+ catch (SQLException se)
+ {
+ println( "As expected, failed to connect to " + clientURL );
+ }
+
+ //
+ // Verify that the client driver registered itself.
+ //
+ Driver clientDriver = DriverManager.getDriver( clientURL );
+
+ assertNotNull( "Client driver should be registered.", clientDriver );
+ assertEquals
+ ( "Client driver has correct name.", CLIENT_DRIVER_NAME, clientDriver.getClass().getName() );
+ }
+
+}
+
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java Thu Jul 13 15:22:25 2006
@@ -44,15 +44,14 @@
//
/////////////////////////////////////////////////////////////
+ private static final String NONEXISTENT_DATABASE = "nonexistentDatabase";
+
/////////////////////////////////////////////////////////////
//
// STATE
//
/////////////////////////////////////////////////////////////
- private static final String NONEXISTENT_DATABASE = "nonexistentDatabase";
- private static final String DRIVER_LIST = "jdbc.drivers";
-
/////////////////////////////////////////////////////////////
//
// CONSTRUCTOR
@@ -101,7 +100,7 @@
// We expect that the connection to the database will fail for
// one reason or another.
//
- if ( autoloading() )
+ if ( CONFIG.autoloading() )
{
println( "We ARE autoloading..." );
@@ -151,64 +150,10 @@
catch ( SQLException e ) { se = e; }
println( "Caught expected SQLException: " + se );
-
+
assertSQLState( expectedSQLState, expectedSQLState, se );
}
- /**
- * <p>
- * Return true if we expect that the DriverManager will autoload the client driver.
- * </p>
- */
- private boolean autoloading()
- throws Exception
- {
- //
- // DriverManager autoloads the client only as of JDBC4.
- //
- if ( !CONFIG.supportsJDBC4() )
- {
- println( "NOT JDBC4..." );
- return false;
- }
-
- //
- // The DriverManager will autoload drivers specified by the jdbc.drivers
- // property.
- //
- if ( CONFIG.getSystemStartupProperty( DRIVER_LIST ) != null )
- {
- println( "Drivers list encoded in startup properties..." );
- return true;
- }
-
- //
- // The DriverManager will also look inside our jar files for
- // the generated file META-INF/services/java.sql.Driver. This file
- // will contain the name of the driver to load. So if we are running
- // this test against Derby jar files, we expect that the driver will
- // be autoloaded.
- //
- // Note that if we run with a security manager, we get permissions
- // exception at startup when the driver is autoloaded. This exception
- // is silently swallowed and the result is that the driver is not
- // loaded even though we expect it to be.
- //
- if ( CONFIG.loadingFromJars() )
- {
- println( "Loading from jars..." );
- return true;
- }
-
- //
- // OK, we've run out of options. We do not expect that the driver
- // will be autoloaded.
- //
-
- println( "None of the above. Not autoloading..." );
-
- return false;
- }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java?rev=421717&r1=421716&r2=421717&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java Thu Jul 13 15:22:25 2006
@@ -49,24 +49,15 @@
private static ResultSet rs = null;
/** Statement used to fetch BLOB or CLOB. */
private static Statement stmt = null;
- /** Stream used to insert BLOB. */
- private static InputStream blobInput = null;
/** Blob data. */
private static final byte[] blobData = new byte[] {
0x65, 0x66, 0x67, 0x68, 0x69,
0x69, 0x68, 0x67, 0x66, 0x65
};
- /** Stream used to insert CLOB. */
- private static Reader clobInput = null;
/** Clob data. */
private static final String clobData =
"This is a string, inserted into a CLOB";
- static {
- blobInput = new ByteArrayInputStream(blobData, 0, blobData.length);
- clobInput = new StringReader(clobData);
- }
-
/**
* Create a test setup for the specified blob or clob test.
*
@@ -116,6 +107,7 @@
*/
public static Blob getSampleBlob(Connection con)
throws SQLException {
+ InputStream blobInput = new ByteArrayInputStream(blobData, 0, blobData.length);
PreparedStatement pStmt =
con.prepareStatement("update BLOBCLOB set BLOBDATA = ? where ID = ?");
try {
@@ -145,6 +137,7 @@
*/
public static Clob getSampleClob(Connection con)
throws SQLException {
+ Reader clobInput = new StringReader(clobData);
PreparedStatement pStmt =
con.prepareStatement("update BLOBCLOB set CLOBDATA = ? where ID = ?");
try {
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=421717&r1=421716&r2=421717&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 Thu Jul 13 15:22:25 2006
@@ -201,6 +201,56 @@
return isVerbose;
}
+ /**
+ * <p>
+ * Return true if we expect that the DriverManager will autoload the client driver.
+ * </p>
+ */
+ public boolean autoloading()
+ throws Exception
+ {
+ //
+ // DriverManager autoloads the client only as of JDBC4.
+ //
+ if ( !supportsJDBC4() )
+ {
+ return false;
+ }
+
+ //
+ // The DriverManager will autoload drivers specified by the jdbc.drivers
+ // property.
+ //
+ if ( getSystemStartupProperty( DRIVER_LIST ) != null )
+ {
+ return true;
+ }
+
+ //
+ // The DriverManager will also look inside our jar files for
+ // the generated file META-INF/services/java.sql.Driver. This file
+ // will contain the name of the driver to load. So if we are running
+ // this test against Derby jar files, we expect that the driver will
+ // be autoloaded.
+ //
+ // Note that if we run with a security manager, we get permissions
+ // exception at startup when the driver is autoloaded. This exception
+ // is silently swallowed and the result is that the driver is not
+ // loaded even though we expect it to be.
+ //
+ if ( loadingFromJars() )
+ {
+ return true;
+ }
+
+ //
+ // OK, we've run out of options. We do not expect that the driver
+ // will be autoloaded.
+ //
+
+ return false;
+ }
+
/**
* <p>
* Return true if the client supports JDBC4, i.e., if the VM level is at
@@ -273,6 +323,7 @@
private final static String KEY_PORT = "port";
private final static String KEY_VERBOSE = "derby.tests.debug";
private final static String KEY_SINGLE_LEG_XA = "derbyTesting.xa.single";
+ private final static String DRIVER_LIST = "jdbc.drivers";
/**
* Possible values of system properties.