コード例 #1
0
  @Override
  public String getSourceComment(ExecutionContext context, Command command) {
    String comment = super.getSourceComment(context, command);

    boolean usingPayloadComment = false;
    if (context != null) {
      // Check for db hints
      Object payload = context.getCommandPayload();
      if (payload instanceof String) {
        String payloadString = (String) payload;
        if (payloadString.startsWith(HINT_PREFIX)) {
          int i = payloadString.indexOf(HINT_SUFFIX);
          if (i > 0 && payloadString.substring(i + 2).trim().length() == 0) {
            comment += payloadString + " "; // $NON-NLS-1$
            usingPayloadComment = true;
          } else {
            String msg =
                JDBCPlugin.Util.gs(
                    JDBCPlugin.Event.TEIID11003, "Execution Payload", payloadString); // $NON-NLS-1$
            context.addWarning(new TranslatorException(msg));
            LogManager.logWarning(LogConstants.CTX_CONNECTOR, msg);
          }
        }
      }
    }

    if (!usingPayloadComment && context != null) {
      String hint = context.getSourceHint();
      if (context.getGeneralHint() != null) {
        if (hint != null) {
          hint += (" " + context.getGeneralHint()); // $NON-NLS-1$
        } else {
          hint = context.getGeneralHint();
        }
      }
      if (hint != null) {
        // append a source hint
        if (!hint.contains(HINT_PREFIX)) {
          comment += HINT_PREFIX + ' ' + hint + ' ' + HINT_SUFFIX + ' ';
        } else {
          String msg =
              JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11003, "Source Hint", hint); // $NON-NLS-1$
          context.addWarning(new TranslatorException(msg));
          LogManager.logWarning(LogConstants.CTX_CONNECTOR, msg);
        }
      }
    }

    if (command instanceof Select) {
      //
      // This simple algorithm determines the hint which will be added to the
      // query.
      // Right now, we look through all functions passed in the query
      // (returned as a collection)
      // Then we check if any of those functions are sdo_relate
      // If so, the ORDERED hint is added, if not, it isn't
      Collection<Function> col = CollectorVisitor.collectObjects(Function.class, command);
      for (Function func : col) {
        if (func.getName().equalsIgnoreCase(OracleExecutionFactory.RELATE)) {
          return comment + "/*+ ORDERED */ "; // $NON-NLS-1$
        }
      }
    }
    return comment;
  }
コード例 #2
0
  public void handleInsertSequences(Insert insert) throws TranslatorException {
    /*
     * If a missing auto_increment column is modeled with name in source indicating that an Oracle Sequence
     * then pull the Sequence name out of the name in source of the column.
     */
    if (!(insert.getValueSource() instanceof ExpressionValueSource)) {
      return;
    }
    ExpressionValueSource values = (ExpressionValueSource) insert.getValueSource();
    if (insert.getTable().getMetadataObject() == null) {
      return;
    }
    List<Column> allElements = insert.getTable().getMetadataObject().getColumns();
    if (allElements.size() == values.getValues().size()) {
      return;
    }

    int index = 0;
    List<ColumnReference> elements = insert.getColumns();

    for (Column element : allElements) {
      if (!element.isAutoIncremented()) {
        continue;
      }
      String name = element.getNameInSource();
      int seqIndex = name.indexOf(SEQUENCE);
      if (seqIndex == -1) {
        continue;
      }
      boolean found = false;
      while (index < elements.size()) {
        if (element.equals(elements.get(index).getMetadataObject())) {
          found = true;
          break;
        }
        index++;
      }
      if (found) {
        continue;
      }

      String sequence = name.substring(seqIndex + SEQUENCE.length());

      int delimiterIndex = sequence.indexOf(Tokens.DOT);
      if (delimiterIndex == -1) {
        throw new TranslatorException(
            JDBCPlugin.Event.TEIID11017,
            JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11017, SEQUENCE, name));
      }
      String sequenceGroupName = sequence.substring(0, delimiterIndex);
      String sequenceElementName = sequence.substring(delimiterIndex + 1);

      NamedTable sequenceGroup =
          this.getLanguageFactory().createNamedTable(sequenceGroupName, null, null);
      ColumnReference sequenceElement =
          this.getLanguageFactory()
              .createColumnReference(
                  sequenceElementName, sequenceGroup, null, element.getJavaType());
      insert
          .getColumns()
          .add(
              index,
              this.getLanguageFactory()
                  .createColumnReference(
                      element.getName(), insert.getTable(), element, element.getJavaType()));
      values.getValues().add(index, sequenceElement);
    }
  }