db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r753239 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
Date Fri, 13 Mar 2009 13:23:25 GMT
Author: kristwaa
Date: Fri Mar 13 13:23:24 2009
New Revision: 753239

URL: http://svn.apache.org/viewvc?rev=753239&view=rev
Log:
DERBY-4093: Improve handling of the database temporary directory.
Defers creation of the temporary directory until Derby is ready (when
uniqueName is specified), and makes the temporary database directory
always be created within the database directory.
Patch file: derby-4093-1b-tmp_dir_handling.diff


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.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/io/VFMemoryStorageFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java?rev=753239&r1=753238&r2=753239&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java Fri
Mar 13 13:23:24 2009
@@ -69,7 +69,7 @@
     private String canonicalName;
     /** The data directory of the database. */
     private StorageFile dataDirectory;
-    /** The temporary directory for the database. */
+    /** The temporary directory for the database (absolute path). */
     private StorageFile tempDir;
     /** The data store used for the database. */
     private DataStore dbData;
@@ -94,12 +94,13 @@
      * @param databaseName the name of the database, all relative pathnames are
      *      relative to this name
      * @param tempDirNameIgnored ignored
-     * @param uniqueNameIgnored ignored
+     * @param uniqueName used to determine when the temporary directory can be
+     *      created, but not to name the temporary directory itself
      *
      * @exception IOException on an error (unexpected).
      */
     public void init(String home, String databaseName,
-                     String tempDirNameIgnored, String uniqueNameIgnored)
+                     String tempDirNameIgnored, String uniqueName)
             throws IOException {
         // Handle cases where a database name is specified.
         if (databaseName != null) {
@@ -124,7 +125,8 @@
             }
             // Specify the data directory and the temp directory.
             dataDirectory = new VirtualFile(canonicalName, dbData);
-            tempDir = new VirtualFile(getSeparator() + "tmp", dbData);
+            tempDir = new VirtualFile(PathUtil.join(canonicalName, "tmp"),
+                                      dbData);
 
         // Handle cases where the database name is null, but a system home
         // directory has been specified.
@@ -145,7 +147,10 @@
         }
 
         // Create the temporary directory, if one has been specified.
-        if (tempDir != null && !tempDir.exists()) {
+        // Creating the temporary directory too early casues the
+        // BaseDataFileFactory to fail, hence the check for uniqueName.
+        // This check is also used by BaseStorageFactory.
+        if (uniqueName != null && tempDir != null && !tempDir.exists()) {
             tempDir.mkdirs();
         }
     }

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=753239&r1=753238&r2=753239&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
Fri Mar 13 13:23:24 2009
@@ -165,6 +165,46 @@
         // How to fix that?
     }
 
+    /**
+     * Makes sure shutting down an in-memory database works.
+     *
+     * @throws SQLException if something goes wrong
+     */
+    public void testShutdown()
+            throws SQLException {
+        DriverManager.getConnection("jdbc:derby:memory:/tmp/myDB;create=true");
+        try {
+            DriverManager.getConnection(
+                    "jdbc:derby:memory:/tmp/myDB;shutdown=true");
+            fail("Engine shutdown should have caused exception");
+        } catch (SQLException sqle) {
+            assertSQLState("08006", sqle);
+        }
+    }
+
+    /**
+     * Makes sure shutting down the Derby engine with an in-memory database
+     * already booted works.
+     * <p>
+     * Related to DERBY-4093
+     *
+     * @throws SQLException if something goes wrong
+     */
+    public void testEnginehutdown()
+            throws SQLException {
+        DriverManager.getConnection("jdbc:derby:memory:/tmp/myDB;create=true");
+        try {
+            DriverManager.getConnection(
+                    "jdbc:derby:;shutdown=true");
+            fail("Engine shutdown should have caused exception");
+        } catch (SQLException sqle) {
+            assertSQLState("XJ015", sqle);
+        }
+        // Another hack, to make sure later tests in this class doesn't fail.
+        // Get a connection to the default database to reload the engine.
+        getConnection();
+    }
+
     public static Test suite() {
         // Run only in embedded-mode for now.
         return new SupportFilesSetup(new TestSuite(BasicInMemoryDbTest.class));



Mime
View raw message