Esempio n. 1
0
  private static void writeData(Table t1, Table t2, int start, int end) throws Exception {
    Database db = t1.getDatabase();
    ((DatabaseImpl) db).getPageChannel().startWrite();
    try {
      for (int i = start; i < end; ++i) {
        t1.addRow(null, "rowdata-" + i + TestUtil.createString(100));
        t2.addRow(null, "rowdata-" + i + TestUtil.createString(100));
      }
    } finally {
      ((DatabaseImpl) db).getPageChannel().finishWrite();
    }

    Cursor c1 = t1.newCursor().setIndex(t1.getPrimaryKeyIndex()).toCursor();
    Cursor c2 = t2.newCursor().setIndex(t2.getPrimaryKeyIndex()).toCursor();

    Iterator<? extends Row> i1 = c1.iterator();
    Iterator<? extends Row> i2 = c2.newIterable().reverse().iterator();

    int t1rows = 0;
    int t2rows = 0;
    ((DatabaseImpl) db).getPageChannel().startWrite();
    try {
      while (i1.hasNext() || i2.hasNext()) {
        if (i1.hasNext()) {
          checkRow(i1.next());
          i1.remove();
          ++t1rows;
        }
        if (i2.hasNext()) {
          checkRow(i2.next());
          i2.remove();
          ++t2rows;
        }
      }
    } finally {
      ((DatabaseImpl) db).getPageChannel().finishWrite();
    }

    assertEquals(100, t1rows);
    assertEquals(100, t2rows);
  }
Esempio n. 2
0
  private static void doTestCodecHandler(boolean simple) throws Exception {
    for (Database.FileFormat ff : SUPPORTED_FILEFORMATS) {
      Database db = TestUtil.create(ff);
      int pageSize = ((DatabaseImpl) db).getFormat().PAGE_SIZE;
      File dbFile = db.getFile();
      db.close();

      // apply encoding to file
      encodeFile(dbFile, pageSize, simple);

      db =
          new DatabaseBuilder(dbFile)
              .setCodecProvider(simple ? SIMPLE_PROVIDER : FULL_PROVIDER)
              .open();

      Table t1 =
          new TableBuilder("test1")
              .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true))
              .addColumn(new ColumnBuilder("data", DataType.TEXT).setLength(250))
              .setPrimaryKey("id")
              .addIndex(new IndexBuilder("data_idx").addColumns("data"))
              .toTable(db);

      Table t2 =
          new TableBuilder("test2")
              .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true))
              .addColumn(new ColumnBuilder("data", DataType.TEXT).setLength(250))
              .setPrimaryKey("id")
              .addIndex(new IndexBuilder("data_idx").addColumns("data"))
              .toTable(db);

      int autonum = 1;
      for (int i = 1; i < 2; ++i) {
        writeData(t1, t2, autonum, autonum + 100);
        autonum += 100;
      }

      db.close();
    }
  }