use of org.teiid.language.ExpressionValueSource in project teiid by teiid.
the class AccumuloUpdateExecution method performInsert.
private void performInsert(Insert insert) throws TranslatorException, TableNotFoundException, MutationsRejectedException {
Table table = insert.getTable().getMetadataObject();
this.updateCount = 0;
Connector connector = this.connection.getInstance();
BatchWriter writer = createBatchWriter(table, connector);
List<ColumnReference> columns = insert.getColumns();
if (insert.getParameterValues() == null) {
List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
writeMutation(writer, columns, values);
this.updateCount++;
} else {
int batchSize = this.executionContext.getBatchSize();
// bulk insert; should help
Iterator<? extends List<Expression>> args = (Iterator<? extends List<Expression>>) insert.getParameterValues();
while (args.hasNext()) {
List<Expression> values = args.next();
writeMutation(writer, columns, values);
this.updateCount++;
if ((this.updateCount % batchSize) == 0) {
writer.close();
writer = createBatchWriter(table, connector);
}
}
}
// write the mutation
writer.close();
}
use of org.teiid.language.ExpressionValueSource in project teiid by teiid.
the class TestInsertImpl method testGetValues.
public void testGetValues() throws Exception {
// $NON-NLS-1$
Insert insert = example("a.b");
assertNotNull(insert.getValueSource());
assertEquals(4, ((ExpressionValueSource) insert.getValueSource()).getValues().size());
for (Iterator i = ((ExpressionValueSource) insert.getValueSource()).getValues().iterator(); i.hasNext(); ) {
assertTrue(i.next() instanceof Expression);
}
}
use of org.teiid.language.ExpressionValueSource in project teiid by teiid.
the class ODataUpdateVisitor method visit.
@Override
public void visit(Insert obj) {
this.operationType = OperationType.INSERT;
visitNode(obj.getTable());
try {
// read the properties
int elementCount = obj.getColumns().size();
for (int i = 0; i < elementCount; i++) {
Column column = obj.getColumns().get(i).getMetadataObject();
List<Expression> values = ((ExpressionValueSource) obj.getValueSource()).getValues();
Expression expr = values.get(i);
Object value = resolveExpressionValue(expr);
this.odataQuery.addInsertProperty(column, ODataMetadataProcessor.getNativeType(column), value);
}
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
use of org.teiid.language.ExpressionValueSource in project teiid by teiid.
the class InsertExecutionImpl method buildBulkRowPayload.
protected List<com.sforce.async.SObject> buildBulkRowPayload(Insert insert, Iterator<? extends List<?>> it, int rowCount) throws TranslatorException {
List<com.sforce.async.SObject> rows = new ArrayList<com.sforce.async.SObject>();
List<ColumnReference> columns = insert.getColumns();
int boundCount = 0;
List<Expression> literalValues = ((ExpressionValueSource) insert.getValueSource()).getValues();
while (it.hasNext()) {
if (boundCount >= rowCount) {
break;
}
boundCount++;
List<?> values = it.next();
com.sforce.async.SObject sobj = new com.sforce.async.SObject();
for (int i = 0; i < columns.size(); i++) {
Expression ex = literalValues.get(i);
ColumnReference element = columns.get(i);
Column column = element.getMetadataObject();
Class<?> type = ex.getType();
Object value = null;
if (ex instanceof Parameter) {
value = values.get(((Parameter) ex).getValueIndex());
} else if (!(ex instanceof Literal)) {
throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13007));
} else {
value = ((Literal) ex).getValue();
}
sobj.setField(column.getSourceName(), getStringValue(value, type));
}
rows.add(sobj);
}
return rows;
}
use of org.teiid.language.ExpressionValueSource 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);
}
}
Aggregations