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 ka...@apache.org on 2011/01/04 09:47:30 UTC
svn commit: r1054933 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4:
CallableStatementTest.java ResultSetTest.java Wrapper41Test.java
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 <code>java.sql.CallableStatement</code> 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;
/**
* <p>
@@ -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());
+ }
+
}