예제 #1
0
  @Test
  public void testBulkRequest() {
    Connection db = getConnection();
    long app = getAppId();
    try {
      Record record;
      List<Record> records = new ArrayList<Record>();
      List<Long> ids = insertRecords();

      ResultSet rs = db.select(app, "order by Record_number asc");
      if (rs.size() != 3) {
        fail("invalid count");
      }
      int i = 0;
      while (rs.next()) {
        record = new Record();
        record.setId(rs.getId());
        record.setRevision(rs.getRevision());
        record.setString("Single_line_text", "hoge" + i);

        records.add(record);
        i++;
      }

      BulkRequest bulk = new BulkRequest();
      bulk.updateByRecords(app, records);

      records = new ArrayList<Record>();

      record = new Record();
      record.setString("Single_line_text", "fuga");
      records.add(record);
      record = new Record();
      record.setString("Single_line_text", "piyo");
      records.add(record);
      bulk.insert(app, records);

      bulk.delete(app, ids.get(1));

      db.bulkRequest(bulk);

      rs = db.select(app, "order by Record_number asc");
      if (rs.size() != 4) {
        fail("invalid count");
      }
      i = 0;
      String[] values = {"hoge0", "hoge2", "fuga", "piyo"};
      while (rs.next()) {
        if (!rs.getString("Single_line_text").equals(values[i])) {
          fail("invalid value:" + values[i]);
        }
        i++;
      }

    } catch (Exception e) {
      fail("db exception:" + e.getMessage());
    }
  }