Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 42629 invoked from network); 4 Jan 2011 08:47:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Jan 2011 08:47:53 -0000 Received: (qmail 76656 invoked by uid 500); 4 Jan 2011 08:47:53 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 76593 invoked by uid 500); 4 Jan 2011 08:47:52 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 76586 invoked by uid 99); 4 Jan 2011 08:47:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jan 2011 08:47:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jan 2011 08:47:51 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 010C4238897A; Tue, 4 Jan 2011 08:47:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1054933 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4: CallableStatementTest.java ResultSetTest.java Wrapper41Test.java Date: Tue, 04 Jan 2011 08:47:30 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110104084731.010C4238897A@eris.apache.org> Author: kahatlen Date: Tue Jan 4 08:47:30 2011 New Revision: 1054933 URL: http://svn.apache.org/viewvc?rev=1054933&view=rev Log: DERBY-4869: Implement JDBC 4.1, the api increment introduced by Java 7 Calculate expected time and timestamp strings in a way that takes the time zone into consideration. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java?rev=1054933&r1=1054932&r2=1054933&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java Tue Jan 4 08:47:30 2011 @@ -26,16 +26,12 @@ import junit.framework.*; import org.apache.derby.iapi.types.HarmonySerialBlob; import org.apache.derby.iapi.types.HarmonySerialClob; -import org.apache.derbyTesting.junit.BaseJDBCTestCase; import org.apache.derbyTesting.junit.TestConfiguration; - import java.io.IOException; import java.io.Reader; import java.math.BigDecimal; import java.sql.*; -import java.lang.reflect.Method; -import java.util.Vector; /** * Tests of the java.sql.CallableStatement JDBC40 API. @@ -722,8 +718,8 @@ public class CallableStatementTest exte numericarg[0] = new BigDecimal( "1.0" ); realarg[0] = floatValue; smallintarg[0] = intValue; - timearg[0] = new Time( 83342000L ); - timestamparg[0] = new Timestamp( -229527385766L ); + timearg[0] = new Time(TIME_VALUE); + timestamparg[0] = new Timestamp(TIMESTAMP_VALUE); varchararg[0] = stringValue; varcharforbitdataarg[0] = BINARY_VALUE; } Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java?rev=1054933&r1=1054932&r2=1054933&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java Tue Jan 4 08:47:30 2011 @@ -21,7 +21,6 @@ package org.apache.derbyTesting.functionTests.tests.jdbc4; -import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -30,7 +29,6 @@ import java.sql.ResultSet; import java.sql.Statement; import java.sql.Blob; import java.sql.Clob; -import java.sql.Date; import java.sql.NClob; import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLException; @@ -49,9 +47,7 @@ import org.apache.derbyTesting.functionT import junit.framework.Test; import junit.framework.TestSuite; -import junit.extensions.TestSetup; -import org.apache.derbyTesting.junit.BaseJDBCTestCase; import org.apache.derbyTesting.junit.BaseJDBCTestSetup; import org.apache.derbyTesting.junit.TestConfiguration; @@ -2062,12 +2058,14 @@ public class ResultSetTest extends Wrap " 1.0,\n" + " 1.0,\n" + " 1,\n" + - " time('15:09:02'),\n" + - " timestamp('1962-09-23 03:23:34.234'),\n" + + " ?,\n" + + " ?,\n" + " 'a',\n" + " X'DE'\n" + ")\n" ); + ps.setTime(1, new Time(TIME_VALUE)); + ps.setTimestamp(2, new Timestamp(TIMESTAMP_VALUE)); ps.executeUpdate(); ps.close(); Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java?rev=1054933&r1=1054932&r2=1054933&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java Tue Jan 4 08:47:30 2011 @@ -23,23 +23,17 @@ package org.apache.derbyTesting.function import java.math.BigDecimal; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.CallableStatement; -import java.sql.ResultSet; -import java.sql.Statement; import java.sql.Blob; import java.sql.Clob; import java.sql.Date; -import java.sql.NClob; -import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; -import junit.framework.*; +import java.util.Calendar; import org.apache.derbyTesting.junit.BaseJDBCTestCase; -import org.apache.derbyTesting.junit.TestConfiguration; /** *

@@ -62,6 +56,8 @@ public class Wrapper41Test extends public static final byte[] BINARY_VALUE = new byte[] { (byte) 0xde }; + static final long TIME_VALUE = 83342000L; + static final long TIMESTAMP_VALUE = -229527385766L; /////////////////////////////////////////////////////////////////////// @@ -433,12 +429,14 @@ public class Wrapper41Test extends } private void vetWrappedTime( Wrapper41 wrapper ) throws Exception { + Time expectedTime = new Time(TIME_VALUE); + vetWrapperOK ( wrapper, 16, "TIMECOL", - VARIABLE_STRING, + expectedTime.toString(), new Class[] { String.class, Time.class, Object.class } ); vetWrapperOK @@ -446,7 +444,7 @@ public class Wrapper41Test extends wrapper, 16, "TIMECOL", - VARIABLE_STRING, + timeToTimestamp(expectedTime).toString(), new Class[] { Timestamp.class } ); @@ -467,28 +465,33 @@ public class Wrapper41Test extends } private void vetWrappedTimestamp( Wrapper41 wrapper ) throws Exception { + String expectedTimestamp = new Timestamp(TIMESTAMP_VALUE).toString(); vetWrapperOK ( wrapper, 17, "TIMESTAMPCOL", - "1962-09-23 03:23:34.234", + expectedTimestamp, new Class[] { String.class, Timestamp.class, Object.class } ); + + String expectedTime = new Time(TIMESTAMP_VALUE).toString(); vetWrapperOK ( wrapper, 17, "TIMESTAMPCOL", - "03:23:34", + expectedTime, new Class[] { Time.class } ); + + String expectedDate = new Date(TIMESTAMP_VALUE).toString(); vetWrapperOK ( wrapper, 17, "TIMESTAMPCOL", - "1962-09-23", + expectedDate, new Class[] { Date.class } ); @@ -633,4 +636,40 @@ public class Wrapper41Test extends return cs; } + /** + * Convert a Time value to a Timestamp value the same way as when we call + * getTimestamp() on a TIME column. That is, construct a Timestamp value + * with the date component set to the current date and the time component + * set to the specified time of day. + * + * @param time the Time value to convert + * @return a Timestamp value representing the specified time on the + * current date + */ + private static Timestamp timeToTimestamp(Time time) { + // Create a calendar object representing the time value + Calendar timeCal = Calendar.getInstance(); + timeCal.setTime(time); + + // Create a calendar object for the timestamp, initialized with + // the current time value + Calendar tsCal = Calendar.getInstance(); + + // Copy all fields, except the date fields, from the time calendar + // to the timestamp calendar + int[] timeFields = { + Calendar.HOUR_OF_DAY, + Calendar.MINUTE, + Calendar.SECOND, + Calendar.MILLISECOND + }; + + for (int field : timeFields) { + tsCal.set(field, timeCal.get(field)); + } + + // Return a timestamp based on the current date and the specified time + return new Timestamp(tsCal.getTimeInMillis()); + } + }