db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1471331 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/io/ iapi/sql/compile/ iapi/sql/execute/ impl/sql/ impl/sql/compile/ impl/sql/execute/
Date Wed, 24 Apr 2013 09:43:12 GMT
Author: kahatlen
Date: Wed Apr 24 09:43:12 2013
New Revision: 1471331

URL: http://svn.apache.org/r1471331
Log:
DERBY-6169: Reduce visibility of classes and methods under impl/sql

Stop exposing references to the internal array of saved objects in
GenericPreparedStatement by making the following changes:

- IndexRowToBaseRowResultSet: Since it doesn't need the complete
  array, make it use getSavedObject(int) instead of getSavedObjects()
  so that it only retrieves the single object that the caller is
  interested in.

- VTIResultSet: Remove code that may perform lazy initialization of
  one of the saved objects at run time if it was initially null.
  Instead, make sure it is initialized when the query is compiled.

- GenericPreparedStatement: Change getSavedObjects() to return a
  read-only view of the internal array, so that callers cannot
  accidentally modify it.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java?rev=1471331&r1=1471330&r2=1471331&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java Wed Apr
24 09:43:12 2013
@@ -21,11 +21,12 @@
 
 package org.apache.derby.iapi.services.io;
 
-import org.apache.derby.iapi.services.sanity.SanityManager;
 import java.io.ObjectOutput;
 import java.io.ObjectInput;
 import java.io.IOException;
-import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 
 /**
   Utility class for constructing and reading and writing arrays from/to
@@ -72,6 +73,16 @@ public abstract class ArrayUtil
         return (original == null) ? null : (int[]) original.clone();
     }
 
+    /**
+     * Make the contents of an array available as a read-only list. If the
+     * array is null, an empty list will be returned.
+     */
+    public static List asReadOnlyList(Object[] array) {
+        return array == null ?
+                Collections.EMPTY_LIST :
+                Collections.unmodifiableList(Arrays.asList(array));
+    }
+
 	///////////////////////////////////////////////////////////////////
 	//
 	// Methods for Arrays of OBJECTS.  Cannot be used for an

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java?rev=1471331&r1=1471330&r2=1471331&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java
Wed Apr 24 09:43:12 2013
@@ -342,8 +342,9 @@ public interface CompilerContext extends
 	 *	Set the saved object pool (for putting into the prepared statement).
 	 *
 	 * @param objs	 The new saved objects
+     * @throws NullPointerException if {@code objs} is null
 	 */
-	public void setSavedObjects(Object[] objs); 
+    void setSavedObjects(List objs);
 
 	/**
 	 * Set the in use state for the compiler context.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java?rev=1471331&r1=1471330&r2=1471331&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java
Wed Apr 24 09:43:12 2013
@@ -67,9 +67,9 @@ public interface ExecPreparedStatement 
 	 *	Get all the saved objects.  Used for stored prepared
 	 * 	statements.
 	 *
-	 *	@return	Object[]	the saved objects
+     *  @return a list with all the saved objects
 	 */
-	Object[]	getSavedObjects();
+    List getSavedObjects();
 
 	/**
 	 *	Get the saved cursor info.  Used for stored prepared

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java?rev=1471331&r1=1471330&r2=1471331&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
Wed Apr 24 09:43:12 2013
@@ -31,6 +31,7 @@ import org.apache.derby.iapi.services.mo
 
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
+import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
 import org.apache.derby.iapi.services.cache.Cacheable;
 
@@ -706,9 +707,11 @@ recompileOutOfDatePlan:
 	 *
 	 *	@return all the saved objects
 	 */
-	public	final Object[]	getSavedObjects()
+    public final List getSavedObjects()
 	{
-		return	savedObjects;
+        // Return an unmodifiable view of the underlying array, so that
+        // the caller cannot modify the internal state.
+        return ArrayUtil.asReadOnlyList(savedObjects);
 	}
 
 	//

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java?rev=1471331&r1=1471330&r2=1471331&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java
Wed Apr 24 09:43:12 2013
@@ -346,17 +346,12 @@ public class CompilerContextImpl extends
 	}
 
 	/** @see CompilerContext#setSavedObjects */
-	public void setSavedObjects(Object[] objs) 
+    public void setSavedObjects(List objs)
 	{
-		if (objs == null)
-		{
-			return;
-		}
-
-		for (int i = 0; i < objs.length; i++)
-		{
-			addSavedObject(objs[i]);
-		}		
+        Iterator it = objs.iterator();
+        while (it.hasNext()) {
+            addSavedObject(it.next());
+        }
 	}
 
 	/** @see CompilerContext#setCursorInfo */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=1471331&r1=1471330&r2=1471331&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Wed Apr
24 09:43:12 2013
@@ -91,7 +91,8 @@ public class FromVTI extends FromTable i
 	boolean				isRestrictedTableFunction;
 	ResultSet			rs;
 
-	private	FormatableHashtable	compileTimeConstants;
+    private final FormatableHashtable compileTimeConstants =
+            new FormatableHashtable();
 
 	// Number of columns returned by the VTI
 	protected int numVTICols;
@@ -1656,7 +1657,13 @@ public class FromVTI extends FromTable i
 			erdNumber = acb.addItem(referencedCols);
 		}
 
-		// compileTimeConstants can be null
+        // compileTimeConstants cannot be null, even if there are no
+        // constants, since VTIResultSet.setSharedState() may want to
+        // add constants to it during execution.
+        if (SanityManager.DEBUG) {
+            SanityManager.ASSERT(compileTimeConstants != null,
+                                 "compileTimeConstants is null");
+        }
 		int ctcNumber = acb.addItem(compileTimeConstants);
 
 		acb.pushThisAsActivation(mb); // arg 1
@@ -1957,15 +1964,13 @@ public class FromVTI extends FromTable i
 		if (key == null)
 			return;
 
-		if (compileTimeConstants == null)
-			compileTimeConstants = new FormatableHashtable();
-
 		compileTimeConstants.put(key, value);
 	}
 
 	public Object getSharedState(String key) {
-		if ((key == null) || (compileTimeConstants == null))
+        if (key == null) {
 			return null;
+        }
 
 		return compileTimeConstants.get(key);
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java?rev=1471331&r1=1471330&r2=1471331&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java
Wed Apr 24 09:43:12 2013
@@ -103,9 +103,8 @@ class IndexRowToBaseRowResultSet extends
 		super(a, resultSetNumber, optimizerEstimatedRowCount, optimizerEstimatedCost);
 		final GenericPreparedStatement gp =
 			(GenericPreparedStatement)a.getPreparedStatement();
-		final Object[] saved = gp.getSavedObjects();
 
-		scoci = (StaticCompiledOpenConglomInfo)saved[scociItem];
+        scoci = (StaticCompiledOpenConglomInfo) gp.getSavedObject(scociItem);
 		TransactionController tc = activation.getTransactionController();
 		dcoci = tc.getDynamicCompiledConglomInfo(conglomId);
         this.source = source;
@@ -120,20 +119,24 @@ class IndexRowToBaseRowResultSet extends
 		// retrieve the valid column list from
 		// the saved objects, if it exists
 		if (heapColRefItem != -1) {
-			this.accessedHeapCols = (FormatableBitSet)saved[heapColRefItem];
+            this.accessedHeapCols =
+                    (FormatableBitSet) gp.getSavedObject(heapColRefItem);
 		}
 		if (allColRefItem != -1) {
-			this.accessedAllCols = (FormatableBitSet)saved[allColRefItem];
+            this.accessedAllCols =
+                    (FormatableBitSet) gp.getSavedObject(allColRefItem);
 		}
 
 		// retrieve the array of columns coming from the index
 		indexCols = 
 			((ReferencedColumnsDescriptorImpl)
-			 saved[indexColMapItem]).getReferencedColumnPositions();
+                gp.getSavedObject(indexColMapItem))
+                .getReferencedColumnPositions();
 
 		/* Get the result row template */
-        ExecRow resultRow = ((ExecRowBuilder) saved[resultRowAllocator])
-                                .build(a.getExecutionFactory());
+        ExecRow resultRow =
+                ((ExecRowBuilder) gp.getSavedObject(resultRowAllocator))
+                    .build(a.getExecutionFactory());
 
 		// Note that getCompactRow will assign its return value to the
 		// variable compactRow which can be accessed through
@@ -154,7 +157,7 @@ class IndexRowToBaseRowResultSet extends
 			final DataValueDescriptor[] resultRowArray =
 				resultRow.getRowArray();
 			final FormatableBitSet heapOnly =
-				(FormatableBitSet)saved[heapOnlyColRefItem];
+                (FormatableBitSet) gp.getSavedObject(heapOnlyColRefItem);
 			final int heapOnlyLen = heapOnly.getLength();
 
 			// Need a separate DataValueDescriptor array in this case

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java?rev=1471331&r1=1471330&r2=1471331&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java Wed
Apr 24 09:43:12 2013
@@ -81,8 +81,7 @@ class VTIResultSet extends NoPutResultSe
 	private boolean version2;
 	private boolean reuseablePs;
 	private boolean isTarget;
-	private FormatableHashtable compileTimeConstants;
-	private int ctcNumber;
+    private final FormatableHashtable compileTimeConstants;
 
 	private boolean pushedProjection;
 	private IFastPath	fastPath;
@@ -161,10 +160,17 @@ class VTIResultSet extends NoPutResultSe
 								getSavedObject(erdNumber));
 		}
 
-		this.ctcNumber = ctcNumber;
 		compileTimeConstants = (FormatableHashtable) (activation.getPreparedStatement().
 								getSavedObject(ctcNumber));
 
+        // compileTimeConstants cannot be null, even if there are no
+        // constants, since VTIResultSet.setSharedState() may want to
+        // add constants to it during execution.
+        if (SanityManager.DEBUG) {
+            SanityManager.ASSERT(compileTimeConstants != null,
+                                 "compileTimeConstants is null");
+        }
+
 		recordConstructorTime();
     }
 
@@ -706,20 +712,6 @@ class VTIResultSet extends NoPutResultSe
 		if (key == null)
 			return;
 
-		if (compileTimeConstants == null) {
-
-			Object[] savedObjects = activation.getPreparedStatement().getSavedObjects();
-
-			synchronized (savedObjects) {
-
-				compileTimeConstants = (FormatableHashtable) savedObjects[ctcNumber];
-				if (compileTimeConstants == null) {
-					compileTimeConstants = new FormatableHashtable();
-					savedObjects[ctcNumber] = compileTimeConstants;
-				}
-			}
-		}
-
 		if (value == null)
 			compileTimeConstants.remove(key);
 		else



Mime
View raw message