Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 38013 invoked from network); 26 Aug 2005 22:00:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Aug 2005 22:00:53 -0000 Received: (qmail 1712 invoked by uid 500); 26 Aug 2005 22:00:53 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 1692 invoked by uid 500); 26 Aug 2005 22:00:53 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 1678 invoked by uid 99); 26 Aug 2005 22:00:53 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 26 Aug 2005 15:00:52 -0700 Received: (qmail 38007 invoked by uid 65534); 26 Aug 2005 22:00:52 -0000 Message-ID: <20050826220052.37999.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r240352 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ Date: Fri, 26 Aug 2005 22:00:51 -0000 To: derby-commits@db.apache.org From: kmarsden@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: kmarsden Date: Fri Aug 26 15:00:39 2005 New Revision: 240352 URL: http://svn.apache.org/viewcvs?rev=240352&view=rev Log: DERBY-535 Driver.acceptsURL() for embedded driver incorrectly returns true for a client url like jdbc:derby:// Changed embedded driver to reject network URL's Added test for testing driver methods. Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDriver.out (with props) db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java (with props) Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java?rev=240352&r1=240351&r2=240352&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java Fri Aug 26 15:00:39 2005 @@ -44,7 +44,7 @@ public interface Attribute { /** - Not an attribute but the root for the JDBC URL that Cloudscape supports. + Not an attribute but the root for the JDBC URL that Derby supports. */ String PROTOCOL = "jdbc:derby:"; @@ -54,7 +54,21 @@ */ String SQLJ_NESTED = "jdbc:default:connection"; - + + // Network Protocols. These need to be rejected by the embedded driver. + + /** + * The protocol for Derby Network Client + */ + String DNC_PROTOCOL = "jdbc:derby://"; + + /** + * The protocol for the IBM Universal JDBC Driver + * + */ + String JCC_PROTOCOL = "jdbc:derby:net:"; + + /** Attribute name to encrypt the database on disk. If set to true, all user data is stored encrypted on disk. Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java?rev=240352&r1=240351&r2=240352&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 Aug 26 15:00:39 2005 @@ -102,7 +102,11 @@ ** Methods from java.sql.Driver */ public boolean acceptsURL(String url) { - return active && (url.startsWith(Attribute.PROTOCOL) || url.equals(Attribute.SQLJ_NESTED)); + return active && + // 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)); + } public Connection connect(String url, Properties info) Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDriver.out URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDriver.out?rev=240352&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDriver.out (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDriver.out Fri Aug 26 15:00:39 2005 @@ -0,0 +1,4 @@ +checking acceptsURL(jdbc:derby:wombat;create=true) +checking acceptsURL(jdbc:derby://localhost:1527/wombat;create=true) +checking acceptsURL(jdbc:derby:net://localhost:1527/wombat;create=true) +checking acceptsURL(jdbc:db2j:wombat;create=true) Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDriver.out ------------------------------------------------------------------------------ svn:eol-style = native Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java?rev=240352&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java Fri Aug 26 15:00:39 2005 @@ -0,0 +1,153 @@ +/* + +Derby - Class org.apache.derby.jdbc.EmbeddedDriver + +Copyright 2005 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.derbyTesting.functionTests.tests.jdbcapi; +import org.apache.derbyTesting.functionTests.util.TestUtil; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Properties; + +/** + * @author marsden + * + * This test tests java.sql.Driver methods. + * Right now it just tests acceptsURL. + * Tests for getPropertyInfo need to be added. as well as connection attributes + * + */ + +public class checkDriver { + + private static String EMBEDDED_URL = "jdbc:derby:wombat;create=true"; + private static String CLIENT_URL = "jdbc:derby://localhost:1527/wombat;create=true"; + private static String JCC_URL = "jdbc:derby:net://localhost:1527/wombat;create=true"; + private static String INVALID_URL = "jdbc:db2j:wombat;create=true"; + + // URLS to check. New urls need to also be added to the acceptsUrl table + private static String[] urls = new String[] + { + EMBEDDED_URL, + CLIENT_URL, + JCC_URL, + INVALID_URL, + }; + + + + + // The acceptsURLTable uses the frameworkOffset column int he table + // to check for valid results for each framework + private static int frameworkOffset; + + + private static int EMBEDDED_OFFSET = 0; + private static int DERBYNETCLIENT_OFFSET = 1; + private static int DERBYNET_OFFSET = 2; // JCC + + static { + if (TestUtil.isEmbeddedFramework()) + frameworkOffset = EMBEDDED_OFFSET; + else if (TestUtil.isDerbyNetClientFramework()) + frameworkOffset = DERBYNETCLIENT_OFFSET; + else if (TestUtil.isJCCFramework()) + frameworkOffset = DERBYNET_OFFSET; // JCC + } + + // Table that shows whether tested urls should return true for acceptsURL + // under the given framework + private static boolean[][] acceptsURLTable = new boolean[][] + { + // Framework/url EMBEDDED DERBYNETCLIENT DERBYNET (JCC) + /*EMBEDDED_URL */ { true , false , false }, + /*CLIENT_URL */ { false , true , false }, + /* JCC_URL */ { false , false , true }, + /* INVALID_URL */ { false , false , false } + }; + + + + public static void main(String[] args) { + try { + Driver driver = loadAndCheckDriverForFramework(); + checkAcceptsURL(driver); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + + /** + * + * @param driver + */ + private static void checkAcceptsURL(Driver driver) throws SQLException{ + for (int u = 0; u < urls.length;u++) + { + String url = urls[u]; + //System.out.println("acceptsURLTable[" + u +"][" + frameworkOffset+ "]"); + boolean expectedAcceptance = acceptsURLTable[u][frameworkOffset]; + boolean actualAcceptance = driver.acceptsURL(url); + System.out.println("checking acceptsURL(" + url + ")" ); + assertExpectedURLAcceptance(url, expectedAcceptance, actualAcceptance); + + } + + } + + + private static Driver loadAndCheckDriverForFramework() throws Exception + { + TestUtil.loadDriver(); + + String frameworkURL = TestUtil.getJdbcUrlPrefix() + "wombat;create=true"; + TestUtil.loadDriver(); + + // Test that we loaded the right driver by making a connection + Driver driver = DriverManager.getDriver(frameworkURL); + Properties props = new Properties(); + props.put("user","APP"); + props.put("password","xxx"); + Connection conn = driver.connect(frameworkURL,props); + //System.out.println("Successfully made connection for " + conn.getMetaData().getDriverName()); + conn.close(); + //System.out.println("jdbcCompliant = " + driver.jdbcCompliant()); + return driver; + } + + + + + private static void assertExpectedURLAcceptance(String url, boolean expectedAcceptance, + boolean actualAcceptance) + { + if (actualAcceptance != expectedAcceptance) + { + new Exception("FAILED acceptURL check. url = " + url + + " expectedAcceptance = " + expectedAcceptance + + " actualAcceptance = " + actualAcceptance).printStackTrace(System.out); + } + + } + + +} \ No newline at end of file Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant?rev=240352&r1=240351&r2=240352&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant Fri Aug 26 15:00:39 2005 @@ -6,6 +6,7 @@ blobclob4BLOB_derby.properties bestrowidentifier.sql bestrowidentifier_app.properties +checkDriver_app.properties dbMetaDataJdbc30_app.properties dbMetaDataJdbc30_sed.properties default_app.properties