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 dj...@apache.org on 2007/03/13 17:57:46 UTC

svn commit: r517770 - in /db/derby/code/trunk/java/engine/org/apache/derby: catalog/ impl/db/ impl/sql/execute/

Author: djd
Date: Tue Mar 13 09:57:45 2007
New Revision: 517770

URL: http://svn.apache.org/viewvc?view=rev&rev=517770
Log:
DERBY-2397 (refactor) Refactor the implementation of the SQLJ routines (INSTALL_JAR,
REMOVE_JAR and REPLACE_JAR) so that the methods for the system procedures directly
call the code to install, remove or replace a jar file. Previously these routines
created ConstantActions and executed those, resulting in four extra classes that
just routed the procedures to the real code. Since these executions are not DDL
statements they should not use ConstantAction, no Activation was available (since no
compilation) which meant that executeConstantAction() was called with null which
is not the intended api for a ConstantAction. This resulted in NPEs if modifying
code in these jar constant action to use the activation as might be expected from
looking at other ConstantAction implementations.

Removed:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AddJarConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropJarConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarDDL.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ReplaceJarConstantAction.java
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java?view=diff&rev=517770&r1=517769&r2=517770
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java Tue Mar 13 09:57:45 2007
@@ -21,34 +21,30 @@
 
 package org.apache.derby.catalog;
 
-import org.apache.derby.iapi.services.sanity.SanityManager;
-
-import org.apache.derby.iapi.services.i18n.MessageService;
-import org.apache.derby.iapi.error.PublicAPI;
-import org.apache.derby.iapi.error.StandardException;
-import org.apache.derby.iapi.reference.SQLState;
-import java.sql.ResultSet;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.DatabaseMetaData;
-import java.util.StringTokenizer;
 import java.util.NoSuchElementException;
 import java.util.Random;
+import java.util.StringTokenizer;
 
-import org.apache.derby.jdbc.InternalDriver;
 import org.apache.derby.iapi.db.Factory;
 import org.apache.derby.iapi.db.PropertyInfo;
-import org.apache.derby.impl.jdbc.Util;
-import org.apache.derby.impl.load.Export;
-import org.apache.derby.impl.load.Import;
-import org.apache.derby.impl.jdbc.EmbedDatabaseMetaData;
-
-import org.apache.derby.impl.sql.execute.JarDDL;
-import org.apache.derby.iapi.util.IdUtil;
 import org.apache.derby.iapi.error.PublicAPI;
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.services.i18n.MessageService;
 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.util.IdUtil;
+import org.apache.derby.impl.jdbc.EmbedDatabaseMetaData;
+import org.apache.derby.impl.jdbc.Util;
+import org.apache.derby.impl.load.Export;
+import org.apache.derby.impl.load.Import;
+import org.apache.derby.impl.sql.execute.JarUtil;
+import org.apache.derby.jdbc.InternalDriver;
 
 
 /**
@@ -969,26 +965,28 @@
 		throws SQLException {
 
 		try {
+            
+            LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
 
 			String[] st = IdUtil.parseQualifiedName(jar.trim(), true);
 
-			String schemaName = null;
-			String sqlName = null;
-
-			switch (st.length) {
-			case 1:
-				schemaName = null;
+			String schemaName;
+			String sqlName;
+            
+            if (st.length == 1)
+            {
+				schemaName = lcc.getCurrentSchemaName();
 				sqlName = st[0];
-				break;
-			case 2:
-				schemaName = st[0];
+            }
+            else
+            {
+                schemaName = st[0];
 				sqlName = st[1];
-			default:
-				; // RESOLVE
 			}
 
 			checkJarSQLName(sqlName);
-			JarDDL.add(schemaName, sqlName, url);
+            
+            JarUtil.install(lcc, schemaName, sqlName, url);
 		} 
 		catch (StandardException se) {
 			throw PublicAPI.wrapStandardException(se);
@@ -1009,26 +1007,29 @@
 		throws SQLException {
 
 		try {
+            
+            LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
 
 			String[] st = IdUtil.parseQualifiedName(jar.trim(), true);
 
-			String schemaName = null;
-			String sqlName = null;
-
-			switch (st.length) {
-			case 1:
-				schemaName = null;
-				sqlName = st[0];
-				break;
-			case 2:
-				schemaName = st[0];
-				sqlName = st[1];
-			default:
-				; // RESOLVE
-			}
+            String schemaName;
+            String sqlName;
+            
+            if (st.length == 1)
+            {
+                schemaName = lcc.getCurrentSchemaName();
+                sqlName = st[0];
+            }
+            else
+            {
+                schemaName = st[0];
+                sqlName = st[1];
+            }
 
 			checkJarSQLName(sqlName);
-			JarDDL.replace(schemaName, sqlName, url);
+            
+            JarUtil.replace(lcc,
+                    schemaName, sqlName, url);
 		} 
 		catch (StandardException se) {
 			throw PublicAPI.wrapStandardException(se);
@@ -1046,27 +1047,29 @@
 		throws SQLException {
 
 		try {
+            
+            LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
 
 			String[] st = IdUtil.parseQualifiedName(jar.trim(), true);
 
-			String schemaName = null;
-			String sqlName = null;
-
-			switch (st.length) {
-			case 1:
-				schemaName = null;
-				sqlName = st[0];
-				break;
-			case 2:
-				schemaName = st[0];
-				sqlName = st[1];
-			default:
-				; // RESOLVE
-			}
+            String schemaName;
+            String sqlName;
+            
+            if (st.length == 1)
+            {
+                schemaName = lcc.getCurrentSchemaName();
+                sqlName = st[0];
+            }
+            else
+            {
+                schemaName = st[0];
+                sqlName = st[1];
+            }
 
 			checkJarSQLName(sqlName);
+            
+            JarUtil.drop(lcc, schemaName, sqlName);
 
-			JarDDL.drop(schemaName, sqlName);
 		} 
 		catch (StandardException se) {
 			throw PublicAPI.wrapStandardException(se);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java?view=diff&rev=517770&r1=517769&r2=517770
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/db/BasicDatabase.java Tue Mar 13 09:57:45 2007
@@ -69,6 +69,7 @@
 import org.apache.derby.iapi.store.access.TransactionController;
 import org.apache.derby.iapi.jdbc.AuthenticationService;
 import org.apache.derby.iapi.services.uuid.UUIDFactory;
+import org.apache.derby.impl.sql.execute.JarUtil;
 import org.apache.derby.io.StorageFile;
 import org.apache.derby.catalog.UUID;
 
@@ -805,7 +806,7 @@
         ContextManager cm = ContextService.getFactory().getCurrentContextManager();
 		FileResource fr = af.getTransaction(cm).getFileHandler();
 
-		String externalName = org.apache.derby.impl.sql.execute.JarDDL.mkExternalName(schemaName, sqlName, fr.getSeparatorChar());
+		String externalName = JarUtil.mkExternalName(schemaName, sqlName, fr.getSeparatorChar());
 
 		return fr.getAsFile(externalName, generationId);
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java?view=diff&rev=517770&r1=517769&r2=517770
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java Tue Mar 13 09:57:45 2007
@@ -811,56 +811,6 @@
 										);
 	}
 
-	/**
-	 * Make the ConstantAction to Add a jar file to a database.
-	 *
-	 *	@param	schemaName			The SchemaName for the jar file.
-	 *	@param	sqlName			    The sqlName for the jar file.
-	 *  @param  externalPath            The name of the file that holds the jar.
-	 *  @exception StandardException Ooops
-	 */
-	public	ConstantAction getAddJarConstantAction(
-														 String schemaName,
-														 String sqlName,
-														 String externalPath)
-		 throws StandardException
-	{
-		getAuthorizer().authorize(Authorizer.JAR_WRITE_OP);
-		return new AddJarConstantAction(schemaName,sqlName,externalPath);
-	}
-	/**
-	 * Make the ConstantAction to replace a jar file in a database.
-	 *
-	 *	@param	schemaName			The SchemaName for the jar file.
-	 *	@param	sqlName			    The sqlName for the jar file.
-	 *  @param  externalPath            The name of the file that holds the new jar.
-	 *  @exception StandardException Ooops
-	 */
-	public	ConstantAction getReplaceJarConstantAction(
-														 String schemaName,
-														 String sqlName,
-														 String externalPath)
-		 throws StandardException
-	{
-		getAuthorizer().authorize(Authorizer.JAR_WRITE_OP);
-		return new ReplaceJarConstantAction(schemaName,sqlName,externalPath);
-	}
-	/**
-	 * Make the ConstantAction to drop a jar file from a database.
-	 *
-	 *	@param	schemaName			The SchemaName for the jar file.
-	 *	@param	sqlName			    The sqlName for the jar file.
-	 *  @exception StandardException Ooops
-	 */
-	public	ConstantAction getDropJarConstantAction(
-														  String schemaName,
-														  String sqlName)
-		 throws StandardException
-	{
-		getAuthorizer().authorize(Authorizer.JAR_WRITE_OP);
-		return new DropJarConstantAction(schemaName,sqlName);
-	}
-
 	static protected Authorizer getAuthorizer()
 	{
 		LanguageConnectionContext lcc = (LanguageConnectionContext)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java?view=diff&rev=517770&r1=517769&r2=517770
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java Tue Mar 13 09:57:45 2007
@@ -21,64 +21,60 @@
 
 package org.apache.derby.impl.sql.execute;
 
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+
+import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.Property;
-import org.apache.derby.iapi.util.IdUtil;
-import org.apache.derby.impl.sql.execute.JarDDL;
-import org.apache.derby.iapi.services.property.PropertyUtil;
+import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.loader.ClassFactory;
-import org.apache.derby.iapi.services.context.ContextService;
-import org.apache.derby.iapi.services.sanity.SanityManager;
-import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.property.PropertyUtil;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.sql.depend.DependencyManager;
 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor;
 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
-
-import org.apache.derby.iapi.sql.depend.DependencyManager;
-import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.store.access.FileResource;
-import org.apache.derby.catalog.UUID;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
+import org.apache.derby.iapi.util.IdUtil;
 
 
-class JarUtil
+public class JarUtil
 {
 	//
 	//State passed in by the caller
+    private LanguageConnectionContext lcc;
 	private String schemaName;
 	private String sqlName;
 
 	//Derived state
-	private LanguageConnectionContext lcc;
+	
 	private FileResource fr;
 	private DataDictionary dd;
 	private DataDescriptorGenerator ddg;
 	
 	//
 	//State derived from the caller's context
-	private JarUtil(String schemaName, String sqlName)
+	private JarUtil(LanguageConnectionContext lcc,
+            String schemaName, String sqlName)
 		 throws StandardException
 	{
 		this.schemaName = schemaName;
 		this.sqlName = sqlName;
 
-        lcc = (LanguageConnectionContext)
-			ContextService.getContext(LanguageConnectionContext.CONTEXT_ID);
+        this.lcc = lcc;
 		fr = lcc.getTransactionExecute().getFileHandler();
 		dd = lcc.getDataDictionary();
 		ddg = dd.getDataDescriptorGenerator();
 	}
 
 	/**
-	  Add a jar file to the current connection's database.
+	  install a jar file to the current connection's database.
 
 	  @param schemaName the name for the schema that holds the jar file.
 	  @param sqlName the sql name for the jar file.
@@ -87,11 +83,12 @@
 
 	  @exception StandardException Opps
 	  */
-	static long
-	add(String schemaName, String sqlName, String externalPath)
+	public static long
+	install(LanguageConnectionContext lcc,
+            String schemaName, String sqlName, String externalPath)
 		 throws StandardException
 	{
-		JarUtil jutil = new JarUtil(schemaName, sqlName);
+		JarUtil jutil = new JarUtil(lcc, schemaName, sqlName);
 		InputStream is = null;
 		
 		try {
@@ -130,7 +127,7 @@
         try {
             notifyLoader(false);
             dd.invalidateAllSPSPlans();
-            final String jarExternalName = JarDDL.mkExternalName(schemaName,
+            final String jarExternalName = JarUtil.mkExternalName(schemaName,
                     sqlName, fr.getSeparatorChar());
 
             long generationId = setJar(jarExternalName, is, true, 0L);
@@ -155,11 +152,11 @@
      * @exception StandardException
      *                Opps
      */
-	static void
-	drop(String schemaName, String sqlName)
+	public static void
+	drop(LanguageConnectionContext lcc, String schemaName, String sqlName)
 		 throws StandardException
 	{
-		JarUtil jutil = new JarUtil(schemaName,sqlName);
+		JarUtil jutil = new JarUtil(lcc, schemaName,sqlName);
 		jutil.drop();
 	}
 
@@ -211,7 +208,7 @@
 
 			dd.dropFileInfoDescriptor(fid);
 
-			fr.remove(JarDDL.mkExternalName(schemaName, sqlName, fr.getSeparatorChar()),
+			fr.remove(JarUtil.mkExternalName(schemaName, sqlName, fr.getSeparatorChar()),
 				fid.getGenerationId());
 		} finally {
 			notifyLoader(true);
@@ -230,12 +227,12 @@
 
 	  @exception StandardException Opps
 	  */
-	static long
-	replace(String schemaName, String sqlName,
+	public static long
+	replace(LanguageConnectionContext lcc, String schemaName, String sqlName,
 			String externalPath)
 		 throws StandardException
 	{
-		JarUtil jutil = new JarUtil(schemaName,sqlName);
+		JarUtil jutil = new JarUtil(lcc, schemaName,sqlName);
 		InputStream is = null;
 		
 
@@ -280,7 +277,7 @@
 			dd.invalidateAllSPSPlans();
 			dd.dropFileInfoDescriptor(fid);
             final String jarExternalName =
-                JarDDL.mkExternalName(schemaName, sqlName, fr.getSeparatorChar());
+                JarUtil.mkExternalName(schemaName, sqlName, fr.getSeparatorChar());
 
 			//
 			//Replace the file.
@@ -384,5 +381,21 @@
         } catch (PrivilegedActionException e) {
             throw (StandardException) e.getException();
         }
+    }
+    
+    /**
+      Make an external name for a jar file stored in the database.
+      */
+    public static String mkExternalName(String schemaName, String sqlName, char separatorChar)
+    {
+        StringBuffer sb = new StringBuffer(30);
+
+        sb.append(FileResource.JAR_DIRECTORY_NAME);
+        sb.append(separatorChar);
+        sb.append(schemaName);
+        sb.append(separatorChar);
+        sb.append(sqlName);
+        sb.append(".jar");
+        return sb.toString();
     }
 }