Exemplo n.º 1
0
  public boolean executeTestScript() {
    if (dbType.equals("H2")) {
      try {
        Class.forName("org.h2.Driver"); // initialise the driver
        Connection conn = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);

        ScriptRunner runner = new ScriptRunner(conn, false, true);
        runner.runScript(
            new BufferedReader(
                new InputStreamReader(new ClassPathResource("testing-data.sql").getInputStream())));

        testDataEnabled = true;
      } catch (Exception e) {
        warnAndDisplay("Error executing DB setup script: " + e.getMessage());
        return false;
      }
    } else {
      jsfService.addMessage(
          "To run the test data script, the database must be the default in-memory H2.");
      return false;
    }
    jsfService.addMessage("Test data loaded successfully.");
    logger.info("Test data loaded successfully.");
    return true;
  }
Exemplo n.º 2
0
  public boolean initializeDB() {
    if (dbType.equals("MYSQL")) {
      try {
        Class.forName("com.mysql.jdbc.Driver"); // initialise the driver
        Connection conn = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);

        ScriptRunner runner = new ScriptRunner(conn, false, true);
        runner.runScript(
            new BufferedReader(
                new InputStreamReader(
                    new ClassPathResource("openhds-schema.sql").getInputStream())));
        runner.runScript(
            new BufferedReader(
                new InputStreamReader(
                    new ClassPathResource("openhds-required-data.sql").getInputStream())));
        jsfService.addMessage("MYSQL DB initialised successfully.");
        logger.info("MYSQL DB initialised successfully.");
      } catch (Exception e) {
        warnAndDisplay("Error executing DB setup script: " + e.getMessage());
        return false;
      }
    } else {
      warnAndDisplay("Error: only MYSQL DBs can be initialised this way.");
    }
    return true;
  }