db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lily...@apache.org
Subject svn commit: r1075568 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ drda/org/apache/derby/impl/drda/ engine/org/apache/derby/diag/ engine/org/apache/derby/iapi/services/io/ engine/org/apache/derby...
Date Mon, 28 Feb 2011 22:39:30 GMT
Author: lilywei
Date: Mon Feb 28 22:39:30 2011
New Revision: 1075568

URL: http://svn.apache.org/viewvc?rev=1075568&view=rev
Log:
DERBY-5071 use string buffers when building strings in loops

Patch contributed by Dave Brosius <dbrosius@apache.org>

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/engine/org/apache/derby/diag/ErrorLogReader.java
    db/derby/code/trunk/java/engine/org/apache/derby/diag/StatementDuration.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Level2OptimizerImpl.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java Mon Feb 28 22:39:30
2011
@@ -4558,17 +4558,17 @@ public abstract class ResultSet implemen
 
         // For Derby, eg update t1 set c1=?, c2=? where current of cursorname
         boolean foundOneUpdatedColumnAlready = false;
-        String updateString = "UPDATE " + getTableName() + " SET ";
+        StringBuffer updateString = new StringBuffer(64);
+        updateString.append("UPDATE ").append(getTableName()).append(" SET ");
 
         for (column = 1; column <= resultSetMetaData_.columns_; column++) {
             if (columnUpdated_[column - 1]) {
                 if (foundOneUpdatedColumnAlready) {
-                    updateString += ",";
+                    updateString.append(",");
                 }
                 try {
-                    updateString += quoteSqlIdentifier(
-                            resultSetMetaData_.getColumnName(column)) + 
-                            " = ? ";
+                    updateString.append(quoteSqlIdentifier(
+                            resultSetMetaData_.getColumnName(column))).append(" = ? ");
                 } catch ( SQLException sqle ) {
                     throw new SqlException(sqle);
                 }
@@ -4580,13 +4580,13 @@ public abstract class ResultSet implemen
         {
             return null;
         }
-        updateString = updateString + " WHERE CURRENT OF " + getServerCursorName();
+        updateString.append(" WHERE CURRENT OF ").append(getServerCursorName());
 
         if (isRowsetCursor_) {
-            updateString += " FOR ROW ? OF ROWSET";
+            updateString.append(" FOR ROW ? OF ROWSET");
         }
 
-        return updateString;
+        return updateString.toString();
     }
 
     private String buildDeleteString() throws SqlException {
@@ -4644,13 +4644,15 @@ public abstract class ResultSet implemen
 
     private String quoteSqlIdentifier(String orgValue) {
         int i = 0, start = 0;
-        String retValue = "";
+        StringBuffer retValue = new StringBuffer();
+        retValue.append("\"");
         while ((i = orgValue.indexOf("\"", start) + 1) > 0) {
-            retValue += orgValue.substring(start, i) + "\"";
+            retValue.append(orgValue.substring(start, i)).append("\"");
             start = i;
         }
-        retValue += orgValue.substring(start, orgValue.length());
-        return "\"" + retValue + "\"";
+        retValue.append(orgValue.substring(start, orgValue.length()));
+        retValue.append("\"");
+        return retValue.toString();
     }
     
     private String getServerCursorName() throws SqlException {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java Mon Feb
28 22:39:30 2011
@@ -746,7 +746,7 @@ public class NetXAResource implements XA
     }
 
     protected void throwXAException(int rc, boolean resetFlag) throws XAException { // ~~~
-        String xaExceptionText;
+        StringBuffer xaExceptionText = new StringBuffer(64);
         if (resetFlag) {
             // reset the state of the failed connection
             NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
@@ -754,19 +754,19 @@ public class NetXAResource implements XA
             callInfo.xaWasSuspended = false;
         }
 
-        xaExceptionText = getXAExceptionText(rc);
+        xaExceptionText.append(getXAExceptionText(rc));
         // save the SqlException chain to add it to the XAException
         org.apache.derby.client.am.SqlException sqlExceptions = exceptionsOnXA;
 
         while (exceptionsOnXA != null) { // one or more SqlExceptions received, format them
-            xaExceptionText = xaExceptionText + " : " + exceptionsOnXA.getMessage();
+            xaExceptionText.append(" : ").append(exceptionsOnXA.getMessage());
             exceptionsOnXA = (org.apache.derby.client.am.SqlException)
                     exceptionsOnXA.getNextException();
         }
         org.apache.derby.client.am.XaException xaException =
                 new org.apache.derby.client.am.XaException(conn_.agent_.logWriter_,
                         sqlExceptions,
-                        xaExceptionText);
+                        xaExceptionText.toString());
         xaException.errorCode = rc;
         setXaStateForXAException(rc); 
         throw xaException;

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Mon Feb 28
22:39:30 2011
@@ -4495,10 +4495,11 @@ class DRDAConnThread extends Thread {
 						trace("numVars = " + numVars);
 					if (ps == null)		// it is a CallableStatement under construction
 					{
-						String marks = "(?";	// construct parameter marks
+						StringBuffer marks = new StringBuffer();	// construct parameter marks
+                        marks.append("(?");
 						for (int i = 1; i < numVars; i++)
-							marks += ", ?";
-						String prepareString = "call " + stmt.procName + marks + ")";
+							marks.append(", ?");
+						String prepareString = "call " + stmt.procName + marks.toString() + ")";
 						if (SanityManager.DEBUG) 
 							trace ("$$ prepareCall is: "+prepareString);
 						CallableStatement cs = null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/diag/ErrorLogReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/diag/ErrorLogReader.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/diag/ErrorLogReader.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/diag/ErrorLogReader.java Mon Feb 28 22:39:30
2011
@@ -253,10 +253,10 @@ public class ErrorLogReader extends VTIT
 				/* Executing prepared statement is a special case as
 				 * it could span multiple lines
 				 */
-				String output;
+				StringBuffer output = new StringBuffer(64);
 				if (line.indexOf(BEGIN_EXECUTING_STRING) == -1)
 				{
-					output = line.substring(line.indexOf(END_DRDAID_STRING, drdaidIndex) + 3);
+					output.append(line.substring(line.indexOf(END_DRDAID_STRING, drdaidIndex) + 3));
 				}
 				else
 				{
@@ -265,12 +265,12 @@ public class ErrorLogReader extends VTIT
 				int endIndex = line.indexOf(END_EXECUTING_STRING, drdaidIndex);
 				if (endIndex == -1)
 				{
-					output = line.substring(line.indexOf(END_DRDAID_STRING, drdaidIndex) + 3);
+					output.append(line.substring(line.indexOf(END_DRDAID_STRING, drdaidIndex) + 3));
 				}
 				else
 				{
-					output = line.substring(line.indexOf(END_XID_STRING, drdaidIndex) + 3,
-											endIndex);
+					output.append(line.substring(line.indexOf(END_XID_STRING, drdaidIndex) + 3,
+											endIndex));
 				}
 
 				while (endIndex == -1)
@@ -286,18 +286,16 @@ public class ErrorLogReader extends VTIT
 					endIndex = line.indexOf(END_EXECUTING_STRING);
 					if (endIndex == -1)
 					{
-						output = output + line;
+						output.append(line);
 					}
 					else
 					{
-						output = output + line.substring(0, endIndex);
+						output.append(line.substring(0, endIndex));
 					}
 				}
 				}
 
-				output = StringUtil.truncate(output, Limits.DB2_VARCHAR_MAXWIDTH);
-
-				return output;
+				return StringUtil.truncate(output.toString(), Limits.DB2_VARCHAR_MAXWIDTH);
 
 			default:
 				return "";

Modified: db/derby/code/trunk/java/engine/org/apache/derby/diag/StatementDuration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/diag/StatementDuration.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/diag/StatementDuration.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/diag/StatementDuration.java Mon Feb 28
22:39:30 2011
@@ -265,10 +265,10 @@ public class StatementDuration extends V
 				/* Executing prepared statement is a special case as
 				 * it could span multiple lines
 				 */
-				String output;
+				StringBuffer output = new StringBuffer(64);
 				if (line.indexOf(BEGIN_EXECUTING_STRING) == -1)
 				{
-					output = line.substring(line.indexOf(END_XID_STRING, lccidIndex) + 3);
+					output.append(line.substring(line.indexOf(END_XID_STRING, lccidIndex) + 3));
 				}
 				else
 				{
@@ -277,12 +277,12 @@ public class StatementDuration extends V
 				int endIndex = line.indexOf(END_EXECUTING_STRING, lccidIndex);
 				if (endIndex == -1)
 				{
-					output = line.substring(line.indexOf(END_XID_STRING, lccidIndex) + 3);
+					output.append(line.substring(line.indexOf(END_XID_STRING, lccidIndex) + 3));
 				}
 				else
 				{
-					output = line.substring(line.indexOf(END_XID_STRING, lccidIndex) + 3,
-											endIndex);
+					output.append(line.substring(line.indexOf(END_XID_STRING, lccidIndex) + 3,
+											endIndex));
 				}
 
 				while (endIndex == -1)
@@ -298,19 +298,16 @@ public class StatementDuration extends V
 					endIndex = line.indexOf(END_EXECUTING_STRING);
 					if (endIndex == -1)
 					{
-						output = output + line;
+						output.append(line);
 					}
 					else
 					{
-						output = output + line.substring(0, endIndex);
+						output.append(line.substring(0, endIndex));
 					}
 				}
 				}
 
-				output = StringUtil.truncate(output, Limits.DB2_VARCHAR_MAXWIDTH);
-
-
-				return output;
+				return StringUtil.truncate(output.toString(), Limits.DB2_VARCHAR_MAXWIDTH);
 
 			default:
 				return null;

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=1075568&r1=1075567&r2=1075568&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 Mon Feb
28 22:39:30 2011
@@ -238,21 +238,19 @@ public abstract class ArrayUtil
 
     public static String toString(int[] value)
     {
-        String ret_val;
-
         if (value == null || value.length == 0)
         {
-            ret_val = "null";
+            return "null";
         }
         else
         {
-            ret_val = "";
+            StringBuffer ret_val = new StringBuffer();
             for (int i = 0; i < value.length; i++)
             {
-                ret_val += "[" + value[i] + "],";
+                ret_val.append("[").append(value[i]).append("],");
             }
+            return ret_val.toString();
         }
-        return(ret_val);
     }
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/ClassInspector.java
Mon Feb 28 22:39:30 2011
@@ -737,20 +737,20 @@ nextMethod:	for (int i = 0; i < methods.
 		if (ambiguous)
 		{
 			/* Put the parameter type names into a single string */
-			String	parmTypesString = "";
+			StringBuffer parmTypesString = new StringBuffer();
 			for (int i = 0; i < paramClasses.length; i++)
 			{
 				if (i != 0)
-					parmTypesString += ", ";
-				parmTypesString += (paramClasses[i] == null ? "null" : paramClasses[i].getName());
+					parmTypesString.append(", ");
+				parmTypesString.append(paramClasses[i] == null ? "null" : paramClasses[i].getName());
 				if (primParamClasses != null && primParamClasses[i] != null)
-					parmTypesString += "(" + primParamClasses[i].getName() + ")";
+					parmTypesString.append("(").append(primParamClasses[i].getName()).append(")");
 			}
 
 			throw StandardException.newException(SQLState.LANG_AMBIGUOUS_METHOD_INVOCATION, 
 												receiverClass.getName(), 
 												methodName,
-												parmTypesString);
+												parmTypesString.toString());
 		}
 
 		if (candidateIndex == -1)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java
Mon Feb 28 22:39:30 2011
@@ -307,24 +307,24 @@ public final class ConglomerateDescripto
 	{
 		if (SanityManager.DEBUG)
 		{
-			String keyString = "";
+			StringBuffer keyString = new StringBuffer();
 
 			if (indexable && columnNames != null )
 			{
 				int[] keyColumns = indexRowGenerator.baseColumnPositions();
 
-				keyString = ", key columns = {" + columnNames[keyColumns[0] - 1];
+				keyString.append(", key columns = {").append(columnNames[keyColumns[0] - 1]);
 				for (int index = 1; index < keyColumns.length; index++)
 				{
-					keyString = keyString + ", " + columnNames[keyColumns[index] - 1];
+					keyString.append(", ").append(columnNames[keyColumns[index] - 1]);
 				}
-				keyString = keyString + "}";
+				keyString.append("}");
 			}
 
 			return "ConglomerateDescriptor: conglomerateNumber = " + conglomerateNumber +
 				" name = " + name +
 				" uuid = " + uuid +
-				" indexable = " + indexable + keyString;
+				" indexable = " + indexable + keyString.toString();
 		}
 		else
 		{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
Mon Feb 28 22:39:30 2011
@@ -822,7 +822,8 @@ public class TableDescriptor extends Tup
 			return tableName;
 		else
 		{
-			String name = new String(tableName);
+			StringBuffer name = new StringBuffer();
+            name.append(tableName);
 			boolean first = true;
 
 			for (int i = 0; i < columnDescriptorList.size(); i++)
@@ -832,16 +833,16 @@ public class TableDescriptor extends Tup
 				{
 					if (first)
 					{
-						name += "(" + cd.getColumnName();
+						name.append("(").append(cd.getColumnName());
 						first = false;
 					}
 					else
-						name += ", " + cd.getColumnName();
+						name.append(", ").append(cd.getColumnName());
 				}
 			}
 			if (! first)
-				name += ")";
-			return name;
+				name.append(")");
+			return name.toString();
 		}
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Level2OptimizerImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Level2OptimizerImpl.java?rev=1075568&r1=1075567&r2=1075568&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Level2OptimizerImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Level2OptimizerImpl.java
Mon Feb 28 22:39:30 2011
@@ -530,18 +530,20 @@ public class Level2OptimizerImpl extends
 	private String buildJoinOrder(String prefix, boolean addJoinOrderNumber,
 								  int joinOrderNumber, int[] joinOrder)
 	{
-		String joinOrderString = prefix;
+		StringBuffer joinOrderString = new StringBuffer();
+        joinOrderString.append(prefix);
 
 		for (int i = 0; i <= joinPosition; i++)
 		{
-			joinOrderString = joinOrderString + " " + joinOrder[i];
+			joinOrderString.append(" ").append(joinOrder[i]);
 		}
 		if (addJoinOrderNumber)
 		{
-			joinOrderString = joinOrderString + " " + joinOrderNumber;
+			joinOrderString.append(" ").append(joinOrderNumber);
 		}
 
-		return joinOrderString + " with assignedTableMap = " + assignedTableMap + "\n\n";
+        joinOrderString.append(" with assignedTableMap = ").append(assignedTableMap).append("\n\n");
+        return joinOrderString.toString();
 	}
 
 	private String lockModeThreshold(



Mime
View raw message