示例#1
0
  private Procedure inputProcedure(Procedure old) throws InterruptedException {
    Procedure proc = new Procedure();

    if (old == null) proc.setName(readLine("name", null));
    else proc.setName(old.getName());

    proc.setOwner(readLine("owner", old != null ? old.getOwner() : null));
    proc.setGrants(
        new HashSet<String>(
            Strings.tokenize(
                readLine("grants", old != null ? Strings.join(old.getGrants(), ", ") : null),
                ",")));
    proc.setQueryString(readLine("query", old != null ? old.getQueryString() : null));

    List<ProcedureParameter> parameters = new ArrayList<ProcedureParameter>();
    context.println(
        "Type parameter definitions in \"type name\" format. e.g. \"string opt\", press enter to end.");
    int idx = 0;
    while (true) {
      ProcedureParameter oldParam = null;
      if (old != null && idx < old.getParameters().size()) {
        oldParam = old.getParameters().get(idx);
      }

      context.print("parameter? ");
      String line = context.readLine(oldParam != null ? oldParam.toString() : null);
      if (line.isEmpty()) break;

      int p = line.indexOf(" ");
      String type = line.substring(0, p).trim();
      String key = line.substring(p + 1).trim();

      parameters.add(new ProcedureParameter(key, type));
      idx++;
    }

    proc.setParameters(parameters);

    return proc;
  }