mirror of
https://github.com/apache/sqoop.git
synced 2025-05-03 03:59:18 +08:00
Set Oracle session timezone based on property.
From: Aaron Kimball <aaron@cloudera.com> git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149893 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
acba9c1aea
commit
c37e2d0568
@ -27,7 +27,6 @@
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
@ -49,6 +48,8 @@ public class OracleManager extends GenericJdbcManager {
|
|||||||
// driver class to ensure is loaded when making db connection.
|
// driver class to ensure is loaded when making db connection.
|
||||||
private static final String DRIVER_CLASS = "oracle.jdbc.OracleDriver";
|
private static final String DRIVER_CLASS = "oracle.jdbc.OracleDriver";
|
||||||
|
|
||||||
|
// Configuration key to use to set the session timezone.
|
||||||
|
public static final String ORACLE_TIMEZONE_KEY = "oracle.sessionTimeZone";
|
||||||
|
|
||||||
// Oracle XE does a poor job of releasing server-side resources for
|
// Oracle XE does a poor job of releasing server-side resources for
|
||||||
// closed connections. So we actually want to cache connections as
|
// closed connections. So we actually want to cache connections as
|
||||||
@ -255,15 +256,16 @@ private void setSessionTimeZone(Connection conn) throws SQLException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Need to set the time zone in order for Java
|
// Need to set the time zone in order for Java
|
||||||
// to correctly access the column "TIMESTAMP WITH LOCAL TIME ZONE"
|
// to correctly access the column "TIMESTAMP WITH LOCAL TIME ZONE".
|
||||||
String clientTimeZone = TimeZone.getDefault().getID();
|
// The user may have set this in the configuration as 'oracle.sessionTimeZone'.
|
||||||
|
String clientTimeZoneStr = options.getConf().get(ORACLE_TIMEZONE_KEY, "GMT");
|
||||||
try {
|
try {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(conn, clientTimeZone);
|
method.invoke(conn, clientTimeZoneStr);
|
||||||
LOG.info("Time zone has been set");
|
LOG.info("Time zone has been set to " + clientTimeZoneStr);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.warn("Time zone " + clientTimeZone +
|
LOG.warn("Time zone " + clientTimeZoneStr +
|
||||||
" could not be set on oracle database.");
|
" could not be set on Oracle database.");
|
||||||
LOG.info("Setting default time zone: GMT");
|
LOG.info("Setting default time zone: GMT");
|
||||||
try {
|
try {
|
||||||
// Per the documentation at:
|
// Per the documentation at:
|
||||||
|
@ -103,6 +103,7 @@ public void setUp() {
|
|||||||
OracleUtils.setOracleAuth(options);
|
OracleUtils.setOracleAuth(options);
|
||||||
|
|
||||||
manager = new OracleManager(options);
|
manager = new OracleManager(options);
|
||||||
|
options.getConf().set("oracle.sessionTimeZone", "US/Pacific");
|
||||||
|
|
||||||
// Drop the existing table, if there is one.
|
// Drop the existing table, if there is one.
|
||||||
try {
|
try {
|
||||||
@ -172,6 +173,9 @@ public void tearDown() {
|
|||||||
|
|
||||||
CommonArgs.addHadoopFlags(args);
|
CommonArgs.addHadoopFlags(args);
|
||||||
|
|
||||||
|
args.add("-D");
|
||||||
|
args.add("oracle.sessionTimeZone=US/Pacific");
|
||||||
|
|
||||||
args.add("--table");
|
args.add("--table");
|
||||||
args.add(TABLE_NAME);
|
args.add(TABLE_NAME);
|
||||||
args.add("--warehouse-dir");
|
args.add("--warehouse-dir");
|
||||||
|
Loading…
Reference in New Issue
Block a user