Пример #1
0
  @Test
  public void schemaCreationIsRunWhenDatabaseDoesntExist() throws Exception {
    PreparedStatementWrapper prepareStatement =
        connection.prepareStatement("INSERT INTO testtable VALUES(1, 'test');");
    try {
      prepareStatement.execute();
    } finally {
      DatabaseUtil.close(prepareStatement);
    }

    QueryPreparedStatementWrapper prepareQueryStatement =
        connection.prepareQueryStatement("SELECT * FROM testtable");
    try {
      prepareQueryStatement.execute();
      assertThat(prepareQueryStatement.getResultSet().getInt(1), is(1));
    } finally {
      DatabaseUtil.close(prepareQueryStatement);
    }
  }
Пример #2
0
  @Test
  public void schemaCreationIsNotRunWhenDatabaseExists() throws Exception {
    db.shutdown();
    db.start();
    connection = db.getConnection();

    // Would throw an exception if the table didn't exist
    QueryPreparedStatementWrapper prepareQueryStatement =
        connection.prepareQueryStatement("SELECT * FROM testtable");
    try {
      prepareQueryStatement.execute();
    } finally {
      DatabaseUtil.close(prepareQueryStatement);
    }
  }
Пример #3
0
  @Test
  public void upgradeScriptsRunWhenDatabaseIsOlderVersion() throws Exception {
    db.shutdown();
    db = new FileDatabaseVersion2(file);
    db.start();
    connection = db.getConnection();

    // Would throw an exception if the table didn't exist
    QueryPreparedStatementWrapper prepareQueryStatement =
        connection.prepareQueryStatement("SELECT * FROM version2table");
    try {
      prepareQueryStatement.execute();
    } finally {
      DatabaseUtil.close(prepareQueryStatement);
    }
  }