You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2009/06/09 12:56:41 UTC
svn commit: r782954 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
Author: kristwaa
Date: Tue Jun 9 10:56:40 2009
New Revision: 782954
URL: http://svn.apache.org/viewvc?rev=782954&view=rev
Log:
DERBY-4171: Connections to on-disk db go to in-memory db if in-memory db with same name is booted.
If the storage factory isn't the default one (DIRECTORY), don't allow
connections without a subsubprotocol specified.
Added a test.
Patch file: derby-4171-1b-fix.diff
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java?rev=782954&r1=782953&r2=782954&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java Tue Jun 9 10:56:40 2009
@@ -756,6 +756,11 @@
{
String protocolLeadIn = getType() + ":";
int colon = name.indexOf( ':');
+ // If no subsubprotocol is specified and the storage factory type isn't
+ // the default one, abort.
+ if (colon == -1 && !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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java?rev=782954&r1=782953&r2=782954&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java Tue Jun 9 10:56:40 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));