[teiid-commits] teiid SVN: r2932 - in trunk: connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres and 6 other directories.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Wed Feb 23 13:12:03 EST 2011
Author: shawkins
Date: 2011-02-23 13:12:02 -0500 (Wed, 23 Feb 2011)
New Revision: 2932
Added:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/Ingres93ExecutionFactory.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ingres/
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ingres/TestIngresConvertModifier.java
Modified:
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/IngresExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/mm/MetaMatrixExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml
trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml
Log:
TEIID-1059: refining ingres support and making minor updates to the teiidexecutionfactory
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2011-02-23 18:08:23 UTC (rev 2931)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2011-02-23 18:12:02 UTC (rev 2932)
@@ -787,11 +787,16 @@
/**
* Indicates if LOBs are usable after the execution is closed.
* @return true if LOBs can be used after close
+ * @since 7.2
*/
public boolean areLobsUsableAfterClose() {
return false;
}
+ /**
+ * @return true if the WITH clause is supported
+ * @since 7.2
+ */
public boolean supportsCommonTableExpressions() {
return false;
}
Added: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/Ingres93ExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/Ingres93ExecutionFactory.java (rev 0)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/Ingres93ExecutionFactory.java 2011-02-23 18:12:02 UTC (rev 2932)
@@ -0,0 +1,57 @@
+/*
+ * 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.ingres;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.language.Limit;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.jdbc.FunctionModifier;
+
+ at Translator(name="ingres93", description="A translator for Ingres 9.3 or later Database")
+public class Ingres93ExecutionFactory extends IngresExecutionFactory {
+
+ @Override
+ public void start() throws TranslatorException {
+ super.start();
+ convert.addTypeMapping("ansidate", FunctionModifier.DATE); //$NON-NLS-1$
+ convert.addTypeMapping("timestamp(9) with time zone", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<?> translateLimit(Limit limit, ExecutionContext context) {
+ if (limit.getRowOffset() > 0) {
+ return Arrays.asList("OFFSET ", limit.getRowOffset(), " FETCH FIRST ", limit.getRowLimit(), " ROWS ONLY"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ return super.translateLimit(limit, context);
+ }
+
+ @Override
+ public boolean supportsRowOffset() {
+ return true;
+ }
+
+}
Property changes on: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/Ingres93ExecutionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/IngresExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/IngresExecutionFactory.java 2011-02-23 18:08:23 UTC (rev 2931)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ingres/IngresExecutionFactory.java 2011-02-23 18:12:02 UTC (rev 2932)
@@ -41,38 +41,31 @@
import org.teiid.translator.jdbc.FunctionModifier;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
- at Translator(name="ingres", description="A translator for Ingres Database")
+ at Translator(name="ingres", description="A translator for Ingres Databases")
public class IngresExecutionFactory extends JDBCExecutionFactory {
-
- private static final String INGRES = "ingres"; //$NON-NLS-1$
+ private static final String INGRES = "ingres"; //$NON-NLS-1$
+ protected ConvertModifier convert = new ConvertModifier();
+
@Override
public void start() throws TranslatorException {
super.start();
- ConvertModifier convert = new ConvertModifier();
- convert.addTypeMapping("bit", FunctionModifier.BYTE); //$NON-NLS-1$
- convert.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
- convert.addTypeMapping("tinyint", FunctionModifier.BYTE); //$NON-NLS-1$
+ convert.addTypeMapping("tinyint", FunctionModifier.BOOLEAN, 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("real", FunctionModifier.FLOAT); //$NON-NLS-1$
convert.addTypeMapping("float", FunctionModifier.DOUBLE); //$NON-NLS-1$
- convert.addTypeMapping("decimal(15,0)", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
- convert.addTypeMapping("decimal(38,0)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
+ convert.addTypeMapping("decimal(38,19)", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
+ convert.addTypeMapping("decimal(15,0)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
convert.addTypeMapping("date", FunctionModifier.DATE); //$NON-NLS-1$
convert.addTypeMapping("time with time zone", FunctionModifier.TIME); //$NON-NLS-1$
convert.addTypeMapping("timestamp with time zone", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
convert.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
- convert.addTypeMapping("varchar($1)", FunctionModifier.STRING); //$NON-NLS-1$
- convert.addTypeMapping("long varchar", FunctionModifier.STRING); //$NON-NLS-1$
+ convert.addTypeMapping("varchar(4000)", FunctionModifier.STRING); //$NON-NLS-1$
convert.addTypeMapping("blob", FunctionModifier.BLOB); //$NON-NLS-1$
convert.addTypeMapping("clob", FunctionModifier.CLOB); //$NON-NLS-1$
- convert.addTypeMapping("byte($1)", FunctionModifier.OBJECT); //$NON-NLS-1$
- convert.addTypeMapping("long byte", FunctionModifier.OBJECT); //$NON-NLS-1$
- convert.addTypeMapping("varbyte($1)", FunctionModifier.OBJECT); //$NON-NLS-1$
- convert.addTypeMapping("ansidate", FunctionModifier.DATE); //$NON-NLS-1$
- convert.addTypeMapping("timestamp(9) with time zone", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
+ convert.addNumericBooleanConversions();
registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
}
@@ -272,4 +265,5 @@
public boolean supportsInlineViews() {
return true;
}
+
}
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/mm/MetaMatrixExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/mm/MetaMatrixExecutionFactory.java 2011-02-23 18:08:23 UTC (rev 2931)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/mm/MetaMatrixExecutionFactory.java 2011-02-23 18:12:02 UTC (rev 2932)
@@ -14,7 +14,7 @@
/**
* Capabilities compatible with MM 5.5.x
*/
- at Translator(name="metamatrix", description="A translator for MetaMatrix Virtual Database")
+ at Translator(name="metamatrix", description="A translator for MetaMatrix 5.5 or later")
public class MetaMatrixExecutionFactory extends JDBCExecutionFactory {
public List<String> getSupportedFunctions() {
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java 2011-02-23 18:08:23 UTC (rev 2931)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java 2011-02-23 18:12:02 UTC (rev 2932)
@@ -27,19 +27,21 @@
import java.util.ArrayList;
import java.util.List;
+import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
-import org.teiid.translator.ExecutionFactory.NullOrder;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
-
/**
* @since 4.3
*/
- at Translator(name="teiid", description="A translator for Teiid Virtual Database")
+ at Translator(name="teiid", description="A translator for Teiid 7.0 or later")
public class TeiidExecutionFactory extends JDBCExecutionFactory {
public static final String SEVEN_0 = "7.0"; //$NON-NLS-1$
public static final String SEVEN_1 = "7.1"; //$NON-NLS-1$
+ public static final String SEVEN_2 = "7.2"; //$NON-NLS-1$
+ public static final String SEVEN_3 = "7.3"; //$NON-NLS-1$
+ public static final String SEVEN_4 = "7.4"; //$NON-NLS-1$
public TeiidExecutionFactory() {
setDatabaseVersion(SEVEN_0);
@@ -139,6 +141,17 @@
supportedFunctions.add("FROM_UNIXTIME"); //$NON-NLS-1$
supportedFunctions.add("NULLIF"); //$NON-NLS-1$
supportedFunctions.add("COALESCE"); //$NON-NLS-1$
+
+ if (getDatabaseVersion().compareTo(SEVEN_3) >= 0) {
+ supportedFunctions.add(SourceSystemFunctions.UNESCAPE);
+
+ if (getDatabaseVersion().compareTo(SEVEN_4) >= 0) {
+ supportedFunctions.add(SourceSystemFunctions.UUID);
+ supportedFunctions.add(SourceSystemFunctions.ARRAY_GET);
+ supportedFunctions.add(SourceSystemFunctions.ARRAY_LENGTH);
+ }
+ }
+
return supportedFunctions;
}
@@ -178,4 +191,14 @@
public NullOrder getDefaultNullOrder() {
return NullOrder.UNKNOWN;
}
+
+ @Override
+ public boolean supportsBulkUpdate() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsCommonTableExpressions() {
+ return getDatabaseVersion().compareTo(SEVEN_2) >= 0;
+ }
}
Added: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ingres/TestIngresConvertModifier.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ingres/TestIngresConvertModifier.java (rev 0)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ingres/TestIngresConvertModifier.java 2011-02-23 18:12:02 UTC (rev 2932)
@@ -0,0 +1,126 @@
+/*
+ * 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.ingres;
+
+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;
+/**
+ */
+public class TestIngresConvertModifier {
+
+ private static final LanguageFactory LANG_FACTORY = new LanguageFactory();
+
+ public String helpGetString(Expression expr) throws Exception {
+ IngresExecutionFactory trans = new IngresExecutionFactory();
+ 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 char(1))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ @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", "cast(1 AS float)"); //$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(DATE '2003-11-01' AS timestamp with time zone)"); //$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(TIME '23:59:59' 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(TIMESTAMP '2003-11-01 12:05:02.0' AS varchar(4000))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+}
Property changes on: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ingres/TestIngresConvertModifier.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml
===================================================================
--- trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml 2011-02-23 18:08:23 UTC (rev 2931)
+++ trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml 2011-02-23 18:12:02 UTC (rev 2932)
@@ -268,7 +268,7 @@
<section>
<title>Bulk Execution</title>
- <para> Non batched <code>Insert, Update, Delete</code>
+ <para>Non batched <code>Insert, Update, Delete</code>
commands may have <code>Literal</code> values marked as multiValued if the
capabilities shows support for BulkUpdate. Commands with
multiValued <code>Literal</code>s represent multiple executions of the same
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml 2011-02-23 18:08:23 UTC (rev 2931)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml 2011-02-23 18:12:02 UTC (rev 2932)
@@ -237,6 +237,16 @@
</listitem>
<listitem>
<para>
+ <emphasis>ingres</emphasis> - for use with Ingres 2006 or later.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <emphasis>ingres93</emphasis> - for use with Ingres 9.3 or later.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
<emphasis>informix</emphasis> - for use with any version.
</para>
</listitem>
@@ -303,12 +313,7 @@
<para>
<emphasis>teradata</emphasis> - for use with Teradata V2R5.1 or later.
</para>
- </listitem>
- <listitem>
- <para>
- <emphasis>ingres</emphasis> - for use with Ingres Database 9.2 or later.
- </para>
- </listitem>
+ </listitem>
</itemizedlist>
<table>
More information about the teiid-commits
mailing list