[teiid-commits] teiid SVN: r2980 - in trunk: build/kits/jboss-container/teiid-examples/jca and 6 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Mar 8 16:37:54 EST 2011


Author: rareddy
Date: 2011-03-08 16:37:53 -0500 (Tue, 08 Mar 2011)
New Revision: 2980

Added:
   trunk/build/kits/jboss-container/teiid-examples/jca/intersystems-cache-ds.xml
   trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/intersyscache/
   trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/intersyscache/InterSystemsCacheExecutionFactory.java
   trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/
   trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheConvertModifier.java
Modified:
   trunk/build/kits/jboss-container/teiid-releasenotes.html
   trunk/connectors/translator-jdbc/src/main/resources/META-INF/jboss-beans.xml
   trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml
Log:
TEIID-1060: adding Translator for intersystems cache database

Added: trunk/build/kits/jboss-container/teiid-examples/jca/intersystems-cache-ds.xml
===================================================================
--- trunk/build/kits/jboss-container/teiid-examples/jca/intersystems-cache-ds.xml	                        (rev 0)
+++ trunk/build/kits/jboss-container/teiid-examples/jca/intersystems-cache-ds.xml	2011-03-08 21:37:53 UTC (rev 2980)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<datasources>
+    <!-- unfortunately I did not see a XA data source for intersys cache -->
+    <!-- copy the cacheDB.jar to the lib directory -->
+     <local-tx-datasource>
+        <jndi-name>cacheDS</jndi-name>
+        <connection-url>jdbc:Cache://localhost:1972/{database}</connection-url>
+        <driver-class>com.intersys.jdbc.CacheDriver</driver-class>
+        <user-name>user</user-name>
+        <password>pass</password>
+         <min-pool-size>5</min-pool-size>
+         <max-pool-size>20</max-pool-size>
+  </local-tx-datasource>
+</datasources>


Property changes on: trunk/build/kits/jboss-container/teiid-examples/jca/intersystems-cache-ds.xml
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-container/teiid-releasenotes.html	2011-03-08 20:47:01 UTC (rev 2979)
+++ trunk/build/kits/jboss-container/teiid-releasenotes.html	2011-03-08 21:37:53 UTC (rev 2980)
@@ -37,6 +37,7 @@
 	    </UL>
 	<LI><B>ARRAYTABLE</B> - the ARRAYTABLE table function was added to simplify array value extraction into a tabular format.
 	<LI><B>Ingres</B> - Ingres database translator is now available to use as supported source under Teiid.
+	<LI><B>InterSystems Cache</B> - InterSystems Cache database translator is now available to use as supported source under Teiid.
 </UL>
 
 <h2><a name="Compatibility">Compatibility Issues</a></h2>

Added: 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	                        (rev 0)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/intersyscache/InterSystemsCacheExecutionFactory.java	2011-03-08 21:37:53 UTC (rev 2980)
@@ -0,0 +1,253 @@
+/*
+ * 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.intersyscache;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+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.jdbc.AliasModifier;
+import org.teiid.translator.jdbc.ConvertModifier;
+import org.teiid.translator.jdbc.FunctionModifier;
+import org.teiid.translator.jdbc.JDBCExecutionFactory;
+
+ at Translator(name="intersystems-cache", description="A translator for Intersystems Cache Database")
+public class InterSystemsCacheExecutionFactory extends JDBCExecutionFactory {
+	
+	private static final String INTER_CACHE = "intersystems-cache"; //$NON-NLS-1$
+	protected ConvertModifier convert = new ConvertModifier();
+	
+	@Override
+	public void start() throws TranslatorException {
+		super.start();
+		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("varchar(4000)", FunctionModifier.STRING); //$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));          
+	}
+	
+    @Override
+    public List<String> getSupportedFunctions() {
+        List<String> supportedFunctions = new ArrayList<String>();
+        supportedFunctions.addAll(super.getSupportedFunctions());
+
+        supportedFunctions.add(SourceSystemFunctions.ABS);
+        supportedFunctions.add(SourceSystemFunctions.ASCII);
+        supportedFunctions.add(SourceSystemFunctions.CEILING);
+        supportedFunctions.add(SourceSystemFunctions.CHAR);
+        supportedFunctions.add(SourceSystemFunctions.COALESCE);
+        supportedFunctions.add(SourceSystemFunctions.FLOOR);
+        supportedFunctions.add(SourceSystemFunctions.IFNULL);
+        supportedFunctions.add(SourceSystemFunctions.LCASE);
+        supportedFunctions.add(SourceSystemFunctions.LENGTH);
+        supportedFunctions.add(SourceSystemFunctions.LPAD);
+        supportedFunctions.add(SourceSystemFunctions.LTRIM);
+        supportedFunctions.add(SourceSystemFunctions.NULLIF);
+        supportedFunctions.add(SourceSystemFunctions.POWER);
+        supportedFunctions.add(SourceSystemFunctions.REPEAT);
+        supportedFunctions.add(SourceSystemFunctions.REPLACE);
+        supportedFunctions.add(SourceSystemFunctions.ROUND);
+        supportedFunctions.add(SourceSystemFunctions.RPAD);
+        supportedFunctions.add(SourceSystemFunctions.RTRIM);
+        supportedFunctions.add(SourceSystemFunctions.SIGN);
+        supportedFunctions.add(SourceSystemFunctions.SUBSTRING);
+        supportedFunctions.add(SourceSystemFunctions.UCASE);
+        supportedFunctions.add(SourceSystemFunctions.XMLCONCAT);
+
+        return supportedFunctions;
+    }
+    
+    @Override
+    public List<FunctionMethod> getPushDownFunctions(){
+    	        
+    	List<FunctionMethod> pushdownFunctions = new ArrayList<FunctionMethod>();
+    
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "CHARACTER_LENGTH", "CHARACTER_LENGTH", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+            new FunctionParameter[] {
+                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "CHAR_LENGTH", "CHAR_LENGTH", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+	                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+		
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "CHARINDEX", "CHARINDEX", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("string2", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+		
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "CHARINDEX", "CHARINDEX", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("string2", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("integer1", DataTypeManager.DefaultDataTypes.INTEGER, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$    		
+		
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "INSTR", "INSTR", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("string2", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+		
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "INSTR", "INSTR", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("string2", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("integer1", DataTypeManager.DefaultDataTypes.INTEGER, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$    		
+		
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "IS_NUMERIC", "IS_NUMERIC", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+	                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+				
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "REPLICATE", "REPLICATE", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("integer1", DataTypeManager.DefaultDataTypes.INTEGER, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$    		
+		
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "REVERSE", "REVERSE", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+	                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+		
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "STUFF", "STUFF", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("integer1", DataTypeManager.DefaultDataTypes.STRING, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("integer2", DataTypeManager.DefaultDataTypes.INTEGER, ""), //$NON-NLS-1$ //$NON-NLS-2$
+                new FunctionParameter("string2", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$  		
+		
+		pushdownFunctions.add(new FunctionMethod(INTER_CACHE + '.' + "TRIM", "TRIM", INTER_CACHE, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter[] {
+	                new FunctionParameter("string1", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+	            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+		
+    	return pushdownFunctions;
+    }
+
+    
+    @Override
+    public String translateLiteralDate(Date dateValue) {
+        return "to_date('" + formatDateValue(dateValue) + "', 'yyyy-mm-dd')"; //$NON-NLS-1$//$NON-NLS-2$
+    }
+
+    @Override
+    public String translateLiteralTime(Time timeValue) {
+        return "to_date('" + formatDateValue(timeValue) + "', 'hh:mi:ss')"; //$NON-NLS-1$//$NON-NLS-2$
+    }
+    
+    @Override
+    public String translateLiteralTimestamp(Timestamp timestampValue) {
+        return "to_timestamp('" + formatDateValue(timestampValue) + "', 'yyyy-mm-dd hh:mi:ss.fffffffff')"; //$NON-NLS-1$//$NON-NLS-2$ 
+    }	
+    
+    @Override
+    public NullOrder getDefaultNullOrder() {
+    	return NullOrder.LAST;
+    }    
+    
+    @Override
+    public boolean supportsInlineViews() {
+        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); 
+		}
+    }
+}


Property changes on: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/intersyscache/InterSystemsCacheExecutionFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/connectors/translator-jdbc/src/main/resources/META-INF/jboss-beans.xml
===================================================================
--- trunk/connectors/translator-jdbc/src/main/resources/META-INF/jboss-beans.xml	2011-03-08 20:47:01 UTC (rev 2979)
+++ trunk/connectors/translator-jdbc/src/main/resources/META-INF/jboss-beans.xml	2011-03-08 21:37:53 UTC (rev 2980)
@@ -304,4 +304,20 @@
             <parameter class="java.lang.String">Ingres</parameter>
         </constructor>
     </bean>     
+    
+    <!-- InterSystems Cache -->
+    <bean name="translator-intersystems-cache-template" class="org.teiid.templates.TranslatorDeploymentTemplate">
+        <property name="info"><inject bean="translator-intersystems-cache" /> </property>
+        <property name="managedObjectFactory"> <inject bean="ManagedObjectFactory" /> </property>
+    </bean>
+
+    <bean name="translator-intersystems-cache" class="org.teiid.templates.TranslatorTemplateInfo">
+        <constructor factoryMethod="createTemplateInfo">
+            <factory bean="TranslatorDeploymentTemplateInfoFactory" />
+            <parameter class="java.lang.Class">org.teiid.templates.TranslatorTemplateInfo</parameter>
+            <parameter class="java.lang.Class">org.teiid.translator.jdbc.intersyscache.InterSystemsCacheExecutionFactory</parameter>
+            <parameter class="java.lang.String">translator-intersystems-cache</parameter>
+            <parameter class="java.lang.String">InterSystems Cache</parameter>
+        </constructor>
+    </bean>     
 </deployment>
\ No newline at end of file

Added: 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	                        (rev 0)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheConvertModifier.java	2011-03-08 21:37:53 UTC (rev 2980)
@@ -0,0 +1,138 @@
+/*
+ * 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$
+    }
+
+}


Property changes on: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/intersystemscache/TestInterSystemsCacheConvertModifier.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml	2011-03-08 20:47:01 UTC (rev 2979)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml	2011-03-08 21:37:53 UTC (rev 2980)
@@ -247,6 +247,11 @@
                 </listitem>
                 <listitem>
                     <para>
+                    <emphasis>intersystems-cache</emphasis> - for use with Intersystems Cache Object database (only relational aspect of it)
+                    </para>
+                </listitem>                
+                <listitem>
+                    <para>
                     <emphasis>informix</emphasis> - for use with any version.
                     </para>
                 </listitem>



More information about the teiid-commits mailing list