Skip to content

Commit 1d173c6

Browse files
Merge pull request #259 from hiroyuki-sato/topic/accept-new-timeutil
initializes com.mysql.jdbc.TimeUtil.timeZoneMappings if needed (Connector/J 5.x)
2 parents 4d0d07b + 53dee52 commit 1d173c6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected MySQLInputConnection newConnection(PluginTask task) throws SQLExceptio
125125
logConnectionProperties(url, props);
126126

127127
// load timezone mappings
128-
loadTimeZoneMappings();
128+
loadTimeZoneMappingsIfNeeded();
129129

130130
Connection con = DriverManager.getConnection(url, props);
131131
try {
@@ -145,7 +145,7 @@ protected ColumnGetterFactory newColumnGetterFactory(final PageBuilder pageBuild
145145
return new MySQLColumnGetterFactory(pageBuilder, dateTimeZone);
146146
}
147147

148-
private void loadTimeZoneMappings()
148+
private void loadTimeZoneMappingsIfNeeded()
149149
{
150150
// Here initializes com.mysql.jdbc.TimeUtil.timeZoneMappings static field by calling
151151
// static timeZoneMappings method using reflection.
@@ -156,7 +156,11 @@ private void loadTimeZoneMappings()
156156
// from the classloader. It seems like a bug of JDBC Driver where it should use the class loader
157157
// that loaded com.mysql.jdbc.TimeUtil class rather than system class loader to read the
158158
// property file because the file should be in the same classpath with the class.
159-
// Here implements a workaround as as workaround.
159+
// Here implements a workaround as a workaround.
160+
//
161+
// This workaround seems required only for Connector/J 5.x (com.mysql.jdbc.TimeUtil),
162+
// not necessary for Connector/J 8.x (com.mysql.cj.util.TimeUtil).
163+
// TODO: Clarify for Connector/J 8.x just in case.
160164
Field f = null;
161165
try {
162166
Class<?> timeUtilClass = Class.forName("com.mysql.jdbc.TimeUtil");
@@ -172,7 +176,16 @@ private void loadTimeZoneMappings()
172176
f.set(null, timeZoneMappings);
173177
}
174178
}
175-
catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | IOException e) {
179+
catch (ClassNotFoundException e) {
180+
try {
181+
Class.forName("com.mysql.cj.util.TimeUtil");
182+
} catch (final ClassNotFoundException ex2) {
183+
// Throw if neither the Connector/J 5.x nor 8.x driver is found.
184+
throw new RuntimeException(e);
185+
}
186+
}
187+
// Pass-through if the Connector/J 8.x driver is found. }
188+
catch (IllegalAccessException | NoSuchFieldException | IOException e) {
176189
throw new RuntimeException(e);
177190
}
178191
finally {

0 commit comments

Comments
 (0)