Author: rareddy
Date: 2011-04-20 15:43:03 -0400 (Wed, 20 Apr 2011)
New Revision: 3107
Added:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
Log:
TEIID-1561: fixing to correctly set calender for the calling thread.
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2011-04-20
18:30:08 UTC (rev 3106)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2011-04-20
19:43:03 UTC (rev 3107)
@@ -127,9 +127,19 @@
};
public final static TimeZone DEFAULT_TIME_ZONE = TimeZone.getDefault();
- private static final ThreadLocal<Calendar> CALENDAR = new
ThreadLocal<Calendar>() {
+ static class DatbaseCalender extends ThreadLocal<Calendar> {
+ private String timeZone;
+ public DatbaseCalender(String tz) {
+ this.timeZone = tz;
+ }
@Override
protected Calendar initialValue() {
+ if(this.timeZone != null && this.timeZone.trim().length() > 0) {
+ TimeZone tz = TimeZone.getTimeZone(this.timeZone);
+ if(!DEFAULT_TIME_ZONE.hasSameRules(tz)) {
+ return Calendar.getInstance(tz);
+ }
+ }
return Calendar.getInstance();
}
};
@@ -142,6 +152,7 @@
private boolean useCommentsInSourceQuery;
private String version;
private int maxInsertBatchSize = 2048;
+ private DatbaseCalender databaseCalender;
private AtomicBoolean initialConnection = new AtomicBoolean(true);
@@ -157,15 +168,8 @@
@Override
public void start() throws TranslatorException {
- super.start();
-
- String timeZone = getDatabaseTimeZone();
- if(timeZone != null && timeZone.trim().length() > 0) {
- TimeZone tz = TimeZone.getTimeZone(timeZone);
- if(!DEFAULT_TIME_ZONE.hasSameRules(tz)) {
- CALENDAR.set(Calendar.getInstance(tz));
- }
- }
+ super.start();
+ this.databaseCalender = new DatbaseCalender(this.databaseTimeZone);
}
@TranslatorProperty(display="Database Version", description= "Database
Version")
@@ -492,7 +496,7 @@
* @return the database calendar
*/
public Calendar getDatabaseCalendar() {
- return CALENDAR.get();
+ return this.databaseCalender.get();
}
/**
Added:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java 2011-04-20
19:43:03 UTC (rev 3107)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.translator.jdbc;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+import java.util.Calendar;
+
+public class TestJDBCExecutionFactory {
+
+ @Test public void testDatabaseCalender() throws Exception {
+ final JDBCExecutionFactory jef = new JDBCExecutionFactory();
+ jef.setDatabaseTimeZone("GMT"); //$NON-NLS-1$
+ jef.start();
+
+ final Calendar[] cals = new Calendar[2];
+
+ Thread t1 = new Thread() {
+ public void run() {
+ cals[0] = jef.getDatabaseCalendar();
+ }
+ };
+ t1.start();
+
+ Thread t2 = new Thread() {
+ public void run() {
+ cals[1] = jef.getDatabaseCalendar();
+ }
+ };
+ t2.start();
+ t1.join();
+ t2.join();
+
+ assertNotSame(cals[0], cals[1]);
+ }
+}
Property changes on:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Show replies by date