db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r884105 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
Date Wed, 25 Nov 2009 14:02:18 GMT
Author: kristwaa
Date: Wed Nov 25 14:02:17 2009
New Revision: 884105

URL: http://svn.apache.org/viewvc?rev=884105&view=rev
Log:
DERBY-4428 (partial): Add proper delete mechanism for in-memory databases 
Refactored code into getProtocolLeadIn()
Changed an ASSERT, as it expected equality between something that couldn't be
equal unless the default storage back end was used. It failed for the in-memory
back end, and would also fail for all other back ends. This code path hasn't
been enabled for other storage back ends before now (deleting the service root).

Patch file: derby-4428-3b-canonical_name_handling.diff


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.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=884105&r1=884104&r2=884105&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
Wed Nov 25 14:02:17 2009
@@ -639,15 +639,7 @@
 		Throwable t = null;
         try
         {
-			String protocolLeadIn = "";
-			//prepend the subsub protocol name to the storage factoty canonical
-			//name to form the service name except in case of the the 
-			//default subsubprototcol(PersistentService.DIRECTORY)
-
-			if (!(getType().equals( PersistentService.DIRECTORY))) 
-				protocolLeadIn = getType() + ":";
-
-            return protocolLeadIn + (String) AccessController.doPrivileged(
+            return getProtocolLeadIn() + (String) AccessController.doPrivileged(
                 new PrivilegedExceptionAction()
                 {
                     public Object run()
@@ -733,12 +725,23 @@
                         {
                             if (SanityManager.DEBUG)
                             {
+                                // Run this through getCanonicalServiceName as
+                                // an extra sanity check. Prepending the
+                                // protocol lead in to the canonical name from
+                                // the storage factory should be enough.
+                                String tmpCanonical = getCanonicalServiceName(
+                                        getProtocolLeadIn() +
+                                        storageFactory.getCanonicalName());
+                                // These should give the same result.
+                                SanityManager.ASSERT(
+                                        tmpCanonical.equals(getProtocolLeadIn()
+                                        + storageFactory.getCanonicalName()));
                                 SanityManager.ASSERT(
-                                    serviceName.equals(
-                                        storageFactory.getCanonicalName()), 
+                                    serviceName.equals(tmpCanonical),
                                     "serviceName = " + serviceName +
-                                    ";storageFactory.getCanonicalName() = " + 
-                                    storageFactory.getCanonicalName());
+                                    " ; protocolLeadIn + " +
+                                    "storageFactory.getCanoicalName = " +
+                                    tmpCanonical);
                             }
                             StorageFile serviceDirectory = storageFactory.newStorageFile(
null);
                             return serviceDirectory.deleteAll() ? this : null;
@@ -754,7 +757,6 @@
 	public String getCanonicalServiceName(String name)
 		throws StandardException
     {
-		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
@@ -766,17 +768,15 @@
         }
         if( colon > 1) // Subsubprotocols must be at least 2 characters long
         {
-            if( ! name.startsWith( protocolLeadIn))
+            if( ! name.startsWith(getType() + ":"))
                 return null; // It is not our database
             name = name.substring( colon + 1);
         }
-        if( getType().equals( PersistentService.DIRECTORY)) // The default subsubprototcol
-            protocolLeadIn = "";
         final String nm = name;
 
         try
         {
-            return protocolLeadIn + (String) AccessController.doPrivileged(
+            return getProtocolLeadIn() + (String) AccessController.doPrivileged(
                 new PrivilegedExceptionAction()
                 {
                     public Object run()
@@ -854,6 +854,24 @@
     {
         return storageFactoryClass;
     }
+
+    /**
+     * Returns the protocol lead in for this service.
+     *
+     * @return An empty string if the protocol is the default one
+     *      (PersistentService.DIRECTORY), the subsub protocol name followed by
+     *      colon otherwise.
+     */
+    private String getProtocolLeadIn() {
+        // We prepend the subsub protocol name to the storage factory canonical
+        // name to form the service name, except in case of the default
+        // subsub prototcol (which is PersistentService.DIRECTORY).
+        if (getType().equals(PersistentService.DIRECTORY)) {
+            return "";
+        } else {
+            return getType() + ":";
+        }
+    }
     
     final class DirectoryList implements Enumeration, PrivilegedAction
     {



Mime
View raw message