db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1454600 - in /db/derby/code/trunk/java: build/org/apache/derbyBuild/ client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ engine/org/apache/derby/catalog/ engine/org/apache/derby/impl/db/ engine/org/apache/derby/impl/jdbc...
Date Fri, 08 Mar 2013 22:05:10 GMT
Author: rhillegas
Date: Fri Mar  8 22:05:09 2013
New Revision: 1454600

URL: http://svn.apache.org/r1454600
Log:
DERBY-6094: Enforce login timeouts in the embedded driver and data sources.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java   (with props)
Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver169.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedBaseDataSource.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedSimpleDataSource.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/RollBackWrappingWhenFailOnImportTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCClient.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java Fri Mar  8 22:05:09 2013
@@ -232,7 +232,8 @@ public class splitmessages {
         // to clientMessageIds
         if ( messageId.startsWith("XJ") || messageId.startsWith("J")  ||
              messageId.startsWith("XN") || messageId.startsWith("58") ||
-             messageId.startsWith("57") || messageId.startsWith("08"))
+             messageId.startsWith("57") || messageId.startsWith("08") ||
+             messageId.startsWith( "XBD" ) )
         {
             return true;
         }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java Fri Mar  8 22:05:09 2013
@@ -91,7 +91,11 @@ public class SQLExceptionFactory40 exten
             sqlState.equals(DRDA_REPLY_MSG_NOT_SUPPORTED)           ) {
             ex = new SQLFeatureNotSupportedException(message, sqlState, 
                     errCode);
-        } else if (sqlState.equals(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT.substring(0, 5))) {
+        } else if
+                (
+                 sqlState.equals(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT.substring(0, 5)) ||
+                 sqlState.equals(SQLState.LOGIN_TIMEOUT.substring(0, 5))
+                 ) {
             ex = new SQLTimeoutException(message, sqlState, errCode);
         }
         // If the sub-class cannot be determined based on the SQLState, use

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java Fri Mar  8 22:05:09 2013
@@ -444,6 +444,9 @@ public class NetConnection extends org.a
             // to retrieve error message text if an error SQLCA
             // is returned in one of the connect flows.
             open_ = false;
+
+            handleLoginTimeout( e );
+            
             // logWriter may be closed in agent_.close(),
             // so SqlException needs to be created before that
             // but to be thrown after.
@@ -488,6 +491,9 @@ public class NetConnection extends org.a
             // to retrieve error message text if an error SQLCA
             // is returned in one of the connect flows.
             open_ = false;
+
+            handleLoginTimeout( e );
+            
             // logWriter may be closed in agent_.close(),
             // so SqlException needs to be created before that
             // but to be thrown after.
@@ -513,6 +519,20 @@ public class NetConnection extends org.a
         }
     }
 
+    /** Handle socket timeouts during connection attempts */
+    private void    handleLoginTimeout( Throwable original )
+        throws SqlException
+    {
+        for ( Throwable cause = original; cause != null; cause = cause.getCause() )
+        {
+            if ( cause instanceof java.net.SocketTimeoutException )
+            {
+                throw new SqlException
+                    ( agent_.logWriter_, new ClientMessageId( SQLState.LOGIN_TIMEOUT ), original );
+            }
+        }
+    }
+
     protected boolean flowReconnect(String password, int securityMechanism) throws SqlException {
         constructExtnam();
         // these calls need to be after newing up the agent

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java Fri Mar  8 22:05:09 2013
@@ -192,7 +192,7 @@ public class SystemProcedures  {
 	{
 		InternalDriver id = InternalDriver.activeDriver();
 		if (id != null) { 
-			Connection conn = id.connect("jdbc:default:connection", null);
+			Connection conn = id.connect( "jdbc:default:connection", null, 0 );
 			if (conn != null)
 				return conn;
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/db/SlaveDatabase.java Fri Mar  8 22:05:09 2013
@@ -432,7 +432,7 @@ public class SlaveDatabase extends Basic
 
             InternalDriver driver = InternalDriver.activeDriver();
             if (driver != null) {
-                driver.connect(conStr, (Properties) null);
+                driver.connect( conStr, (Properties) null, 0 );
             }
         } catch (Exception e) {
             // Todo: report error to derby.log if exception is not

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java Fri Mar  8 22:05:09 2013
@@ -369,7 +369,7 @@ public class LOBStoredProcedure {
         // some other product's Driver might hijack our stored procedure.
         InternalDriver id = InternalDriver.activeDriver();
         if (id != null) { 
-            EmbedConnection conn = (EmbedConnection) id.connect("jdbc:default:connection", null);
+            EmbedConnection conn = (EmbedConnection) id.connect( "jdbc:default:connection", null, 0 );
             if (conn != null)
                 return conn;
         }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java Fri Mar  8 22:05:09 2013
@@ -72,10 +72,9 @@ public class SQLExceptionFactory40 exten
 
         final SQLException ex;
         if (sqlState.startsWith(SQLState.CONNECTIVITY_PREFIX)) {
-            //none of the sqlstate supported by derby belongs to
+            //no derby sqlstate belongs to
             //TransientConnectionException DERBY-3074
-            ex = new SQLNonTransientConnectionException(message, sqlState,
-                    severity, t);
+            ex = new SQLNonTransientConnectionException(message, sqlState, severity, t);
         } else if (sqlState.startsWith(SQLState.SQL_DATA_PREFIX)) {
             ex = new SQLDataException(message, sqlState, severity, t);
         } else if (sqlState.startsWith(SQLState.INTEGRITY_VIOLATION_PREFIX)) {
@@ -92,7 +91,11 @@ public class SQLExceptionFactory40 exten
             ex = new SQLSyntaxErrorException(message, sqlState, severity, t);
         } else if (sqlState.startsWith(SQLState.UNSUPPORTED_PREFIX)) {
             ex = new SQLFeatureNotSupportedException(message, sqlState, severity, t);
-        } else if (sqlState.equals(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT.substring(0, 5))) {
+        } else if
+                (
+                 sqlState.equals(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT.substring(0, 5)) ||
+                 sqlState.equals(SQLState.LOGIN_TIMEOUT.substring(0, 5))
+                 ) {
             ex = new SQLTimeoutException(message, sqlState, severity, t);
         } else {
             ex = new SQLException(message, sqlState, severity, t);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java Fri Mar  8 22:05:09 2013
@@ -423,7 +423,7 @@ public final class NativeAuthenticationS
 
             String  connectionURL = Attribute.PROTOCOL + _credentialsDB;
 
-            Connection  conn = InternalDriver.activeDriver().connect( connectionURL, properties );
+            Connection  conn = InternalDriver.activeDriver().connect( connectionURL, properties, 0 );
             
             warnings = conn.getWarnings();
             conn.close();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver169.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver169.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver169.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver169.java Fri Mar  8 22:05:09 2013
@@ -60,6 +60,16 @@ public class Driver169 extends InternalD
         return new EmbedConnection(this, url, info);
 	}
 
+    /**
+     * This method does not enforce timeouts on JSR 169. If that functionality is important
+     * on CDC/FP 1.1 then a separate implementation can be plugged in here.
+     */
+    protected EmbedConnection  timeLogin( String url, Properties info, int loginTimeoutSeconds )
+        throws SQLException
+    {
+        return getNewEmbedConnection( url, info );
+    }
+    
 
 	/**
  	 * Get a new nested connection.

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=1454600&r1=1454599&r2=1454600&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 Fri Mar  8 22:05:09 2013
@@ -29,6 +29,7 @@ import org.apache.derby.iapi.error.Stand
 import org.apache.derby.iapi.sql.ResultSet;
 import org.apache.derby.iapi.jdbc.BrokeredConnection;
 import org.apache.derby.iapi.jdbc.BrokeredConnectionControl;
+import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.i18n.MessageService;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.io.FormatableProperties;
@@ -36,14 +37,25 @@ import org.apache.derby.iapi.security.Se
 
 import org.apache.derby.impl.jdbc.*;
 
-import java.sql.SQLException;
+import java.sql.Connection;
 import java.sql.Driver;
+import java.sql.DriverManager;
 import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
 
 import java.security.Permission;
 import java.security.AccessControlException;
 
 import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.TimeUnit;
 
 /**
 	This class extends the local JDBC driver in order to determine at JBMS
@@ -54,6 +66,13 @@ import java.util.Properties;
 
 public abstract class Driver20 extends InternalDriver implements Driver {
 
+    private static  ExecutorService _executorPool;
+    static
+    {
+        _executorPool = Executors.newCachedThreadPool();
+        ((ThreadPoolExecutor) _executorPool).setThreadFactory( new DaemonThreadFactory() );
+    } 
+
 	private static final String[] BOOLEAN_CHOICES = {"false", "true"};
 
 	private Class  antiGCDriverManager;
@@ -219,4 +238,78 @@ public abstract class Driver20 extends I
         throws Exception {
         SecurityUtil.checkUserHasPermission(user, perm);
     }
+
+	public Connection connect( String url, Properties info )
+		 throws SQLException 
+	{
+        return connect( url, info, DriverManager.getLoginTimeout() );
+    }
+    
+    /**
+     * Use java.util.concurrent package to enforce login timeouts.
+     */
+    protected EmbedConnection  timeLogin( String url, Properties info, int loginTimeoutSeconds )
+        throws SQLException
+    {
+        LoginCallable callable = new LoginCallable( this, url, info );
+        Future<EmbedConnection>  task = _executorPool.submit( callable );
+
+        try {
+            return task.get( loginTimeoutSeconds, TimeUnit.SECONDS );
+        }
+        catch (InterruptedException ie) { throw processException( ie ); }
+        catch (ExecutionException ee) { throw processException( ee ); }
+        catch (TimeoutException te) { throw Util.generateCsSQLException( SQLState.LOGIN_TIMEOUT ); }
+    }
+    /** Process exceptions raised while running a timed login */
+    private SQLException    processException( Throwable t )
+    {
+        Throwable   cause = t.getCause();
+        if ( !(cause instanceof SQLException) ) { return Util.javaException( t ); }
+        else { return (SQLException) cause; }
+    }
+
+    /** Thread factory to produce daemon threads which don't block VM shutdown */
+    public  static  final   class   DaemonThreadFactory implements ThreadFactory
+    {
+        public  Thread newThread( Runnable r )
+        {
+            Thread  result = new Thread( r );
+            result.setDaemon( true );
+            return result;
+        }
+    }
+
+    /**
+     * This code is called in a thread which puts time limits on it.
+     */
+    public  static  final   class   LoginCallable implements  Callable<EmbedConnection>
+    {
+        private Driver20        _driver;
+        private String      _url;
+        private Properties  _info;
+
+        public  LoginCallable( Driver20 driver, String url, Properties info )
+        {
+            _driver = driver;
+            _url = url;
+            _info = info;
+        }
+
+        public  EmbedConnection call()  throws SQLException
+        {
+            // erase the state variables after we use them.
+            // might be paranoid but there could be security-sensitive info
+            // in here.
+            String  url = _url;
+            Properties  info = _info;
+            Driver20    driver = _driver;
+            _url = null;
+            _info = null;
+            _driver = null;
+            
+            return driver.getNewEmbedConnection( url, info );
+        }
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedBaseDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedBaseDataSource.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedBaseDataSource.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedBaseDataSource.java Fri Mar  8 22:05:09 2013
@@ -612,7 +612,7 @@ public abstract class EmbeddedBaseDataSo
             url = sb.toString();
         }
 
-        Connection conn =  findDriver().connect(url, info);
+        Connection conn =  findDriver().connect( url, info, loginTimeout );
 
         // JDBC driver's getConnection method returns null if
         // the driver does not handle the request's URL.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedSimpleDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedSimpleDataSource.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedSimpleDataSource.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedSimpleDataSource.java Fri Mar  8 22:05:09 2013
@@ -405,7 +405,7 @@ public final class EmbeddedSimpleDataSou
 		if (shutdownDatabase != null)
 			info.put(Attribute.SHUTDOWN_ATTR, "true");
 
-		Connection conn = findDriver().connect(jdbcurl, info);
+		Connection conn = findDriver().connect( jdbcurl, info, loginTimeout );
 
 		// JDBC driver's getConnection method returns null if
 		// the driver does not handle the request's URL.

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=1454600&r1=1454599&r2=1454600&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 Fri Mar  8 22:05:09 2013
@@ -156,7 +156,7 @@ public abstract class InternalDriver imp
 				
 	}
 
-	public Connection connect(String url, Properties info)
+	public Connection connect( String url, Properties info, int loginTimeoutSeconds )
 		 throws SQLException 
 	{
 		if (!acceptsURL(url)) { return null; }
@@ -258,9 +258,12 @@ public abstract class InternalDriver imp
                                          SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN);
 				}
 			}
-			
-			EmbedConnection conn = getNewEmbedConnection(url, finfo);
 
+            EmbedConnection conn;
+			
+            if ( loginTimeoutSeconds <= 0 ) { conn = getNewEmbedConnection( url, finfo ); }
+            else { conn = timeLogin( url, finfo, loginTimeoutSeconds ); }
+            
 			// if this is not the correct driver a EmbedConnection
 			// object is returned in the closed state.
 			if (conn.isClosed()) {
@@ -282,6 +285,12 @@ public abstract class InternalDriver imp
 	}
 
     /**
+     * Enforce the login timeout.
+     */
+    protected abstract EmbedConnection  timeLogin( String url, Properties info, int loginTimeoutSeconds )
+        throws SQLException;
+    
+    /**
      * Checks for System Privileges.
      *
      * Abstract since some of the javax security classes are not available
@@ -662,4 +671,6 @@ public abstract class InternalDriver imp
     static boolean getDeregister() {
         return InternalDriver.deregister;
     }
+
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Fri Mar  8 22:05:09 2013
@@ -4025,6 +4025,16 @@ ln=lower-case two-letter ISO-639 languag
 
         </family>
 
+        <family>
+            <title>Class XBD: Communication exceptions</title>
+
+            <msg>
+                <name>XBDA0.C.1</name>
+                <text>Login timeout exceeded.</text>
+            </msg>
+
+        </family>
+
 
         <family>
             <title>Class XCL: Execution exceptions</title>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java (original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java Fri Mar  8 22:05:09 2013
@@ -107,7 +107,7 @@ package org.apache.derby.shared.common.r
 	  <LI> XBCM ClassManager
 	  <LI> XBCX	Cryptography
 	  <LI> XBM0	Monitor
-	  <LI> XBDA DataComm
+	  <LI> XBDA Communications
 	  <LI> XCY0 Properties
 	  </UL>
 
@@ -195,6 +195,11 @@ public interface SQLState {
     String INSTANTIATE_STORAGE_FACTORY_ERROR    = "XBM08.D";
 
 	/*
+	** Communications
+	*/
+    String LOGIN_TIMEOUT                        = "XBDA0.C.1";
+
+	/*
 	** Upgrade
 	*/
 	String UPGRADE_UNSUPPORTED				= "XCW00.D";

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java?rev=1454600&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java Fri Mar  8 22:05:09 2013
@@ -0,0 +1,368 @@
+/*
+ 
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.LoginTimeoutTest
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you 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.derbyTesting.functionTests.tests.jdbc4;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.SQLTimeoutException;
+import java.util.Properties;
+import javax.sql.DataSource;
+import javax.sql.CommonDataSource;
+import javax.sql.ConnectionPoolDataSource;
+import javax.sql.XADataSource;
+
+import junit.framework.*;
+
+import org.apache.derby.authentication.UserAuthenticator;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
+import org.apache.derbyTesting.junit.J2EEDataSource;
+import org.apache.derbyTesting.junit.JDBCClient;
+import org.apache.derbyTesting.junit.JDBCClientSetup;
+import org.apache.derbyTesting.junit.JDBCDataSource;
+import org.apache.derbyTesting.junit.NetworkServerTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+
+/**
+ * Test login timeouts.
+ */
+
+public class LoginTimeoutTest extends BaseJDBCTestCase
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private static  final   String[][]    SYSTEM_PROPERTIES =
+    {
+        { "derby.connection.requireAuthentication", "true" },
+        { "derby.authentication.provider", LoginTimeoutTest.class.getName() + "$SluggishAuthenticator" },
+    };
+
+    private static  final   boolean SUCCEED = true;
+    private static  final   boolean FAIL = false;
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private static  final   String      RUTH = "RUTH";
+    private static  final   String      RUTH_PASSWORD = "RUTHPASSWORD";
+
+    private static  final   String      LOGIN_TIMEOUT = "XBDA0";
+    private static  final   String      LOGIN_FAILED = "08004";
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // NESTED CLASSES
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /** User authenticator which sleeps for a while */
+    public  static  final   class   SluggishAuthenticator   implements  UserAuthenticator
+    {
+        private static  final   long    MILLIS_PER_SECOND = 1000L;
+        
+        public  static  long    secondsToSleep = 2;
+        public  static  boolean returnValue = true;
+        
+        public  SluggishAuthenticator() {}
+    
+        public boolean authenticateUser
+            (
+             String userName,
+             String userPassword,
+             String databaseName,
+             Properties info
+             )
+            throws SQLException
+        {
+            // sleepy...
+            try {
+                Thread.sleep( secondsToSleep * MILLIS_PER_SECOND );
+            } catch (Exception e) { throw new SQLException( e.getMessage(), e ); }
+
+            // ...and vacuous.
+            return returnValue;
+        }
+    }
+
+    /** Behavior shared by DataSource and DriverManager */
+    public  static  interface   Connector
+    {
+        public  Connection  getConnection( String user, String password ) throws SQLException;
+
+        public  void    setLoginTimeout( int seconds ) throws SQLException;
+    }
+
+    public  static  final   class   DriverManagerConnector  implements Connector
+    {
+        private BaseJDBCTestCase    _test;
+
+        public  DriverManagerConnector( BaseJDBCTestCase test ) { _test = test; }
+
+        public  Connection  getConnection( String user, String password ) throws SQLException
+        {
+            return _test.openDefaultConnection( user, password );
+        }
+
+        public  void    setLoginTimeout( int seconds ) { DriverManager.setLoginTimeout( seconds ); }
+
+        public  String  toString()  { return "DriverManagerConnector"; }
+    }
+    
+    public  static  final   class   DataSourceConnector  implements Connector
+    {
+        private CommonDataSource  _dataSource;
+
+        public  DataSourceConnector( CommonDataSource dataSource )
+        {
+            _dataSource = dataSource;
+        }
+
+        public  Connection  getConnection( String user, String password ) throws SQLException
+        {
+            if ( _dataSource instanceof DataSource )
+            {
+                return ((DataSource) _dataSource).getConnection( user, password );
+            }
+            else if ( _dataSource instanceof ConnectionPoolDataSource )
+            {
+                return ((ConnectionPoolDataSource) _dataSource).getPooledConnection( user, password ).getConnection();
+            }
+            else if ( _dataSource instanceof XADataSource )
+            {
+                return ((XADataSource) _dataSource).getXAConnection( user, password ).getConnection();
+            }
+            else { throw new SQLException( "Unknown data source type: " + _dataSource.getClass().getName() ); }
+        }
+
+        public  void    setLoginTimeout( int seconds ) throws SQLException
+        { _dataSource.setLoginTimeout( seconds ); }
+
+        public  String  toString()
+        {
+            return "DataSourceConnector( " + _dataSource.getClass().getName() + " )";
+        }
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTORS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     *
+     * Create a test with the given name.
+     */
+    public LoginTimeoutTest(String name) { super(name); }
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // JUnit MACHINERY
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+    
+    /**
+     * Return suite with all tests of the class.
+     */
+    public static Test suite()
+    {
+        TestSuite   suite = new TestSuite();
+
+        Test    embedded = new TestSuite( LoginTimeoutTest.class, "embedded LoginTimeoutTest" );
+        embedded = TestConfiguration.singleUseDatabaseDecorator( embedded );
+        embedded = new SystemPropertyTestSetup( embedded, systemProperties() );
+        suite.addTest( embedded );
+        
+        Test    clientServer = new TestSuite( LoginTimeoutTest.class, "client/server LoginTimeoutTest" );
+        clientServer = TestConfiguration.singleUseDatabaseDecorator( clientServer );
+        clientServer = new JDBCClientSetup( clientServer, JDBCClient.DERBYNETCLIENT );
+        clientServer = new NetworkServerTestSetup( clientServer, systemPropertiesArray(), new String[]{}, true );
+        suite.addTest( clientServer );
+
+        return suite;
+    }
+    private static  Properties  systemProperties()
+    {
+        Properties  props = new Properties();
+
+        for ( int i = 0; i < SYSTEM_PROPERTIES.length; i++ )
+        {
+            String[]    raw = SYSTEM_PROPERTIES[ i ];
+
+            props.put( raw[ 0 ], raw[ 1 ] );
+        }
+
+        return props;
+    }
+    private static  String[]    systemPropertiesArray()
+    {
+        String[]    result = new String[ SYSTEM_PROPERTIES.length ];
+
+        for ( int i = 0; i < SYSTEM_PROPERTIES.length; i++ )
+        {
+            String[]    raw = SYSTEM_PROPERTIES[ i ];
+
+            result[ i ] = raw[ 0 ] + "=" + raw[ 1 ];
+        }
+
+        return result;
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // TESTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * Basic test of login timeouts.
+     */
+    public  void    testBasic() throws Exception
+    {
+        DataSource  ds = JDBCDataSource.getDataSource();
+        
+        vetConnector( new DriverManagerConnector( this ), true );
+        vetConnector( new DataSourceConnector( JDBCDataSource.getDataSource() ), true );
+        vetConnector( new DataSourceConnector( J2EEDataSource.getConnectionPoolDataSource() ), true );
+        vetConnector( new DataSourceConnector( J2EEDataSource.getXADataSource() ), true );
+
+        if ( usingEmbedded() ) { vetExceptionPassthrough(); }
+        if ( usingDerbyNetClient() ) { vetServerTimeouts(); }
+    }
+    private void    vetConnector( Connector connector, boolean shouldSucceed ) throws Exception
+    {
+        tryTimeout( connector, 1, FAIL && shouldSucceed );
+        tryTimeout( connector, 10, SUCCEED && shouldSucceed );
+        tryTimeout( connector, 0, SUCCEED && shouldSucceed );
+
+        // revert to default state
+        connector.setLoginTimeout( 0 );
+    }
+    private static  void    tryTimeout( Connector connector, int timeout, boolean shouldSucceed ) throws Exception
+    {
+        println( "Setting timeout " + timeout + " on " + connector );
+        connector.setLoginTimeout( timeout );
+
+        tryTimeout( connector, shouldSucceed );
+    }
+    private static  void    tryTimeout( Connector connector, boolean shouldSucceed ) throws Exception
+    {
+        long    startTime = System.currentTimeMillis();
+        
+        try {
+            Connection  conn = connector.getConnection( RUTH, RUTH_PASSWORD );
+            println( "    Got a " + conn.getClass().getName() );
+            if ( !shouldSucceed )   { fail( "Should not have been able to connect!" ); }
+        }
+        catch (SQLException se)
+        {
+            if ( shouldSucceed ) { fail( "Should have been able to connect!" ); }
+
+            assertTrue( "Didn't expect to see a " + se.getClass().getName(), (se instanceof SQLTimeoutException) );
+            assertSQLState( LOGIN_TIMEOUT, se );
+        }
+
+        long    duration = System.currentTimeMillis() - startTime;
+
+        println( "        Experiment took " + duration + " milliseconds." );
+    }
+    private void    vetExceptionPassthrough() throws Exception
+    {
+        println( "Verifying that exceptions are not swallowed by the embedded login timer." );
+        // set a long timeout which we won't exceed
+        DriverManager.setLoginTimeout( 10 );
+
+        // tell the authenticator to always fail
+        SluggishAuthenticator.returnValue = false;
+
+        try {
+            openDefaultConnection( RUTH, RUTH_PASSWORD );
+            fail( "Didn't expect to get a connection!" );
+        }
+        catch (SQLException se) { assertSQLState( LOGIN_FAILED, se ); }
+
+        // return to default position
+        DriverManager.setLoginTimeout( 0 );
+        SluggishAuthenticator.returnValue = true;
+    }
+    private void    vetServerTimeouts() throws Exception
+    {
+        println( "Verifying behavior when timeouts are also set on the server." );
+
+        Connection  controlConnection = openDefaultConnection( RUTH, RUTH_PASSWORD );
+
+        // create a procedure for changing the login timeout on the server
+        String  createProc = 
+            "create procedure setLoginTimeout( timeout int ) language java parameter style java no sql\n" +
+            "external name '" + getClass().getName() + ".setLoginTimeout'";
+        println( createProc );
+        controlConnection.prepareStatement( createProc ).execute();
+
+        Connector   connector = new DriverManagerConnector( this );
+
+        vetServerTimeout( controlConnection, connector, 1, FAIL );
+        vetServerTimeout( controlConnection, connector, 10, SUCCEED );
+        vetServerTimeout( controlConnection, connector, 0, SUCCEED );
+
+        // reset server timeout to default
+        setServerTimeout( controlConnection, 0 );
+    }
+    private void    vetServerTimeout
+        ( Connection controlConnection, Connector connector, int serverTimeout, boolean shouldSucceed )
+        throws Exception
+    {
+        setServerTimeout( controlConnection, serverTimeout );
+        vetConnector( connector, shouldSucceed );
+    }
+    private void    setServerTimeout( Connection conn, int seconds ) throws Exception
+    {
+        CallableStatement   cs = conn.prepareCall( "call setLoginTimeout( ? )" );
+        cs.setInt( 1, seconds );
+        cs.execute();
+        cs.close();
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // SQL ROUTINES
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /** Routine to set the DriverManager login timeout on the server */
+    public  static  void    setLoginTimeout( int seconds ) throws Exception
+    {
+        DriverManager.setLoginTimeout( seconds );
+    }
+    
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java Fri Mar  8 22:05:09 2013
@@ -79,6 +79,7 @@ public class _Suite extends BaseTestCase
         suite.addTest(AbortTest.suite());
         suite.addTest(Driver40Test.suite());
         suite.addTest(Driver40UnbootedTest.suite());
+        suite.addTest(LoginTimeoutTest.suite());
 
         if ( isJava8() )
         {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java Fri Mar  8 22:05:09 2013
@@ -162,6 +162,7 @@ public final class ErrorCodeTest extends
         		{"58015","The DDM object 0x{0} is not supported.  The connection has been terminated.","40000"},
         		{"58016","The DDM parameter 0x{0} is not supported.  The connection has been terminated.","40000"},
         		{"58017","The DDM parameter value 0x{0} is not supported.  An input host variable may not be within the range the server supports.  The connection has been terminated.","40000"},
+        		{"XBDA0","Login timeout exceeded.","40000"},
         		{"XBM01","Startup failed due to an exception. See next exception for details. ","45000"},
         		{"XBM02","Startup failed due to missing functionality for {0}. Please ensure your classpath includes the correct Derby software.","45000"},
         		{"XBM03","Supplied value '{0}' for collation attribute is invalid, expecting UCS_BASIC or TERRITORY_BASED.","45000"},

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/RollBackWrappingWhenFailOnImportTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/RollBackWrappingWhenFailOnImportTest.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/RollBackWrappingWhenFailOnImportTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/RollBackWrappingWhenFailOnImportTest.java Fri Mar  8 22:05:09 2013
@@ -59,10 +59,10 @@ public class RollBackWrappingWhenFailOnI
             }
         }
 
-        public Connection connect(String url, Properties info) {
+        public Connection connect( String url, Properties info, int loginTimeout ) {
             Connection conn = null;
             try {
-                conn = super.connect(url, info);
+                conn = super.connect( url, info, loginTimeout );
             } catch (Exception e) {
                 //this exception is ignored for mocking
             }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java Fri Mar  8 22:05:09 2013
@@ -178,6 +178,16 @@ public class ConnectionPoolDataSourceCon
         tmpDs.getPooledConnection();
     }
     
+    public void setLoginTimeout( int seconds ) throws SQLException
+    {
+        ds.setLoginTimeout( seconds );
+    }
+    
+    public int getLoginTimeout() throws SQLException
+    {
+        return ds.getLoginTimeout();
+    }
+    
     public String getDatabaseName() {
         String databaseName=null;
         try {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java Fri Mar  8 22:05:09 2013
@@ -106,4 +106,14 @@ interface Connector {
      * Return nothing, exception is expected to be thrown with SQLState XJ015
      */
     abstract void shutEngine() throws SQLException;
+   
+    /**
+     * Set the login timeout for getting connections. Timeout is measured in seconds.
+     */
+    abstract void setLoginTimeout( int seconds ) throws SQLException;
+    
+    /**
+     * Get the login timeout in seconds.
+     */
+    abstract int getLoginTimeout() throws SQLException;
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java Fri Mar  8 22:05:09 2013
@@ -146,6 +146,16 @@ public class DataSourceConnector impleme
         tmpDs.getConnection();
     }
     
+    public void setLoginTimeout( int seconds ) throws SQLException
+    {
+        ds.setLoginTimeout( seconds );
+    }
+    
+    public int getLoginTimeout() throws SQLException
+    {
+        return ds.getLoginTimeout();
+    }
+    
     /**
      * Get a connection from a single use DataSource configured
      * from the configuration but with the passed in property set.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java Fri Mar  8 22:05:09 2013
@@ -100,6 +100,9 @@ public class DriverManagerConnector impl
             return DriverManager.getConnection(url, connectionAttributes);
         } catch (SQLException e) {
 
+            // Uncomment this for more information
+            // printFullException( e, 0 );
+
             // Expected state for database not found.
             // For the client the generic 08004 is returned,
             // will just retry on that.
@@ -119,6 +122,33 @@ public class DriverManagerConnector impl
         }
     }
 
+    private static void printFullException( Throwable t, int indentLevel )
+    {
+        if ( t == null ) { return; }
+
+        String              tab = "    ";
+        StringBuilder   buffer = new StringBuilder();
+
+        for ( int i = 0; i < indentLevel; i++ ) { buffer.append( tab ); }
+        buffer.append( "Message:  " + t.getMessage() );
+
+        SQLException    nextSQLException = null;
+        
+        if ( t instanceof SQLException )
+        {
+            SQLException    se = (SQLException) t;
+
+            buffer.append( se.getClass().getName() + " : SQLState = " + se.getSQLState() );
+
+            nextSQLException = se.getNextException();
+        }
+
+        System.out.println( buffer.toString() );
+
+        printFullException( nextSQLException, indentLevel + 1 );
+        printFullException( t.getCause(), indentLevel + 1 );
+    }
+
     /**
      * Shutdown the database using the attributes shutdown=true
      * with the user and password defined by the configuration.
@@ -141,6 +171,16 @@ public class DriverManagerConnector impl
         getConnectionByAttributes("jdbc:derby:", "shutdown", "true");
     }
     
+    public void setLoginTimeout( int seconds ) throws SQLException
+    {
+        DriverManager.setLoginTimeout( seconds );
+    }
+    
+    public int getLoginTimeout() throws SQLException
+    {
+        return DriverManager.getLoginTimeout();
+    }
+    
     /**
      * Open a connection using JDBC attributes with a JDBC URL.
      * The attributes user and password are set from the configuration

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCClient.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCClient.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCClient.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCClient.java Fri Mar  8 22:05:09 2013
@@ -90,7 +90,7 @@ public final class JDBCClient {
     /**
      * The Derby network client.
      */
-    static final JDBCClient DERBYNETCLIENT= new JDBCClient(
+    public static final JDBCClient DERBYNETCLIENT= new JDBCClient(
             "DerbyNetClient",
             "org.apache.derby.jdbc.ClientDriver",
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Fri Mar  8 22:05:09 2013
@@ -105,7 +105,7 @@ public class JDBCDataSource {
         if (beanProperties == null)
              beanProperties = getDataSourceProperties(config);
         
-        return (javax.sql.DataSource) getDataSourceObject(dsClassName,
+        return getDataSourceObject(dsClassName,
             beanProperties);
     }
     
@@ -143,7 +143,7 @@ public class JDBCDataSource {
      * If a thread context class loader exists then it is used
      * to try and load the class.
      */
-    static Object getDataSourceObject(String classname, HashMap beanProperties)
+    static javax.sql.DataSource getDataSourceObject(String classname, HashMap beanProperties)
     {
         ClassLoader contextLoader =
             (ClassLoader) AccessController.doPrivileged
@@ -155,11 +155,11 @@ public class JDBCDataSource {
         });
     
         try {
-            Object ds = null;
+            javax.sql.DataSource ds = null;
             if (contextLoader != null)
             {
                 try {
-                    ds = Class.forName(classname, true, contextLoader).newInstance();
+                    ds = (javax.sql.DataSource) Class.forName(classname, true, contextLoader).newInstance();
                 } catch (Exception e) {
                     // context loader may not be correctly hooked up
                     // with parent, try without it.
@@ -167,7 +167,9 @@ public class JDBCDataSource {
             }
             
             if (ds == null)
-                ds = Class.forName(classname).newInstance();
+            {
+                ds = (javax.sql.DataSource) Class.forName(classname).newInstance();
+            }
             
             for (Iterator i = beanProperties.keySet().iterator();
                 i.hasNext(); )
@@ -177,6 +179,9 @@ public class JDBCDataSource {
                 
                 setBeanProperty(ds, property, value);
             }
+
+            ds.setLoginTimeout( TestConfiguration.getCurrent().getLoginTimeout() );
+            
             return ds;
         } catch (Exception e) {
             BaseTestCase.fail("unexpected error", e);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Fri Mar  8 22:05:09 2013
@@ -117,6 +117,7 @@ public final class TestConfiguration {
     private final static String KEY_HOSTNAME = "hostName";
     private final static String KEY_PORT = "port";
     private final static String KEY_VERBOSE = "derby.tests.debug";    
+    private final static String KEY_LOGIN_TIMEOUT = "derby.tests.login.timeout";    
     private final static String KEY_TRACE = "derby.tests.trace";
     private final static String KEY_SSL = "ssl";
     private final static String KEY_JMX_PORT = "jmxPort";
@@ -1481,6 +1482,18 @@ public final class TestConfiguration {
             connector = new DataSourceConnector();
         }
         connector.setConfiguration(this);
+
+        try {
+            String  loginTimeoutString = BaseTestCase.getSystemProperty( KEY_LOGIN_TIMEOUT );
+            
+            if ( loginTimeoutString != null )
+            {
+                int loginTimeout = Integer.parseInt( loginTimeoutString );
+
+                connector.setLoginTimeout( loginTimeout );
+            }
+        }
+        catch (Exception e) { Assert.fail(e.getMessage()); }
     }
 
     /**
@@ -1804,7 +1817,13 @@ public final class TestConfiguration {
         } catch (SQLException e) {
              BaseJDBCTestCase.assertSQLState("Engine shutdown", "XJ015", e);
         }
-    }    
+    }
+
+    /** Get the login timeout from the connector */
+    public  int getLoginTimeout() throws SQLException
+    {
+        return connector.getLoginTimeout();
+    }
 
     public void waitForShutdownComplete(String physicalDatabaseName) {
         String path = getDatabasePath(physicalDatabaseName);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java?rev=1454600&r1=1454599&r2=1454600&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java Fri Mar  8 22:05:09 2013
@@ -145,6 +145,16 @@ public class XADataSourceConnector imple
         Assert.fail("shutdown engine not implemened");
     }
     
+    public void setLoginTimeout( int seconds ) throws SQLException
+    {
+        ds.setLoginTimeout( seconds );
+    }
+    
+    public int getLoginTimeout() throws SQLException
+    {
+        return ds.getLoginTimeout();
+    }
+    
     public String getDatabaseName() {
         String databaseName=null;
         try {



Mime
View raw message