db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r517756 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/dictionary/ impl/sql/execute/
Date Tue, 13 Mar 2007 16:26:05 GMT
Author: djd
Date: Tue Mar 13 09:25:59 2007
New Revision: 517756

URL: http://svn.apache.org/viewvc?view=rev&rev=517756
Log:
DERBY-2397 (cleanup) Move drop code to SchemaDescriptor and AliasDescriptor and clean up
various comments related to these objects.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSchemaConstantAction.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java?view=diff&rev=517756&r1=517755&r2=517756
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
Tue Mar 13 09:25:59 2007
@@ -21,7 +21,10 @@
 
 package org.apache.derby.iapi.sql.dictionary;
 
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.sql.depend.DependencyManager;
 import org.apache.derby.iapi.sql.depend.Provider;
+import org.apache.derby.iapi.store.access.TransactionController;
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.sanity.SanityManager;
@@ -327,5 +330,59 @@
     public boolean isPersistent()
     {
         return !getSchemaUUID().toString().equals(SchemaDescriptor.SYSFUN_SCHEMA_UUID);
+    }
+   
+    /**
+     * Drop the routine or synonym.
+     * For a routine its permission descriptors will be dropped as well.
+     * For a synonym its TableDescriptor will be dropped as well.
+     * @param lcc
+     * @throws StandardException
+     */
+    public void drop(LanguageConnectionContext lcc) throws StandardException {
+        
+        DataDictionary dd = getDataDictionary();
+        TransactionController tc = lcc.getTransactionExecute();
+        DependencyManager dm = dd.getDependencyManager();
+        
+        
+        /* Prepare all dependents to invalidate.  (This is their chance
+         * to say that they can't be invalidated.  For example, an open
+         * cursor referencing a table/view that the user is attempting to
+         * drop.) If no one objects, then invalidate any dependent objects.
+         * We check for invalidation before we drop the descriptor
+         * since the descriptor may be looked up as part of
+         * decoding tuples in SYSDEPENDS.
+         */
+        int invalidationType = 0;
+        switch (getAliasType())
+        {
+        case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
+        case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
+            invalidationType = DependencyManager.DROP_METHOD_ALIAS;
+            break;
+            
+        case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+            invalidationType = DependencyManager.DROP_SYNONYM;
+            break;
+        }
+        
+        dm.invalidateFor(this, invalidationType, lcc);
+        
+        if (getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
+        {
+            SchemaDescriptor sd = dd.getSchemaDescriptor(schemaID, tc);
+            
+            // Drop the entry from SYSTABLES as well.
+            DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
+            TableDescriptor td = ddg.newTableDescriptor(aliasName, sd,
+                    TableDescriptor.SYNONYM_TYPE, TableDescriptor.DEFAULT_LOCK_GRANULARITY);
+            dd.dropTableDescriptor(td, sd, tc);
+        }
+        else
+            dd.dropAllRoutinePermDescriptors(getUUID(), tc);
+        
+        /* Drop the alias */
+        dd.dropAliasDescriptor(this, tc);
     }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java?view=diff&rev=517756&r1=517755&r2=517756
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
Tue Mar 13 09:25:59 2007
@@ -21,10 +21,15 @@
 
 package org.apache.derby.iapi.sql.dictionary;
 
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.sql.depend.DependencyManager;
 import org.apache.derby.iapi.sql.depend.Provider;
+import org.apache.derby.iapi.store.access.TransactionController;
 import org.apache.derby.catalog.DependableFinder;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
+import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.Property;
+import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.catalog.Dependable;
 
@@ -358,5 +363,60 @@
 	public String getDescriptorType()
 	{
 		return "Schema";
+    }
+    
+    /**
+     * Drop this schema.
+     * Drops the schema if it is empty. If the schema was
+     * the current default then the current default will be
+     * reset through the language connection context.
+     * @throws StandardException Schema could not be dropped.
+     */
+	public void drop(LanguageConnectionContext lcc) throws StandardException
+	{
+        DataDictionary dd = getDataDictionary();
+        DependencyManager dm = dd.getDependencyManager();
+        TransactionController tc = lcc.getTransactionExecute();
+       
+	    //If user is attempting to drop SESSION schema and there is no physical SESSION schema,
then throw an exception
+	    //Need to handle it this special way is because SESSION schema is also used for temporary
tables. If there is no
+	    //physical SESSION schema, we internally generate an in-memory SESSION schema in order
to support temporary tables
+	    //But there is no way for the user to access that in-memory SESSION schema. Following
if will be true if there is
+	    //no physical SESSION schema and hence getSchemaDescriptor has returned an in-memory
SESSION schema
+	    if (getSchemaName().equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME)
+                && (getUUID() == null))
+	        throw StandardException.newException(SQLState.LANG_SCHEMA_DOES_NOT_EXIST, getSchemaName());
+	    
+	    /*
+	     ** Make sure the schema is empty.
+	     ** In the future we want to drop everything
+	     ** in the schema if it is CASCADE.
+	     */
+	    if (!dd.isSchemaEmpty(this))
+	    {
+	        throw StandardException.newException(SQLState.LANG_SCHEMA_NOT_EMPTY, getSchemaName());
+	    } 
+	    
+	    /* Prepare all dependents to invalidate.  (This is there chance
+	     * to say that they can't be invalidated.  For example, an open
+	     * cursor referencing a table/view that the user is attempting to
+	     * drop.) If no one objects, then invalidate any dependent objects.
+	     */
+	    dm.invalidateFor(this, DependencyManager.DROP_SCHEMA, lcc);
+	    
+	    dd.dropSchemaDescriptor(getSchemaName(), tc);
+	    
+	    /*
+	     ** If we have dropped the current default schema,
+	     ** then we will set the default to null.  The
+	     ** LCC is free to set the new default schema to 
+	     ** some system defined default.
+	     */
+	    SchemaDescriptor currentDefault = lcc.getDefaultSchema();
+	    if ((currentDefault != null) &&
+                getSchemaName().equals(currentDefault.getSchemaName()))
+	    {
+	        lcc.setDefaultSchema((SchemaDescriptor)null);
+	    }        
 	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java?view=diff&rev=517756&r1=517755&r2=517756
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
Tue Mar 13 09:25:59 2007
@@ -39,9 +39,10 @@
 import org.apache.derby.iapi.store.access.TransactionController;
 
 /**
- *	This class  describes actions that are ALWAYS performed for a
+ *	This class performs actions that are ALWAYS performed for a
  *	CREATE FUNCTION, PROCEDURE or SYNONYM Statement at execution time.
- *  These SQL objects are stored in the SYS.SYSALIASES table.
+ *  These SQL objects are stored in the SYS.SYSALIASES table and
+ *  represented as AliasDescriptors.
  *
  */
 class CreateAliasConstantAction extends DDLConstantAction
@@ -141,9 +142,34 @@
 	/**
 	 *	This is the guts of the Execution-time logic for
      *  CREATE FUNCTION, PROCEDURE or SYNONYM.
-     *  Each will result in a row inserted into SYS.SYSALIASES.
-	 *
-	 *	@see ConstantAction#executeConstantAction
+     *  <P>
+     *  A routine (function or procedure) is represented as:
+     *  <UL>
+     *  <LI> AliasDescriptor
+     *  </UL>
+     *  Routine dependencies are created as:
+     *  <UL>
+     *  <LI> None
+     *  </UL>
+     *  
+     *  <P>
+     *  A synonym is represented as:
+     *  <UL>
+     *  <LI> AliasDescriptor
+     *  <LI> TableDescriptor
+     *  </UL>
+     *  Synonym dependencies are created as:
+     *  <UL>
+     *  <LI> None
+     *  </UL>
+     *  
+     *  In both cases a SchemaDescriptor will be created if
+     *  needed. No dependency is created on the SchemaDescriptor.
+     *  
+	 * @see ConstantAction#executeConstantAction
+     * @see AliasDescriptor
+     * @see TableDescriptor
+     * @see SchemaDescriptor
 	 *
 	 * @exception StandardException		Thrown on failure
 	 */
@@ -272,6 +298,6 @@
 		}
 
 		dd.addDescriptor(ads, null, DataDictionary.SYSALIASES_CATALOG_NUM,
-						 false, lcc.getTransactionExecute());
+						 false, tc);
 	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java?view=diff&rev=517756&r1=517755&r2=517756
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java
Tue Mar 13 09:25:59 2007
@@ -21,23 +21,19 @@
 
 package org.apache.derby.impl.sql.execute;
 
-import org.apache.derby.catalog.AliasInfo;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.sql.Activation;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
-import org.apache.derby.iapi.sql.depend.DependencyManager;
 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
-import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
-import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
 import org.apache.derby.iapi.sql.execute.ConstantAction;
-import org.apache.derby.iapi.store.access.TransactionController;
 
 /**
- *	This class  describes actions that are ALWAYS performed for a
- *	DROP ALIAS Statement at Execution time.
+ *	This class performs actions that are ALWAYS performed for a
+ *	DROP FUNCTION/PROCEDURE/SYNONYM statement at execution time.
+ *  All of these SQL objects are represented by an AliasDescriptor.
  *
  */
 
@@ -45,7 +41,6 @@
 {
 
 	private SchemaDescriptor	sd;
-	private final String schemaName;
 	private final String				aliasName;
 	private final char				nameSpace;
 
@@ -63,7 +58,6 @@
 	DropAliasConstantAction(SchemaDescriptor sd, String aliasName, char nameSpace)
 	{
 		this.sd = sd;
-		this.schemaName = sd.getSchemaName();
 		this.aliasName = aliasName;
 		this.nameSpace = nameSpace;
 	}
@@ -92,9 +86,6 @@
 	{
 		LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
 		DataDictionary dd = lcc.getDataDictionary();
-		TransactionController tc = lcc.getTransactionExecute();
-		DependencyManager dm = dd.getDependencyManager();
-
 
 		/*
 		** Inform the data dictionary that we are about to write to it.
@@ -107,11 +98,6 @@
 		*/
 		dd.startWriting(lcc);
 
-		if (sd == null) {
-			sd = dd.getSchemaDescriptor(schemaName, lcc.getTransactionExecute(), true);
-		}
-
-
 		/* Get the alias descriptor.  We're responsible for raising
 		 * the error if it isn't found 
 		 */
@@ -122,43 +108,8 @@
 		{
 			throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, ad.getAliasType(nameSpace),
 aliasName);
 		}
-
-		/* Prepare all dependents to invalidate.  (This is their chance
-		 * to say that they can't be invalidated.  For example, an open
-		 * cursor referencing a table/view that the user is attempting to
-		 * drop.) If no one objects, then invalidate any dependent objects.
-		 * We check for invalidation before we drop the descriptor
-		 * since the descriptor may be looked up as part of
-		 * decoding tuples in SYSDEPENDS.
-		 */
-		int invalidationType = 0;
-		switch (ad.getAliasType())
-		{
-			case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
-			case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
-				invalidationType = DependencyManager.DROP_METHOD_ALIAS;
-				break;
-
-			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
-				invalidationType = DependencyManager.DROP_SYNONYM;
-				break;
-		}
-
-		dm.invalidateFor(ad, invalidationType, lcc);
-
-		if (ad.getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
-		{
-			// Drop the entry from SYSTABLES as well.
-			DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
-			TableDescriptor td = ddg.newTableDescriptor(aliasName, sd,
-				TableDescriptor.SYNONYM_TYPE, TableDescriptor.DEFAULT_LOCK_GRANULARITY);
-			dd.dropTableDescriptor(td, sd, tc);
-		}
-		else
-			dd.dropAllRoutinePermDescriptors(ad.getUUID(), tc);
-			
-		/* Drop the alias */
-		dd.dropAliasDescriptor(ad, tc);
+        
+        ad.drop(lcc);
 
 	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSchemaConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSchemaConstantAction.java?view=diff&rev=517756&r1=517755&r2=517756
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSchemaConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSchemaConstantAction.java
Tue Mar 13 09:25:59 2007
@@ -21,25 +21,13 @@
 
 package org.apache.derby.impl.sql.execute;
 
-import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.error.StandardException;
-import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
-import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
+import org.apache.derby.iapi.sql.Activation;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
-
-import org.apache.derby.iapi.sql.depend.DependencyManager;
-import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
-import org.apache.derby.iapi.store.access.TransactionController;
-
-import org.apache.derby.iapi.reference.SQLState;
-
 import org.apache.derby.iapi.sql.execute.ConstantAction;
 
-import org.apache.derby.iapi.sql.Activation;
-
-import org.apache.derby.catalog.UUID;
-
 /**
  *	This class  describes actions that are ALWAYS performed for a
  *	DROP SCHEMA Statement at Execution time.
@@ -92,12 +80,8 @@
 	public void	executeConstantAction( Activation activation )
 						throws StandardException
 	{
-		SchemaDescriptor	sd;
-
 		LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
 		DataDictionary dd = lcc.getDataDictionary();
-		DependencyManager dm = dd.getDependencyManager();
-		TransactionController tc = lcc.getTransactionExecute();
 
 		/*
 		** Inform the data dictionary that we are about to write to it.
@@ -110,50 +94,9 @@
 		*/
 		dd.startWriting(lcc);
 
-		sd = dd.getSchemaDescriptor(schemaName, null, true);
-
-    //If user is attempting to drop SESSION schema and there is no physical SESSION schema,
then throw an exception
-    //Need to handle it this special way is because SESSION schema is also used for temporary
tables. If there is no
-    //physical SESSION schema, we internally generate an in-memory SESSION schema in order
to support temporary tables
-    //But there is no way for the user to access that in-memory SESSION schema. Following
if will be true if there is
-    //no physical SESSION schema and hence getSchemaDescriptor has returned an in-memory
SESSION schema
-    if (schemaName.equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME)
&& (sd != null) && (sd.getUUID() == null))
-			throw StandardException.newException(SQLState.LANG_SCHEMA_DOES_NOT_EXIST, schemaName);
-
-		/*
-		** Make sure the schema is empty.
-		** In the future we want to drop everything
-		** in the schema if it is CASCADE.
-		*/
-		if (!dd.isSchemaEmpty(sd))
-		{
-			throw StandardException.newException(SQLState.LANG_SCHEMA_NOT_EMPTY, schemaName);
-		} 
-
-		/* Prepare all dependents to invalidate.  (This is there chance
-		 * to say that they can't be invalidated.  For example, an open
-		 * cursor referencing a table/view that the user is attempting to
-		 * drop.) If no one objects, then invalidate any dependent objects.
-		 * We check for invalidation before we drop the table descriptor
-		 * since the table descriptor may be looked up as part of
-		 * decoding tuples in SYSDEPENDS.
-		 */
-		dm.invalidateFor(sd, DependencyManager.DROP_SCHEMA, lcc);
-
-		dd.dropSchemaDescriptor(schemaName, tc);
+        SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);
 
-		/*
-		** If we have dropped the current default schema,
-		** then we will set the default to null.  The
-		** LCC is free to set the new default schema to 
-	 	** some system defined default.
-		*/
-		sd = lcc.getDefaultSchema();
-		if ((sd != null) &&
-			schemaName.equals(sd.getSchemaName()))
-		{
-			lcc.setDefaultSchema((SchemaDescriptor)null);
-		}
+        sd.drop(lcc);
 
 	}
 



Mime
View raw message