use of org.teiid.language.SetClause in project teiid by teiid.
the class CoherenceUpdateExecution method updateChildObject.
private void updateChildObject(Table t) throws TranslatorException {
List<ForeignKey> fks = t.getForeignKeys();
ForeignKey fk = fks.get(0);
Table parentTable = fk.getParent();
// the name of the method to obtain the collection is the nameInSource of the foreginKey
String parentToChildMethod = fk.getNameInSource();
if (parentToChildMethod == null) {
// $NON-NLS-1$
final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.noNameInSourceForForeingKey", new Object[] { fk.getName() });
throw new TranslatorException(msg);
}
// there must only be 1 column in the primary key
String parentColName = visitor.getNameFromElement(fk.getPrimaryKey().getColumns().get(0));
List<SetClause> updateList = ((Update) command).getChanges();
Condition criteria = ((Update) command).getWhere();
ColumnReference leftElement;
Expression rightExpr;
String nameLeftElement;
Object valueRightExpr;
// API).
for (int i = 0; i < updateList.size(); i++) {
SetClause setClause = updateList.get(i);
// trust that connector API is right and left side
// will always be an IElement
leftElement = setClause.getSymbol();
// call utility method to get NameInSource/Name for element
nameLeftElement = visitor.getNameFromElement(leftElement.getMetadataObject());
// get right expression - if it is not a literal we
// can't handle that so throw an exception
rightExpr = setClause.getValue();
// if (!(rightExpr instanceof Literal)) {
// final String msg = CoherencePlugin.Util.getString("LDAPUpdateExecution.valueNotLiteralError",nameLeftElement); //$NON-NLS-1$
// throw new TranslatorException(msg);
// }
valueRightExpr = ((Literal) rightExpr).getValue();
// add in the modification as a replacement - meaning
// any existing value(s) for this attribute will
// be replaced by the new value. If the attribute
// didn't exist, it will automatically be created
// TODO - since null is a valid attribute
// value, we don't do any special handling of it right
// now. But maybe null should mean to delete an
// attribute?
}
}
use of org.teiid.language.SetClause 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.SetClause 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();
}
use of org.teiid.language.SetClause in project teiid by teiid.
the class SpreadsheetUpdateVisitor method visit.
public void visit(Update obj) {
worksheetTitle = obj.getTable().getName();
changes = new ArrayList<UpdateSet>();
String columnName;
if (obj.getTable().getMetadataObject().getNameInSource() != null) {
this.worksheetTitle = obj.getTable().getMetadataObject().getNameInSource();
}
for (SetClause s : obj.getChanges()) {
if (s.getSymbol().getMetadataObject().getNameInSource() != null) {
columnName = s.getSymbol().getMetadataObject().getNameInSource();
} else {
columnName = s.getSymbol().getMetadataObject().getName();
}
changes.add(new UpdateSet(columnName, getStringValue(s.getValue())));
}
translateWhere(obj.getWhere());
}
Aggregations