db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r370574 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
Date Thu, 19 Jan 2006 18:56:26 GMT
Author: djd
Date: Thu Jan 19 10:56:25 2006
New Revision: 370574

URL: http://svn.apache.org/viewcvs?rev=370574&view=rev
Log:
DERBY-818 Remove the object allocation and reseting overhead for updateable ResultSet information
when the ResultSet is read-only. Similar changes for the stream single fetch (getXXXStream)
logic.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=370574&r1=370573&r2=370574&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Thu Jan
19 10:56:25 2006
@@ -72,6 +72,7 @@
 import java.io.IOException;
 import java.net.URL;
 
+import java.util.Arrays;
 import java.util.Calendar;
 
 /**
@@ -158,6 +159,10 @@
     private int fetchDirection;
     private int fetchSize;
     
+    /**
+     * Indicates which columns have already been fetched
+     * as a stream for a row. Created on-demand by a getXXXStream call.
+     */
     private boolean[] streamUsedFlags;
 
 	/**
@@ -205,11 +210,14 @@
 		// Fill in the column types
 		resultDescription = theResults.getResultDescription();
 
-		//initialize arrays related to updateRow implementation
-		columnGotUpdated = new boolean[getMetaData().getColumnCount()];
-		copyOfDatabaseRow = new DataValueDescriptor[columnGotUpdated.length];
-		
-		initStreamUseFlags(getMetaData().getColumnCount());
+		// Only incur the cost of allocating and maintaining
+		// updated column information if the columns can be updated.
+		if (concurrencyOfThisResultSet == JDBC20Translation.CONCUR_UPDATABLE)
+		{
+		    //initialize arrays related to updateRow implementation
+		    columnGotUpdated = new boolean[getMetaData().getColumnCount()];
+		    copyOfDatabaseRow = new DataValueDescriptor[columnGotUpdated.length];
+		}
 
         // assign the max rows and maxfiled size limit for this result set
         if (stmt != null)
@@ -302,10 +310,12 @@
             }
         }
 
-	    //since we are moving off of the current row, need to initialize state corresponding
to updateRow implementation
-	    for (int i=0; i < columnGotUpdated.length; i++)
-            columnGotUpdated[i] = false;
-	    currentRowHasBeenUpdated = false;
+        if (columnGotUpdated != null)
+        {
+	        //since we are moving off of the current row, need to initialize state corresponding
to updateRow implementation
+	        Arrays.fill(columnGotUpdated, false);
+	        currentRowHasBeenUpdated = false;
+        }
 
 	    return movePosition(NEXT, 0, "next");
 	}
@@ -447,7 +457,9 @@
 
 			rowData = onRow ? currentRow.getRowArray() : null;
 			
-			unuseStreams();
+			// Clear the indication of which columns were fetched as streams.
+			if (streamUsedFlags != null)
+			    Arrays.fill(streamUsedFlags, false);
 			
 			return onRow;
 			} finally {
@@ -545,10 +557,6 @@
 			currentRow = null;
 			rowData = null;
 			rMetaData = null; // let it go, we can make a new one
-	    //since we are moving off of the current row(by closing the resultset), need to initialize
state corresponding to updateRow implementation
-	    for (int i=0; i < columnGotUpdated.length; i++)
-				columnGotUpdated[i] = false;
-	    currentRowHasBeenUpdated = false;
 
 			// we hang on to theResults and messenger
 			// in case more calls come in on this resultSet
@@ -3977,41 +3985,21 @@
 			resultDescription.getColumnDescriptor(column).getType().getTypeId().getSQLTypeName(),
targetType);
 	}
     
-    
-    private void initStreamUseFlags(int numOfCol){
-	
-	streamUsedFlags = new boolean[numOfCol];
-	
-	// Next code is not neccesary because initial value is false, which is default initial value
for boolean.
-	/*
-	  clearStreamUsedFlags();
-	*/
-    }
-    
-    
-    void useStream(int columnIndex) throws SQLException {
-	
-	if(streamUsedFlags[columnIndex - 1]){
-	    throw newSQLException(SQLState.LANG_STREAM_RETRIEVED_ALREADY);
-	}
-
-	streamUsedFlags[columnIndex - 1] = true;
-
-    }
-
-
-    private void unuseStreams(){
-	
-	for(int i = 0;
-	    i < streamUsedFlags.length;
-	    i ++){
-	    
-	    streamUsedFlags[i] = false;
-	    
-	}
-	
+    /**
+     * Mark a column as already having a stream accessed from it.
+     * If the stream was already accessed, then throw an exception.
+     * @param columnIndex
+     * @throws SQLException
+     */
+    final void useStream(int columnIndex) throws SQLException {
+    	
+    	if (streamUsedFlags == null)
+    		streamUsedFlags = new boolean[getMetaData().getColumnCount()];
+    	
+    	else if (streamUsedFlags[columnIndex - 1])
+	        throw newSQLException(SQLState.LANG_STREAM_RETRIEVED_ALREADY);
+    	
+    	streamUsedFlags[columnIndex - 1] = true;
     }
-    
-    
 }
 



Mime
View raw message