예제 #1
0
  public static void main(String[] args) throws Exception {
    CLIArguments cli = new CLIArguments(args);
    String file = cli.getOption("s");
    String outfile = cli.getOption("o");
    long numStr = cli.getLongOption("n", 1000);
    String type = cli.getOption("t", "CSV");
    if (file == null || outfile == null) {
      usage();
      return;
    }

    File f = new File(file);
    if (!f.exists()) {
      System.err.printf("Script file %s does not exists\n", file);
      return;
    }
    File of = new File(outfile);
    if (!of.exists()) {
      System.err.printf("Outout Directory %s does not exists\n", outfile);
      return;
    }
    SQLScriptParser parser = new SQLScriptParser(f);
    BottomUpSchemaDataGenerator dg = null;
    try {
      CodeGenConfig config = new CodeGenConfig();
      config.setNumberOfRecords(numStr);
      config.setOutputType(DataOutputType.valueOf(type.toUpperCase()));
      config.setDataOutputDir(outfile);
      dg = new BottomUpSchemaDataGenerator(parser.parseSql());
      dg.setConfig(config);
      dg.generateData();
    } finally {
      if (dg != null) {
        dg.close();
      }
      parser.close();
    }
  }
예제 #2
0
  public boolean validateArguments(CLIArguments cliArgs) {
    boolean valid = true;
    StringBuilder buf = new StringBuilder();
    String sfs = cliArgs.getOption("s");
    boolean good = sfs != null;
    if (!good) {
      valid = good;
      buf.append("Missing schema files with argment -s\n");
    } else {
      configuration.setSchemaFiles(sfs);
    }
    String d = cliArgs.getOption("d");
    configuration.setGenDomainObject(d != null);
    if (configuration.isGenDomainObject()) {
      configuration.setDomainPackageName(d);
    }
    String m = cliArgs.getOption("m");
    configuration.setGenMyBatisMapper(m != null);
    if (configuration.isGenMyBatisMapper()) {
      configuration.setMapperPackageName(m);
    }

    String r = cliArgs.getOption("r");
    configuration.setGenRestController(r != null);
    if (configuration.isGenRestController()) {
      configuration.setRestPackageName(r);
    }

    if (!configuration.isGenDomainObject()
        && !configuration.isGenMyBatisMapper()
        && !configuration.isGenRestController()) {
      valid = false;
      buf.append("Need at least one code options with argment -d, -m or -r\n");
    }

    if (!valid) {
      System.err.println(buf.toString());
      usage();
    } else {
      String ig = cliArgs.getOption("i");
      if (ig != null) {
        configuration.setIgnores(ig);
      }
      if (cliArgs.getOption("S") != null) {
        configuration.setSuffixSequenceIfExists(cliArgs.getBooleanOption("S"));
      }
      String spring = cliArgs.getOption("spring");
      if (spring != null) {
        if (spring.equalsIgnoreCase("true")) {
          configuration.setGenSpringContext(true);
        } else if (spring.equalsIgnoreCase("false")) {
          configuration.setGenSpringContext(false);
        } else {
          configuration.setGenSpringContext(true);
          configuration.setSpringXmlBaseDir(spring);
        }
      }

      if (cliArgs.getOption("j") != null) {
        configuration.setJavaBaseDir(cliArgs.getOption("j"));
      }

      if (cliArgs.getOption("x") != null) {
        configuration.setMyBatisXmlBaseDir(cliArgs.getOption("x"));
      }
    }

    return valid;
  }