db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1362420 - in /db/derby/code/trunk/java/client/org/apache/derby/client/am: Clob.java ClobOutputStream.java ClobWriter.java LogicalCallableStatement.java LogicalPreparedStatement.java ResultSet.java
Date Tue, 17 Jul 2012 09:08:26 GMT
Author: kahatlen
Date: Tue Jul 17 09:08:25 2012
New Revision: 1362420

URL: http://svn.apache.org/viewvc?rev=1362420&view=rev
Log:
DERBY-5840: Silence deprecation warnings in the network client

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobOutputStream.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobWriter.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java?rev=1362420&r1=1362419&r2=1362420&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java Tue Jul 17 09:08:25
2012
@@ -677,12 +677,9 @@ public class Clob extends Lob implements
         }
         else {
             //The Clob is not locator enabled.
-            String newString = string_.substring(0, (int) pos - 1);
-            string_ = newString.concat(str.substring(offset, offset + length));
-            asciiStream_ = new java.io.StringBufferInputStream(string_);
-            unicodeStream_ = new java.io.StringBufferInputStream(string_);
-            characterStream_ = new java.io.StringReader(string_);
-            setSqlLength(string_.length());
+            reInitForNonLocator(
+                string_.substring(0, (int) pos - 1)
+                    .concat(str.substring(offset, offset + length)));
         }
         return length;
     }
@@ -800,12 +797,7 @@ public class Clob extends Lob implements
                 }
                 else {
                     //The Lob is not locator enabled.
-                    String newstr = string_.substring(0, (int) len);
-                    string_ = newstr;
-                    asciiStream_ = new java.io.StringBufferInputStream(string_);
-                    unicodeStream_ = new java.io.StringBufferInputStream(string_);
-                    characterStream_ = new java.io.StringReader(string_);
-                    setSqlLength(string_.length());
+                    reInitForNonLocator(string_.substring(0, (int) len));
                 }
             }
         }
@@ -1033,6 +1025,25 @@ public class Clob extends Lob implements
     }
 
 
+    /**
+     * Reinitialize the value of this CLOB.
+     *
+     * This is legacy code, only used when talking to servers that don't
+     * support locators.
+     *
+     * @param newString the new value
+     */
+    // The StringBufferInputStream class is deprecated, but we don't care too
+    // much since this code is only for talking to very old servers. Suppress
+    // the deprecation warnings for now.
+    @SuppressWarnings("deprecation")
+    void reInitForNonLocator(String newString) {
+        string_ = newString;
+        asciiStream_ = new java.io.StringBufferInputStream(string_);
+        unicodeStream_ = new java.io.StringBufferInputStream(string_);
+        characterStream_ = new java.io.StringReader(string_);
+        setSqlLength(string_.length());
+    }
 
 
     /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobOutputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobOutputStream.java?rev=1362420&r1=1362419&r2=1362420&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobOutputStream.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobOutputStream.java Tue Jul
17 09:08:25 2012
@@ -68,13 +68,8 @@ public class ClobOutputStream extends ja
         // Since this is an OutputStream returned by Clob.setAsciiStream 
         // use Ascii encoding when creating the String from bytes
         String str = new String(b, "ISO-8859-1");
-        clob_.string_ = clob_.string_.substring(0, (int) offset_ - 1);
-        clob_.string_ = clob_.string_.concat(str);
-        clob_.asciiStream_ = new java.io.StringBufferInputStream(clob_.string_);
-        clob_.unicodeStream_ 
-            = new java.io.StringBufferInputStream(clob_.string_);
-        clob_.characterStream_ = new java.io.StringReader(clob_.string_);
-        clob_.setSqlLength(clob_.string_.length());
+        clob_.reInitForNonLocator(
+                clob_.string_.substring(0, (int) offset_ - 1).concat(str));
         offset_ += b.length;
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobWriter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobWriter.java?rev=1362420&r1=1362419&r2=1362420&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobWriter.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobWriter.java Tue Jul 17
09:08:25 2012
@@ -82,12 +82,7 @@ public class ClobWriter extends java.io.
     
     private void updateClob(StringBuffer sb) 
     {
-        clob_.string_ = sb.toString();
-        clob_.asciiStream_ = new java.io.StringBufferInputStream(clob_.string_);
-        clob_.unicodeStream_ 
-            = new java.io.StringBufferInputStream(clob_.string_);
-        clob_.characterStream_ = new java.io.StringReader(clob_.string_);
-        clob_.setSqlLength(clob_.string_.length());
+        clob_.reInitForNonLocator(sb.toString());
         offset_ = clob_.string_.length() + 1;
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java?rev=1362420&r1=1362419&r2=1362420&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java
Tue Jul 17 09:08:25 2012
@@ -203,6 +203,7 @@ public class LogicalCallableStatement
         return getPhysCs().getBigDecimal(parameterIndex);
     }
 
+    @Deprecated
     public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
         return getPhysCs().getBigDecimal(parameterIndex, scale);
     }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java?rev=1362420&r1=1362419&r2=1362420&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
Tue Jul 17 09:08:25 2012
@@ -134,6 +134,7 @@ public class LogicalPreparedStatement
          getPhysPs().setBinaryStream(parameterIndex, x, length);
     }
 
+    @Deprecated
     public void setUnicodeStream(int parameterIndex, InputStream x, int length)
             throws SQLException {
          getPhysPs().setUnicodeStream(parameterIndex, x, length);

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=1362420&r1=1362419&r2=1362420&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 Tue Jul 17 09:08:25
2012
@@ -998,6 +998,17 @@ public abstract class ResultSet implemen
     }
 
     /**
+     * Create a calendar with default locale and time zone.
+     * @param date the initial time of the calendar
+     * @return a calendar initialized to the specified time
+     */
+    private static Calendar createCalendar(java.util.Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        return cal;
+    }
+
+    /**
      * Convert a date originally set using the default calendar to a value
      * representing the same date in a different calendar.
      *
@@ -1006,9 +1017,11 @@ public abstract class ResultSet implemen
      * @return a date object that represents the date in {@code cal}
      */
     private Date convertFromDefaultCalendar(Date date, Calendar cal) {
+        Calendar from = createCalendar(date);
         cal.clear();
-        cal.set(date.getYear() + 1900, date.getMonth(), date.getDate(),
-                0, 0, 0); // normalized time: 00:00:00
+        cal.set(from.get(Calendar.YEAR),
+                from.get(Calendar.MONTH),
+                from.get(Calendar.DAY_OF_MONTH));
         return new Date(cal.getTimeInMillis());
     }
 
@@ -1021,9 +1034,12 @@ public abstract class ResultSet implemen
      * @return a time object that represents the time in {@code cal}
      */
     private Time convertFromDefaultCalendar(Time time, Calendar cal) {
+        Calendar from = createCalendar(time);
         cal.clear();
         cal.set(1970, Calendar.JANUARY, 1, // normalized date: 1970-01-01
-                time.getHours(), time.getMinutes(), time.getSeconds());
+                from.get(Calendar.HOUR_OF_DAY),
+                from.get(Calendar.MINUTE),
+                from.get(Calendar.SECOND));
         return new Time(cal.getTimeInMillis());
     }
 
@@ -1036,9 +1052,14 @@ public abstract class ResultSet implemen
      * @return a timestamp object that represents the timestamp in {@code cal}
      */
     private Timestamp convertFromDefaultCalendar(Timestamp ts, Calendar cal) {
+        Calendar from = createCalendar(ts);
         cal.clear();
-        cal.set(ts.getYear() + 1900, ts.getMonth(), ts.getDate(),
-                ts.getHours(), ts.getMinutes(), ts.getSeconds());
+        cal.set(from.get(Calendar.YEAR),
+                from.get(Calendar.MONTH),
+                from.get(Calendar.DAY_OF_MONTH),
+                from.get(Calendar.HOUR_OF_DAY),
+                from.get(Calendar.MINUTE),
+                from.get(Calendar.SECOND));
 
         Timestamp result = new Timestamp(cal.getTimeInMillis());
         result.setNanos(ts.getNanos());



Mime
View raw message