Search in sources :

Example 11 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class InsertExecutionImpl method buildSingleRowInsertPayload.

private void buildSingleRowInsertPayload(Insert insert, DataPayload data) throws TranslatorException {
    List<ColumnReference> columns = insert.getColumns();
    List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
    if (columns.size() != values.size()) {
        throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13006));
    }
    for (int i = 0; i < columns.size(); i++) {
        Column column = columns.get(i).getMetadataObject();
        Object value = values.get(i);
        if (!(value instanceof Literal)) {
            throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13007));
        }
        Literal literalValue = (Literal) values.get(i);
        Object val = literalValue.getValue();
        if (val instanceof Timestamp) {
            Calendar cal = Calendar.getInstance();
            cal.setTime((Timestamp) val);
            val = cal;
        }
        data.addField(column.getSourceName(), val);
    }
}
Also used : Expression(org.teiid.language.Expression) Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) Calendar(java.util.Calendar) TranslatorException(org.teiid.translator.TranslatorException) SObject(com.sforce.async.SObject) Timestamp(java.sql.Timestamp) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 12 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class JDBCBaseExecution method bind.

/**
 * Bind the values in the TranslatedCommand to the PreparedStatement
 */
protected void bind(PreparedStatement stmt, List<?> params, List<?> batchValues) throws SQLException {
    for (int i = 0; i < params.size(); i++) {
        Object paramValue = params.get(i);
        Object value = null;
        Class<?> paramType = null;
        if (paramValue instanceof Literal) {
            Literal litParam = (Literal) paramValue;
            value = litParam.getValue();
            paramType = litParam.getType();
        } else if (paramValue instanceof Argument) {
            Argument arg = (Argument) paramValue;
            value = ((Literal) arg.getExpression()).getValue();
            paramType = arg.getType();
        } else {
            Parameter param = (Parameter) paramValue;
            if (batchValues == null) {
                // $NON-NLS-1$
                throw new AssertionError("Expected batchValues when using a Parameter");
            }
            value = batchValues.get(param.getValueIndex());
            paramType = param.getType();
        }
        this.executionFactory.bindValue(stmt, value, paramType, i + 1);
    }
    if (batchValues != null) {
        stmt.addBatch();
    }
}
Also used : Argument(org.teiid.language.Argument) Literal(org.teiid.language.Literal) Parameter(org.teiid.language.Parameter)

Example 13 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class LocateFunctionModifier method ensurePositiveStartIndex.

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;
}
Also used : Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal)

Example 14 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class ParseFormatFunctionModifier method translate.

@Override
public List<?> translate(Function function) {
    if (!(function.getParameters().get(1) instanceof Literal)) {
        // shouldn't happen
        return null;
    }
    Literal l = (Literal) function.getParameters().get(1);
    List<Object> result = new ArrayList<Object>();
    result.add(prefix);
    translateFormat(result, function.getParameters().get(0), (String) l.getValue());
    // $NON-NLS-1$
    result.add(")");
    return result;
}
Also used : Literal(org.teiid.language.Literal) ArrayList(java.util.ArrayList)

Example 15 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class DB2ExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    registerFunctionModifier(SourceSystemFunctions.TRIM, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            List<Expression> p = function.getParameters();
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            return Arrays.asList("STRIP(", p.get(2), ", ", ((Literal) p.get(0)).getValue(), ", ", p.get(1), ")");
        }
    });
    registerFunctionModifier(SourceSystemFunctions.WEEK, new AliasModifier(WEEK_ISO));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    addPushDownFunction("db2", "substr", "string", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.INTEGER);
}
Also used : Function(org.teiid.language.Function) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) Literal(org.teiid.language.Literal) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Literal (org.teiid.language.Literal)82 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)18 Expression (org.teiid.language.Expression)17 TranslatorException (org.teiid.translator.TranslatorException)16 Function (org.teiid.language.Function)15 Argument (org.teiid.language.Argument)12 ColumnReference (org.teiid.language.ColumnReference)10 Column (org.teiid.metadata.Column)10 Comparison (org.teiid.language.Comparison)9 ExpressionValueSource (org.teiid.language.ExpressionValueSource)7 List (java.util.List)5 Call (org.teiid.language.Call)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4 DBCollection (com.mongodb.DBCollection)3 Timestamp (java.sql.Timestamp)3 Array (org.teiid.language.Array)3 Command (org.teiid.language.Command)3 Insert (org.teiid.language.Insert)3