Package org.teiid.query.validator.UpdateValidator

Examples of org.teiid.query.validator.UpdateValidator.UpdateInfo


            if (group.getModelMetadataId() != null) {
              node.setProperty(Info.MODEL_ID, group.getModelMetadataId());
            }
            node.addGroup(group);
            if (nestedCommand != null) {
              UpdateInfo info = ProcedureContainerResolver.getUpdateInfo(group, metadata);
              if (info != null && info.getPartitionInfo() != null && !info.getPartitionInfo().isEmpty()) {
                node.setProperty(NodeConstants.Info.PARTITION_INFO, info.getPartitionInfo());
              }
              addNestedCommand(node, group, nestedCommand, nestedCommand, true);
            }
            parent.addLastChild(node);
        } else if(clause instanceof JoinPredicate) {
View Full Code Here


        }
    return null;
  }
 
  public static UpdateInfo getUpdateInfo(GroupSymbol group, QueryMetadataInterface metadata, int type) throws QueryMetadataException, TeiidComponentException, QueryResolverException {
    UpdateInfo info = getUpdateInfo(group, metadata);
   
    if (info == null) {
      return null;
    }
     
      if ((info.isDeleteValidationError() && type == Command.TYPE_DELETE)
        || (info.isUpdateValidationError() && type == Command.TYPE_UPDATE)
        || (info.isInsertValidationError() && type == Command.TYPE_INSERT)) {
        String name = "Delete"; //$NON-NLS-1$
        if (type == Command.TYPE_UPDATE) {
          name = "Update"; //$NON-NLS-1$
        } else if (type == Command.TYPE_INSERT) {
          name = "Insert"; //$NON-NLS-1$
View Full Code Here

        }
        return storedProcedure;
    }

  private Insert rewriteInsert(Insert insert) throws TeiidComponentException, TeiidProcessingException{
    UpdateInfo info = insert.getUpdateInfo();
    if (info != null && info.isInherentInsert()) {
      //TODO: update error messages
      UpdateMapping mapping = info.findInsertUpdateMapping(insert, true);
      if (mapping == null) {
        throw new QueryValidatorException(QueryPlugin.Util.getString("ValidationVisitor.nonUpdatable", insert.getVariables())); //$NON-NLS-1$
      }
      Map<ElementSymbol, ElementSymbol> symbolMap = mapping.getUpdatableViewSymbols();
      List<ElementSymbol> mappedSymbols = new ArrayList<ElementSymbol>(insert.getVariables().size());
View Full Code Here

            }
        }
    }

  private Command rewriteUpdate(Update update) throws TeiidComponentException, TeiidProcessingException{
    UpdateInfo info = update.getUpdateInfo();
    if (info != null && info.isInherentUpdate()) {
      if (!info.getUnionBranches().isEmpty()) {
        List<Command> batchedUpdates = new ArrayList<Command>(info.getUnionBranches().size() + 1);
        for (UpdateInfo branchInfo : info.getUnionBranches()) {
          batchedUpdates.add(rewriteInherentUpdate((Update)update.clone(), branchInfo));
        }
        batchedUpdates.add(0, rewriteInherentUpdate(update, info));
        return new BatchedUpdateCommand(batchedUpdates);
      }
View Full Code Here

       
        return true;
    }

  private Command rewriteDelete(Delete delete) throws TeiidComponentException, TeiidProcessingException{
    UpdateInfo info = delete.getUpdateInfo();
    if (info != null && info.isInherentDelete()) {
      if (!info.getUnionBranches().isEmpty()) {
        List<Command> batchedUpdates = new ArrayList<Command>(info.getUnionBranches().size() + 1);
        for (UpdateInfo branchInfo : info.getUnionBranches()) {
          batchedUpdates.add(rewriteInherentDelete((Delete)delete.clone(), branchInfo));
        }
        batchedUpdates.add(0, rewriteInherentDelete(delete, info));
        return new BatchedUpdateCommand(batchedUpdates);
      }
View Full Code Here

        String insertPlan = qmi.getInsertPlan(virtualGroup.getMetadataID());

              List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
          UpdateValidator validator = new UpdateValidator(qmi, determineType(insertPlan), determineType(updatePlan), determineType(deletePlan));
        validator.validate(result, elements);
          UpdateInfo info = validator.getUpdateInfo();
          cachedNode.setUpdateInfo(info);
      }
          qmi.addToMetadataCache(virtualGroup.getMetadataID(), cacheString, cachedNode);
        }
    return cachedNode;
View Full Code Here

      }
    }
   
    protected void validateUpdate(Update update) {
        try {
            UpdateInfo info = update.getUpdateInfo();

            // list of elements that are being updated
        for (SetClause entry : update.getChangeList().getClauses()) {
              ElementSymbol elementID = entry.getSymbol();

                // Check that left side element is updatable
                if(! getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.UPDATE)) {
                    handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0059", elementID), elementID); //$NON-NLS-1$
                }
               
                Object metadataID = elementID.getMetadataID();
                if (getMetadata().isMultiSourceElement(metadataID)){
                  handleValidationError(QueryPlugin.Util.getString("multi_source_update_not_allowed", elementID), elementID); //$NON-NLS-1$
                }

          // Check that right expression is a constant and is non-null
                Expression value = entry.getValue();
               
                if (EvaluatableVisitor.isFullyEvaluatable(value, true)) {
                    try {
                        value = new Constant(Evaluator.evaluate(value));
                    } catch (ExpressionEvaluationException err) {
                    }
                }
               
                if(value instanceof Constant) {
              // If value is null, check that element supports this as a nullable column
                    if(((Constant)value).isNull() && ! getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.NULL)) {
                        handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0060", SQLStringVisitor.getSQLString(elementID)), elementID); //$NON-NLS-1$
                    }// end of if
                } else if (info != null && info.getUpdateType() == UpdateType.UPDATE_PROCEDURE && getMetadata().isVirtualGroup(update.getGroup().getMetadataID()) && !EvaluatableVisitor.willBecomeConstant(value)) {
                    // If this is an update on a virtual group, verify that no elements are in the right side
                    Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(value, false);
                    for (ElementSymbol element : elements) {
                        if(! element.isExternalReference()) {
                            handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0061", SQLStringVisitor.getSQLString(value)), value); //$NON-NLS-1$
                        }
                    }
                }
        }
            if (info != null && info.isInherentUpdate()) {
              Set<ElementSymbol> updateCols = update.getChangeList().getClauseMap().keySet();
              if (!info.hasValidUpdateMapping(updateCols)) {
                handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.nonUpdatable", updateCols), update); //$NON-NLS-1$
              }
            }
        } catch(TeiidException e) {
            handleException(e, update);
View Full Code Here

     
      UpdateValidator uv = new UpdateValidator(md, UpdateType.INHERENT, UpdateType.INHERENT, UpdateType.INHERENT);
      GroupSymbol gs = new GroupSymbol(vGroup);
      ResolverUtil.resolveGroup(gs, md);
      uv.validate(command, ResolverUtil.resolveElementsInGroup(gs, md));
      UpdateInfo info = uv.getUpdateInfo();
      assertEquals(uv.getReport().getFailureMessage(), failInsert, info.isInsertValidationError());
      assertEquals(uv.getReport().getFailureMessage(), failUpdate, info.isUpdateValidationError());
      assertEquals(uv.getReport().getFailureMessage(), failDelete, info.isDeleteValidationError());
      return uv;
    } catch (TeiidException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

TOP

Related Classes of org.teiid.query.validator.UpdateValidator.UpdateInfo

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.