db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r737758 - in /db/derby/code/trunk/java: client/org/apache/derby/client/net/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Mon, 26 Jan 2009 17:26:01 GMT
Author: kmarsden
Date: Mon Jan 26 17:25:59 2009
New Revision: 737758

URL: http://svn.apache.org/viewvc?rev=737758&view=rev
Log:
DERBY-4008 Only send RDBNAM on ACCSEC if EBCDIC conversion is possible


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectSimpleDSTest.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetAgent.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionRequest.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetAgent.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetAgent.java?rev=737758&r1=737757&r2=737758&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetAgent.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetAgent.java Mon Jan 26 17:25:59
2009
@@ -96,7 +96,8 @@
     public int targetSqlam_ = orignalTargetSqlam_;
 
     public SqlException exceptionOpeningSocket_ = null;
-
+    public SqlException exceptionConvertingRdbnam = null;
+    
     //---------------------constructors/finalizer---------------------------------
     public NetAgent(NetConnection netConnection,
                     org.apache.derby.client.am.LogWriter logWriter) throws SqlException {
@@ -227,7 +228,8 @@
                                int loginTimeout,
                                String server,
                                int port) throws SqlException {
-
+        
+        exceptionConvertingRdbnam = null;
         // most properties will remain unchanged on connect reset.
         targetTypdef_ = originalTargetTypdef_;
         svrcod_ = 0;

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java?rev=737758&r1=737757&r2=737758&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java Mon
Jan 26 17:25:59 2009
@@ -252,6 +252,9 @@
             return;
         }
         parseACCSECRD(netConnection, securityMechanism);
+        // if we didn't get a SYNTAXRM on parseACCSECRD. Reset the conversion exception
+        // if any.
+        netAgent_.exceptionConvertingRdbnam = null;
 
         peekCP = peekCodePoint();
         if (peekCP == Reply.END_OF_SAME_ID_CHAIN) {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionRequest.java?rev=737758&r1=737757&r2=737758&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionRequest.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionRequest.java
Mon Jan 26 17:25:59 2009
@@ -291,8 +291,9 @@
         // the rdbnam will be built and sent.  different sqlam levels support
         // different lengths.  at this point the length has been checked against
         // the maximum allowable length.  so write the bytes and padd up to the
-        // minimum length if needed.
-        buildRDBNAM(rdbnam);
+        // minimum length if needed.  We want to defer sending the rdbnam if an
+        // EBCDIC conversion is not possible.
+        buildRDBNAM(rdbnam,true);
 
         if (sectkn != null) {
             buildSECTKN(sectkn);
@@ -319,7 +320,7 @@
         // different lengths.  at this point the length has been checked against
         // the maximum allowable length.  so write the bytes and padd up to the
         // minimum length if needed.
-        buildRDBNAM(rdbnam);
+        buildRDBNAM(rdbnam,false);
         if (user != null) {
             buildUSRID(user);
         }
@@ -355,7 +356,7 @@
         // support.  the size will have ben previously checked so at this point just
         // write the data and pad with the correct number of bytes as needed.
         // this instance variable is always required.
-        buildRDBNAM(rdbnam);
+        buildRDBNAM(rdbnam,false);
 
         // the rdb access manager class specifies an instance of the SQLAM
         // that accesses the RDB.  the sqlam manager class codepoint
@@ -462,17 +463,33 @@
         writeScalar2Bytes(CodePoint.SECMEC, secmec);
     }
 
-    // Relational Database Name specifies the name of a relational database
-    // of the server.
-    // if length of RDB name <= 18 characters, there is not change to the format
-    // of the RDB name.  The length of the RDBNAM remains fixed at 18 which includes
-    // any right bland padding if necessary.
-    // if length of the RDB name is > 18 characters, the length of the RDB name is
-    // identical to the length of the RDB name.  No right blank padding is required.
-    private void buildRDBNAM(String rdbnam) throws SqlException {
+    /**
+     * 
+     * Relational Database Name specifies the name of a relational database
+     * of the server.
+     * if length of RDB name <= 18 characters, there is not change to the format
+     * of the RDB name.  The length of the RDBNAM remains fixed at 18 which includes
+     * any right bland padding if necessary.
+     * if length of the RDB name is > 18 characters, the length of the RDB name is
+     * identical to the length of the RDB name.  No right blank padding is required.
+     * @param rdbnam  name of the database.
+     * @param dontSendOnConversionError omit sending the RDBNAM if there is an
+     * exception converting to EBCDIC.  This will be used by ACCSEC to defer
+     * sending the RDBNAM to SECCHK if it can't be converted.
+     *
+     */
+    private void buildRDBNAM(String rdbnam, boolean dontSendOnConversionError) throws SqlException
{
         // since this gets built more than once on the connect flow,
         // see if we can optimize
-
+        if (dontSendOnConversionError) {
+            try {
+                ccsidManager_.convertFromUCS2(rdbnam, netAgent_);
+            } catch (SqlException se)  {
+                netAgent_.exceptionConvertingRdbnam = se;
+                return;
+            }
+            
+        }
         int rdbnamLength = rdbnam.length();
         if (rdbnamLength <= NetConfiguration.PKG_IDENTIFIER_FIXED_LEN) {
             writeScalarPaddedString(CodePoint.RDBNAM,

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java?rev=737758&r1=737757&r2=737758&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java Mon Jan 26 17:25:59
2009
@@ -949,12 +949,22 @@
     //          transaction is rolled back and the application is disconnected
     //          from the remote database.
     final void doSyntaxrmSemantics(int syntaxErrorCode) throws DisconnectException {
-        agent_.accumulateChainBreakingReadExceptionAndThrow(
-            new DisconnectException(agent_,
+        DisconnectException e = new DisconnectException(agent_,
                 new ClientMessageId(SQLState.DRDA_CONNECTION_TERMINATED),
                 SqlException.getMessageUtil().getTextMessage(
                     MessageId.CONN_DRDA_DATASTREAM_SYNTAX_ERROR,
-                    new Integer(syntaxErrorCode))));
+                    new Integer(syntaxErrorCode)));
+            
+        // if we are communicating to an older server, we may get a SYNTAXRM on
+        // ACCSEC (missing codepoint RDBNAM) if we were unable to convert to
+        // EBCDIC (See DERBY-4008/DERBY-4004).  In that case we should chain 
+        // the original conversion exception, so it is clear to the user what
+        // the problem was.
+        if (netAgent_.exceptionConvertingRdbnam != null) {
+            e.setNextException(netAgent_.exceptionConvertingRdbnam);
+            netAgent_.exceptionConvertingRdbnam = null;
+        }
+        agent_.accumulateChainBreakingReadExceptionAndThrow(e);
     }
 
 

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectSimpleDSTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectSimpleDSTest.java?rev=737758&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectSimpleDSTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectSimpleDSTest.java
Mon Jan 26 17:25:59 2009
@@ -0,0 +1,109 @@
+/*
+ 
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.InternationalConnectSimpleDSTest
+ 
+   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.jdbcapi;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import junit.framework.Test;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBCDataSource;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+public class InternationalConnectSimpleDSTest extends BaseJDBCTestCase {
+
+    /**
+     * Test chinese characters in 
+     * - Database Name
+     * - User 
+     * - Password
+     * This test runs with J2ME and tests only simple DataSource.
+     * DriverManager, XADataSource and ConnectionPoolDataSource are tested with
+     * InternationalConnectTests which runs on J2SE.
+     */
+  
+    public InternationalConnectSimpleDSTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Test Connection for chinese database name, user and password.
+     * @throws SQLException
+     */
+    public void testSimpleDSConnect() throws SQLException {
+        // Test chinese database name.
+        DataSource ds = JDBCDataSource.getDataSource();
+        JDBCDataSource.setBeanProperty(ds, "databaseName", "\u4e10");
+        JDBCDataSource.setBeanProperty(ds, "createDatabase", "create");        
+        try {
+            Connection conn = ds.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        }   
+        // Chinese user
+        try {
+            JDBCDataSource.setBeanProperty(ds, "user", "\u4e10");
+            Connection conn = ds.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        } 
+        // Chinese password
+        try {
+            JDBCDataSource.setBeanProperty(ds, "password", "\u4e10");            
+            Connection conn = ds.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        } 
+    }
+    
+    public void tearDown() {
+        DataSource ds = JDBCDataSource.getDataSource("\u4e10");
+        JDBCDataSource.setBeanProperty(ds, "shutdownDatabase", "shutdown");
+        try {
+            ds.getConnection();
+        } catch (SQLException se) {
+            // ignore shutdown exception 
+        }
+        removeDirectory(getSystemProperty("derby.system.home") +
+                File.separator + "\u4e10");
+    }
+   
+    public static Test suite() {
+        return TestConfiguration.defaultSuite(InternationalConnectSimpleDSTest.class);
+    }
+    
+}
\ No newline at end of file

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java?rev=737758&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java
Mon Jan 26 17:25:59 2009
@@ -0,0 +1,243 @@
+/*
+ 
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.InternationalConnectTest
+ 
+   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.jdbcapi;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import javax.sql.ConnectionPoolDataSource;
+import javax.sql.PooledConnection;
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.J2EEDataSource;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+public class InternationalConnectTest extends BaseJDBCTestCase {
+
+    /**
+     * Test connecting with multibyte characters in:
+     * - Database name 
+     * - User
+     * - Password
+     * 
+     * Currently just throws an exception for client.
+     * Works ok for embedded.
+     * 
+     * This test tests DriverManager, XADataSource and ConnectionPoolDataSource
+     * and is not run with J2ME.  Simple DataSource is tested with 
+     * InternationalConnectSimpleDSTest
+     * 
+     */
+   
+    /**
+     * @param name
+     */
+    public InternationalConnectTest(String name) {
+        super(name);
+    
+    }
+
+    /**
+     * Test Chinese character in database name, user and password, using 
+     * DriverManager methods.
+     * 
+     * @throws SQLException
+     */
+    public void testDriverManagerConnect() throws SQLException {
+        //get a connection to load the driver
+        getConnection();
+        Connection conn = null;
+        String url = null;
+        try {
+            //Test Chinese database name
+            url = TestConfiguration.getCurrent().getJDBCUrl("\u4e10;create=true");
+            
+            conn = DriverManager.getConnection(url);
+            conn.close();
+        } catch (SQLException se) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        }            
+        try {
+            // Test Chinese user name
+            url = TestConfiguration.getCurrent().getJDBCUrl("\u4e10;user=\u4e10");
+            conn = DriverManager.getConnection(url);
+            conn.close();
+        } catch (SQLException se ){
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        }
+        try {
+            // Test Chinese user name in parameter to getConnection
+            url = TestConfiguration.getCurrent().getJDBCUrl("\u4e10");
+            conn = DriverManager.getConnection(url,"\u4e10","pass");
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        }
+        try {
+            // Test Chinese password in url
+            url = TestConfiguration.getCurrent().getJDBCUrl("\u4e10;user=user;password=\u4e10");
+            conn = DriverManager.getConnection(url);
+            conn.close();
+        } catch (SQLException se ){
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        }
+        try {
+            // Test Chinese password in parameter to getConnection()
+            url = TestConfiguration.getCurrent().getJDBCUrl("\u4e10");
+            conn = DriverManager.getConnection(url,"\u4e10","\u4e10");
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        }
+       
+    }
+    
+    
+    /**
+     * Test XA Connection for chinese database name, user and password.
+     * @throws SQLException
+     */
+    public void testXADSConnect() throws SQLException {
+        // Test chinese database name.
+        XADataSource ds = J2EEDataSource.getXADataSource();
+        J2EEDataSource.setBeanProperty(ds, "databaseName", "\u4e10");
+        J2EEDataSource.setBeanProperty(ds, "createDatabase", "create");        
+        try {
+            XAConnection xaconn = ds.getXAConnection();
+            Connection conn = xaconn.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        }   
+        // Chinese user
+        try {
+            J2EEDataSource.setBeanProperty(ds, "user", "\u4e10");
+            XAConnection xaconn = ds.getXAConnection();
+            Connection conn = xaconn.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        } 
+        // Chinese password
+        try {
+            J2EEDataSource.setBeanProperty(ds, "password", "\u4e10");
+            XAConnection xaconn = ds.getXAConnection();
+            Connection conn = xaconn.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        } 
+    }
+    
+    
+    /**
+     * Test pooled connetion for chinese database name, user and password.
+     * @throws SQLException
+     */
+    public void testCPDSConnect() throws SQLException {
+        // Test chinese database name.
+        ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
+        J2EEDataSource.setBeanProperty(ds, "databaseName", "\u4e10");
+        J2EEDataSource.setBeanProperty(ds, "createDatabase", "create");        
+        try {
+            PooledConnection poolConn = ds.getPooledConnection();
+            Connection conn = poolConn.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        }   
+        // Chinese user
+        try {
+            J2EEDataSource.setBeanProperty(ds, "user", "\u4e10");
+            PooledConnection poolConn = ds.getPooledConnection();
+            Connection conn = poolConn.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        } 
+        // Chinese password
+        try {
+            J2EEDataSource.setBeanProperty(ds, "password", "\u4e10");
+            PooledConnection poolConn= ds.getPooledConnection();
+            Connection conn = poolConn.getConnection();
+            conn.close();
+        } catch (SQLException se ) {
+            if (usingEmbedded())
+                throw se;
+            else
+                assertSQLState("22005",se);
+        } 
+    }
+    
+    public void tearDown() throws SQLException {
+        String shutdownUrl = TestConfiguration.getCurrent().getJDBCUrl("\u4e10;shutdown=true");
+        try {
+            DriverManager.getConnection(shutdownUrl);
+        } catch (SQLException se) {
+            // ignore shutdown exception
+        }
+        removeDirectory(getSystemProperty("derby.system.home") +  File.separator + 
+                "\u4e10");
+    }
+    
+    public static Test suite() {
+        return TestConfiguration.defaultSuite(InternationalConnectTest.class);
+    }
+   
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java?rev=737758&r1=737757&r2=737758&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
Mon Jan 26 17:25:59 2009
@@ -87,7 +87,8 @@
         suite.addTest(SavepointJdbc30Test.suite());
         suite.addTest(RelativeTest.suite());
         suite.addTest(metadataMultiConnTest.suite());
-	suite.addTest(ResultSetStreamTest.suite());
+        suite.addTest(ResultSetStreamTest.suite());
+        suite.addTest(InternationalConnectSimpleDSTest.suite());
         
         // Old harness .java tests that run using the HarnessJavaTest
         // adapter and continue to use a single master file.
@@ -155,6 +156,10 @@
                 suite.addTest(XAJNDITest.suite());
             }
             suite.addTest(InvalidLDAPServerAuthenticationTest.suite());
+            
+            // XA and ConnectionPool Datasource are not available with
+            // JSR169 so can't run InternationalConnectTest. 
+            suite.addTest(InternationalConnectTest.suite());
         }
 
         return suite;



Mime
View raw message