diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2014-06-11 22:23:04 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2014-06-11 22:23:04 +0000 |
commit | 70497648605fd00bed3a62a41605a9aeb410662d (patch) | |
tree | cb0c0c40706eec5ed4155a2e32d09a375722ccfe /src/test/java | |
parent | 9fb7e5415328d6a8468bcbadad804824f6a50957 (diff) | |
download | jackcess-70497648605fd00bed3a62a41605a9aeb410662d.tar.gz jackcess-70497648605fd00bed3a62a41605a9aeb410662d.zip |
Add Cursor.findRow(RowId) for moving to a specific Table row using only the RowId
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@864 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/CursorTest.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java index bafee57..cf55e2b 100644 --- a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java @@ -1205,5 +1205,75 @@ public class CursorTest extends TestCase { } } + public void testFindByRowId() throws Exception { + for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { + Database db = createTestTable(fileFormat); + + Table table = db.getTable("test"); + Cursor cursor = CursorBuilder.createCursor(table); + doTestFindByRowId(cursor); + db.close(); + } + } + + public void testFindByRowIdIndex() throws Exception { + for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { + Database db = createTestIndexTable(indexCursorDB); + + Table table = db.getTable("test"); + Index idx = table.getIndexes().get(0); + + assertTable(createUnorderedTestTableData(), table); + + Cursor cursor = CursorBuilder.createCursor(idx); + doTestFindByRowId(cursor); + + db.close(); + } + } + + private static void doTestFindByRowId(Cursor cursor) + throws Exception + { + for(int i = 0; i < 3; ++i) { + cursor.moveToNextRow(); + } + + Row r1 = cursor.getCurrentRow(); + + for(int i = 0; i < 3; ++i) { + cursor.moveToNextRow(); + } + + Row r2 = cursor.getCurrentRow(); + + doTestFindByRowId(cursor, r1, 2); + + doTestFindByRowId(cursor, r2, 5); + } + + private static void doTestFindByRowId(Cursor cursor, Row row, int id) + throws Exception + { + cursor.reset(); + assertTrue(cursor.findRow(row.getId())); + Row rFound = cursor.getCurrentRow(); + assertEquals(id, rFound.get("id")); + assertEquals(row, rFound); + Cursor.Savepoint save = cursor.getSavepoint(); + + assertTrue(cursor.moveToNextRow()); + assertEquals(id + 1, cursor.getCurrentRow().get("id")); + + cursor.restoreSavepoint(save); + + assertTrue(cursor.moveToPreviousRow()); + assertEquals(id - 1, cursor.getCurrentRow().get("id")); + + assertFalse(cursor.findRow(RowIdImpl.FIRST_ROW_ID)); + + assertEquals(id - 1, cursor.getCurrentRow().get("id")); + } + } |