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);
}
}
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();
}
}
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;
}
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;
}
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);
}
Aggregations