Пример #1
0
  private void visit(FunctionMethod function) {
    if (this.filter != null && !filter.matcher(function.getName()).matches()) {
      return;
    }
    append(CREATE).append(SPACE);
    if (function.getPushdown().equals(FunctionMethod.PushDown.MUST_PUSHDOWN)) {
      append(FOREIGN);
    } else {
      append(VIRTUAL);
    }
    append(SPACE)
        .append(FUNCTION)
        .append(SPACE)
        .append(SQLStringVisitor.escapeSinglePart(function.getName()));
    append(LPAREN);

    boolean first = true;
    for (FunctionParameter fp : function.getInputParameters()) {
      if (first) {
        first = false;
      } else {
        append(COMMA).append(SPACE);
      }
      visit(fp);
    }
    append(RPAREN);

    append(SPACE).append(RETURNS);
    appendOptions(function.getOutputParameter());
    append(SPACE);
    append(function.getOutputParameter().getType());

    // options
    String options = buildFunctionOptions(function);
    if (!options.isEmpty()) {
      append(NEWLINE).append(OPTIONS).append(SPACE).append(LPAREN).append(options).append(RPAREN);
    }

    /*if (function.getDefinition() != null) {
    	append(NEWLINE).append(SQLConstants.Reserved.AS).append(NEWLINE);
    	append(function.getDefinition());
    }*/

    append(SQLConstants.Tokens.SEMICOLON);
  }
Пример #2
0
  private String buildFunctionOptions(FunctionMethod function) {
    StringBuilder options = new StringBuilder();
    addCommonOptions(options, function);

    if (function.getCategory() != null) {
      addOption(options, CATEGORY, function.getCategory());
    }

    if (!function.getDeterminism().equals(Determinism.DETERMINISTIC)) {
      addOption(options, DETERMINISM, function.getDeterminism().name());
    }

    if (function.getInvocationClass() != null) {
      addOption(options, JAVA_CLASS, function.getInvocationClass());
    }

    if (function.getInvocationMethod() != null) {
      addOption(options, JAVA_METHOD, function.getInvocationMethod());
    }

    if (!function.getProperties().isEmpty()) {
      for (String key : function.getProperties().keySet()) {
        addOption(options, key, function.getProperty(key, false));
      }
    }

    return options.toString();
  }