Package org.teiid.language

Examples of org.teiid.language.Literal


        helpTestMod(arg1, "Month", //$NON-NLS-1$
            "rtrim(TO_CHAR({ts '2004-01-21 10:05:00.01'}, 'Month'))"); //$NON-NLS-1$
    }

    public void test2() throws Exception {
        Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
        helpTestMod(arg1, "Month", //$NON-NLS-1$
            "rtrim(TO_CHAR({d '2004-01-21'}, 'Month'))"); //$NON-NLS-1$
    }
View Full Code Here


        helpTestMod(arg1, "Month", //$NON-NLS-1$
            "rtrim(TO_CHAR({d '2004-01-21'}, 'Month'))"); //$NON-NLS-1$
    }
   
    public void test3() throws Exception {
        Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 10000000), Timestamp.class);
        helpTestMod(arg1, "Day"//$NON-NLS-1$
            "rtrim(TO_CHAR({ts '2004-01-21 10:05:00.01'}, 'Day'))"); //$NON-NLS-1$
    }
View Full Code Here

        helpTestMod(arg1, "Day"//$NON-NLS-1$
            "rtrim(TO_CHAR({ts '2004-01-21 10:05:00.01'}, 'Day'))"); //$NON-NLS-1$
    }

    public void test4() throws Exception {
        Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
        helpTestMod(arg1, "Day", //$NON-NLS-1$
            "rtrim(TO_CHAR({d '2004-01-21'}, 'Day'))"); //$NON-NLS-1$
    }
View Full Code Here

    }
   
    @Test public void testVisitConvertFunctionOracleStyle() throws Exception {
        String expected = "convert(columnA, integer)"; //$NON-NLS-1$
       
        List<? extends Expression> params = Arrays.asList(new ColumnReference(null, "columnA", null, String.class), new Literal("integer", String.class));
        Function test = new Function("convert", params, Integer.class); //$NON-NLS-1$
       
        assertEquals(expected, getString(test));
    }
View Full Code Here

        registerFunctionModifier(SourceSystemFunctions.RIGHT, new LeftOrRightFunctionModifier(getLanguageFactory(), this.convert));
        registerFunctionModifier(SourceSystemFunctions.COT, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        function.setName(SourceSystemFunctions.TAN);
        return Arrays.asList(getLanguageFactory().createFunction(SourceSystemFunctions.DIVIDE_OP, new Expression[] {new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER), function}, TypeFacility.RUNTIME_TYPES.DOUBLE));
      }
    });       
        registerFunctionModifier(SourceSystemFunctions.LTRIM, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
View Full Code Here

        registerFunctionModifier(SourceSystemFunctions.ARRAY_LENGTH, new FunctionModifier() {
     
      @Override
      public List<?> translate(Function function) {
        if (function.getParameters().size() == 1) {
          function.getParameters().add(new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER));
        }
        return null;
      }
    });
               
View Full Code Here

        }
    }

  private Expression ensurePositiveStartIndex(Expression startIndex) {
    if (startIndex instanceof Literal) {
      Literal literal = (Literal)startIndex; 
      if (literal.getValue() instanceof Integer && ((Integer)literal.getValue() < 1)) {
        literal.setValue(1);
      }
    } else {
      Comparison whenExpr = langFactory.createCompareCriteria(
          Operator.LT,
          startIndex,
          langFactory.createLiteral(1, Integer.class)
        );
      Literal thenExpr = langFactory.createLiteral(1, Integer.class);
      startIndex = langFactory.createSearchedCaseExpression(Arrays.asList(langFactory.createSearchedWhenCondition(whenExpr, thenExpr)), startIndex, TypeFacility.RUNTIME_TYPES.INTEGER);
    }
    return startIndex;
  }
View Full Code Here

    protected void bindPreparedStatementValues(PreparedStatement stmt, TranslatedCommand tc, int rowCount) throws SQLException {
        List<?> params = tc.getPreparedValues();

        for (int row = 0; row < rowCount; row++) {
          for (int i = 0; i< params.size(); i++) {
              Literal paramValue = (Literal)params.get(i);
              Object value = paramValue.getValue();
              if (paramValue.isMultiValued()) {
                value = ((List<?>)value).get(row);
              }
              Class<?> paramType = paramValue.getType();
              this.executionFactory.bindValue(stmt, value, paramType, i+1);
          }
          if (rowCount > 1) {
              stmt.addBatch();
            }
View Full Code Here

public class TestJDBCUpdateExecution {

  @Test public void testBulkUpdate() throws Exception {
    Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "insert into BQT1.SmallA (IntKey, IntNum) values (1, 2)"); //$NON-NLS-1$
    Literal value = ((Literal)((ExpressionValueSource)((Insert)command).getValueSource()).getValues().get(0));
    Literal value1 = ((Literal)((ExpressionValueSource)((Insert)command).getValueSource()).getValues().get(1));
    value.setMultiValued(true);
    value.setBindValue(true);
    value.setValue(Arrays.asList(1, 2));
    value1.setMultiValued(true);
    value1.setBindValue(true);
    value1.setValue(Arrays.asList(2, 3));
    Connection connection = Mockito.mock(Connection.class);
    PreparedStatement p = Mockito.mock(PreparedStatement.class);
    Mockito.stub(p.executeBatch()).toReturn(new int [] {1, 1});
    Mockito.stub(connection.prepareStatement("INSERT INTO SmallA (IntKey, IntNum) VALUES (?, ?)")).toReturn(p); //$NON-NLS-1$
   
View Full Code Here

        return new Constant(val);
    }
   
    public static Literal example(int val) {
        Constant c = helpExample(val);
        return new Literal(c.getValue(), c.getType());
    }
View Full Code Here

TOP

Related Classes of org.teiid.language.Literal

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.