use of org.teiid.query.sql.lang.SetClauseList in project teiid by teiid.
the class TestDynamicCommand method testClone2.
public void testClone2() {
List symbols = new ArrayList();
// $NON-NLS-1$
ElementSymbol a1 = new ElementSymbol("a1");
a1.setType(DataTypeManager.DefaultDataClasses.STRING);
symbols.add(a1);
// $NON-NLS-1$
Expression sql = new Constant("SELECT * FROM g");
SetClauseList using = new SetClauseList();
using.addClause(a1, a1);
// $NON-NLS-1$
DynamicCommand sqlCmd = new DynamicCommand(sql, symbols, new GroupSymbol("#g"), using);
UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
use of org.teiid.query.sql.lang.SetClauseList in project teiid by teiid.
the class TestAccessNode method testShouldExecuteUpdate.
@Test
public void testShouldExecuteUpdate() throws Exception {
Update update = new Update();
// $NON-NLS-1$
update.setGroup(new GroupSymbol("test"));
// $NON-NLS-1$ //$NON-NLS-2$
update.addChange(new ElementSymbol("e1"), new Constant("1"));
assertTrue(RelationalNodeUtil.shouldExecute(update, false));
update.setChangeList(new SetClauseList());
assertFalse(RelationalNodeUtil.shouldExecute(update, false));
}
use of org.teiid.query.sql.lang.SetClauseList in project teiid by teiid.
the class TempTable method update.
public TupleSource update(Criteria crit, final SetClauseList update) throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {
final boolean primaryKeyChangePossible = canChangePrimaryKey(update);
final TupleBrowser browser = createTupleBrower(crit, OrderBy.ASC);
UpdateProcessor up = new UpdateProcessor(crit, browser, true) {
protected TupleBuffer changeSet;
protected UpdateProcessor changeSetProcessor;
@Override
protected void tuplePassed(List tuple) throws BlockedException, TeiidComponentException, TeiidProcessingException {
List<Object> newTuple = new ArrayList<Object>(tuple);
for (Map.Entry<ElementSymbol, Expression> entry : update.getClauseMap().entrySet()) {
newTuple.set(columnMap.get(entry.getKey()), eval.evaluate(entry.getValue(), tuple));
}
validateNotNull(newTuple);
if (primaryKeyChangePossible) {
browser.removed();
deleteTuple(tuple);
if (changeSet == null) {
changeSet = bm.createTupleBuffer(columns, sessionID, TupleSourceType.PROCESSOR);
}
changeSet.addTuple(newTuple);
} else {
browser.update(newTuple);
}
}
@Override
protected void undo(List<?> tuple) throws TeiidComponentException, TeiidProcessingException {
if (primaryKeyChangePossible) {
insertTuple(tuple, false, true);
} else {
updateTuple(tuple);
}
}
@Override
void success() throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {
// changeSet contains possible updates
if (primaryKeyChangePossible) {
changeSet.close();
if (changeSetProcessor == null) {
changeSetProcessor = new InsertUpdateProcessor(changeSet.createIndexedTupleSource(true), false, null, true, false);
}
// when this returns, we're up to date
changeSetProcessor.process();
}
}
@Override
public void close() {
super.close();
changeSetProcessor = null;
if (changeSet != null) {
changeSet.remove();
changeSet = null;
}
}
};
long updateCount = up.process();
tid.getTableData().dataModified(updateCount);
return CollectionTupleSource.createUpdateCountTupleSource((int) Math.min(Integer.MAX_VALUE, updateCount));
}
Aggregations