Search in sources :

Example 1 with SetClauseList

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());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) DynamicCommand(org.teiid.query.sql.lang.DynamicCommand) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) List(java.util.List) SetClauseList(org.teiid.query.sql.lang.SetClauseList) ArrayList(java.util.ArrayList) SetClauseList(org.teiid.query.sql.lang.SetClauseList)

Example 2 with SetClauseList

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));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) SetClauseList(org.teiid.query.sql.lang.SetClauseList) Update(org.teiid.query.sql.lang.Update) Test(org.junit.Test)

Example 3 with SetClauseList

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));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ArrayList(java.util.ArrayList) Expression(org.teiid.query.sql.symbol.Expression) SetClauseList(org.teiid.query.sql.lang.SetClauseList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TupleBrowser(org.teiid.common.buffer.TupleBrowser)

Aggregations

SetClauseList (org.teiid.query.sql.lang.SetClauseList)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Constant (org.teiid.query.sql.symbol.Constant)2 Expression (org.teiid.query.sql.symbol.Expression)2 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 TupleBrowser (org.teiid.common.buffer.TupleBrowser)1 TupleBuffer (org.teiid.common.buffer.TupleBuffer)1 DynamicCommand (org.teiid.query.sql.lang.DynamicCommand)1 Update (org.teiid.query.sql.lang.Update)1