[teiid-commits] teiid SVN: r2984 - in trunk/connectors/translator-jdbc/src: test/java/org/teiid/translator/jdbc/intersystemscache and 1 other directory.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Wed Mar 9 11:11:51 EST 2011
Author: shawkins
Date: 2011-03-09 11:11:50 -0500 (Wed, 09 Mar 2011)
New Revision: 2984
Added:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheTranslation.java
Removed:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheConvertModifier.java
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/intersyscache/InterSystemsCacheExecutionFactory.java
Log:
TEIID-1060 additional changes to intersystems cache support
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/intersyscache/InterSystemsCacheExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/intersyscache/InterSystemsCacheExecutionFactory.java 2011-03-09 15:16:40 UTC (rev 2983)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/intersyscache/InterSystemsCacheExecutionFactory.java 2011-03-09 16:11:50 UTC (rev 2984)
@@ -29,15 +29,16 @@
import java.util.List;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.Expression;
import org.teiid.language.Function;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.FunctionParameter;
import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.AliasModifier;
import org.teiid.translator.jdbc.ConvertModifier;
+import org.teiid.translator.jdbc.EscapeSyntaxModifier;
import org.teiid.translator.jdbc.FunctionModifier;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
@@ -50,50 +51,66 @@
@Override
public void start() throws TranslatorException {
super.start();
+ convert.addTypeMapping("tinyint", FunctionModifier.BYTE); //$NON-NLS-1$
+ convert.addTypeMapping("smallint", FunctionModifier.SHORT); //$NON-NLS-1$
+ convert.addTypeMapping("integer", FunctionModifier.INTEGER); //$NON-NLS-1$
convert.addTypeMapping("bigint", FunctionModifier.LONG); //$NON-NLS-1$
- convert.addTypeMapping("character", FunctionModifier.CHAR); //$NON-NLS-1$
convert.addTypeMapping("decimal(38,19)", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
convert.addTypeMapping("decimal(19,0)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
- convert.addTypeMapping("smallint", FunctionModifier.SHORT); //$NON-NLS-1$
- convert.addTypeMapping("tinyint", FunctionModifier.BYTE); //$NON-NLS-1$
+ convert.addTypeMapping("character", FunctionModifier.CHAR); //$NON-NLS-1$
convert.addTypeMapping("varchar(4000)", FunctionModifier.STRING); //$NON-NLS-1$
+ convert.addTypeMapping("date", FunctionModifier.DATE); //$NON-NLS-1$
+ convert.addTypeMapping("time", FunctionModifier.TIME); //$NON-NLS-1$
+ convert.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
convert.addNumericBooleanConversions();
registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("nvl")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.CONCAT, new ModifiedFunction(SourceSystemFunctions.CONCAT));
- registerFunctionModifier(SourceSystemFunctions.ACOS, new ModifiedFunction(SourceSystemFunctions.ACOS));
- registerFunctionModifier(SourceSystemFunctions.ASIN, new ModifiedFunction(SourceSystemFunctions.ASIN));
- registerFunctionModifier(SourceSystemFunctions.ATAN, new ModifiedFunction(SourceSystemFunctions.ATAN));
- registerFunctionModifier(SourceSystemFunctions.COS, new ModifiedFunction(SourceSystemFunctions.COS));
- registerFunctionModifier(SourceSystemFunctions.COT, new ModifiedFunction(SourceSystemFunctions.COT));
- registerFunctionModifier(SourceSystemFunctions.CURDATE, new ModifiedFunction(SourceSystemFunctions.CURDATE));
- registerFunctionModifier(SourceSystemFunctions.CURTIME, new ModifiedFunction(SourceSystemFunctions.CURTIME));
- registerFunctionModifier(SourceSystemFunctions.DAYNAME, new ModifiedFunction(SourceSystemFunctions.DAYNAME));
- registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new ModifiedFunction(SourceSystemFunctions.DAYOFMONTH));
- registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new ModifiedFunction(SourceSystemFunctions.DAYOFWEEK));
- registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new ModifiedFunction(SourceSystemFunctions.DAYOFYEAR));
- registerFunctionModifier(SourceSystemFunctions.EXP, new ModifiedFunction(SourceSystemFunctions.EXP));
- registerFunctionModifier(SourceSystemFunctions.HOUR, new ModifiedFunction(SourceSystemFunctions.HOUR));
- registerFunctionModifier(SourceSystemFunctions.LOG,new ModifiedFunction(SourceSystemFunctions.LOG));
- registerFunctionModifier(SourceSystemFunctions.LOG10, new ModifiedFunction(SourceSystemFunctions.LOG10));
- registerFunctionModifier(SourceSystemFunctions.LEFT, new ModifiedFunction(SourceSystemFunctions.LEFT));
- registerFunctionModifier(SourceSystemFunctions.MINUTE, new ModifiedFunction(SourceSystemFunctions.MINUTE));
- registerFunctionModifier(SourceSystemFunctions.MONTH, new ModifiedFunction(SourceSystemFunctions.MONTH));
- registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new ModifiedFunction(SourceSystemFunctions.MONTHNAME));
- registerFunctionModifier(SourceSystemFunctions.MOD, new ModifiedFunction(SourceSystemFunctions.MOD));
- registerFunctionModifier(SourceSystemFunctions.NOW, new ModifiedFunction(SourceSystemFunctions.NOW));
- registerFunctionModifier(SourceSystemFunctions.PI, new ModifiedFunction(SourceSystemFunctions.PI));
- registerFunctionModifier(SourceSystemFunctions.QUARTER, new ModifiedFunction(SourceSystemFunctions.QUARTER));
- registerFunctionModifier(SourceSystemFunctions.RIGHT, new ModifiedFunction(SourceSystemFunctions.RIGHT));
- registerFunctionModifier(SourceSystemFunctions.SIN, new ModifiedFunction(SourceSystemFunctions.SIN));
- registerFunctionModifier(SourceSystemFunctions.SECOND, new ModifiedFunction(SourceSystemFunctions.SECOND));
- registerFunctionModifier(SourceSystemFunctions.SQRT,new ModifiedFunction(SourceSystemFunctions.SQRT));
- registerFunctionModifier(SourceSystemFunctions.TAN,new ModifiedFunction(SourceSystemFunctions.TAN));
- registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new ModifiedFunction(SourceSystemFunctions.TIMESTAMPADD));
- registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new ModifiedFunction(SourceSystemFunctions.TIMESTAMPDIFF));
- registerFunctionModifier(SourceSystemFunctions.TRUNCATE,new ModifiedFunction(SourceSystemFunctions.TRUNCATE));
- registerFunctionModifier(SourceSystemFunctions.WEEK,new ModifiedFunction(SourceSystemFunctions.WEEK));
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.ACOS, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.ASIN, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.ATAN, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.COS, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.COT, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.CURDATE, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.CURTIME, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYNAME, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.EXP, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.HOUR, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.LOG,new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.LOG10, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.LEFT, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.MINUTE, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.MONTH, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.MOD, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.NOW, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.PI, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.QUARTER, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.RIGHT, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.SIN, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.SECOND, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.SQRT,new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TAN, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TRUNCATE, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.WEEK, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DIVIDE_OP, new FunctionModifier() {
+
+ @Override
+ public List<?> translate(Function function) {
+ if (function.getType() == TypeFacility.RUNTIME_TYPES.INTEGER || function.getType() == TypeFacility.RUNTIME_TYPES.LONG) {
+ Function result = convert.createConvertFunction(getLanguageFactory(), function, TypeFacility.getDataTypeName(function.getType()));
+ function.setType(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
+ return Arrays.asList(result);
+ }
+ return null;
+ }
+ });
}
@Override
@@ -227,28 +244,4 @@
return true;
}
- static class ModifiedFunction extends FunctionModifier{
- String name;
- ModifiedFunction(String name){
- this.name = name;
- }
-
- @Override
- public List<?> translate(Function function) {
- StringBuilder sb = new StringBuilder();
- sb.append("{fn ").append(this.name).append('(');//$NON-NLS-1$
- List<Expression> params = function.getParameters();
- if (params != null && !params.isEmpty()) {
- for (int i = 0; i < params.size(); i++) {
- sb.append(params.get(0));
- if (i < (params.size()-1)) {
- sb.append(',');
- }
- }
- }
- sb.append(")}");//$NON-NLS-1$
-
- return Arrays.asList(sb);
- }
- }
}
Deleted: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheConvertModifier.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheConvertModifier.java 2011-03-09 15:16:40 UTC (rev 2983)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheConvertModifier.java 2011-03-09 16:11:50 UTC (rev 2984)
@@ -1,138 +0,0 @@
-/*
- * 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.intersystemscache;
-
-import static org.junit.Assert.*;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.Arrays;
-
-import org.junit.Test;
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.LanguageFactory;
-import org.teiid.query.unittest.TimestampUtil;
-import org.teiid.translator.TypeFacility;
-import org.teiid.translator.jdbc.SQLConversionVisitor;
-import org.teiid.translator.jdbc.intersyscache.InterSystemsCacheExecutionFactory;
-/**
- */
-public class TestInterSystemsCacheConvertModifier {
-
- private static final LanguageFactory LANG_FACTORY = new LanguageFactory();
-
- public String helpGetString(Expression expr) throws Exception {
- InterSystemsCacheExecutionFactory trans = new InterSystemsCacheExecutionFactory();
- trans.start();
- SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
- sqlVisitor.append(expr);
-
- return sqlVisitor.toString();
- }
-
- public void helpTest(Expression srcExpression, String tgtType, String expectedExpression) throws Exception {
- Function func = LANG_FACTORY.createFunction("convert", //$NON-NLS-1$
- Arrays.asList(
- srcExpression,
- LANG_FACTORY.createLiteral(tgtType, String.class)),
- TypeFacility.getDataTypeClass(tgtType));
-
- assertEquals("Error converting from " + srcExpression.getType() + " to " + tgtType, //$NON-NLS-1$ //$NON-NLS-2$
- expectedExpression, helpGetString(func));
- }
-
- // Source = STRING
- @Test public void testStringToChar() throws Exception {
- helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "cast('5' AS character)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = Boolean
-
- @Test public void testBooleanToBigDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "bigdecimal", "cast(1 AS decimal(38,19))"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BYTE
-
- @Test public void testByteToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "cast(1 AS varchar(4000))"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testByteToBoolean() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "boolean", "CASE WHEN 1 = 0 THEN 0 WHEN 1 IS NOT NULL THEN 1 END"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testBigIntegerToDouble() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testBigIntegerDecimal() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "biginteger", "cast(1 AS decimal(19,0))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = FLOAT
-
- @Test public void testFloatToLong() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "long", "cast(1.2 AS bigint)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = DOUBLE
-
- @Test public void testDoubleToShort() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "short", "cast(1.2 AS smallint)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = BIGDECIMAL
-
- @Test public void testBigDecimalToByte() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "byte", "cast(1.0 AS tinyint)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- // Source = DATE
-
- @Test public void testDateToTimestamp() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "timestamp", "to_date('2003-11-01', 'yyyy-mm-dd')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = TIME
-
- @Test public void testTimeToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "string", "cast(to_date('23:59:59', 'hh:mi:ss') AS varchar(4000))"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-
- // Source = TIMESTAMP
-
- @Test public void testTimestampToString() throws Exception {
- Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
- helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "cast(to_timestamp('2003-11-01 12:05:02.0', 'yyyy-mm-dd hh:mi:ss.fffffffff') AS varchar(4000))"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Source = LONG
- @Test public void testLongToBigInt() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(5, Long.class), "long", "cast(5 AS bigint)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
Copied: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheTranslation.java (from rev 2981, trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheConvertModifier.java)
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheTranslation.java (rev 0)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheTranslation.java 2011-03-09 16:11:50 UTC (rev 2984)
@@ -0,0 +1,157 @@
+/*
+ * 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.intersystemscache;
+
+import static org.junit.Assert.*;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Arrays;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.teiid.language.Expression;
+import org.teiid.language.Function;
+import org.teiid.language.LanguageFactory;
+import org.teiid.query.unittest.TimestampUtil;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TypeFacility;
+import org.teiid.translator.jdbc.SQLConversionVisitor;
+import org.teiid.translator.jdbc.TranslationHelper;
+import org.teiid.translator.jdbc.intersyscache.InterSystemsCacheExecutionFactory;
+/**
+ */
+public class TestInterSystemsCacheTranslation {
+
+ private static final LanguageFactory LANG_FACTORY = new LanguageFactory();
+
+ private static InterSystemsCacheExecutionFactory TRANSLATOR;
+
+ @BeforeClass
+ public static void setUp() throws TranslatorException {
+ TRANSLATOR = new InterSystemsCacheExecutionFactory();
+ TRANSLATOR.setUseBindVariables(false);
+ TRANSLATOR.start();
+ }
+
+ public String helpGetString(Expression expr) throws Exception {
+ SQLConversionVisitor sqlVisitor = TRANSLATOR.getSQLConversionVisitor();
+ sqlVisitor.append(expr);
+
+ return sqlVisitor.toString();
+ }
+
+ public void helpTest(Expression srcExpression, String tgtType, String expectedExpression) throws Exception {
+ Function func = LANG_FACTORY.createFunction("convert", //$NON-NLS-1$
+ Arrays.asList(
+ srcExpression,
+ LANG_FACTORY.createLiteral(tgtType, String.class)),
+ TypeFacility.getDataTypeClass(tgtType));
+
+ assertEquals("Error converting from " + srcExpression.getType() + " to " + tgtType, //$NON-NLS-1$ //$NON-NLS-2$
+ expectedExpression, helpGetString(func));
+ }
+
+ // Source = STRING
+ @Test public void testStringToChar() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "cast('5' AS character)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = Boolean
+
+ @Test public void testBooleanToBigDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class), "bigdecimal", "cast(1 AS decimal(38,19))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BYTE
+
+ @Test public void testByteToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "cast(1 AS varchar(4000))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Test public void testByteToBoolean() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "boolean", "CASE WHEN 1 = 0 THEN 0 WHEN 1 IS NOT NULL THEN 1 END"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Test public void testBigIntegerToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "double", "1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ @Test public void testBigIntegerDecimal() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "biginteger", "cast(1 AS decimal(19,0))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = FLOAT
+
+ @Test public void testFloatToLong() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Float(1.2f), Float.class), "long", "cast(1.2 AS bigint)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = DOUBLE
+
+ @Test public void testDoubleToShort() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.2), Double.class), "short", "cast(1.2 AS smallint)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = BIGDECIMAL
+
+ @Test public void testBigDecimalToByte() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "byte", "cast(1.0 AS tinyint)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Source = DATE
+
+ @Test public void testDateToTimestamp() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createDate(103, 10, 1), java.sql.Date.class), "timestamp", "cast(to_date('2003-11-01', 'yyyy-mm-dd') AS timestamp)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = TIME
+
+ @Test public void testTimeToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(TimestampUtil.createTime(23, 59, 59), java.sql.Time.class), "string", "cast(to_date('23:59:59', 'hh:mi:ss') AS varchar(4000))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ // Source = TIMESTAMP
+
+ @Test public void testTimestampToString() throws Exception {
+ Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 0);
+ helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "cast(to_timestamp('2003-11-01 12:05:02.0', 'yyyy-mm-dd hh:mi:ss.fffffffff') AS varchar(4000))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Source = LONG
+ @Test public void testLongToBigInt() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(5, Long.class), "long", "cast(5 AS bigint)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Test public void testSubstring1() throws Exception {
+ String input = "SELECT intnum/intkey FROM BQT1.SMALLA"; //$NON-NLS-1$
+ String output = "SELECT cast((SmallA.IntNum / SmallA.IntKey) AS integer) FROM SmallA"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
+ input, output,
+ TRANSLATOR);
+ }
+
+}
Property changes on: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheTranslation.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
More information about the teiid-commits
mailing list