Skip to content

Commit 7ca3a9b

Browse files
committed
throw SQLException if timezone comparison query fail.
1 parent 21adf05 commit 7ca3a9b

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

embulk-input-mysql/src/main/java/org/embulk/input/MySQLTimeZoneComparison.java

+29-32
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,37 @@ public void compareTimeZone()
3131
TimeZone serverTimeZone = null;
3232
try {
3333
serverTimeZone = getServerTimeZone();
34-
if (serverTimeZone == null) {
35-
logger.warn("Can't get server TimeZone.");
36-
return;
37-
}
34+
}
35+
catch (SQLException ex) {
36+
logger.warn("Can't get server TimeZone.");
37+
logger.warn(String.format(Locale.ENGLISH, "SQLException raised %s", ex.toString()));
38+
}
3839

39-
TimeZone clientTimeZone = TimeZone.getDefault();
40-
Date today = new Date();
41-
int clientOffset = clientTimeZone.getRawOffset();
40+
TimeZone clientTimeZone = TimeZone.getDefault();
41+
Date today = new Date();
42+
int clientOffset = clientTimeZone.getRawOffset();
4243

43-
if (clientTimeZone.inDaylightTime(today)) {
44-
clientOffset += clientTimeZone.getDSTSavings();
45-
}
44+
if (clientTimeZone.inDaylightTime(today)) {
45+
clientOffset += clientTimeZone.getDSTSavings();
46+
}
4647

47-
//
48-
// Compare offset only. Although I expect to return true, the following code return false,
49-
//
50-
// TimeZone tz_jst = TimeZone.getTimeZone("JST");
51-
// TimeZone tz_gmt9 = TimeZone.getTimeZone("GMT+9");
52-
// tz_jst.hasSameRules(tz_gmt9) // return false.
53-
//
54-
if (clientOffset != serverTimeZone.getRawOffset()) {
55-
logger.warn(String.format(Locale.ENGLISH,
56-
"The client timezone(%s) is different from the server timezone(%s). The plugin will fetch wrong datetime values.",
57-
clientTimeZone.getID(), serverTimeZone.getID()));
58-
logger.warn(String.format(Locale.ENGLISH,
59-
"You may need to set options `useLegacyDatetimeCode` and `serverTimeZone`"));
60-
logger.warn(String.format(Locale.ENGLISH,
61-
"Example: `options: { useLegacyDatetimeCode: false, serverTimeZone: UTC }`"));
62-
}
63-
logger.warn(String.format(Locale.ENGLISH, "The plugin will set `useLegacyDatetimeCode=false` by default in future.")); }
64-
catch (SQLException ex) {
65-
logger.warn(String.format(Locale.ENGLISH, "SQLException raised %s", ex.toString()));
48+
//
49+
// Compare offset only. Although I expect to return true, the following code return false,
50+
//
51+
// TimeZone tz_jst = TimeZone.getTimeZone("JST");
52+
// TimeZone tz_gmt9 = TimeZone.getTimeZone("GMT+9");
53+
// tz_jst.hasSameRules(tz_gmt9) // return false.
54+
//
55+
if (clientOffset != serverTimeZone.getRawOffset()) {
56+
logger.warn(String.format(Locale.ENGLISH,
57+
"The client timezone(%s) is different from the server timezone(%s). The plugin will fetch wrong datetime values.",
58+
clientTimeZone.getID(), serverTimeZone.getID()));
59+
logger.warn(String.format(Locale.ENGLISH,
60+
"You may need to set options `useLegacyDatetimeCode` and `serverTimeZone`"));
61+
logger.warn(String.format(Locale.ENGLISH,
62+
"Example. `options: { useLegacyDatetimeCode: false, serverTimeZone: UTC }`"));
6663
}
64+
logger.warn(String.format(Locale.ENGLISH, "The plugin will set `useLegacyDatetimeCode=false` by default in future."));
6765
}
6866

6967
private TimeZone getServerTimeZone()
@@ -82,9 +80,8 @@ private TimeZone getServerTimeZone()
8280
int offsetSeconds = rs.getInt(1);
8381
return fromGMTOffsetSeconds(offsetSeconds);
8482
}
85-
else {
86-
return null;
87-
}
83+
throw new SQLException(String.format(Locale.ENGLISH,
84+
"The timezone comparison query(%s) doesn't return the result.",query));
8885
}
8986
finally {
9087
stmt.close();

0 commit comments

Comments
 (0)