[teiid-commits] teiid SVN: r1781 - in trunk/connectors/connector-jdbc/src: main/java/org/teiid/connector/jdbc/translator and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Jan 26 12:51:24 EST 2010


Author: shawkins
Date: 2010-01-26 12:51:24 -0500 (Tue, 26 Jan 2010)
New Revision: 1781

Modified:
   trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
   trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ModFunctionModifier.java
   trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestModFunctionModifier.java
Log:
TEIID-941 fix to postgresql mod function for float and double types.

Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java	2010-01-26 16:02:53 UTC (rev 1780)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java	2010-01-26 17:51:24 UTC (rev 1781)
@@ -41,6 +41,7 @@
 import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
 import org.teiid.connector.jdbc.translator.ExtractFunctionModifier;
 import org.teiid.connector.jdbc.translator.FunctionModifier;
+import org.teiid.connector.jdbc.translator.ModFunctionModifier;
 import org.teiid.connector.jdbc.translator.Translator;
 import org.teiid.connector.language.IAggregate;
 import org.teiid.connector.language.IExpression;
@@ -93,6 +94,8 @@
         registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier()); 
         registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));
         registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
+        
+        registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("%", getLanguageFactory(), Arrays.asList(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, TypeFacility.RUNTIME_TYPES.BIG_DECIMAL))); //$NON-NLS-1$ 
 
         //specific to 8.2 client or later
         registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());

Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ModFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ModFunctionModifier.java	2010-01-26 16:02:53 UTC (rev 1780)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ModFunctionModifier.java	2010-01-26 17:51:24 UTC (rev 1781)
@@ -24,6 +24,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -39,20 +40,27 @@
  */
 public class ModFunctionModifier extends AliasModifier {
 
-	private static Set<Class> SUPPORTED_TYPES = new HashSet<Class>(Arrays.asList(TypeFacility.RUNTIME_TYPES.INTEGER, TypeFacility.RUNTIME_TYPES.LONG));
+	private Set<Class> supportedTypes = new HashSet<Class>(Arrays.asList(TypeFacility.RUNTIME_TYPES.INTEGER, TypeFacility.RUNTIME_TYPES.LONG));
 
 	private ILanguageFactory langFactory;
-    
+
     public ModFunctionModifier(String modFunction, ILanguageFactory langFactory) {
+    	this(modFunction, langFactory, null);
+    }
+
+    public ModFunctionModifier(String modFunction, ILanguageFactory langFactory, Collection<Class> supportedTypes) {
     	super(modFunction);
-        this.langFactory = langFactory;
+    	this.langFactory = langFactory;
+    	if (supportedTypes != null) {
+    		this.supportedTypes.addAll(supportedTypes);
+    	}
     }
     
     @Override
     public List<?> translate(IFunction function) {
     	List<IExpression> expressions = function.getParameters();
 		Class<?> type = function.getType();
-		if (SUPPORTED_TYPES.contains(type)) {
+		if (supportedTypes.contains(type)) {
 			modify(function);
 			return null;
 		}

Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestModFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestModFunctionModifier.java	2010-01-26 16:02:53 UTC (rev 1780)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestModFunctionModifier.java	2010-01-26 17:51:24 UTC (rev 1781)
@@ -145,22 +145,6 @@
 
     /**
      * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
-     * MOD(x,y) using {@link Integer} constants for both parameters returns 
-     * MOD(x,y).  {@link ModFunctionModifier} will be constructed with a 
-     * function name of "MOD" and a supported type list which contains {@link Integer}. 
-     * 
-     * @throws Exception
-     */
-    public void testTwoIntConst3() throws Exception {
-        IExpression[] args = new IExpression[] {
-                LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
-                LANG_FACTORY.createLiteral(new Integer(6), Integer.class)           
-        };
-        helpTestMod("MOD", args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-    /**
-     * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
      * x % y using {@link Integer} constants for both parameters returns (x % y).  
      * {@link ModFunctionModifier} will be constructed with a function name of 
      * "%" and no supported type list. 
@@ -177,22 +161,6 @@
 
     /**
      * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
-     * x % y using {@link Integer} constants for both parameters returns (x % y).  
-     * {@link ModFunctionModifier} will be constructed with a function name of 
-     * "%" and a supported type list which contains {@link Integer}. 
-     * 
-     * @throws Exception
-     */
-    public void testTwoIntConst6() throws Exception {
-        IExpression[] args = new IExpression[] {
-                LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
-                LANG_FACTORY.createLiteral(new Integer(6), Integer.class)           
-        };
-        helpTestMod("%", args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-    /**
-     * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
      * MOD(x,y) using {@link Long} constants for both parameters returns 
      * MOD(x,y).  {@link ModFunctionModifier} will be constructed without 
      * specifying a function name or a supported type list.
@@ -225,22 +193,6 @@
 
     /**
      * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
-     * MOD(x,y) using {@link Long} constants for both parameters returns 
-     * MOD(x,y).  {@link ModFunctionModifier} will be constructed with a 
-     * function name of "MOD" and a supported type list which contains {@link Long}. 
-     * 
-     * @throws Exception
-     */
-    public void testTwoLongConst3() throws Exception {
-        IExpression[] args = new IExpression[] {
-                LANG_FACTORY.createLiteral(new Long(10), Long.class),
-                LANG_FACTORY.createLiteral(new Long(6), Long.class)           
-        };
-        helpTestMod("MOD", args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-    /**
-     * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
      * x % y using {@link Long} constants for both parameters returns (x % y).  
      * {@link ModFunctionModifier} will be constructed with a function name of 
      * "%" and no supported type list. 
@@ -257,22 +209,6 @@
 
     /**
      * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
-     * x % y using {@link Long} constants for both parameters returns (x % y).  
-     * {@link ModFunctionModifier} will be constructed with a function name of 
-     * "%" and a supported type list which contains {@link Long}. 
-     * 
-     * @throws Exception
-     */
-    public void testTwoLongConst6() throws Exception {
-        IExpression[] args = new IExpression[] {
-                LANG_FACTORY.createLiteral(new Long(10), Long.class),
-                LANG_FACTORY.createLiteral(new Long(6), Long.class)           
-        };
-        helpTestMod("%", args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-    /**
-     * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
      * MOD(x,y) using {@link Float} constants for both parameters returns 
      * (x - (TRUNC((x / y), 0) * y)).  {@link ModFunctionModifier} will be 
      * constructed without specifying a function name or a supported type list.
@@ -355,23 +291,6 @@
 
     /**
      * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
-     * MOD(e1,y) using a {@link Integer} element and a {@link Integer} constant 
-     * for parameters returns MOD(e1,y).  {@link ModFunctionModifier} will be 
-     * constructed with a function name of "MOD" and a supported type list which 
-     * contains {@link Integer}. 
-     * 
-     * @throws Exception
-     */
-    public void testOneIntElemOneIntConst3() throws Exception {
-        IExpression[] args = new IExpression[] {
-                LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
-                LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
-        };
-        helpTestMod("MOD", args, "MOD(e1, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-    /**
-     * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
      * e1 % y using a {@link Integer} element and a {@link Integer} constant for 
      * parameters returns (e1 % y).  {@link ModFunctionModifier} will be 
      * constructed with a function name of "%" and no supported type list. 
@@ -389,23 +308,6 @@
 
     /**
      * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
-     * e1 % y using a {@link Integer} element and a {@link Integer} constant for 
-     * parameters returns (e1 % y).  {@link ModFunctionModifier} will be 
-     * constructed with a function name of "%" and a supported type list which 
-     * contains {@link Integer}. 
-     * 
-     * @throws Exception
-     */
-    public void testOneIntElemOneIntConst6() throws Exception {
-        IExpression[] args = new IExpression[] {
-                LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
-                LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
-        };
-        helpTestMod("%", args, "(e1 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-    /**
-     * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to 
      * MOD(e1,y) using a {@link BigDecimal} element and a {@link BigDecimal} 
      * constant for parameters returns (e1 - (TRUNC((e1 / y), 0) * y)).  
      * {@link ModFunctionModifier} will be constructed without specifying a 



More information about the teiid-commits mailing list