Package org.teiid.query.sql.lang

Examples of org.teiid.query.sql.lang.Update


 
     
    @Test public void testUpdateSetClauseReferenceType() {
      String sql = "UPDATE pm1.g1 SET pm1.g1.e1 = 1, pm1.g1.e2 = ?;"; //$NON-NLS-1$
     
      Update update = (Update)helpResolve(sql, FakeMetadataFactory.example1Cached());
     
      Expression ref = update.getChangeList().getClauses().get(1).getValue();
      assertTrue(ref instanceof Reference);
      assertNotNull(ref.getType());
    }
View Full Code Here


        if (command instanceof Delete) {
          Delete query = (Delete) command;
            return query.getCriteria() == null;
        }
        if (command instanceof Update) {
          Update query = (Update) command;
            return query.getCriteria() == null;
        }
        if (command instanceof SetQuery) {
          SetQuery query = (SetQuery)command;
          return hasNoCriteria(query.getLeftQuery()) || hasNoCriteria(query.getRightQuery());
        }
        return false;
    }
View Full Code Here

                 "DELETE FROM m.g OPTION NOCACHE"//$NON-NLS-1$
                 delete);                    
    }
   
    @Test public void testUpdateWithOption() {
        Update update = new Update();    
        update.setGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
        update.addChange(new ElementSymbol("a"), new Reference(0));
        Option option = new Option();
        option.setNoCache(true);
        Criteria crit = new CompareCriteria(new ElementSymbol("b"), CompareCriteria.EQ, new Reference(1)); //$NON-NLS-1$
        update.setCriteria(crit);
        TestParser.helpTest("UPDATE m.g SET a = ? WHERE b = ? OPTION NOCACHE"//$NON-NLS-1$
                 "UPDATE m.g SET a = ? WHERE b = ? OPTION NOCACHE"//$NON-NLS-1$
                 update);                    
    }
View Full Code Here

        node.open();
        assertEquals(Arrays.asList("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5"), dataManager.getQueries()); //$NON-NLS-1$
    }
 
    @Test public void testShouldExecuteUpdate() throws Exception {
        Update update = new Update();
       
        update.setGroup(new GroupSymbol("test")); //$NON-NLS-1$
       
        update.addChange(new ElementSymbol("e1"), new Constant("1")); //$NON-NLS-1$ //$NON-NLS-2$
       
        assertTrue(RelationalNodeUtil.shouldExecute(update, false));
       
        update.setChangeList(new SetClauseList());
       
        assertFalse(RelationalNodeUtil.shouldExecute(update, false));
    }
View Full Code Here

                Arrays.asList(4)
        };
     
      // Create the plan and process the query
      TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, FakeMetadataFactory.example1Cached(), prepPlanCache, false, false, false,FakeMetadataFactory.example1VDB());
      Update update = (Update)dataManager.getCommandHistory().iterator().next();
      assertTrue(((Constant)update.getChangeList().getClauses().get(0).getValue()).isMultiValued());
    }
View Full Code Here

              ts = new CollectionTupleSource(Arrays.asList(values).iterator());
            }
            return table.insert(ts, insert.getVariables());
          }
          if (command instanceof Update) {
            final Update update = (Update)command;
            final Criteria crit = update.getCriteria();
            return table.update(crit, update.getChangeList());
          }
          if (command instanceof Delete) {
            final Delete delete = (Delete)command;
            final Criteria crit = delete.getCriteria();
            if (crit == null) {
View Full Code Here

     */
    public void resolveProceduralCommand(Command command, TempMetadataAdapter metadata)
        throws QueryMetadataException, QueryResolverException, TeiidComponentException {

        //Cast to known type
        Update update = (Update) command;

        // Resolve elements and functions
        Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
        groups.add(update.getGroup());
        for (SetClause clause : update.getChangeList().getClauses()) {
          ResolverVisitor.resolveLanguageObject(clause.getSymbol(), groups, null, metadata);
    }
        QueryResolver.resolveSubqueries(command, metadata, groups);
        ResolverVisitor.resolveLanguageObject(update, groups, update.getExternalGroupContexts(), metadata);
    }
View Full Code Here

    public Map<ElementSymbol, Expression> getVariableValues(Command command, boolean changingOnly,
                                 QueryMetadataInterface metadata) throws QueryMetadataException,
                                                                 TeiidComponentException {
        Map<ElementSymbol, Expression> result = new HashMap<ElementSymbol, Expression>();
       
        Update update = (Update) command;
       
        Map<ElementSymbol, Expression> changing = update.getChangeList().getClauseMap();
       
        for (Entry<ElementSymbol, Expression> entry : changing.entrySet()) {
          ElementSymbol leftSymbol = entry.getKey().clone();
            leftSymbol.getGroupSymbol().setName(ProcedureReservedWords.CHANGING);
            result.put(leftSymbol, new Constant(Boolean.TRUE));
            if (!changingOnly) {
              leftSymbol = leftSymbol.clone();
              leftSymbol.getGroupSymbol().setName(ProcedureReservedWords.INPUTS);
              result.put(leftSymbol, entry.getValue());
            }
        }
       
        Collection<ElementSymbol> insertElmnts = ResolverUtil.resolveElementsInGroup(update.getGroup(), metadata);

        insertElmnts.removeAll(changing.keySet());

        Iterator<ElementSymbol> defaultIter = insertElmnts.iterator();
        while(defaultIter.hasNext()) {
View Full Code Here

            case Statement.TYPE_COMMAND:
        CommandStatement cmdStmt = (CommandStatement) statement;
                rewriteSubqueryContainer(cmdStmt, false);
               
        if(cmdStmt.getCommand().getType() == Command.TYPE_UPDATE) {
                    Update update = (Update)cmdStmt.getCommand();
                    if (update.getChangeList().isEmpty()) {
                        return null;
                    }
        }
                return statement;
            case Statement.TYPE_LOOP:
View Full Code Here

  private Command createUpdateProcedure(Update update, Query query,
      GroupSymbol group, String correlationName)
      throws TeiidComponentException, QueryMetadataException,
      QueryResolverException, TeiidProcessingException {
    Update newUpdate = new Update();
    newUpdate.setChangeList(update.getChangeList());
    newUpdate.setGroup(group.clone());
    List<Criteria> pkCriteria = createPkCriteria(group, correlationName, query);
    newUpdate.setCriteria(new CompoundCriteria(pkCriteria));
    return asLoopProcedure(update.getGroup(), query, newUpdate);
  }
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.lang.Update

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.