Search in sources :

Example 6 with EscapeSyntaxModifier

use of org.teiid.translator.jdbc.EscapeSyntaxModifier in project teiid by teiid.

the class SAPIQExecutionFactory method start.

public void start() throws TranslatorException {
    super.start();
    registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()) {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$
            function.setName("||");
            return super.translate(function);
        }
    });
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CONCAT2, new AliasModifier("STRING"));
    registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new EscapeSyntaxModifier());
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new TemplateFunctionModifier("DATEPART(dy,", 0, ")"));
    registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.WEEK, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new AddDiffModifier(true, this.getLanguageFactory()).supportsQuarter(true));
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new AddDiffModifier(false, this.getLanguageFactory()).supportsQuarter(true));
    registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier(SourceSystemFunctions.COALESCE));
    registerFunctionModifier(SourceSystemFunctions.LOCATE, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            List<Expression> params = function.getParameters();
            Expression param1 = params.get(0);
            Expression param2 = params.set(1, param1);
            params.set(0, param2);
            return null;
        }
    });
    // add in type conversion
    ConvertModifier convertModifier = new ConvertModifier();
    convertModifier.setBooleanNullable(booleanNullable());
    convertModifier.addNumericBooleanConversions();
    // boolean isn't treated as bit, since it doesn't support null
    // byte is treated as smallint, since tinyint is unsigned
    // $NON-NLS-1$
    convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("bigint", FunctionModifier.LONG);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("int", FunctionModifier.INTEGER);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("double", FunctionModifier.DOUBLE);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("real", FunctionModifier.FLOAT);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("numeric(38, 0)", FunctionModifier.BIGINTEGER);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("numeric(38, 19)", FunctionModifier.BIGDECIMAL);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("varchar(4000)", FunctionModifier.STRING);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("varbinary", FunctionModifier.VARBINARY);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("date", FunctionModifier.DATE);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("time", FunctionModifier.TIME);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP);
    convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            return convertTimeToString(function);
        }
    });
    convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            return convertDateToString(function);
        }
    });
    convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            return convertTimestampToString(function);
        }
    });
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
}
Also used : Function(org.teiid.language.Function) TemplateFunctionModifier(org.teiid.translator.jdbc.TemplateFunctionModifier) Expression(org.teiid.language.Expression) TemplateFunctionModifier(org.teiid.translator.jdbc.TemplateFunctionModifier) ConcatFunctionModifier(org.teiid.translator.jdbc.oracle.ConcatFunctionModifier) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) EscapeSyntaxModifier(org.teiid.translator.jdbc.EscapeSyntaxModifier) ConcatFunctionModifier(org.teiid.translator.jdbc.oracle.ConcatFunctionModifier) AddDiffModifier(org.teiid.translator.jdbc.hsql.AddDiffModifier) ConvertModifier(org.teiid.translator.jdbc.ConvertModifier)

Aggregations

EscapeSyntaxModifier (org.teiid.translator.jdbc.EscapeSyntaxModifier)6 List (java.util.List)5 ArrayList (java.util.ArrayList)4 AliasModifier (org.teiid.translator.jdbc.AliasModifier)4 FunctionModifier (org.teiid.translator.jdbc.FunctionModifier)4 Function (org.teiid.language.Function)3 LinkedList (java.util.LinkedList)2 ConvertModifier (org.teiid.translator.jdbc.ConvertModifier)2 ModFunctionModifier (org.teiid.translator.jdbc.ModFunctionModifier)2 ConcatFunctionModifier (org.teiid.translator.jdbc.oracle.ConcatFunctionModifier)2 LeftOrRightFunctionModifier (org.teiid.translator.jdbc.oracle.LeftOrRightFunctionModifier)2 Expression (org.teiid.language.Expression)1 Literal (org.teiid.language.Literal)1 ExtractFunctionModifier (org.teiid.translator.jdbc.ExtractFunctionModifier)1 ParseFormatFunctionModifier (org.teiid.translator.jdbc.ParseFormatFunctionModifier)1 TemplateFunctionModifier (org.teiid.translator.jdbc.TemplateFunctionModifier)1 AddDiffModifier (org.teiid.translator.jdbc.hsql.AddDiffModifier)1 MonthOrDayNameFunctionModifier (org.teiid.translator.jdbc.oracle.MonthOrDayNameFunctionModifier)1 OracleFormatFunctionModifier (org.teiid.translator.jdbc.oracle.OracleFormatFunctionModifier)1