Revision: 5921
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5921&view=rev
Author: gerdwagner
Date: 2010-10-16 16:56:19 +0000 (Sat, 16 Oct 2010)
Log Message:
-----------
3086444: Date/Time/Timestamp types did not display right after application restart when others than standard
formats were chosen in Global Prefs. (See patch 3087989)
Modified Paths:
--------------
trunk/sql12/doc/src/main/resources/changes.txt
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDate.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTime.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTimestamp.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ThreadSafeDateFormat.java
trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateTest.java
Added Paths:
-----------
trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateWithCustomDateFormatTest.java
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2010-10-15 16:22:00 UTC (rev 5920)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2010-10-16 16:56:19 UTC (rev 5921)
@@ -38,6 +38,10 @@
Bug-fixes:
+3086444: Date/Time/Timestamp types did not display right after application restart when others than standard
+ formats were chosen in Global Prefs. (See patch 3087989)
+
+
Popup-Menu for adding or removing driver specific properties didn't appear in driver properties
tab of alias properties on Win XP. (See patch 3083166)
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDate.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDate.java 2010-10-15 16:22:00 UTC (rev 5920)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDate.java 2010-10-16 16:56:19 UTC (rev 5921)
@@ -205,8 +205,22 @@
{
readDateAsTimestamp = true;
}
+
+ /*
+ * After loading the properties, we must initialize the dateFormat.
+ * See Bug 3086444
+ */
+ initDateFormat(localeFormat, lenient);
}
}
+
+ /**
+ * Defines the dateFormat with the specific format and lenient options
+ */
+ private static void initDateFormat(int format, boolean lenient) {
+ dateFormat = new ThreadSafeDateFormat(format); // lenient is set next
+ dateFormat.setLenient(lenient);
+ }
public static boolean getReadDateAsTimestamp() {
propertiesAlreadyLoaded = false;
@@ -909,6 +923,9 @@
DTProperties.put(thisClassName,
"readDateAsTimestamp",
Boolean.valueOf(readDateAsTimestamp).toString());
+
+ initDateFormat(localeFormat, lenient);
+
}
} // end of inner class
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTime.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTime.java 2010-10-15 16:22:00 UTC (rev 5920)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTime.java 2010-10-16 16:56:19 UTC (rev 5921)
@@ -190,10 +190,26 @@
thisClassName, "lenient");
if (lenientString != null && lenientString.equals("false"))
lenient =false;
+
+ /*
+ * After loading the properties, we must initialize the dateFormat.
+ * See Bug 3086444
+ */
+ initDateFormat(localeFormat, lenient);
+
}
}
/**
+ * Defines the dateFormat with the specific format and lenient options
+ */
+ private static void initDateFormat(int format, boolean lenient) {
+ dateFormat = new ThreadSafeDateFormat(format, true); // lenient is set next
+ dateFormat.setLenient(lenient);
+ }
+
+
+ /**
* Return the name of the java class used to hold this data type.
*/
public String getClassName() {
@@ -841,6 +857,9 @@
DTProperties.put(thisClassName,
"lenient",
Boolean.valueOf(lenient).toString());
+
+ initDateFormat(localeFormat, lenient);
+
}
} // end of inner class
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTimestamp.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTimestamp.java 2010-10-15 16:22:00 UTC (rev 5920)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeTimestamp.java 2010-10-16 16:56:19 UTC (rev 5921)
@@ -216,10 +216,22 @@
thisClassName, "whereClauseUsage");
if (whereClauseUsageString != null)
whereClauseUsage = Integer.parseInt(whereClauseUsageString);
+
+ initDateFormat(localeFormat, lenient);
+
}
}
/**
+ * Defines the dateFormat with the specific format and lenient options
+ */
+ private static void initDateFormat(int format, boolean lenient) {
+ dateFormat = new ThreadSafeDateFormat(localeFormat, localeFormat); // lenient is set next
+ dateFormat.setLenient(lenient);
+ }
+
+
+ /**
* Return the name of the java class used to hold this data type.
*/
public String getClassName() {
@@ -925,6 +937,10 @@
DTProperties.put(thisClassName,
"whereClauseUsage",
Integer.toString(whereClauseUsage));
+
+
+ initDateFormat(localeFormat, lenient);
+
}
} // end of inner class
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ThreadSafeDateFormat.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ThreadSafeDateFormat.java 2010-10-15 16:22:00 UTC (rev 5920)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ThreadSafeDateFormat.java 2010-10-16 16:56:19 UTC (rev 5921)
@@ -32,17 +32,9 @@
/** internal protected instance of DateFormat */
private DateFormat dateFormat;
-
- /**
+
+ /**
* Constructor
- * @param dateFormat the DateFormat instance to protect.
- */
- public ThreadSafeDateFormat(DateFormat dateFormat) {
- this.dateFormat = dateFormat;
- }
-
- /**
- * Constructor
* @param style the given formatting style. For example,
* SHORT for "M/d/yy" in the US locale.
*/
Modified: trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateTest.java
===================================================================
--- trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateTest.java 2010-10-15 16:22:00 UTC (rev 5920)
+++ trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateTest.java 2010-10-16 16:56:19 UTC (rev 5921)
@@ -1,9 +1,12 @@
package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.*;
import java.sql.Date;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
import org.junit.Before;
@@ -54,6 +57,23 @@
assertFalse("Expected default value to be false for read date as timestamp",
DataTypeDate.getReadDateAsTimestamp());
}
+
+
+ /**
+ * Ensure, that the Bug 3086444 is solved.
+ * If the user didn't choose a custom DateFormat, then we must use the default.
+ */
+ @Test
+ public void testUseCustomDateFormatAfterLoadingProperties()
+ {
+
+ Date currentDate = Date.valueOf("2010-10-15");
+
+
+ String renderedDate = classUnderTest.renderObject(currentDate);
+ assertEquals("Must use the default format", "2010-10-15", renderedDate);
+
+ }
@Override
protected Object getEqualsTestObject()
Added: trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateWithCustomDateFormatTest.java
===================================================================
--- trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateWithCustomDateFormatTest.java (rev 0)
+++ trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDateWithCustomDateFormatTest.java 2010-10-16 16:56:19 UTC (rev 5921)
@@ -0,0 +1,99 @@
+package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
+
+import static org.junit.Assert.*;
+
+import java.sql.Date;
+import java.text.DateFormat;
+
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/*
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * JUnit test for DataTypeDate class when using custom properties.
+ *
+ * @author Stefan Willinger
+ */
+public class DataTypeDateWithCustomDateFormatTest extends AbstractDataTypeComponentTest
+{
+
+ private static int userDefinedDateFormat = DateFormat.MEDIUM;
+
+ /**
+ * Setup the test case with user defined properties
+ * @see net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.AbstractDataTypeComponentTest#setUp()
+ */
+ @Before
+ public void setUp() throws Exception
+ {
+ DTProperties.put(DataTypeDate.class.getName(), "useJavaDefaultFormat", "false");
+ DTProperties.put(DataTypeDate.class.getName(), "localeFormat", ""+DateFormat.MEDIUM);
+ DTProperties.put(DataTypeDate.class.getName(), "lenient", "false");
+ DTProperties.put(DataTypeDate.class.getName(), "readDateAsTimestamp", "true");
+
+
+ ColumnDisplayDefinition columnDisplayDefinition = getMockColumnDisplayDefinition();
+ mockHelper.replayAll();
+ classUnderTest = new DataTypeDate(null, columnDisplayDefinition);
+ mockHelper.resetAll();
+ super.setUp();
+ }
+
+ /**
+ *1757076 (DATE column seen as TIMESTAMP, update in editable mode fails)
+ * Ensure that we use the user specified value
+ * */
+ @Test
+ public void testGetReadDateAsTimestamp()
+ {
+ assertTrue("Expected the user specified value",
+ DataTypeDate.getReadDateAsTimestamp());
+ }
+
+
+ /**
+ * Ensure, that the Bug 3086444 is solved.
+ * If the user defines a custom DateFormat, then we must use this after reading the
+ * properties at startup.
+ */
+ @Test
+ public void testUseCustomDateFormatAfterLoadingProperties()
+ {
+
+ Date currentDate = Date.valueOf("2010-10-15");
+
+ String expectedDate = DateFormat.getDateInstance(userDefinedDateFormat).format(currentDate);
+
+ String renderedDate = classUnderTest.renderObject(currentDate);
+ assertEquals("Must use the user defined format", expectedDate, renderedDate);
+
+ }
+
+ @Override
+ protected Object getEqualsTestObject()
+ {
+ return new Date(System.currentTimeMillis());
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|