db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r989918 - in /db/derby/code/trunk/java/engine/org/apache/derby/iapi/types: DateTimeParser.java SQLTime.java SQLTimestamp.java
Date Thu, 26 Aug 2010 20:49:34 GMT
Author: kahatlen
Date: Thu Aug 26 20:49:33 2010
New Revision: 989918

URL: http://svn.apache.org/viewvc?rev=989918&view=rev
Log:
DERBY-3173: Removed cached String objects from SQLTime and SQLTimestamp

Patch contributed by Eranda Sooriyabandara <070468D at gmail dot com>.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DateTimeParser.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTime.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DateTimeParser.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DateTimeParser.java?rev=989918&r1=989917&r2=989918&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DateTimeParser.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DateTimeParser.java Thu Aug
26 20:49:33 2010
@@ -31,7 +31,6 @@ class DateTimeParser
 {
 
     private String str;
-    private String trimmedString;
     private int len;
     private int fieldStart;
     private char currentSeparator;
@@ -189,33 +188,17 @@ class DateTimeParser
      * @return the original string with trailing blanks trimmed off.
      * @exception StandardException if there are more non-blank characters.
      */
-    String checkEnd() throws StandardException
+    void checkEnd() throws StandardException
     {
-        int end = fieldStart;
         for( ; fieldStart < len; fieldStart++)
         {
             if( str.charAt( fieldStart) != ' ')
                 throw StandardException.newException( SQLState.LANG_DATE_SYNTAX_EXCEPTION);
         }
         currentSeparator = 0;
-        while( end > 0 && str.charAt( end - 1) == ' ')
-            end--;
-        trimmedString = (end == len) ? str : str.substring( 0, end);
-        return trimmedString;
     } // end of checkEnd
 
     /**
-     * Get the parsed string with trailing blanks removed. <b>This method is only valid
after checkEnd
-     * has been called.</b>
-     *
-     * @return The string with trailing blanks removed.
-     */
-    String getTrimmedString()
-    {
-        return trimmedString;
-    }
-
-    /**
      * @return the next separator, 0 if there are none
      */
     char nextSeparator()

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTime.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTime.java?rev=989918&r1=989917&r2=989918&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTime.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTime.java Thu Aug 26 20:49:33
2010
@@ -93,9 +93,6 @@ public final class SQLTime extends DataT
 	private int		encodedTimeFraction; //currently always 0 since we don't
 											 //support time precision
 
-	// The cached value.toString()
-	private String	valueString;
-
 	/*
 	** DataValueDescriptor interface
 	** (mostly implemented in DataType)
@@ -105,30 +102,17 @@ public final class SQLTime extends DataT
 
     public int estimateMemoryUsage()
     {
-        return BASE_MEMORY_USAGE + ClassSize.estimateMemoryUsage( valueString);
+        return BASE_MEMORY_USAGE;
     } // end of estimateMemoryUsage
 
 	public String getString()
 	{
 		if (!isNull())
 		{
-			if (valueString == null)
-			{
-				valueString = encodedTimeToString(encodedTime);
-			}
-			return valueString;
+			return encodedTimeToString(encodedTime);
 		}
 		else
 		{
-			if (SanityManager.DEBUG)
-			{
-				if (valueString != null)
-				{
-					SanityManager.THROWASSERT(
-						"valueString expected to be null, not " +
-						valueString);
-				}
-			}
 			return null;
 		}
 	}
@@ -231,15 +215,11 @@ public final class SQLTime extends DataT
 	{
 		encodedTime = in.readInt();
 		encodedTimeFraction = in.readInt();
-		// reset cached values
-		valueString = null;
 	}
 	public void readExternalFromArray(ArrayInputStream in) throws IOException
 	{
 		encodedTime = in.readInt();
 		encodedTimeFraction = in.readInt();
-		// reset cached values
-		valueString = null;
 	}
 
 	/*
@@ -269,9 +249,6 @@ public final class SQLTime extends DataT
 	{
 		encodedTime = -1;
 		encodedTimeFraction = 0;
-
-		// clear cached valueString
-		valueString = null;
 	}
 
 	/*
@@ -470,7 +447,6 @@ public final class SQLTime extends DataT
             if( parser.nextSeparator() == SQLTimestamp.DATE_SEPARATOR)
             {
                     encodedTime = SQLTimestamp.parseDateOrTimestamp( parser, true)[1];
-                    valueString = parser.getTrimmedString();
                     return;
             }
             hour = parser.parseInt( 2, true, ANY_SEPARATOR, false);
@@ -551,7 +527,7 @@ public final class SQLTime extends DataT
                 else if( hour > 12)
                     throw StandardException.newException( SQLState.LANG_DATE_RANGE_EXCEPTION);
             }
-            valueString = parser.checkEnd();
+            parser.checkEnd();
             encodedTime = computeEncodedTime( hour, minute, second);
         }
         else
@@ -585,7 +561,6 @@ public final class SQLTime extends DataT
                     throw StandardException.newException( SQLState.LANG_DATE_SYNTAX_EXCEPTION);
                 }
             }
-            valueString = timeStr;
         }
     } // end of parseTime
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java?rev=989918&r1=989917&r2=989918&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java Thu Aug
26 20:49:33 2010
@@ -93,10 +93,6 @@ public final class SQLTimestamp extends 
 	private int	encodedDate;
 	private int	encodedTime;
 	private int	nanos;
-
-	// The cached value.toString()
-	private String	valueString;
-
 	/*
 	** DataValueDescriptor interface
 	** (mostly implemented in DataType)
@@ -106,7 +102,7 @@ public final class SQLTimestamp extends 
 
     public int estimateMemoryUsage()
     {
-        int sz = BASE_MEMORY_USAGE + ClassSize.estimateMemoryUsage( valueString);
+        int sz = BASE_MEMORY_USAGE;
         return sz;
     } // end of estimateMemoryUsage
 
@@ -114,37 +110,25 @@ public final class SQLTimestamp extends 
 	{
 		if (!isNull())
 		{
-			if (valueString == null)
-			{
-				valueString = getTimestamp((Calendar) null).toString();
-                /* The java.sql.Timestamp.toString() method is supposed to return a string
in
-                 * the JDBC escape format. However the JDK 1.3 libraries truncate leading
zeros from
-                 * the year. This is not acceptable to DB2. So add leading zeros if necessary.
-                 */
-                int separatorIdx = valueString.indexOf( '-');
-                if( separatorIdx >= 0 && separatorIdx < 4)
-                {
-                    StringBuffer sb = new StringBuffer();
-                    for( ; separatorIdx < 4; separatorIdx++)
-                        sb.append('0');
-                    sb.append( valueString);
-                    valueString = sb.toString();
-                }
-			}
+            String valueString = getTimestamp((Calendar) null).toString();
+            /* The java.sql.Timestamp.toString() method is supposed to return a string in
+             * the JDBC escape format. However the JDK 1.3 libraries truncate leading zeros
from
+             * the year. This is not acceptable to DB2. So add leading zeros if necessary.
+             */
+            int separatorIdx = valueString.indexOf('-');
+            if (separatorIdx >= 0 && separatorIdx < 4)
+            {
+                StringBuffer sb = new StringBuffer();
+                for( ; separatorIdx < 4; separatorIdx++)
+                    sb.append('0');
+                sb.append(valueString);
+                valueString = sb.toString();
+            }
 
 			return valueString;
 		}
 		else
 		{
-			if (SanityManager.DEBUG)
-			{
-				if (valueString != null)
-				{
-					SanityManager.THROWASSERT(
-						"valueString expected to be null, not " +
-						valueString);
-				}
-			}
 			return null;
 		}
 	}
@@ -253,16 +237,12 @@ public final class SQLTimestamp extends 
 		encodedDate = in.readInt();
 		encodedTime = in.readInt();
 		nanos = in.readInt();
-		// reset cached values
-		valueString = null;
 	}
 	public void readExternalFromArray(ArrayInputStream in) throws IOException
 	{
 		encodedDate = in.readInt();
 		encodedTime = in.readInt();
 		nanos = in.readInt();
-		// reset cached values
-		valueString = null;
 	}
 
 	/*
@@ -294,8 +274,6 @@ public final class SQLTimestamp extends 
 		encodedTime = 0;
 		nanos = 0;
 
-		// clear cached valueString
-		valueString = null;
 	}
 
 	/*



Mime
View raw message