Package org.teiid.translator.jdbc

Examples of org.teiid.translator.jdbc.ConvertModifier$FormatModifier


        registerFunctionModifier(SourceSystemFunctions.BITXOR, new BitFunctionModifier("^", getLanguageFactory())); //$NON-NLS-1$
        registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));
        registerFunctionModifier(SourceSystemFunctions.LPAD, new PadFunctionModifier());
        registerFunctionModifier(SourceSystemFunctions.RPAD, new PadFunctionModifier());
        //add in type conversion
        ConvertModifier convertModifier = new ConvertModifier();
        convertModifier.addTypeMapping("signed", FunctionModifier.BOOLEAN, FunctionModifier.BYTE, FunctionModifier.SHORT, FunctionModifier.INTEGER, FunctionModifier.LONG); //$NON-NLS-1$
      //char(n) assume 4.1 or later
      convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
      convertModifier.addTypeMapping("char", FunctionModifier.STRING); //$NON-NLS-1$
      convertModifier.addTypeMapping("date", FunctionModifier.DATE); //$NON-NLS-1$
      convertModifier.addTypeMapping("time", FunctionModifier.TIME); //$NON-NLS-1$
      convertModifier.addTypeMapping("datetime", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DATE, new ConvertModifier.FormatModifier("DATE")); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIME, new ConvertModifier.FormatModifier("TIME")); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIMESTAMP, new ConvertModifier.FormatModifier("TIMESTAMP")); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new ConvertModifier.FormatModifier("date_format", "%Y-%m-%d")); //$NON-NLS-1$ //$NON-NLS-2$
      convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new ConvertModifier.FormatModifier("date_format", "%H:%i:%S")); //$NON-NLS-1$ //$NON-NLS-2$
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("date_format", "%Y-%m-%d %H:%i:%S.%f")); //$NON-NLS-1$ //$NON-NLS-2$
      convertModifier.addTypeConversion(new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        return Arrays.asList(function.getParameters().get(0), " + 0.0"); //$NON-NLS-1$
      }
    }, FunctionModifier.BIGDECIMAL, FunctionModifier.BIGINTEGER, FunctionModifier.FLOAT, FunctionModifier.DOUBLE);
      convertModifier.addNumericBooleanConversions();
      convertModifier.setWideningNumericImplicit(true);
      registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
   
View Full Code Here


        registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
        registerFunctionModifier(SourceSystemFunctions.LENGTH, new EscapeSyntaxModifier());
        registerFunctionModifier(SourceSystemFunctions.ATAN2, new EscapeSyntaxModifier());
       
        //add in type conversion
        ConvertModifier convertModifier = new ConvertModifier();
        convertModifier.setBooleanNullable(booleanNullable());
        //boolean isn't treated as bit, since it doesn't support null
        //byte is treated as smallint, since tinyint is unsigned
      convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT); //$NON-NLS-1$
      convertModifier.addTypeMapping("int", FunctionModifier.INTEGER); //$NON-NLS-1$
      convertModifier.addTypeMapping("numeric(19,0)", FunctionModifier.LONG); //$NON-NLS-1$
      convertModifier.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
      convertModifier.addTypeMapping("double precision", FunctionModifier.DOUBLE); //$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(40)", FunctionModifier.STRING); //$NON-NLS-1$
      convertModifier.addTypeMapping("datetime", FunctionModifier.DATE, FunctionModifier.TIME, FunctionModifier.TIMESTAMP); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        List<Object> result = new ArrayList<Object>();
        result.add("cast("); //$NON-NLS-1$
        boolean needsEnd = false;
        if (!nullPlusNonNullIsNull() && !ConcatFunctionModifier.isNotNull(function.getParameters().get(0))) {
          result.add("CASE WHEN "); //$NON-NLS-1$
          result.add(function.getParameters().get(0));
          result.add(" IS NOT NULL THEN "); //$NON-NLS-1$
          needsEnd = true;
        }
        result.add("'1970-01-01 ' + "); //$NON-NLS-1$
        result.addAll(convertTimeToString(function));
        if (needsEnd) {
          result.add(" END"); //$NON-NLS-1$
        }
        result.add(" AS datetime)"); //$NON-NLS-1$
        return result;
      }
    });
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        List<Object> result = new ArrayList<Object>();
        result.add("cast("); //$NON-NLS-1$
        result.addAll(convertDateToString(function));
        result.add(" AS datetime)"); //$NON-NLS-1$
        return result;
      }
    });
      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);
      }
    });
      convertModifier.addNumericBooleanConversions();
      registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
    }
View Full Code Here

public class InformixExecutionFactory extends JDBCExecutionFactory {

  @Override
  public void start() throws TranslatorException {
    super.start();
      registerFunctionModifier(SourceSystemFunctions.CONVERT, new ConvertModifier());
    }
View Full Code Here

        return null;
      }
    });
               
        //add in type conversion
        ConvertModifier convertModifier = new ConvertModifier();
        convertModifier.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
      convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT); //$NON-NLS-1$
      convertModifier.addTypeMapping("integer", FunctionModifier.INTEGER); //$NON-NLS-1$
      convertModifier.addTypeMapping("bigint", FunctionModifier.LONG); //$NON-NLS-1$
      convertModifier.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
      convertModifier.addTypeMapping("float8", FunctionModifier.DOUBLE); //$NON-NLS-1$
      convertModifier.addTypeMapping("numeric(38)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
      convertModifier.addTypeMapping("decimal", 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("date", FunctionModifier.DATE); //$NON-NLS-1$
      convertModifier.addTypeMapping("time", FunctionModifier.TIME); //$NON-NLS-1$
      convertModifier.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        return Arrays.asList(function.getParameters().get(0), " + TIMESTAMP '1970-01-01'"); //$NON-NLS-1$
      }
    });
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        return Arrays.asList("cast(date_trunc('second', ", function.getParameters().get(0), ") AS time)"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    });
      convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD")); //$NON-NLS-1$ //$NON-NLS-2$
      convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "HH24:MI:SS")); //$NON-NLS-1$ //$NON-NLS-2$
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD HH24:MI:SS.US")); //$NON-NLS-1$ //$NON-NLS-2$
      convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        Expression stringValue = function.getParameters().get(0);
        return Arrays.asList("CASE WHEN ", stringValue, " THEN 'true' WHEN not(", stringValue, ") THEN 'false' END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
    });
      convertModifier.addSourceConversion(new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        ((Literal)function.getParameters().get(1)).setValue("integer"); //$NON-NLS-1$
        return null;
      }
View Full Code Here

        registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new SubstringFunctionModifier())

        registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("MOD", getLanguageFactory()))//$NON-NLS-1$
       
        //add in type conversion
        ConvertModifier convertModifier = new ConvertModifier();
      convertModifier.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
      convertModifier.addTypeMapping("numeric(31,0)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
      convertModifier.addTypeMapping("numeric(31,12)", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
      convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
      convertModifier.addTypeMapping("blob", FunctionModifier.BLOB, FunctionModifier.OBJECT); //$NON-NLS-1$
      convertModifier.addTypeMapping("clob", FunctionModifier.CLOB, FunctionModifier.XML); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        return Arrays.asList("timestamp('1970-01-01', ", function.getParameters().get(0), ")"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    });
      convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.TIMESTAMP, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        return Arrays.asList("timestamp(",function.getParameters().get(0), ", '00:00:00')"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    });
      //the next convert is not strictly necessary for db2, but it also works for derby
      convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.FLOAT, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        return Arrays.asList("cast(double(", function.getParameters().get(0), ") as real)"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    });
      convertModifier.addTypeConversion(new NullHandlingFormatModifier("char"), FunctionModifier.STRING); //$NON-NLS-1$
      convertModifier.addTypeConversion(new NullHandlingFormatModifier("smallint"), FunctionModifier.BYTE, FunctionModifier.SHORT); //$NON-NLS-1$
      convertModifier.addTypeConversion(new NullHandlingFormatModifier("integer"), FunctionModifier.INTEGER); //$NON-NLS-1$
      convertModifier.addTypeConversion(new NullHandlingFormatModifier("bigint"), FunctionModifier.LONG); //$NON-NLS-1$
      convertModifier.addTypeConversion(new NullHandlingFormatModifier("double"), FunctionModifier.DOUBLE); //$NON-NLS-1$
      convertModifier.addTypeConversion(new NullHandlingFormatModifier("date"), FunctionModifier.DATE); //$NON-NLS-1$
      convertModifier.addTypeConversion(new NullHandlingFormatModifier("time"), FunctionModifier.TIME); //$NON-NLS-1$
      convertModifier.addTypeConversion(new NullHandlingFormatModifier("timestamp"), FunctionModifier.TIMESTAMP); //$NON-NLS-1$
      convertModifier.addNumericBooleanConversions();
      registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
    }
View Full Code Here

    registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()));
   
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new AddDiffModifier(true, getLanguageFactory()));
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new AddDiffModifier(false, getLanguageFactory()));
 
    ConvertModifier convert = new ConvertModifier();
    convert.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
    convert.addTypeMapping("tinyint", FunctionModifier.BYTE); //$NON-NLS-1$
    convert.addTypeMapping("smallint", FunctionModifier.SHORT); //$NON-NLS-1$
    convert.addTypeMapping("int", FunctionModifier.INTEGER); //$NON-NLS-1$
    convert.addTypeMapping("bigint", FunctionModifier.LONG); //$NON-NLS-1$
    convert.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
    convert.addTypeMapping("double", FunctionModifier.DOUBLE); //$NON-NLS-1$
    convert.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
    convert.addTypeMapping("decimal(38,0)", FunctionModifier.BIGINTEGER); //$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.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
    convert.addTypeMapping("varchar", FunctionModifier.STRING); //$NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);   
  }
View Full Code Here

        registerFunctionModifier(OracleSpatialFunctions.NEAREST_NEIGHBOR, new OracleSpatialFunctionModifier());
        registerFunctionModifier(OracleSpatialFunctions.FILTER, new OracleSpatialFunctionModifier());
        registerFunctionModifier(OracleSpatialFunctions.WITHIN_DISTANCE, new OracleSpatialFunctionModifier());
       
        //add in type conversion
        ConvertModifier convertModifier = new ConvertModifier();
      convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
      convertModifier.addTypeMapping("date", FunctionModifier.DATE, FunctionModifier.TIME); //$NON-NLS-1$
      convertModifier.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new FunctionModifier() {
        @Override
        public List<?> translate(Function function) {
          return Arrays.asList("case when ", function.getParameters().get(0), " is null then null else to_date('1970-01-01 ' || to_char(",function.getParameters().get(0),", 'HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS') end"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
      });
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        return Arrays.asList("trunc(cast(",function.getParameters().get(0)," AS date))"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    });
      convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", DATE_FORMAT)); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", TIME_FORMAT)); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        //if column and type is date, just use date format
        Expression ex = function.getParameters().get(0);
        String format = TIMESTAMP_FORMAT;
        if (ex instanceof ColumnReference && "date".equalsIgnoreCase(((ColumnReference)ex).getMetadataObject().getNativeType())) { //$NON-NLS-1$
          format = DATETIME_FORMAT;
        } else if (!(ex instanceof Literal) && !(ex instanceof Function)) {
          //this isn't needed in every case, but it's simpler than inspecting the expression more
          ex = ConvertModifier.createConvertFunction(getLanguageFactory(), function.getParameters().get(0), TypeFacility.RUNTIME_NAMES.TIMESTAMP);
        }
        return Arrays.asList("to_char(", ex, ", '", format, "')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
    });
      convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DATE, new ConvertModifier.FormatModifier("to_date", DATE_FORMAT)); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIME, new ConvertModifier.FormatModifier("to_date", TIME_FORMAT)); //$NON-NLS-1$
      convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIMESTAMP, new ConvertModifier.FormatModifier("to_timestamp", TIMESTAMP_FORMAT)); //$NON-NLS-1$
      convertModifier.addTypeConversion(new ConvertModifier.FormatModifier("to_char"), FunctionModifier.STRING); //$NON-NLS-1$
      //NOTE: numeric handling in Oracle is split only between integral vs. floating/decimal types
      convertModifier.addTypeConversion(new ConvertModifier.FormatModifier("to_number"), //$NON-NLS-1$
          FunctionModifier.FLOAT, FunctionModifier.DOUBLE, FunctionModifier.BIGDECIMAL);
      convertModifier.addTypeConversion(new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        if (Number.class.isAssignableFrom(function.getParameters().get(0).getType())) {
          return Arrays.asList("trunc(", function.getParameters().get(0), ")"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        return Arrays.asList("trunc(to_number(", function.getParameters().get(0), "))"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    },
    FunctionModifier.BYTE, FunctionModifier.SHORT, FunctionModifier.INTEGER, FunctionModifier.LONG,  FunctionModifier.BIGINTEGER);
      convertModifier.addNumericBooleanConversions();
      convertModifier.setWideningNumericImplicit(true);
      registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
    }
View Full Code Here

  public void start() throws TranslatorException {
    super.start();
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new AddDiffModifier(true, getLanguageFactory()));
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new AddDiffModifier(false, getLanguageFactory()));
 
    ConvertModifier convert = new ConvertModifier();
    convert.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
    convert.addTypeMapping("tinyint", FunctionModifier.BYTE); //$NON-NLS-1$
    convert.addTypeMapping("smallint", FunctionModifier.SHORT); //$NON-NLS-1$
    convert.addTypeMapping("int", FunctionModifier.INTEGER); //$NON-NLS-1$
    convert.addTypeMapping("bigint", FunctionModifier.LONG); //$NON-NLS-1$
    convert.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
    convert.addTypeMapping("double", FunctionModifier.DOUBLE); //$NON-NLS-1$
    convert.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
    convert.addTypeMapping("decimal(38,0)", FunctionModifier.BIGINTEGER); //$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.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
    convert.addTypeMapping("varchar", FunctionModifier.STRING); //$NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);   
  }
View Full Code Here

TOP

Related Classes of org.teiid.translator.jdbc.ConvertModifier$FormatModifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.