db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1041192 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/catalog/ storeless/org/apache/derby/impl/storeless/
Date Wed, 01 Dec 2010 22:23:21 GMT
Author: kristwaa
Date: Wed Dec  1 22:23:20 2010
New Revision: 1041192

URL: http://svn.apache.org/viewvc?rev=1041192&view=rev
Log:
DERBY-4918: Minor refactoring of SPSDescriptor

Minor cleanup, including:
 o declare variables final where appropriate
 o replace Vector with List (local use, synchronization not needed)
 o added/removed synchronize keyword where appropriate
 o added/corrected some comments/documentation

Patch file: derby-4918-1a-misc.diff (moved import line in DataDictImpl)

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java?rev=1041192&r1=1041191&r2=1041192&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
Wed Dec  1 22:23:20 2010
@@ -21,19 +21,10 @@
 
 package org.apache.derby.iapi.sql.dictionary;
 
-import org.apache.derby.iapi.services.context.ContextManager;
-
 import org.apache.derby.iapi.sql.depend.DependencyManager;
-import org.apache.derby.iapi.sql.depend.Dependent;
-import org.apache.derby.iapi.sql.depend.Provider;
-
-import org.apache.derby.iapi.sql.PreparedStatement;
 import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.NumberDataValue;
 import org.apache.derby.iapi.types.DataValueFactory;
-import org.apache.derby.iapi.types.DataValueDescriptor;
-import org.apache.derby.iapi.types.StringDataValue;
-import org.apache.derby.iapi.sql.compile.CostEstimate;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
 import org.apache.derby.iapi.error.StandardException;
@@ -47,8 +38,6 @@ import org.apache.derby.iapi.services.uu
 import java.sql.Types;
 import java.util.List;
 import java.util.Hashtable;
-import java.util.Properties;
-import java.util.Vector;
 
 /**
  * The DataDictionary interface is used with the data dictionary to get
@@ -1074,8 +1063,8 @@ public interface DataDictionary
 	 *
 	 * @exception StandardException		Thrown on error
 	 */
-	public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, Vector defaults)
-		throws StandardException;
+    public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, List defaults)
+            throws StandardException;
 
 	/**
 	 * Adds the given SPSDescriptor to the data dictionary,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java?rev=1041192&r1=1041191&r2=1041192&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
Wed Dec  1 22:23:20 2010
@@ -22,8 +22,8 @@
 package org.apache.derby.iapi.sql.dictionary;
 
 import java.sql.Timestamp;
-import java.util.Enumeration;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.derby.catalog.Dependable;
 import org.apache.derby.catalog.DependableFinder;
@@ -43,7 +43,6 @@ import org.apache.derby.iapi.sql.conn.La
 import org.apache.derby.iapi.sql.depend.DependencyManager;
 import org.apache.derby.iapi.sql.depend.Dependent;
 import org.apache.derby.iapi.sql.depend.Provider;
-import org.apache.derby.iapi.sql.depend.ProviderInfo;
 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement;
 import org.apache.derby.iapi.store.access.TransactionController;
 import org.apache.derby.iapi.types.DataTypeDescriptor;
@@ -73,7 +72,7 @@ public class SPSDescriptor extends Tuple
 	/**
 	 * Statement types.  
 	 * <UL>
-	 * <LI> SPS_TYPE_TRIGGER	- trigger (<B>NOT IMPLEMENTED</B>) </LI>
+     * <LI> SPS_TYPE_TRIGGER    - trigger</LI>
 	 * <LI> SPS_TYPE_EXPLAIN	- explain (<B>NOT IMPLEMENTED</B>) </LI>
 	 * <LI> SPS_TYPE_REGULAR	- catchall</LI>
 	 * </UL>
@@ -119,14 +118,15 @@ public class SPSDescriptor extends Tuple
 
 		
 	// Class contents
-	private SchemaDescriptor		sd;
-	private String					name;
+    private final SchemaDescriptor sd;
+    private final String name;
+    private final UUID compSchemaId;
+    private final char type;
+    private final String text;
+    private final String usingText;
+
 	private UUID					uuid;
-	private UUID					compSchemaId;
-	private char					type;
 	private	boolean					valid;
-	private	String					text;
-	private	String					usingText;
 	private	ExecPreparedStatement	preparedStatement;
 	private	DataTypeDescriptor		params[];
 	private	Timestamp				compileTime;
@@ -303,6 +303,19 @@ public class SPSDescriptor extends Tuple
 		prepareAndRelease(lcc, (TableDescriptor)null, (TransactionController)null);
 	}
 
+    /**
+     * Compiles this SPS.
+     * <p>
+     * <em>Note:</em> This SPS may still be marked as invalid after this method
+     * has completed, because an invalidation request may have been received
+     * while compiling.
+     *
+     * @param lcc connection
+     * @param triggerTable subject table (may be {@code null})
+     * @param tc transaction controller to use (may be {@code null})
+     * @throws StandardException if something fails
+     */
+    //@GuardedBy("this")
 	private void compileStatement
 	(
 		LanguageConnectionContext	lcc,
@@ -312,9 +325,6 @@ public class SPSDescriptor extends Tuple
 		throws StandardException
 	{
 		ContextManager cm = lcc.getContextManager();
-		DependencyManager dm;
-		ProviderInfo[] providerInfo;
-
 		LanguageConnectionFactory	lcf = lcc.getLanguageConnectionFactory();
 
 		DataDictionary dd = getDataDictionary();
@@ -330,6 +340,8 @@ public class SPSDescriptor extends Tuple
 		*/
 		if (type == SPS_TYPE_TRIGGER && triggerTable == null)
 		{
+            // 49 because name consists of (see CreateTriggerConstantAction):
+            // TRIGGER<ACTN|WHEN>_<UUID:36>_<UUID:36>
 			String uuidStr = name.substring(49);
 			triggerTable = dd.getTableDescriptor(recreateUUID(uuidStr));
 			if (SanityManager.DEBUG)
@@ -386,7 +398,7 @@ public class SPSDescriptor extends Tuple
 			*/
 			dd.startWriting(lcc);
 
-			dm = dd.getDependencyManager();
+            DependencyManager dm = dd.getDependencyManager();
 			/*
 			** Clear out all the dependencies that exist
 			** before we recreate them so we don't grow
@@ -457,12 +469,9 @@ public class SPSDescriptor extends Tuple
 	 *
 	 * @return type as a string
 	 */	
-	public final String getTypeAsString()
-	{
-		char[] charArray = new char[1];
-		charArray[0] = type;
-		return new String(charArray);
-	}
+    public final String getTypeAsString() {
+        return String.valueOf(type);
+    }
 
 	/**
 	 * Is the statement initially compilable?  
@@ -480,7 +489,7 @@ public class SPSDescriptor extends Tuple
 	 *
 	 * @return true/false	
 	 */
-	public final static boolean validType(char type)
+    public static boolean validType(char type)
 	{
 		return (type == SPSDescriptor.SPS_TYPE_REGULAR) || 
 				(type == SPSDescriptor.SPS_TYPE_TRIGGER);
@@ -522,7 +531,7 @@ public class SPSDescriptor extends Tuple
 	 *
 	 * @return The text
 	 */
-	public final synchronized String getUsingText()
+    public final String getUsingText()
 	{
 		return usingText;
 	}
@@ -542,8 +551,7 @@ public class SPSDescriptor extends Tuple
 	 *
 	 * @return	the uuid
 	 */
-	public final UUID	getUUID()
-	{
+    public final synchronized UUID getUUID() {
 		return uuid;
 	}
 	
@@ -561,19 +569,12 @@ public class SPSDescriptor extends Tuple
 	public final synchronized DataTypeDescriptor[] getParams()
 		throws StandardException
 	{
-		if (params == null && !lookedUpParams)
-		{
-			Vector v = new Vector();
-			params = getDataDictionary().getSPSParams(this, v);
-			paramDefaults = new Object[v.size()];	
-			Enumeration iterator = v.elements();
-			for (int i = 0; iterator.hasMoreElements(); i++)
-			{
-				paramDefaults[i] = iterator.nextElement();
-			}
-
-			lookedUpParams = true;
-		}
+        if (params == null && !lookedUpParams) {
+            List tmpDefaults = new ArrayList();
+            params = getDataDictionary().getSPSParams(this, tmpDefaults);
+            paramDefaults = tmpDefaults.toArray();
+            lookedUpParams = true;
+        }
 
 		return params;
 	}
@@ -618,16 +619,6 @@ public class SPSDescriptor extends Tuple
 	}
 	
 	/**
-	 * Get the constant action for this statement
-	 *
-	 * @return the constant action
-	 */
-	//public final synchronized ConstantAction getConstantAction()
-	//{
-	//	return preparedStatement.getConstantAction();
-	//}
-	
-	/**
 	 * Get the preparedStatement for this statement.
 	 * If stmt is invalid or hasn't been compiled yet,
 	 * it will be recompiled.
@@ -857,7 +848,7 @@ public class SPSDescriptor extends Tuple
 	 *
 	 * @exception StandardException thrown if unable to make it invalid
 	 */
-	public final synchronized void prepareToInvalidate(
+    public final void prepareToInvalidate(
 									Provider p, int action,
 									LanguageConnectionContext lcc) 
 		throws StandardException

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1041192&r1=1041191&r2=1041192&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Wed Dec  1 22:23:20 2010
@@ -143,13 +143,13 @@ import org.apache.derby.iapi.services.lo
 import org.apache.derby.iapi.services.locks.ShExQual;
 import org.apache.derby.iapi.util.IdUtil;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.Hashtable;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Properties;
-import java.util.Vector;
 
 import java.util.List;
 import java.util.Iterator;
@@ -4110,10 +4110,9 @@ public final class	DataDictionaryImpl
 		*/
 		if (spsd != null)
 		{
-			Vector v = new Vector();
-			spsd.setParams(getSPSParams(spsd, v));
-			Object[] defaults = new Object[v.size()];
-			v.copyInto(defaults);
+            List tmpDefaults = new ArrayList();
+            spsd.setParams(getSPSParams(spsd, tmpDefaults));
+            Object[] defaults = tmpDefaults.toArray();
 			spsd.setParameterDefaults(defaults);
 		}
 
@@ -4216,14 +4215,14 @@ public final class	DataDictionaryImpl
 	 * into parameter descriptors.  
 	 *
 	 * @param spsd	sps descriptor
-	 * @param defaults	vector for storing column defaults
+     * @param defaults list for storing column defaults
 	 *
 	 * @return array of data type descriptors
 	 *
 	 * @exception StandardException		Thrown on error
 	 */
-	public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, Vector defaults)
-		throws StandardException
+    public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, List defaults)
+        throws StandardException
 	{
 		ColumnDescriptorList cdl = new ColumnDescriptorList();
 		getColumnDescriptorsScan(spsd.getUUID(), cdl, spsd);
@@ -4234,9 +4233,8 @@ public final class	DataDictionaryImpl
 		{
 			ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
 			params[index] = cd.getType();
-			if (defaults != null)
-			{
-				defaults.addElement(cd.getDefaultValue());
+            if (defaults != null) {
+                defaults.add(cd.getDefaultValue());
 			}
 		}
 

Modified: db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java?rev=1041192&r1=1041191&r2=1041192&view=diff
==============================================================================
--- db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java
(original)
+++ db/derby/code/trunk/java/storeless/org/apache/derby/impl/storeless/EmptyDictionary.java
Wed Dec  1 22:23:20 2010
@@ -23,7 +23,6 @@ package org.apache.derby.impl.storeless;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Properties;
-import java.util.Vector;
 
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.iapi.error.StandardException;
@@ -445,7 +444,7 @@ public class EmptyDictionary implements 
 		return null;
 	}
 
-	public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, Vector defaults)
+	public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, List defaults)
 			throws StandardException {
 		// TODO Auto-generated method stub
 		return null;



Mime
View raw message