use of org.teiid.language.Literal in project teiid by teiid.
the class UpdateExecutionImpl method processIds.
@Override
protected int processIds(String[] ids, IQueryProvidingVisitor visitor) throws ResourceException {
List<DataPayload> updateDataList = new ArrayList<DataPayload>();
for (int i = 0; i < ids.length; i++) {
DataPayload data = new DataPayload();
for (SetClause clause : ((Update) command).getChanges()) {
ColumnReference element = clause.getSymbol();
Column column = element.getMetadataObject();
String val = ((Literal) clause.getValue()).toString();
data.addField(column.getSourceName(), Util.stripQutes(val));
}
data.setType(visitor.getTableName());
data.setID(ids[i]);
updateDataList.add(data);
}
return getConnection().update(updateDataList);
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TickerCollectorVisitor method addTickerFromExpression.
private void addTickerFromExpression(Expression expr) {
if (expr instanceof Literal) {
Literal literal = (Literal) expr;
if (literal.getType() == String.class) {
String ticker = (String) literal.getValue();
this.tickers.add(ticker.toUpperCase());
} else {
// $NON-NLS-1$
this.exception = new TranslatorException(YahooPlugin.Util.getString("TickerCollectorVisitor.Unexpected_type", literal.getType().getName()));
}
} else {
// $NON-NLS-1$
this.exception = new TranslatorException(YahooPlugin.Util.getString("TickerCollectorVisitor.Unexpected_expression", expr));
}
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestAggregateImpl method testGetExpression.
public void testGetExpression() throws Exception {
// $NON-NLS-1$
AggregateFunction agg = example("testName", NonReserved.COUNT, true, 42);
assertNotNull(agg.getExpression());
assertTrue(agg.getExpression() instanceof Literal);
assertEquals(new Integer(42), ((Literal) agg.getExpression()).getValue());
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestCompareCriteriaImpl method testGetRightExpression.
public void testGetRightExpression() throws Exception {
Comparison impl = example(AbstractCompareCriteria.GE, 200, 100);
assertNotNull(impl.getRightExpression());
assertTrue(impl.getRightExpression() instanceof Literal);
assertEquals(new Integer(100), ((Literal) impl.getRightExpression()).getValue());
}
use of org.teiid.language.Literal in project teiid by teiid.
the class AccumuloUpdateExecution method performUpdate.
private void performUpdate(Update update) throws TranslatorException, TableNotFoundException, MutationsRejectedException {
Table table = update.getTable().getMetadataObject();
if (update.getParameterValues() != null) {
throw new TranslatorException(AccumuloPlugin.Event.TEIID19005, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19005));
}
AccumuloQueryVisitor visitor = new AccumuloQueryVisitor(this.aef);
visitor.visitNode(update.getWhere());
if (!visitor.exceptions.isEmpty()) {
throw visitor.exceptions.get(0);
}
Connector connector = this.connection.getInstance();
BatchWriter writer = createBatchWriter(table, connector);
Text prevRow = null;
Iterator<Entry<Key, Value>> results = AccumuloQueryExecution.runQuery(this.aef, this.connection.getInstance(), this.connection.getAuthorizations(), visitor.getRanges(), table, visitor.scanIterators());
while (results.hasNext()) {
Key key = results.next().getKey();
Text rowId = key.getRow();
if (prevRow == null || !prevRow.equals(rowId)) {
prevRow = rowId;
Mutation mutation = new Mutation(rowId);
List<SetClause> changes = update.getChanges();
for (SetClause clause : changes) {
Column column = clause.getSymbol().getMetadataObject();
if (SQLStringVisitor.getRecordName(column).equalsIgnoreCase(AccumuloMetadataProcessor.ROWID)) {
throw new TranslatorException(AccumuloPlugin.Event.TEIID19002, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19002, table.getName()));
}
Expression value = clause.getValue();
if (value instanceof Literal) {
buildMutation(mutation, column, ((Literal) value).getValue());
} else {
throw new TranslatorException(AccumuloPlugin.Event.TEIID19001, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19001));
}
}
writer.addMutation(mutation);
this.updateCount++;
}
}
writer.close();
}
Aggregations