[teiid-commits] teiid SVN: r4398 - in trunk: common-core/src/test/java/org/teiid/core/types/basic and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Sep 4 10:10:44 EDT 2012


Author: shawkins
Date: 2012-09-04 10:10:43 -0400 (Tue, 04 Sep 2012)
New Revision: 4398

Modified:
   trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
   trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java
   trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
   trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
Log:
TEIID-2184 fixing unit tests and month/dayname to not be specific to the en/us locale

Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html	2012-09-04 12:30:31 UTC (rev 4397)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html	2012-09-04 14:10:43 UTC (rev 4398)
@@ -46,7 +46,8 @@
 <ul>
   <li>TEIID-2166 array_get will return null if the index is out of bounds rather than raising an error.
   <li>TEIID-2175 for 8.0 and 8.1 clients the server will check if serialized date/time values fall outside of 32-bit value ranges (year 1900 - 9999 for dates and times between years 1901 and 2038) and throw an exception.  The previous behavior was
-  to truncate.  The exception and the use of 32 bit serialization can be avoided by setting the system property org.teiid.longDatesTimes to true. 
+  to truncate.  The exception and the use of 32 bit serialization can be avoided by setting the system property org.teiid.longDatesTimes to true.
+  <li>TEIID-2184 to be consistent with the rest of Teiid's logic the system functions dayName and monthName will return values from the default locale, rather than only the English names.  Use the system property org.teiid.enDateNames true to revert to the pre-8.2 behavior.   
 </ul>
 
 <h4>from 8.0</h4>

Modified: trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java	2012-09-04 12:30:31 UTC (rev 4397)
+++ trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java	2012-09-04 14:10:43 UTC (rev 4398)
@@ -31,6 +31,7 @@
 import java.sql.Timestamp;
 
 import org.junit.Test;
+import org.teiid.core.CorePlugin;
 import org.teiid.core.types.ClobImpl;
 import org.teiid.core.types.ClobType;
 import org.teiid.core.types.DataTypeManager;
@@ -249,7 +250,8 @@
     }
     
     @Test public void testRangeCheck1() throws Exception {
-    	helpTransformException(new Double("1E11"), DataTypeManager.DefaultDataClasses.INTEGER, "TEIID10058 The Double value '100,000,000,000' is outside the of range for Integer"); //$NON-NLS-1$ //$NON-NLS-2$  
+    	Double value = new Double("1E11");//$NON-NLS-1$
+		helpTransformException(value, DataTypeManager.DefaultDataClasses.INTEGER, CorePlugin.Util.gs(CorePlugin.Event.TEIID10058, value, Double.class.getSimpleName(), Integer.class.getSimpleName())); //$NON-NLS-1$ //$NON-NLS-2$  
     }
 
 

Modified: trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java	2012-09-04 12:30:31 UTC (rev 4397)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java	2012-09-04 14:10:43 UTC (rev 4398)
@@ -36,11 +36,14 @@
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.text.DateFormat;
+import java.text.DateFormatSymbols;
 import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Locale;
 import java.util.Properties;
 import java.util.TimeZone;
 import java.util.UUID;
@@ -55,6 +58,7 @@
 import org.teiid.core.types.TransformationException;
 import org.teiid.core.types.InputStreamFactory.BlobInputStreamFactory;
 import org.teiid.core.types.InputStreamFactory.ClobInputStreamFactory;
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.core.util.TimestampWithTimezone;
 import org.teiid.language.SQLConstants;
 import org.teiid.language.SQLConstants.NonReserved;
@@ -374,13 +378,34 @@
 
 	// ================== Function = dayname =====================
 
-	static final String[] dayNames = new String[] {
-		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
-
+	static String[] dayNames;
+	static String[] monthNames;
+	
 	public static Object dayName(Date x) {
-		return dayNames[getField(x, Calendar.DAY_OF_WEEK) - 1];
+		return getDayNames()[getField(x, Calendar.DAY_OF_WEEK) - 1];
 	}
+	
+	private static Locale getSymbolLocale() {
+		return PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.enDateNames", false)?Locale.ENGLISH:Locale.getDefault(); //$NON-NLS-1$
+	}
 
+	static String[] getMonthNames() {
+		if (monthNames == null) {
+			DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(getSymbolLocale());
+			String[] months = dateFormatSymbols.getMonths();
+			monthNames = Arrays.copyOf(months, 12);
+		}
+		return monthNames;
+	}
+
+	static String[] getDayNames() {
+		if (dayNames == null) {
+			DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(getSymbolLocale());
+			dayNames = Arrays.copyOfRange(dateFormatSymbols.getWeekdays(), 1, 8);
+		}
+		return dayNames;
+	}
+
 	// ================== Function = dayofmonth =====================
 
 	public static  Object dayOfMonth(Date x) {
@@ -423,12 +448,8 @@
 
 	// ================== Function = monthname =====================
 
-	static final String[] monthNames = new String[] {
-		"January", "February", "March", "April", "May", "June", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-		"July", "August", "September", "October", "November", "December" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-
 	public static Object monthName(Date x) {
-		return monthNames[getField(x, Calendar.MONTH)];
+		return getMonthNames()[getField(x, Calendar.MONTH)];
 	}
 
 	// ================== Function = second =====================
@@ -1068,7 +1089,7 @@
             SimpleDateFormat sdf = CommandContext.getDateFormat(context, format);
             return sdf.format(date);
 		} catch (IllegalArgumentException iae) {
-			 throw new FunctionExecutionException(QueryPlugin.Event.TEIID30409, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30409,iae.getMessage()));
+			 throw new FunctionExecutionException(QueryPlugin.Event.TEIID30409, iae, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30409,iae.getMessage()));
 		}
 	}
 
@@ -1079,7 +1100,7 @@
 		try {
 			return df.parse(date);
 		} catch (ParseException e) {
-			 throw new FunctionExecutionException(QueryPlugin.Event.TEIID30410, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30410, date, format));
+			 throw new FunctionExecutionException(QueryPlugin.Event.TEIID30410, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30410, date, format));
 		}
 	}
 	
@@ -1095,7 +1116,7 @@
 	        DecimalFormat df = CommandContext.getDecimalFormat(context, format);
 	        return df.format(number);
 		} catch (IllegalArgumentException iae) {
-			 throw new FunctionExecutionException(QueryPlugin.Event.TEIID30411, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30411, iae.getMessage()));
+			 throw new FunctionExecutionException(QueryPlugin.Event.TEIID30411, iae, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30411, iae.getMessage()));
 		}
 	}
 

Modified: trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java	2012-09-04 12:30:31 UTC (rev 4397)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java	2012-09-04 14:10:43 UTC (rev 4398)
@@ -33,6 +33,7 @@
 import java.sql.Timestamp;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Locale;
 import java.util.Properties;
 import java.util.TimeZone;
 
@@ -80,12 +81,18 @@
 	private static final Class<Timestamp> T_TIMESTAMP = DataTypeManager.DefaultDataClasses.TIMESTAMP;
 	
 	private FunctionLibrary library = new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions());
+	private Locale locale;
 
-	@Before public void setUp() { 
+	@Before public void setUp() {
+		locale = Locale.getDefault();
+		Locale.setDefault(Locale.US);
 		TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$ 
 	}
 	
 	@After public void tearDown() { 
+		Locale.setDefault(locale);
+		FunctionMethods.dayNames = null;
+		FunctionMethods.monthNames = null;
 		TimestampWithTimezone.resetCalendar(null);
 	}
 	
@@ -1270,9 +1277,10 @@
     }
     
     @Test public void testInvokeDayName() {
-        for (int i = 0; i < FunctionMethods.dayNames.length; i++) {
+        String[] dayNames = FunctionMethods.getDayNames();
+		for (int i = 0; i < dayNames.length; i++) {
             Date time = TimestampUtil.createDate(100, 0, i + 2);
-            helpInvokeMethod("dayName", new Object[] { time }, FunctionMethods.dayNames[i]); //$NON-NLS-1$ 
+            helpInvokeMethod("dayName", new Object[] { time }, dayNames[i]); //$NON-NLS-1$ 
         }
     }
     
@@ -1297,9 +1305,10 @@
     }
     
     @Test public void testInvokeMonthName() {
-        for (int i = 0; i < FunctionMethods.monthNames.length; i++) {
+        String[] monthNames = FunctionMethods.getMonthNames();
+		for (int i = 0; i < monthNames.length; i++) {
             Date time = TimestampUtil.createDate(100, i, 1);
-            helpInvokeMethod("monthName", new Object[] { time }, FunctionMethods.monthNames[i]); //$NON-NLS-1$ 
+            helpInvokeMethod("monthName", new Object[] { time }, monthNames[i]); //$NON-NLS-1$ 
         }
     }
     



More information about the teiid-commits mailing list