Skip to content

Commit 275dbf3

Browse files
committed
Add error check and change log messages
1 parent 14f82b0 commit 275dbf3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ public MySQLTimeZoneComparison(Connection connection)
2727

2828
public void compareTimeZone() throws SQLException
2929
{
30-
// TODO error check.
31-
TimeZone serverTimeZone = getServerTimeZone();
30+
TimeZone serverTimeZone = null;
31+
try {
32+
serverTimeZone = getServerTimeZone();
33+
} catch (SQLException ex) {
34+
logger.error(String.format(Locale.ENGLISH,"SQLException raised %s",ex.toString()));
35+
}
36+
37+
if( serverTimeZone == null ){
38+
logger.warn("Can't get server TimeZone");
39+
return;
40+
}
41+
3242
TimeZone clientTimeZone = TimeZone.getDefault();
3343
Date today = new Date();
3444
int clientOffset = clientTimeZone.getRawOffset();
@@ -49,7 +59,9 @@ public void compareTimeZone() throws SQLException
4959
"The client timezone(%s) is different from the server timezone(%s). The plugin will fetch wrong datetime values.",
5060
clientTimeZone.getID(),serverTimeZone.getID()));
5161
logger.warn(String.format(Locale.ENGLISH,
52-
"Use `options: { useLegacyDatetimeCode: false }`"));
62+
"Use `You may need to set options useLegacyDatetimeCode and serverTimeZone`"));
63+
logger.warn(String.format(Locale.ENGLISH,
64+
"Ex. `options: { useLegacyDatetimeCode: false, serverTimeZone: UTC }`"));
5365
}
5466
logger.warn(String.format(Locale.ENGLISH,"The plugin will set `useLegacyDatetimeCode=false` by default in future."));
5567

@@ -72,7 +84,6 @@ private TimeZone getServerTimeZone() throws SQLException
7284
return fromGMTOffsetSeconds(offsetSeconds);
7385
}
7486
else {
75-
// TODO Error check.
7687
return null;
7788
}
7889

0 commit comments

Comments
 (0)