db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r786043 - in /db/derby/code/branches/10.5/java: engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
Date Thu, 18 Jun 2009 12:50:55 GMT
Author: kristwaa
Date: Thu Jun 18 12:50:55 2009
New Revision: 786043

URL: http://svn.apache.org/viewvc?rev=786043&view=rev
Log:
DERBY-4171: Connections to on-disk db go to in-memory db if in-memory db with same name is
booted.
Merged fix from trunk (782954, 784682).

Modified:
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java?rev=786043&r1=786042&r2=786043&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
Thu Jun 18 12:50:55 2009
@@ -756,6 +756,14 @@
     {
 		String protocolLeadIn = getType() + ":";
         int colon = name.indexOf( ':');
+        // If no subsubprotocol is specified and the storage factory type isn't
+        // the default one, abort. We have to deal with Windows drive
+        // specifications here, which contain a colon (i.e. 'C:').
+        // The logic in this method may break in some cases if a colon is used
+        // in the directory or database name.
+        if (colon < 2 && !getType().equals(PersistentService.DIRECTORY)) {
+            return null;
+        }
         if( colon > 1) // Subsubprotocols must be at least 2 characters long
         {
             if( ! name.startsWith( protocolLeadIn))

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java?rev=786043&r1=786042&r2=786043&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
Thu Jun 18 12:50:55 2009
@@ -205,6 +205,37 @@
         getConnection();
     }
 
+    /**
+     * Verify that booting two databases with the same name but with different
+     * subsubprotocols doesn't result in two connections to the same database.
+     *
+     * @throws SQLException if something goes wrong
+     */
+    public void testBootSameDbDifferentSubSubProtocol()
+            throws SQLException {
+        final String dbName = "BSDDSSP";
+        // Connect to the in-memory database and create a table.
+        Connection con1 = DriverManager.getConnection(
+                "jdbc:derby:memory:" + dbName + ";create=true");
+        Statement stmt1 = con1.createStatement();
+        stmt1.execute("create table t (text varchar(255))");
+        stmt1.execute("insert into t values ('Inserted into in-memory db')");
+        // Connect to the on-disk database. The table we created in the
+        // in-memory database shouldn't exist in the on-disk database.
+        Connection con2 = DriverManager.getConnection(
+                "jdbc:derby:" + dbName + ";create=true");
+        // Table t should not exist.
+        Statement stmt2 = con2.createStatement();
+        try {
+            stmt2.executeQuery("select * from t");
+            fail("Table 't' should not exist");
+        } catch (SQLException sqle) {
+            assertSQLState("42X05", sqle);
+        }
+        con2.close();
+        con1.close();
+    }
+
     public static Test suite() {
         // Run only in embedded-mode for now.
         return new SupportFilesSetup(new TestSuite(BasicInMemoryDbTest.class));



Mime
View raw message