You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2006/04/22 00:20:07 UTC

svn commit: r396021 - in /db/derby/code/branches/10.1/java: client/org/apache/derby/client/am/DateTime.java client/org/apache/derby/client/net/Request.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java

Author: kmarsden
Date: Fri Apr 21 15:20:04 2006
New Revision: 396021

URL: http://svn.apache.org/viewcvs?rev=396021&view=rev
Log:
DERBY-1127  client gives SqlException for test callable.java and parameterMapping.java on zOS

Contributed by Sunitha Kambhampati


Modified:
    db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java
    db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/Request.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java

Modified: db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java?rev=396021&r1=396020&r2=396021&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java (original)
+++ db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java Fri Apr 21 15:20:04 2006
@@ -20,6 +20,7 @@
 package org.apache.derby.client.am;
 
 import java.io.UnsupportedEncodingException;
+import org.apache.derby.client.net.Typdef;
 
 
 /**
@@ -219,12 +220,20 @@
     // ********************************************************
 
     /**
-     * The returned character representation is in JDBC date format: <code>yyyy-mm-dd</code> date format in DERBY string
-     * representation of a date.
+     * Date is converted to a char representation in JDBC date format: <code>yyyy-mm-dd</code> date format
+     * and then converted to bytes using UTF8 encoding
+     * @param buffer  bytes in UTF8 encoding of the date
+     * @param offset  write into the buffer from this offset 
+     * @param date    date value
+     * @return DateTime.dateRepresentationLength. This is the fixed length in 
+     * bytes taken to represent the date value
+     * @throws SqlException
+     * @throws UnsupportedEncodingException if UTF8 Encoding is not supported
      */
     public static final int dateToDateBytes(byte[] buffer,
                                             int offset,
-                                            java.sql.Date date) throws ConversionException {
+                                            java.sql.Date date) 
+    throws ConversionException,UnsupportedEncodingException {
         int year = date.getYear() + 1900;
         if (year > 9999) {
             throw new ConversionException("Year exceeds the maximum \"9999\".");
@@ -244,19 +253,32 @@
         dateChars[7] = '-';
         dateChars[8] = (char) (day / 10 + zeroBase);
         dateChars[9] = (char) (day % 10 + zeroBase);
-        byte[] dateBytes = (new String(dateChars)).getBytes();
+        
+        // Network server expects to read the date parameter value bytes with
+        // UTF-8 encoding.  Reference - DERBY-1127
+        // see DRDAConnThread.readAndSetParams
+        byte[] dateBytes = (new String(dateChars)).getBytes(Typdef.UTF8ENCODING);
         System.arraycopy(dateBytes, 0, buffer, offset, DateTime.dateRepresentationLength);
 
         return DateTime.dateRepresentationLength;
     }
 
     /**
-     * The returned character representation is in JDBC time escape format: <code>hh:mm:ss</code>, which is the same as
-     * JIS time format in DERBY string representation of a time.
+     * java.sql.Time is converted to character representation which is in JDBC time escape
+     * format: <code>hh:mm:ss</code>, which is the same as JIS time format in DERBY string 
+     * representation of a time.  The char representation is converted to bytes using UTF8 
+     * encoding.
+     * @param buffer  bytes in UTF8 encoding of the time
+     * @param offset  write into the buffer from this offset 
+     * @param time  java.sql.Time value
+     * @return DateTime.timeRepresentationLength. This is the fixed length in 
+     * bytes taken to represent the time value
+     * @throws UnsupportedEncodingException
      */
     public static final int timeToTimeBytes(byte[] buffer,
                                             int offset,
-                                            java.sql.Time time) {
+                                            java.sql.Time time)
+    throws UnsupportedEncodingException {
         int hour = time.getHours();
         int minute = time.getMinutes();
         int second = time.getSeconds();
@@ -271,19 +293,32 @@
         timeChars[5] = ':';
         timeChars[6] = (char) (second / 10 + zeroBase);
         timeChars[7] = (char) (second % 10 + zeroBase);
-        byte[] timeBytes = (new String(timeChars)).getBytes();
+        
+        // Network server expects to read the time parameter value bytes with
+        // UTF-8 encoding.  Reference - DERBY-1127
+        // see DRDAConnThread.readAndSetParams
+        byte[] timeBytes = (new String(timeChars)).getBytes(Typdef.UTF8ENCODING);
         System.arraycopy(timeBytes, 0, buffer, offset, DateTime.timeRepresentationLength);
 
         return DateTime.timeRepresentationLength;
     }
 
     /**
-     * The returned character representation is in DERBY string representation of a timestamp:
-     * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+     * java.sql.Timestamp is converted to a character representation which is in DERBY string 
+     * representation of a timestamp: <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+     * and then converted to bytes using UTF8 encoding
+     * @param buffer  bytes in UTF8 encoding of the timestamp
+     * @param offset  write into the buffer from this offset 
+     * @param timestamp  timestamp value
+     * @return DateTime.timestampRepresentationLength. This is the fixed 
+     * length in bytes, taken to represent the timestamp value
+     * @throws SqlException
+     * @throws UnsupportedEncodingException
      */
     public static final int timestampToTimestampBytes(byte[] buffer,
                                                       int offset,
-                                                      java.sql.Timestamp timestamp) throws ConversionException {
+                                                      java.sql.Timestamp timestamp) 
+    throws ConversionException,UnsupportedEncodingException {
         int year = timestamp.getYear() + 1900;
         if (year > 9999) {
             throw new ConversionException("Year exceeds the maximum \"9999\".");
@@ -323,8 +358,11 @@
         timestampChars[23] = (char) ((microsecond % 1000) / 100 + zeroBase);
         timestampChars[24] = (char) ((microsecond % 100) / 10 + zeroBase);
         timestampChars[25] = (char) (microsecond % 10 + zeroBase);
-
-        byte[] timestampBytes = (new String(timestampChars)).getBytes();
+        
+        // Network server expects to read the timestamp parameter value bytes with
+        // UTF-8 encoding.  Reference - DERBY-1127
+        // see DRDAConnThread.readAndSetParams
+        byte[] timestampBytes = (new String(timestampChars)).getBytes(Typdef.UTF8ENCODING);
         System.arraycopy(timestampBytes, 0, buffer, offset, DateTime.timestampRepresentationLength);
 
         return DateTime.timestampRepresentationLength;
@@ -539,12 +577,21 @@
     // *********************************************************
 
     /**
-     * The returned character representation is in JDBC date escape format: <code>yyyy-mm-dd</code>, which is the same
-     * as JIS date format in DERBY string representation of a date.
+     * java.sql.Timestamp is converted to character representation that is in JDBC date escape 
+     * format: <code>yyyy-mm-dd</code>, which is the same as JIS date format in DERBY string representation of a date.
+     * and then converted to bytes using UTF8 encoding.
+     * @param buffer  
+     * @param offset  write into the buffer from this offset 
+     * @param timestamp  timestamp value
+     * @return DateTime.dateRepresentationLength. This is the fixed length 
+     * in bytes, that is taken to represent the timestamp value as a date.
+     * @throws ConversionException
+     * @throws UnsupportedEncodingException
      */
     public static final int timestampToDateBytes(byte[] buffer,
                                                  int offset,
-                                                 java.sql.Timestamp timestamp) throws ConversionException {
+                                                 java.sql.Timestamp timestamp)
+    throws ConversionException,UnsupportedEncodingException {
         int year = timestamp.getYear() + 1900;
         if (year > 9999) {
             throw new ConversionException("Year exceeds the maximum \"9999\".");
@@ -564,19 +611,31 @@
         dateChars[7] = '-';
         dateChars[8] = (char) (day / 10 + zeroBase);
         dateChars[9] = (char) (day % 10 + zeroBase);
-        byte[] dateBytes = (new String(dateChars)).getBytes();
+        // Network server expects to read the date parameter value bytes with
+        // UTF-8 encoding.  Reference - DERBY-1127
+        // see DRDAConnThread.readAndSetParams
+        byte[] dateBytes = (new String(dateChars)).getBytes(Typdef.UTF8ENCODING);
         System.arraycopy(dateBytes, 0, buffer, offset, DateTime.dateRepresentationLength);
 
         return DateTime.dateRepresentationLength;
     }
 
     /**
-     * The returned character representation is in JDBC time escape format: <code>hh:mm:ss</code>, which is the same as
-     * JIS time format in DERBY string representation of a time.
+     * java.sql.Timestamp is converted to character representation in JDBC time escape format:
+     *  <code>hh:mm:ss</code>, which is the same as
+     * JIS time format in DERBY string representation of a time. The char representation is 
+     * then converted to bytes using UTF8 encoding and written out into the buffer
+     * @param buffer
+     * @param offset  write into the buffer from this offset 
+     * @param timestamp timestamp value
+     * @return DateTime.timeRepresentationLength. This is the fixed length 
+     * in bytes taken to represent the timestamp value as Time.
+     * @throws UnsupportedEncodingException
      */
     public static final int timestampToTimeBytes(byte[] buffer,
                                                  int offset,
-                                                 java.sql.Timestamp timestamp) {
+                                                 java.sql.Timestamp timestamp)
+        throws UnsupportedEncodingException {
         int hour = timestamp.getHours();
         int minute = timestamp.getMinutes();
         int second = timestamp.getSeconds();
@@ -591,19 +650,32 @@
         timeChars[5] = ':';
         timeChars[6] = (char) (second / 10 + zeroBase);
         timeChars[7] = (char) (second % 10 + zeroBase);
-        byte[] timeBytes = (new String(timeChars)).getBytes();
+        
+        // Network server expects to read the time parameter value bytes with
+        // UTF-8 encoding.  Reference - DERBY-1127
+        // see DRDAConnThread.readAndSetParams 
+        byte[] timeBytes = (new String(timeChars)).getBytes(Typdef.UTF8ENCODING);
         System.arraycopy(timeBytes, 0, buffer, offset, DateTime.timeRepresentationLength);
 
         return DateTime.timeRepresentationLength;
     }
 
     /**
-     * The returned character representation is in DERBY string representation of a timestamp:
-     * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+     * java.sql.Date is converted to character representation that is in DERBY string 
+     * representation of a timestamp:<code>yyyy-mm-dd-hh.mm.ss.ffffff</code> and then 
+     * converted to bytes using UTF8 encoding and written out to the buffer
+     * @param buffer
+     * @param offset offset in buffer to start writing to
+     * @param date date value
+     * @return DateTime.timestampRepresentationLength. This is the fixed length
+     * in bytes, taken to represent the timestamp value.
+     * @throws ConversionException
+     * @throws UnsupportedEncodingException
      */
     public static final int dateToTimestampBytes(byte[] buffer,
                                                  int offset,
-                                                 java.sql.Date date) throws ConversionException {
+                                                 java.sql.Date date)
+    throws ConversionException, UnsupportedEncodingException {
         int year = date.getYear() + 1900;
         if (year > 9999) {
             throw new ConversionException("Year exceeds the maximum \"9999\".");
@@ -639,20 +711,30 @@
         timestampChars[23] = '0';
         timestampChars[24] = '0';
         timestampChars[25] = '0';
-
-        byte[] timestampBytes = (new String(timestampChars)).getBytes();
+        
+        // Network server expects to read the timestamp parameter value bytes with
+        // UTF-8 encoding.  Reference - DERBY-1127
+        // see DRDAConnThread.readAndSetParams 
+        byte[] timestampBytes = (new String(timestampChars)).getBytes(Typdef.UTF8ENCODING);
         System.arraycopy(timestampBytes, 0, buffer, offset, DateTime.timestampRepresentationLength);
 
         return DateTime.timestampRepresentationLength;
     }
 
     /**
-     * The returned character representation is in DERBY string representation of a timestamp:
-     * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+     * java.sql.Time is converted to a character representation that is in DERBY string representation of a timestamp:
+     * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code> and converted to bytes using UTF8 encoding 
+     * @param buffer
+     * @param offset offset in buffer to start writing to
+     * @param time time value
+     * @return DateTime.timestampRepresentationLength which is the fixed length
+     * taken up by the conversion of time to timestamp in bytes
+     * @throws UnsupportedEncodingException
      */
     public static final int timeToTimestampBytes(byte[] buffer,
                                                  int offset,
-                                                 java.sql.Time time) {
+                                                 java.sql.Time time)
+    throws UnsupportedEncodingException {
         int hour = time.getHours();
         int minute = time.getMinutes();
         int second = time.getSeconds();
@@ -686,7 +768,10 @@
         timestampChars[24] = '0';
         timestampChars[25] = '0';
 
-        byte[] timestampBytes = (new String(timestampChars)).getBytes();
+        // Network server expects to read the timestamp parameter value bytes with
+        // UTF-8 encoding.  Reference - DERBY-1127
+        // see DRDAConnThread.readAndSetParams for TIMESTAMP
+        byte[] timestampBytes = (new String(timestampChars)).getBytes(Typdef.UTF8ENCODING);
         System.arraycopy(timestampBytes, 0, buffer, offset, DateTime.timestampRepresentationLength);
 
         return DateTime.timestampRepresentationLength;

Modified: db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/Request.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/Request.java?rev=396021&r1=396020&r2=396021&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/Request.java (original)
+++ db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/Request.java Fri Apr 21 15:20:04 2006
@@ -24,6 +24,8 @@
 import org.apache.derby.client.am.SqlException;
 import org.apache.derby.client.am.Utils;
 
+import java.io.UnsupportedEncodingException;
+
 public class Request {
 
     // byte array buffer used for constructing requests.
@@ -1538,12 +1540,21 @@
             throw new SqlException(netAgent_.logWriter_, e,
                     "Date conversion exception " + e.getMessage() + ". See attached Throwable.");
         }
+        catch (java.io.UnsupportedEncodingException uee) {
+            throw new SqlException(netAgent_.logWriter_, uee,
+                    "Date conversion exception " + uee.getMessage() + ". See attached Throwable.");
+        }
     }
 
     final void writeTime(java.sql.Time time) throws SqlException {
-        ensureLength(offset_ + 8);
-        org.apache.derby.client.am.DateTime.timeToTimeBytes(bytes_, offset_, time);
-        offset_ += 8;
+        try{
+            ensureLength(offset_ + 8);
+            org.apache.derby.client.am.DateTime.timeToTimeBytes(bytes_, offset_, time);
+            offset_ += 8;
+        } catch(UnsupportedEncodingException uee) {
+            throw new SqlException(netAgent_.logWriter_,uee, 
+                "Time conversion exception "+uee.getMessage() +". See attached Throwable.");
+      }
     }
 
     final void writeTimestamp(java.sql.Timestamp timestamp) throws SqlException {
@@ -1554,6 +1565,10 @@
         } catch (org.apache.derby.client.am.ConversionException e) {
             throw new SqlException(netAgent_.logWriter_, e,
                     "Timestamp conversion exception " + e.getMessage() + ". See attached Throwable.");
+        }
+        catch(UnsupportedEncodingException uee) {
+            throw new SqlException(netAgent_.logWriter_,  uee,
+                    "Timestamp conversion exception " + uee.getMessage() + ". See attached Throwable.");
         }
     }
 

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java?rev=396021&r1=396020&r2=396021&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java Fri Apr 21 15:20:04 2006
@@ -4,8 +4,7 @@
 
    Copyright 2002, 2005 The Apache Software Foundation or its licensors, as applicable.
 
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
+   Licensed under the Apache aexcept in compliance with the License.
    You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0