Esempio n. 1
0
  @Test
  public void testUpdateByRecord() {
    Connection db = getConnection();
    long app = getAppId();
    try {
      Record record = new Record();
      List<Long> ids = insertRecords();
      long id = ids.get(1);
      ResultSet rs = db.select(app, "Record_number = " + id);
      if (rs.size() != 1) {
        fail("invalid count");
      }
      rs.next();
      record.setId(rs.getId());
      record.setRevision(rs.getRevision());
      record.setString("Single_line_text", "hoge");
      db.updateByRecord(app, record);

      rs = db.select(app, "Single_line_text = \"hoge\"");
      if (rs.size() != 1) {
        fail("failed to update");
      }
      rs.next();
      if (rs.getId() != id) {
        fail("invalid id");
      }
    } catch (Exception e) {
      fail("db exception:" + e.getMessage());
    }
  }
Esempio n. 2
0
  @Test
  public void testDeleteByRecords() {
    Connection db = getConnection();
    long app = getAppId();
    try {
      Record record;
      List<Record> records = new ArrayList<Record>();
      List<Long> ids = insertRecords();
      ResultSet rs = db.select(app, "");
      if (rs.size() != 3) {
        fail("invalid count");
      }
      while (rs.next()) {
        record = new Record();
        record.setId(rs.getId());
        record.setRevision(rs.getRevision());

        records.add(record);
      }
      db.deleteByRecords(app, records);

      rs = db.select(app, "");
      if (rs.size() != 0) {
        fail("failed to delete");
      }
    } catch (Exception e) {
      fail("db exception:" + e.getMessage());
    }
  }
Esempio n. 3
0
  @Test
  public void testDeleteByRecord() {
    Connection db = getConnection();
    long app = getAppId();
    try {
      Record record = new Record();
      List<Long> ids = insertRecords();
      long id = ids.get(1);
      ResultSet rs = db.select(app, "Record_number = " + id);
      if (rs.size() != 1) {
        fail("invalid count");
      }
      rs.next();
      record.setId(rs.getId());
      record.setRevision(rs.getRevision());
      db.deleteByRecord(app, record);

      rs = db.select(app, "");
      if (rs.size() != 2) {
        fail("failed to delete");
      }
    } catch (Exception e) {
      fail("db exception:" + e.getMessage());
    }
  }
Esempio n. 4
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());
    }
  }
Esempio n. 5
0
  @Test
  public void testDeleteByRecords2() {
    Connection db = getConnection();
    long app = getAppId();
    Record record;
    List<Record> records = new ArrayList<Record>();
    ResultSet rs = null;

    try {

      List<Long> ids = insertRecords();
      rs = db.select(app, "");
      if (rs.size() != 3) {
        fail("invalid count");
      }

      record = new Record();
      rs.next();
      record.setId(rs.getId());
      record.setString("Single_line_text", "hoge");
      db.updateByRecord(app, record);

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

    try {
      rs.first();
      while (rs.next()) {
        record = new Record();
        record.setId(rs.getId());
        record.setRevision(rs.getRevision());
        record.setString("Single_line_text", "hoge");

        records.add(record);
      }
      db.deleteByRecords(app, records);
      fail("no conflict");
    } catch (Exception e) {
    }
  }