コード例 #1
0
ファイル: DBQueriesTest.java プロジェクト: kminder/cqengine
  void initWithTestData(final ConnectionManager connectionManager) {

    createSchema(connectionManager);

    Connection connection = null;
    Statement statement = null;
    try {
      connection = connectionManager.getConnection(null);
      statement = connection.createStatement();
      assertEquals(statement.executeUpdate("INSERT INTO " + TABLE_NAME + " values (1, 'abs')"), 1);
      assertEquals(statement.executeUpdate("INSERT INTO " + TABLE_NAME + " values (1, 'gps')"), 1);
      assertEquals(
          statement.executeUpdate("INSERT INTO " + TABLE_NAME + " values (2, 'airbags')"), 1);
      assertEquals(statement.executeUpdate("INSERT INTO " + TABLE_NAME + " values (3, 'abs')"), 1);
    } catch (Exception e) {
      throw new IllegalStateException("Unable to initialize test database", e);
    } finally {
      DBUtils.closeQuietly(connection);
      DBUtils.closeQuietly(statement);
    }
  }
コード例 #2
0
ファイル: DBQueriesTest.java プロジェクト: kminder/cqengine
  public void assertQueryResultSet(
      final String query,
      final List<DBQueries.Row<Integer, String>> rows,
      final ConnectionManager connectionManager)
      throws SQLException {

    Connection connection = null;
    Statement statement = null;

    try {
      connection = connectionManager.getConnection(null);
      statement = connection.createStatement();
      ResultSet resultSet = statement.executeQuery(query);
      assertResultSetOrderAgnostic(resultSet, rows);

    } catch (Exception e) {
      throw new IllegalStateException("Unable to verify resultSet", e);
    } finally {
      DBUtils.closeQuietly(connection);
      DBUtils.closeQuietly(statement);
    }
  }
コード例 #3
0
ファイル: DBQueriesTest.java プロジェクト: kminder/cqengine
  void createSchema(final ConnectionManager connectionManager) {
    Connection connection = null;
    Statement statement = null;

    try {
      connection = connectionManager.getConnection(null);
      statement = connection.createStatement();
      assertEquals(
          statement.executeUpdate(
              "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (objectKey INTEGER, value TEXT)"),
          0);
      assertEquals(
          statement.executeUpdate(
              "CREATE INDEX IF NOT EXISTS " + INDEX_NAME + " ON " + TABLE_NAME + "(value)"),
          0);
    } catch (Exception e) {
      throw new IllegalStateException("Unable to create test database schema", e);
    } finally {
      DBUtils.closeQuietly(connection);
      DBUtils.closeQuietly(statement);
    }
  }