示例#1
0
  private static void recreateDatabase(DbRunnerConfig dbRunnerConfig) {
    Scanner reader = new Scanner(System.in);
    System.out.println(
        "Are you sure you want to recreate the database? This will delete everything from the "
            + dbRunnerConfig.getKeyspace()
            + " keyspace. (y/n)");

    if ("y".equalsIgnoreCase(reader.nextLine())) {
      System.out.println("Enter the name of the keyspace you wish to recreate");

      String enteredKeyspace = reader.nextLine();

      if (!dbRunnerConfig.getKeyspace().equals(enteredKeyspace)) {
        System.out.println("Keyspace did not match with keyspace entered in flag");
        System.exit(0);
      }

      dbRunnerConfig.setKeyspace(enteredKeyspace);
    } else {
      System.out.println("Database will not be recreated.");
      System.exit(0);
    }
  }
示例#2
0
  public static void main(String[] args) throws Exception {
    CommandLineParser parser = new DefaultParser();

    Options options = getOptions();

    try {
      CommandLine line = parser.parse(options, args);

      configureLogging(line.hasOption("debug"));

      DbRunnerConfig dbRunnerConfig = getDbRunnerConfig(line);

      if (dbRunnerConfig.getRecreateDatabase()) {
        recreateDatabase(dbRunnerConfig);
      }

      DbScriptsRunner dbScriptsRunner = new DbScriptsRunner(dbRunnerConfig);

      dbScriptsRunner.run();
    } catch (ParseException e) {
      System.out.println("Unexpected exception:" + e.getMessage());
      help(options);
    }
  }
示例#3
0
  private static DbRunnerConfig getDbRunnerConfig(CommandLine line) {
    DbRunnerConfig.DbRunnerConfigBuilder dbConfigBuilder = DbRunnerConfig.builder();

    String username = line.getOptionValue("u");
    String password = line.getOptionValue("pw");

    dbConfigBuilder
        .ip(line.getOptionValue("ip"))
        .port(line.hasOption("p") ? Integer.valueOf(line.getOptionValue("p")) : DEFAULT_PORT)
        .username(username != null ? username : "")
        .password(password != null ? password : "")
        .createKeyspace(line.hasOption("createKeyspace"))
        .keyspace(line.getOptionValue("k"))
        .dbVersion(line.hasOption("v") ? Integer.valueOf(line.getOptionValue("v")) : null)
        .filePath(line.hasOption("f") ? line.getOptionValue("f") : DEFAULT_CQL_PATH)
        .recreateDatabase(line.hasOption("recreateDatabase"));

    return dbConfigBuilder.build();
  }