sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mau...@apache.org
Subject [1/2] sqoop git commit: SQOOP-3071: Fix OracleManager to apply localTimeZone correctly in case of Date objects too
Date Tue, 06 Dec 2016 16:55:47 GMT
Repository: sqoop
Updated Branches:
  refs/heads/trunk bd51d987b -> 642b41a9e


SQOOP-3071: Fix OracleManager to apply localTimeZone correctly in case of Date objects too

(Attila Szabo)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/fe67a0a5
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/fe67a0a5
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/fe67a0a5

Branch: refs/heads/trunk
Commit: fe67a0a5c0a6875e3cd3e87feb3df1a73939be57
Parents: bd51d98
Author: Attila Szabo <maugli@apache.org>
Authored: Tue Dec 6 17:53:31 2016 +0100
Committer: Attila Szabo <maugli@apache.org>
Committed: Tue Dec 6 17:53:31 2016 +0100

----------------------------------------------------------------------
 .../org/apache/sqoop/manager/OracleManager.java  | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/fe67a0a5/src/java/org/apache/sqoop/manager/OracleManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/sqoop/manager/OracleManager.java b/src/java/org/apache/sqoop/manager/OracleManager.java
index 3273435..2f4585c 100644
--- a/src/java/org/apache/sqoop/manager/OracleManager.java
+++ b/src/java/org/apache/sqoop/manager/OracleManager.java
@@ -38,6 +38,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.TimeZone;
 import java.util.TreeMap;
 
 import org.apache.commons.lang.StringUtils;
@@ -396,10 +397,12 @@ public class OracleManager
     // Need to use reflection to call the method setSessionTimeZone on the
     // OracleConnection class because oracle specific java libraries are not
     // accessible in this context.
-    Method method;
+    Method methodSession;
+    Method methodDefaultTimezone;
     try {
-      method = conn.getClass().getMethod(
+      methodSession = conn.getClass().getMethod(
               "setSessionTimeZone", new Class [] {String.class});
+      methodDefaultTimezone = conn.getClass().getMethod("setDefaultTimeZone", TimeZone.class);
     } catch (Exception ex) {
       LOG.error("Could not find method setSessionTimeZone in "
         + conn.getClass().getName(), ex);
@@ -412,9 +415,13 @@ public class OracleManager
     // the configuration as 'oracle.sessionTimeZone'.
     String clientTimeZoneStr = options.getConf().get(ORACLE_TIMEZONE_KEY,
         "GMT");
+    TimeZone timeZone = TimeZone.getTimeZone(clientTimeZoneStr);
+    TimeZone.setDefault(timeZone);
     try {
-      method.setAccessible(true);
-      method.invoke(conn, clientTimeZoneStr);
+      methodSession.setAccessible(true);
+      methodSession.invoke(conn, clientTimeZoneStr);
+      methodDefaultTimezone.setAccessible(true);
+      methodDefaultTimezone.invoke(conn, timeZone);
       LOG.info("Time zone has been set to " + clientTimeZoneStr);
     } catch (Exception ex) {
       LOG.warn("Time zone " + clientTimeZoneStr
@@ -426,7 +433,9 @@ public class OracleManager
         //     /server.102/b14225/applocaledata.htm#i637736
         // The "GMT" timezone is guaranteed to exist in the available timezone
         // regions, whereas others (e.g., "UTC") are not.
-        method.invoke(conn, "GMT");
+        methodSession.invoke(conn, "GMT");
+        methodDefaultTimezone.invoke(conn, "GMT");
+        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
       } catch (Exception ex2) {
         LOG.error("Could not set time zone for oracle connection", ex2);
         // rethrow SQLException


Mime
View raw message