From 4bd080d9d484fe36261779d237e17c51b915e6ce Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 29 Sep 2015 23:39:40 +0200 Subject: [PATCH] [misc] version 1.3.0-beta-2 --- build_release.bat | 2 +- pom.xml | 2 +- src/main/java/org/mariadb/jdbc/Version.java | 4 +- .../jdbc/internal/mysql/MySQLValueObject.java | 47 +++++++-- .../jdbc/TimezoneDaylightSavingTimeTest.java | 98 ++++++++----------- 5 files changed, 84 insertions(+), 69 deletions(-) diff --git a/build_release.bat b/build_release.bat index 7f76c2ff1..dca7d7936 100644 --- a/build_release.bat +++ b/build_release.bat @@ -11,5 +11,5 @@ call %BINDIR%\mysqladmin -uroot shutdown #deploy package #generate javadoc : mvn javadoc:javadoc -#mvn clean deploy -Dmaven.test.skip=true -Dpackage-source +#mvn clean exec:exec deploy package -Dmaven.test.skip=true -Dpackage-source diff --git a/pom.xml b/pom.xml index 826f13abc..0f5c9155c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ mariadb-java-client jar mariadb-java-client - 1.3.0-beta-1 + 1.3.0-beta-2 JDBC driver for MariaDB and MySQL https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/ diff --git a/src/main/java/org/mariadb/jdbc/Version.java b/src/main/java/org/mariadb/jdbc/Version.java index d941c6df1..3224b858c 100644 --- a/src/main/java/org/mariadb/jdbc/Version.java +++ b/src/main/java/org/mariadb/jdbc/Version.java @@ -1,10 +1,10 @@ package org.mariadb.jdbc; public final class Version { - public static final String version = "1.3.0-SNAPSHOT"; + public static final String version = "1.3.0-beta-2"; public static final int majorVersion = 1; public static final int minorVersion = 3; public static final int patchVersion = 0; - public static final String qualifier = "SNAPSHOT"; + public static final String qualifier = "beta-2"; } \ No newline at end of file diff --git a/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLValueObject.java b/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLValueObject.java index 609f5e4a0..7c87c6720 100644 --- a/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLValueObject.java +++ b/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLValueObject.java @@ -658,7 +658,36 @@ public Time getTime(Calendar cal) throws ParseException { } private Date binaryDate(Calendar cal) throws ParseException { - return new Date(getTimestamp(cal).getTime()); + if (rawBytes.length == 0) return null; + int year = 1970; + int month = 1; + int day = 1; + int hour = 0; + int minutes = 0; + int seconds = 0; + + year = ((rawBytes[0] & 0xff) | (rawBytes[1] & 0xff) << 8); + month = rawBytes[2]; + day = rawBytes[3]; + + Calendar c = Calendar.getInstance(); + /*if (!options.useLegacyDatetimeCode) { + c = cal; + }*/ + + Date dt; + synchronized (c) { + c.clear(); + c.set(Calendar.YEAR, year); + c.set(Calendar.MONTH, month - 1); + c.set(Calendar.DAY_OF_MONTH, day); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + dt = new Date(c.getTimeInMillis()); + } + return dt; } private Time binaryTime() { @@ -721,14 +750,14 @@ private Timestamp binaryTimestamp(Calendar cal) throws ParseException { } Calendar c = Calendar.getInstance(); - c.set(Calendar.YEAR, year); - c.set(Calendar.MONTH, month - 1); - c.set(Calendar.DAY_OF_MONTH, day); - c.set(Calendar.HOUR_OF_DAY, hour); - c.set(Calendar.MINUTE, minutes); - c.set(Calendar.SECOND, seconds); - c.set(Calendar.MILLISECOND, microseconds / 1000); - Timestamp tt = new Timestamp(c.getTimeInMillis()); + if (!options.useLegacyDatetimeCode) { + c = cal; + } + Timestamp tt; + synchronized (c) { + c.set(year, month - 1, day, hour, minutes, seconds); + tt = new Timestamp(c.getTimeInMillis()); + } tt.setNanos(microseconds * 1000); return tt; } diff --git a/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java b/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java index 01b9430a6..786f1b830 100644 --- a/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java +++ b/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java @@ -340,82 +340,68 @@ public void testTimeStampOffsetNowUseServer() throws SQLException { @Test public void testDayLightLegacy() throws SQLException { - testDayLight(true, false); - } - - @Test - public void testDayLightLegacyForceServer() throws SQLException { - testDayLight(true, true); + testDayLight(true); } @Test public void testDayLight() throws SQLException { - testDayLight(true, false); - } - - @Test - public void testDayLightForceServer() throws SQLException { - testDayLight(true, true); + testDayLight(false); } - private void testDayLight(boolean legacy, boolean forceServerZone) throws SQLException { + private void testDayLight(boolean legacy) throws SQLException { Assume.assumeTrue(hasSuperPrivilege("testDayLight")); TimeZone.setDefault(parisTimeZone); Connection connection = null; try { - connection = setConnection("&useLegacyDatetimeCode=" + legacy + ((forceServerZone) ? "&serverTimezone=Europe/Paris" : "")); - setSessionTimeZone(connection, "Europe/Paris"); - Statement st = connection.createStatement(); - String serverTimeZone = null; - ResultSet rs = st.executeQuery("SHOW GLOBAL VARIABLES LIKE 'time_zone';"); - if (rs.next()) { - serverTimeZone = rs.getString(2); - } - try { - createTable("daylight", "id int, t1 TIMESTAMP(6), t2 TIME(6), t3 DATETIME(6) , t4 DATE"); - Calendar quarterBeforeChangingHour = Calendar.getInstance(TimeZone.getTimeZone("utc")); - quarterBeforeChangingHour.clear(); - quarterBeforeChangingHour.set(2015, 2, 29, 0, 45, 0); - int offsetBefore = parisTimeZone.getOffset(quarterBeforeChangingHour.getTimeInMillis()); - Assert.assertEquals(offsetBefore, 3600000); + connection = setConnection("&useLegacyDatetimeCode=" + legacy + "&serverTimezone=Canada/Atlantic"); + setSessionTimeZone(connection, "Canada/Atlantic"); - Calendar quarterAfterChangingHour = Calendar.getInstance(TimeZone.getTimeZone("utc")); - quarterAfterChangingHour.clear(); - quarterAfterChangingHour.set(2015, 2, 29, 1, 15, 0); - int offsetAfter = parisTimeZone.getOffset(quarterAfterChangingHour.getTimeInMillis()); - Assert.assertEquals(offsetAfter, 7200000); + createTable("daylight", "id int, t1 TIMESTAMP(6), t2 TIME(6), t3 DATETIME(6) , t4 DATE"); + Calendar quarterBeforeChangingHour = Calendar.getInstance(TimeZone.getTimeZone("utc")); + quarterBeforeChangingHour.clear(); + quarterBeforeChangingHour.set(2015, 2, 29, 0, 45, 0); + int offsetBefore = parisTimeZone.getOffset(quarterBeforeChangingHour.getTimeInMillis()); + Assert.assertEquals(offsetBefore, 3600000); - Timestamp vt1 = new Timestamp(quarterBeforeChangingHour.getTimeInMillis()); - vt1.setNanos(12340000); - PreparedStatement pst = connection.prepareStatement("INSERT INTO daylight VALUES (?, ?, ?, ?, ?)"); - pst.setInt(1, 1); - pst.setTimestamp(2, vt1); - pst.setTime(3, new Time(quarterBeforeChangingHour.getTimeInMillis())); - pst.setTimestamp(4, vt1); - pst.setDate(5, new java.sql.Date(quarterBeforeChangingHour.getTimeInMillis())); - pst.addBatch(); - pst.setInt(1, 2); - pst.setTimestamp(2, new Timestamp(quarterAfterChangingHour.getTimeInMillis())); - pst.setTime(3, new Time(quarterAfterChangingHour.getTimeInMillis())); - pst.setTimestamp(4, new Timestamp(quarterAfterChangingHour.getTimeInMillis())); - pst.setDate(5, new java.sql.Date(quarterAfterChangingHour.getTimeInMillis())); - pst.addBatch(); - pst.executeBatch(); + SimpleDateFormat cDateFormatISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + cDateFormatISO8601.setTimeZone(canadaTimeZone); - checkResult(true, connection); - checkResult(false, connection); + Calendar test = Calendar.getInstance(TimeZone.getTimeZone("Canada/Atlantic")); + test.set(2015, 2, 28, 22, 45, 0); + System.out.println(cDateFormatISO8601.format(test.getTime())); + Calendar quarterAfterChangingHour = Calendar.getInstance(TimeZone.getTimeZone("utc")); + quarterAfterChangingHour.clear(); + quarterAfterChangingHour.set(2015, 2, 29, 1, 15, 0); + int offsetAfter = parisTimeZone.getOffset(quarterAfterChangingHour.getTimeInMillis()); + Assert.assertEquals(offsetAfter, 7200000); - } finally { - if (serverTimeZone != null) - st.executeQuery("SET GLOBAL time_zone = '" + serverTimeZone + "'"); - } + Timestamp vt1 = new Timestamp(quarterBeforeChangingHour.getTimeInMillis()); + vt1.setNanos(12340000); + PreparedStatement pst = connection.prepareStatement("INSERT INTO daylight VALUES (?, ?, ?, ?, ?)"); + pst.setInt(1, 1); + pst.setTimestamp(2, vt1); + pst.setTime(3, new Time(quarterBeforeChangingHour.getTimeInMillis())); + pst.setTimestamp(4, Timestamp.valueOf("2015-03-29 01:45:00")); + pst.setDate(5, new java.sql.Date(quarterBeforeChangingHour.getTimeInMillis())); + pst.addBatch(); + pst.setInt(1, 2); + pst.setTimestamp(2, Timestamp.valueOf("2015-03-29 03:15:00")); + pst.setTime(3, new Time(quarterAfterChangingHour.getTimeInMillis())); + pst.setTimestamp(4, Timestamp.valueOf("2015-03-29 03:15:00")); + pst.setDate(5, new java.sql.Date(quarterAfterChangingHour.getTimeInMillis())); + pst.addBatch(); + pst.executeBatch(); + + checkResult(true, connection); + checkResult(false, connection); + } finally { - connection.close(); + if (connection != null) connection.close(); } }