コード例 #1
0
                @Override
                protected void starting(Description description) {
                  try (PreparedStatement ps =
                      spliceClassWatcher.prepareStatement(
                          String.format("insert into %s (a,b) values (?,?)", baseTable))) {
                    for (int i = 0; i < 10; i++) {
                      ps.setInt(1, i);
                      ps.setInt(2, 2 * i);
                      ps.addBatch();
                    }
                    ps.executeBatch();
                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  }

                  try (PreparedStatement ps =
                      spliceClassWatcher.prepareStatement(
                          String.format("insert into %s (b,c) values (?,?)", rightTable))) {
                    for (int i = 0; i < 10; i++) {
                      ps.setInt(1, 2 * i);
                      ps.setInt(2, i);
                      ps.addBatch();
                    }
                    ps.executeBatch();
                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  }
                }
コード例 #2
0
  @Test
  public void testCreateTableWithData() throws Exception {
    try (PreparedStatement ps =
        methodWatcher.prepareStatement(
            String.format(
                "create table %s.t3 as select * from %s with data",
                spliceSchemaWatcher.schemaName, baseTable))) {
      int numRows = ps.executeUpdate();
      Assert.assertEquals("It does not claim to have updated rows!", 10, numRows);
    }

    try (Statement s = conn.createStatement()) {
      try (ResultSet rs =
          s.executeQuery("select * from " + spliceSchemaWatcher.schemaName + ".t3")) {
        int count = 0;
        while (rs.next()) {
          int first = rs.getInt(1);
          int second = rs.getInt(2);
          Assert.assertEquals("Incorrect row: (" + first + "," + second + ")", first * 2, second);
          count++;
        }
        Assert.assertEquals("Incorrect row count", 10, count);
      }
    }
  }
コード例 #3
0
                @Override
                protected void starting(Description description) {
                  try {
                    PreparedStatement s =
                        spliceClassWatcher.prepareStatement(
                            String.format(
                                "insert into %s.%s values (?, ?)", CLASS_NAME, TABLE_NAME_1));
                    s.setInt(1, 1);
                    s.setInt(2, 10);
                    s.execute();

                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  } finally {
                    spliceClassWatcher.closeAll();
                  }
                }