aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2013-07-30 02:17:15 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2013-07-30 02:17:15 +0000
commitd1a79d0064632cca220409abb799ab1757c6caa7 (patch)
tree5cea8606b34a37ff241f9b24f0d5e6b2178a10b5 /test/src
parent50a356790e619903269a2aa52db7f4a72d1d802d (diff)
downloadjackcess-d1a79d0064632cca220409abb799ab1757c6caa7.tar.gz
jackcess-d1a79d0064632cca220409abb799ab1757c6caa7.zip
merge branch jackcess-2 changes through r759
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@760 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test/src')
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java63
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java13
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java25
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/CursorTest.java211
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java210
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/IndexTest.java90
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java17
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java9
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/TableTest.java86
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/CodecHandlerTest.java)47
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/FKEnforcerTest.java)28
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/IndexCodesTest.java)40
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java)29
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/impl/UsageMapTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java)13
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/impl/scsu/CompressMain.java (renamed from test/src/java/com/healthmarketscience/jackcess/scsu/CompressMain.java)2
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/impl/scsu/CompressTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/scsu/CompressTest.java)2
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java21
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/util/ErrorHandlerTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/ErrorHandlerTest.java)35
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/util/ExportTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/ExportTest.java)13
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/util/ImportTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/ImportTest.java)20
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/util/JoinerTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/JoinerTest.java)47
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/util/MemFileChannelTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/MemFileChannelTest.java)4
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/util/RowFilterTest.java (renamed from test/src/java/com/healthmarketscience/jackcess/RowFilterTest.java)36
23 files changed, 657 insertions, 404 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java
index f6d1c0a..70d63d8 100644
--- a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java
@@ -35,43 +35,26 @@ import java.util.Random;
import junit.framework.TestCase;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
-
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.TableImpl;
+import com.healthmarketscience.jackcess.impl.IndexImpl;
/**
* @author james
*/
public class BigIndexTest extends TestCase {
- private String _oldBigIndexValue = null;
-
public BigIndexTest(String name) {
super(name);
}
-
- @Override
- protected void setUp() {
- _oldBigIndexValue = System.getProperty(Database.USE_BIG_INDEX_PROPERTY);
- System.setProperty(Database.USE_BIG_INDEX_PROPERTY,
- Boolean.TRUE.toString());
- }
-
- @Override
- protected void tearDown() {
- if (_oldBigIndexValue != null) {
- System.setProperty(Database.USE_BIG_INDEX_PROPERTY, _oldBigIndexValue);
- } else {
- System.clearProperty(Database.USE_BIG_INDEX_PROPERTY);
- }
- }
public void testComplexIndex() throws Exception
{
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX, true)) {
// this file has an index with "compressed" entries and node pages
Database db = open(testDB);
- Table t = db.getTable("Table1");
- Index index = t.getIndex("CD_AGENTE");
+ TableImpl t = (TableImpl)db.getTable("Table1");
+ IndexImpl index = t.getIndex("CD_AGENTE");
assertFalse(index.isInitialized());
assertEquals(512, countRows(t));
assertEquals(512, index.getIndexData().getEntryCount());
@@ -84,8 +67,8 @@ public class BigIndexTest extends TestCase {
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.BIG_INDEX)) {
// this file has an index with "compressed" entries and node pages
Database db = open(testDB);
- Table t = db.getTable("Table1");
- Index index = t.getIndex("col1");
+ TableImpl t = (TableImpl)db.getTable("Table1");
+ IndexImpl index = t.getIndex("col1");
assertFalse(index.isInitialized());
assertEquals(0, countRows(t));
assertEquals(0, index.getIndexData().getEntryCount());
@@ -98,12 +81,9 @@ public class BigIndexTest extends TestCase {
// copy to temp file and attempt to edit
db = openCopy(testDB);
- t = db.getTable("Table1");
+ t = (TableImpl)db.getTable("Table1");
index = t.getIndex("col1");
- System.out.println("BigIndexTest: Index type: " +
- index.getIndexData().getClass());
-
// add 2,000 (pseudo) random entries to the table
Random rand = new Random(13L);
for(int i = 0; i < 2000; ++i) {
@@ -131,10 +111,13 @@ public class BigIndexTest extends TestCase {
}
}
- ((BigIndexData)index.getIndexData()).validate();
+ index.getIndexData().validate();
db.flush();
- t = db.getTable("Table1");
+ t = null;
+ System.gc();
+
+ t = (TableImpl)db.getTable("Table1");
index = t.getIndex("col1");
// make sure all entries are there and correctly ordered
@@ -142,7 +125,7 @@ public class BigIndexTest extends TestCase {
String prevValue = firstValue;
int rowCount = 0;
List<String> firstTwo = new ArrayList<String>();
- for(Map<String,Object> row : Cursor.createIndexCursor(t, index)) {
+ for(Map<String,Object> row : CursorBuilder.createCursor(t, index)) {
String origVal = (String)row.get("col1");
String val = origVal;
if(val == null) {
@@ -159,10 +142,10 @@ public class BigIndexTest extends TestCase {
assertEquals(2000, rowCount);
- ((BigIndexData)index.getIndexData()).validate();
+ index.getIndexData().validate();
// delete an entry in the middle
- Cursor cursor = Cursor.createIndexCursor(t, index);
+ Cursor cursor = CursorBuilder.createCursor(t, index);
for(int i = 0; i < (rowCount / 2); ++i) {
assertTrue(cursor.moveToNextRow());
}
@@ -176,17 +159,17 @@ public class BigIndexTest extends TestCase {
cursor.deleteCurrentRow();
}
- ((BigIndexData)index.getIndexData()).validate();
+ index.getIndexData().validate();
List<String> found = new ArrayList<String>();
- for(Map<String,Object> row : Cursor.createIndexCursor(t, index)) {
+ for(Map<String,Object> row : CursorBuilder.createCursor(t, index)) {
found.add((String)row.get("col1"));
}
assertEquals(firstTwo, found);
// remove remaining entries
- cursor = Cursor.createCursor(t);
+ cursor = CursorBuilder.createCursor(t);
for(int i = 0; i < 2; ++i) {
assertTrue(cursor.moveToNextRow());
cursor.deleteCurrentRow();
@@ -195,7 +178,7 @@ public class BigIndexTest extends TestCase {
assertFalse(cursor.moveToNextRow());
assertFalse(cursor.moveToPreviousRow());
- ((BigIndexData)index.getIndexData()).validate();
+ index.getIndexData().validate();
// add 50 (pseudo) random entries to the table
rand = new Random(42L);
@@ -208,14 +191,14 @@ public class BigIndexTest extends TestCase {
t.addRow(nextVal, "this is some row data " + nextInt);
}
- ((BigIndexData)index.getIndexData()).validate();
+ index.getIndexData().validate();
- cursor = Cursor.createIndexCursor(t, index);
+ cursor = CursorBuilder.createCursor(t, index);
while(cursor.moveToNextRow()) {
cursor.deleteCurrentRow();
}
- ((BigIndexData)index.getIndexData()).validate();
+ index.getIndexData().validate();
db.close();
diff --git a/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java b/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java
index 8fea667..173a53c 100644
--- a/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java
@@ -26,13 +26,16 @@ import java.util.List;
import java.util.Map;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
import com.healthmarketscience.jackcess.complex.Attachment;
import com.healthmarketscience.jackcess.complex.ComplexDataType;
import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
import com.healthmarketscience.jackcess.complex.SingleValue;
import com.healthmarketscience.jackcess.complex.UnsupportedValue;
import com.healthmarketscience.jackcess.complex.Version;
+import com.healthmarketscience.jackcess.impl.ByteUtil;
+import com.healthmarketscience.jackcess.impl.ColumnImpl;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.PageChannel;
import junit.framework.TestCase;
@@ -97,7 +100,7 @@ public class ComplexColumnTest extends TestCase
checkVersions(row8ValFk.get(), row8ValFk, "row8-memo",
"row8-memo", upTime);
- Cursor cursor = Cursor.createCursor(t1);
+ Cursor cursor = CursorBuilder.createCursor(t1);
assertTrue(cursor.findFirstRow(t1.getColumn("id"), "row3"));
ComplexValueForeignKey row3ValFk = (ComplexValueForeignKey)
cursor.getCurrentRowValue(verCol);
@@ -196,7 +199,7 @@ public class ComplexColumnTest extends TestCase
checkAttachments(row8ValFk.get(), row8ValFk, "test_data.txt",
"test_data2.txt");
- Cursor cursor = Cursor.createCursor(t1);
+ Cursor cursor = CursorBuilder.createCursor(t1);
assertTrue(cursor.findFirstRow(t1.getColumn("id"), "row4"));
ComplexValueForeignKey row4ValFk = (ComplexValueForeignKey)
cursor.getCurrentRowValue(col);
@@ -277,7 +280,7 @@ public class ComplexColumnTest extends TestCase
row8ValFk.addMultiValue("value2");
checkMultiValues(row8ValFk.get(), row8ValFk, "value1", "value2");
- Cursor cursor = Cursor.createCursor(t1);
+ Cursor cursor = CursorBuilder.createCursor(t1);
assertTrue(cursor.findFirstRow(t1.getColumn("id"), "row2"));
ComplexValueForeignKey row2ValFk = (ComplexValueForeignKey)
cursor.getCurrentRowValue(col);
@@ -425,7 +428,7 @@ public class ComplexColumnTest extends TestCase
UnsupportedValue v = values.get(i);
assertEquals(1, v.getValues().size());
Object rv = v.get("Value");
- assertTrue(Column.isRawData(rv));
+ assertTrue(ColumnImpl.isRawData(rv));
assertEquals(value, rv.toString());
}
}
diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java
index c1872fa..26d22e7 100644
--- a/test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java
@@ -29,7 +29,8 @@ package com.healthmarketscience.jackcess;
import junit.framework.TestCase;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.IndexImpl;
/**
* @author James Ahlborn
@@ -59,20 +60,20 @@ public class CursorBuilderTest extends TestCase {
Database db = CursorTest.createTestIndexTable(indexCursorDB);
Table table = db.getTable("test");
- Index idx = table.getIndexes().get(0);
+ IndexImpl idx = (IndexImpl)table.getIndexes().get(0);
- Cursor expected = Cursor.createCursor(table);
+ Cursor expected = CursorBuilder.createCursor(table);
Cursor found = new CursorBuilder(table).toCursor();
assertCursor(expected, found);
- expected = Cursor.createIndexCursor(table, idx);
+ expected = CursorBuilder.createCursor(table, idx);
found = new CursorBuilder(table)
.setIndex(idx)
.toCursor();
assertCursor(expected, found);
- expected = Cursor.createIndexCursor(table, idx);
+ expected = CursorBuilder.createCursor(table, idx);
found = new CursorBuilder(table)
.setIndexByName("id")
.toCursor();
@@ -86,7 +87,7 @@ public class CursorBuilderTest extends TestCase {
// success
}
- expected = Cursor.createIndexCursor(table, idx);
+ expected = CursorBuilder.createCursor(table, idx);
found = new CursorBuilder(table)
.setIndexByColumns(table.getColumn("id"))
.toCursor();
@@ -108,21 +109,21 @@ public class CursorBuilderTest extends TestCase {
// success
}
- expected = Cursor.createCursor(table);
+ expected = CursorBuilder.createCursor(table);
expected.beforeFirst();
found = new CursorBuilder(table)
.beforeFirst()
.toCursor();
assertCursor(expected, found);
- expected = Cursor.createCursor(table);
+ expected = CursorBuilder.createCursor(table);
expected.afterLast();
found = new CursorBuilder(table)
.afterLast()
.toCursor();
assertCursor(expected, found);
- expected = Cursor.createCursor(table);
+ expected = CursorBuilder.createCursor(table);
expected.moveNextRows(2);
Cursor.Savepoint sp = expected.getSavepoint();
found = new CursorBuilder(table)
@@ -131,7 +132,7 @@ public class CursorBuilderTest extends TestCase {
.toCursor();
assertCursor(expected, found);
- expected = Cursor.createIndexCursor(table, idx);
+ expected = CursorBuilder.createCursor(table, idx);
expected.moveNextRows(2);
sp = expected.getSavepoint();
found = new CursorBuilder(table)
@@ -141,7 +142,7 @@ public class CursorBuilderTest extends TestCase {
.toCursor();
assertCursor(expected, found);
- expected = Cursor.createIndexCursor(table, idx,
+ expected = CursorBuilder.createCursor(table, idx,
idx.constructIndexRowFromEntry(3),
null);
found = new CursorBuilder(table)
@@ -150,7 +151,7 @@ public class CursorBuilderTest extends TestCase {
.toCursor();
assertCursor(expected, found);
- expected = Cursor.createIndexCursor(table, idx,
+ expected = CursorBuilder.createCursor(table, idx,
idx.constructIndexRowFromEntry(3),
false,
idx.constructIndexRowFromEntry(7),
diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
index 897cf53..59de129 100644
--- a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
@@ -38,7 +38,13 @@ import java.util.TreeSet;
import static com.healthmarketscience.jackcess.Database.*;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.JetFormatTest;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.RowIdImpl;
+import com.healthmarketscience.jackcess.util.CaseInsensitiveColumnMatcher;
+import com.healthmarketscience.jackcess.util.ColumnMatcher;
+import com.healthmarketscience.jackcess.util.RowFilterTest;
+import com.healthmarketscience.jackcess.util.SimpleColumnMatcher;
import junit.framework.TestCase;
/**
@@ -170,7 +176,7 @@ public class CursorTest extends TestCase {
int type)
throws Exception
{
- return new CursorBuilder(table)
+ return table.newCursor()
.setIndex(idx)
.setStartEntry(3 - type)
.setStartRowInclusive(type == 0)
@@ -181,16 +187,17 @@ public class CursorTest extends TestCase {
public void testRowId() throws Exception {
// test special cases
- RowId rowId1 = new RowId(1, 2);
- RowId rowId2 = new RowId(1, 3);
- RowId rowId3 = new RowId(2, 1);
+ RowIdImpl rowId1 = new RowIdImpl(1, 2);
+ RowIdImpl rowId2 = new RowIdImpl(1, 3);
+ RowIdImpl rowId3 = new RowIdImpl(2, 1);
- List<RowId> sortedRowIds = new ArrayList<RowId>(new TreeSet<RowId>(
- Arrays.asList(rowId1, rowId2, rowId3, RowId.FIRST_ROW_ID,
- RowId.LAST_ROW_ID)));
+ List<RowIdImpl> sortedRowIds =
+ new ArrayList<RowIdImpl>(new TreeSet<RowIdImpl>(
+ Arrays.asList(rowId1, rowId2, rowId3, RowIdImpl.FIRST_ROW_ID,
+ RowIdImpl.LAST_ROW_ID)));
- assertEquals(Arrays.asList(RowId.FIRST_ROW_ID, rowId1, rowId2, rowId3,
- RowId.LAST_ROW_ID),
+ assertEquals(Arrays.asList(RowIdImpl.FIRST_ROW_ID, rowId1, rowId2, rowId3,
+ RowIdImpl.LAST_ROW_ID),
sortedRowIds);
}
@@ -199,7 +206,7 @@ public class CursorTest extends TestCase {
Database db = createTestTable(fileFormat);
Table table = db.getTable("test");
- Cursor cursor = Cursor.createCursor(table);
+ Cursor cursor = CursorBuilder.createCursor(table);
doTestSimple(cursor, null);
db.close();
}
@@ -226,7 +233,7 @@ public class CursorTest extends TestCase {
Database db = createTestTable(fileFormat);
Table table = db.getTable("test");
- Cursor cursor = Cursor.createCursor(table);
+ Cursor cursor = CursorBuilder.createCursor(table);
doTestMove(cursor, null);
db.close();
@@ -280,12 +287,55 @@ public class CursorTest extends TestCase {
assertEquals(expectedRow, cursor.getCurrentRow());
}
+ public void testMoveNoReset() throws Exception {
+ for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
+ Database db = createTestTable(fileFormat);
+
+ Table table = db.getTable("test");
+ Cursor cursor = CursorBuilder.createCursor(table);
+ doTestMoveNoReset(cursor);
+
+ db.close();
+ }
+ }
+
+ private static void doTestMoveNoReset(Cursor cursor)
+ throws Exception
+ {
+ List<Map<String, Object>> expectedRows = createTestTableData();
+ List<Map<String, Object>> foundRows = new ArrayList<Map<String, Object>>();
+
+ Iterator<Row> iter = cursor.newIterable().iterator();
+
+ for(int i = 0; i < 6; ++i) {
+ foundRows.add(iter.next());
+ }
+
+ iter = cursor.newIterable().reset(false).reverse().iterator();
+ iter.next();
+ Map<String, Object> row = iter.next();
+ assertEquals(expectedRows.get(4), row);
+
+ iter = cursor.newIterable().reset(false).iterator();
+ iter.next();
+ row = iter.next();
+ assertEquals(expectedRows.get(5), row);
+ iter.next();
+
+ iter = cursor.newIterable().reset(false).iterator();
+ for(int i = 6; i < 10; ++i) {
+ foundRows.add(iter.next());
+ }
+
+ assertEquals(expectedRows, foundRows);
+ }
+
public void testSearch() throws Exception {
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = createTestTable(fileFormat);
Table table = db.getTable("test");
- Cursor cursor = Cursor.createCursor(table);
+ Cursor cursor = CursorBuilder.createCursor(table);
doTestSearch(table, cursor, null, 42, -13);
db.close();
@@ -338,28 +388,28 @@ public class CursorTest extends TestCase {
}
assertEquals("data" + 5,
- Cursor.findValue(table,
+ CursorBuilder.findValue(table,
table.getColumn("value"),
table.getColumn("id"), 5));
assertEquals(createExpectedRow("id", 5,
"value", "data" + 5),
- Cursor.findRow(table,
+ CursorBuilder.findRow(table,
createExpectedRow("id", 5)));
if(index != null) {
assertEquals("data" + 5,
- Cursor.findValue(table, index,
+ CursorBuilder.findValue(table, index,
table.getColumn("value"),
table.getColumn("id"), 5));
assertEquals(createExpectedRow("id", 5,
"value", "data" + 5),
- Cursor.findRow(table, index,
+ CursorBuilder.findRow(table, index,
createExpectedRow("id", 5)));
- assertNull(Cursor.findValue(table, index,
+ assertNull(CursorBuilder.findValue(table, index,
table.getColumn("value"),
table.getColumn("id"),
-17));
- assertNull(Cursor.findRow(table, index,
+ assertNull(CursorBuilder.findRow(table, index,
createExpectedRow("id", 13)));
}
}
@@ -369,7 +419,7 @@ public class CursorTest extends TestCase {
Database db = createTestTable(fileFormat);
Table table = db.getTable("test");
- Cursor cursor = Cursor.createCursor(table);
+ Cursor cursor = CursorBuilder.createCursor(table);
doTestReverse(cursor, null);
db.close();
@@ -387,7 +437,7 @@ public class CursorTest extends TestCase {
List<Map<String, Object>> foundRows =
new ArrayList<Map<String, Object>>();
- for(Map<String, Object> row : cursor.reverseIterable()) {
+ for(Map<String, Object> row : cursor.newIterable().reverse()) {
foundRows.add(row);
}
assertEquals(expectedRows, foundRows);
@@ -399,8 +449,8 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
- Cursor cursor1 = Cursor.createCursor(table);
- Cursor cursor2 = Cursor.createCursor(table);
+ Cursor cursor1 = CursorBuilder.createCursor(table);
+ Cursor cursor2 = CursorBuilder.createCursor(table);
doTestLiveAddition(table, cursor1, cursor2, 11);
db.close();
@@ -440,10 +490,10 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
- Cursor cursor1 = Cursor.createCursor(table);
- Cursor cursor2 = Cursor.createCursor(table);
- Cursor cursor3 = Cursor.createCursor(table);
- Cursor cursor4 = Cursor.createCursor(table);
+ Cursor cursor1 = CursorBuilder.createCursor(table);
+ Cursor cursor2 = CursorBuilder.createCursor(table);
+ Cursor cursor3 = CursorBuilder.createCursor(table);
+ Cursor cursor4 = CursorBuilder.createCursor(table);
doTestLiveDeletion(cursor1, cursor2, cursor3, cursor4, 1);
db.close();
@@ -536,7 +586,7 @@ public class CursorTest extends TestCase {
assertTable(createUnorderedTestTableData(), table);
- Cursor cursor = Cursor.createIndexCursor(table, idx);
+ Cursor cursor = CursorBuilder.createCursor(table, idx);
doTestSimple(cursor, null);
db.close();
@@ -549,7 +599,7 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
Index idx = table.getIndexes().get(0);
- Cursor cursor = Cursor.createIndexCursor(table, idx);
+ Cursor cursor = CursorBuilder.createCursor(table, idx);
doTestMove(cursor, null);
db.close();
@@ -562,7 +612,7 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
Index idx = table.getIndexes().get(0);
- Cursor cursor = Cursor.createIndexCursor(table, idx);
+ Cursor cursor = CursorBuilder.createCursor(table, idx);
doTestReverse(cursor, null);
db.close();
@@ -575,7 +625,7 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
Index idx = table.getIndexes().get(0);
- Cursor cursor = Cursor.createIndexCursor(table, idx);
+ Cursor cursor = CursorBuilder.createCursor(table, idx);
doTestSearch(table, cursor, idx, 42, -13);
db.close();
@@ -589,8 +639,8 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
Index idx = table.getIndexes().get(0);
- Cursor cursor1 = Cursor.createIndexCursor(table, idx);
- Cursor cursor2 = Cursor.createIndexCursor(table, idx);
+ Cursor cursor1 = CursorBuilder.createCursor(table, idx);
+ Cursor cursor2 = CursorBuilder.createCursor(table, idx);
doTestLiveAddition(table, cursor1, cursor2, 11);
db.close();
@@ -604,10 +654,10 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
Index idx = table.getIndexes().get(0);
- Cursor cursor1 = Cursor.createIndexCursor(table, idx);
- Cursor cursor2 = Cursor.createIndexCursor(table, idx);
- Cursor cursor3 = Cursor.createIndexCursor(table, idx);
- Cursor cursor4 = Cursor.createIndexCursor(table, idx);
+ Cursor cursor1 = CursorBuilder.createCursor(table, idx);
+ Cursor cursor2 = CursorBuilder.createCursor(table, idx);
+ Cursor cursor3 = CursorBuilder.createCursor(table, idx);
+ Cursor cursor4 = CursorBuilder.createCursor(table, idx);
doTestLiveDeletion(cursor1, cursor2, cursor3, cursor4, 1);
db.close();
@@ -734,7 +784,7 @@ public class CursorTest extends TestCase {
Database db = createDupeTestTable(fileFormat);
Table table = db.getTable("test");
- Cursor cursor = Cursor.createCursor(table);
+ Cursor cursor = CursorBuilder.createCursor(table);
doTestFindAll(table, cursor, null);
@@ -748,7 +798,7 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
Index idx = table.getIndexes().get(0);
- Cursor cursor = Cursor.createIndexCursor(table, idx);
+ Cursor cursor = CursorBuilder.createCursor(table, idx);
doTestFindAll(table, cursor, idx);
@@ -759,11 +809,10 @@ public class CursorTest extends TestCase {
private static void doTestFindAll(Table table, Cursor cursor, Index index)
throws Exception
{
- Column valCol = table.getColumn("value");
- List<Map<String,Object>> rows = RowFilterTest.toList(
- cursor.columnMatchIterable(valCol, "data2"));
+ List<? extends Map<String,Object>> rows = RowFilterTest.toList(
+ cursor.newIterable().setMatchPattern("value", "data2"));
- List<Map<String, Object>> expectedRows = null;
+ List<? extends Map<String, Object>> expectedRows = null;
if(index == null) {
expectedRows =
@@ -794,8 +843,9 @@ public class CursorTest extends TestCase {
}
assertEquals(expectedRows, rows);
+ Column valCol = table.getColumn("value");
rows = RowFilterTest.toList(
- cursor.columnMatchIterable(valCol, "data4"));
+ cursor.newIterable().setMatchPattern(valCol, "data4"));
if(index == null) {
expectedRows =
@@ -815,12 +865,13 @@ public class CursorTest extends TestCase {
assertEquals(expectedRows, rows);
rows = RowFilterTest.toList(
- cursor.columnMatchIterable(valCol, "data9"));
+ cursor.newIterable().setMatchPattern(valCol, "data9"));
assertTrue(rows.isEmpty());
rows = RowFilterTest.toList(
- cursor.rowMatchIterable(Collections.singletonMap("id", 8)));
+ cursor.newIterable().setMatchPattern(
+ Collections.singletonMap("id", 8)));
expectedRows =
createExpectedTable(
@@ -832,22 +883,23 @@ public class CursorTest extends TestCase {
for(Map<String,Object> row : table) {
- expectedRows = new ArrayList<Map<String,Object>>();
+ List<Map<String,Object>> tmpRows = new ArrayList<Map<String,Object>>();
for(Map<String,Object> tmpRow : cursor) {
if(row.equals(tmpRow)) {
- expectedRows.add(tmpRow);
+ tmpRows.add(tmpRow);
}
}
+ expectedRows = tmpRows;
assertFalse(expectedRows.isEmpty());
- rows = RowFilterTest.toList(cursor.rowMatchIterable(row));
+ rows = RowFilterTest.toList(cursor.newIterable().setMatchPattern(row));
assertEquals(expectedRows, rows);
}
rows = RowFilterTest.toList(
- cursor.rowMatchIterable(createExpectedRow(
- "id", 8, "value", "data13")));
+ cursor.newIterable().addMatchPattern("id", 8)
+ .addMatchPattern("value", "data13"));
assertTrue(rows.isEmpty());
}
@@ -859,8 +911,8 @@ public class CursorTest extends TestCase {
Table table = db.getTable("test");
Index idx = table.getIndexes().get(0);
- Cursor tCursor = Cursor.createCursor(table);
- Cursor iCursor = Cursor.createIndexCursor(table, idx);
+ Cursor tCursor = CursorBuilder.createCursor(table);
+ Cursor iCursor = CursorBuilder.createCursor(table, idx);
Cursor.Savepoint tSave = tCursor.getSavepoint();
Cursor.Savepoint iSave = iCursor.getSavepoint();
@@ -882,8 +934,8 @@ public class CursorTest extends TestCase {
// success
}
- Cursor tCursor2 = Cursor.createCursor(table);
- Cursor iCursor2 = Cursor.createIndexCursor(table, idx);
+ Cursor tCursor2 = CursorBuilder.createCursor(table);
+ Cursor iCursor2 = CursorBuilder.createCursor(table, idx);
tCursor2.restoreSavepoint(tSave);
iCursor2.restoreSavepoint(iSave);
@@ -892,7 +944,7 @@ public class CursorTest extends TestCase {
}
}
- public void testColmnMatcher() throws Exception {
+ public void testColumnMatcher() throws Exception {
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
@@ -903,7 +955,7 @@ public class CursorTest extends TestCase {
doTestMatchers(table, SimpleColumnMatcher.INSTANCE, false);
doTestMatchers(table, CaseInsensitiveColumnMatcher.INSTANCE, true);
- Cursor cursor = Cursor.createCursor(table);
+ Cursor cursor = CursorBuilder.createCursor(table);
doTestMatcher(table, cursor, SimpleColumnMatcher.INSTANCE, false);
doTestMatcher(table, cursor, CaseInsensitiveColumnMatcher.INSTANCE,
true);
@@ -989,6 +1041,28 @@ public class CursorTest extends TestCase {
"value", "data" + 4),
cursor.getCurrentRow());
}
+
+ assertEquals(Arrays.asList(createExpectedRow("id", 4,
+ "value", "data" + 4)),
+ RowFilterTest.toList(
+ cursor.newIterable()
+ .setMatchPattern("value", "data4")
+ .setColumnMatcher(SimpleColumnMatcher.INSTANCE)));
+
+ assertEquals(Arrays.asList(createExpectedRow("id", 3,
+ "value", "data" + 3)),
+ RowFilterTest.toList(
+ cursor.newIterable()
+ .setMatchPattern("value", "DaTa3")
+ .setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE)));
+
+ assertEquals(Arrays.asList(createExpectedRow("id", 2,
+ "value", "data" + 2)),
+ RowFilterTest.toList(
+ cursor.newIterable()
+ .addMatchPattern("value", "DaTa2")
+ .addMatchPattern("id", 2)
+ .setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE)));
}
public void testIndexCursor() throws Exception
@@ -998,7 +1072,7 @@ public class CursorTest extends TestCase {
Database db = open(testDB);
Table t1 = db.getTable("Table1");
Index idx = t1.getIndex(IndexBuilder.PRIMARY_KEY_NAME);
- IndexCursor cursor = IndexCursor.createCursor(t1, idx);
+ IndexCursor cursor = CursorBuilder.createCursor(t1, idx);
assertFalse(cursor.findFirstRowByEntry(-1));
cursor.findClosestRowByEntry(-1);
@@ -1025,18 +1099,19 @@ public class CursorTest extends TestCase {
Database db = openCopy(testDB);
Table t1 = db.getTable("Table1");
Index idx = t1.getIndex("Table2Table1");
- IndexCursor cursor = IndexCursor.createCursor(t1, idx);
+ IndexCursor cursor = CursorBuilder.createCursor(t1, idx);
List<String> expectedData = new ArrayList<String>();
- for(Map<String,Object> row : cursor.entryIterable(
- Arrays.asList("data"), 1)) {
+ for(Map<String,Object> row : cursor.newEntryIterable(1)
+ .addColumnNames("data")) {
expectedData.add((String)row.get("data"));
}
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
expectedData = new ArrayList<String>();
- for(Iterator<Map<String,Object>> iter = cursor.entryIterator(1);
+ for(Iterator<? extends Map<String,Object>> iter =
+ cursor.newEntryIterable(1).iterator();
iter.hasNext(); ) {
expectedData.add((String)iter.next().get("data"));
iter.remove();
@@ -1060,8 +1135,8 @@ public class CursorTest extends TestCase {
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
expectedData = new ArrayList<String>();
- for(Map<String,Object> row : cursor.entryIterable(
- Arrays.asList("data"), 1)) {
+ for(Map<String,Object> row : cursor.newEntryIterable(1)
+ .addColumnNames("data")) {
expectedData.add((String)row.get("data"));
}
@@ -1077,10 +1152,10 @@ public class CursorTest extends TestCase {
Database db = openCopy(testDB);
Table t1 = db.getTable("Table1");
- Cursor cursor = Cursor.createCursor(t1);
+ Cursor cursor = CursorBuilder.createCursor(t1);
List<String> expectedData = new ArrayList<String>();
- for(Map<String,Object> row : cursor.iterable(
+ for(Map<String,Object> row : cursor.newIterable().setColumnNames(
Arrays.asList("otherfk1", "data"))) {
if(row.get("otherfk1").equals(1)) {
expectedData.add((String)row.get("data"));
@@ -1090,7 +1165,7 @@ public class CursorTest extends TestCase {
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
expectedData = new ArrayList<String>();
- for(Iterator<Map<String,Object>> iter = cursor.iterator();
+ for(Iterator<? extends Map<String,Object>> iter = cursor.iterator();
iter.hasNext(); ) {
Map<String,Object> row = iter.next();
if(row.get("otherfk1").equals(1)) {
@@ -1117,7 +1192,7 @@ public class CursorTest extends TestCase {
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
expectedData = new ArrayList<String>();
- for(Map<String,Object> row : cursor.iterable(
+ for(Map<String,Object> row : cursor.newIterable().setColumnNames(
Arrays.asList("otherfk1", "data"))) {
if(row.get("otherfk1").equals(1)) {
expectedData.add((String)row.get("data"));
diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
index e73661f..eef4ecb 100644
--- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
@@ -57,10 +57,23 @@ import java.util.TreeSet;
import java.util.UUID;
import static com.healthmarketscience.jackcess.Database.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
+import com.healthmarketscience.jackcess.impl.ByteUtil;
+import com.healthmarketscience.jackcess.impl.ColumnImpl;
+import com.healthmarketscience.jackcess.impl.DatabaseImpl;
+import com.healthmarketscience.jackcess.impl.IndexData;
+import com.healthmarketscience.jackcess.impl.IndexImpl;
+import com.healthmarketscience.jackcess.impl.JetFormat;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.RowIdImpl;
+import com.healthmarketscience.jackcess.impl.RowImpl;
+import com.healthmarketscience.jackcess.impl.TableImpl;
+import com.healthmarketscience.jackcess.util.LinkResolver;
+import com.healthmarketscience.jackcess.util.MemFileChannel;
+import com.healthmarketscience.jackcess.util.RowFilterTest;
import junit.framework.TestCase;
+
/**
* @author Tim McCune
*/
@@ -90,8 +103,9 @@ public class DatabaseTest extends TestCase {
: null);
final Database db = new DatabaseBuilder(file).setReadOnly(true)
.setAutoSync(_autoSync).setChannel(channel).open();
- assertEquals("Wrong JetFormat.", fileFormat.getJetFormat(),
- db.getFormat());
+ assertEquals("Wrong JetFormat.",
+ DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(),
+ ((DatabaseImpl)db).getFormat());
assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat());
return db;
}
@@ -151,8 +165,9 @@ public class DatabaseTest extends TestCase {
File tmp = createTempFile(keep);
copyFile(file, tmp);
Database db = new DatabaseBuilder(tmp).setAutoSync(_autoSync).open();
- assertEquals("Wrong JetFormat.", fileFormat.getJetFormat(),
- db.getFormat());
+ assertEquals("Wrong JetFormat.",
+ DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(),
+ ((DatabaseImpl)db).getFormat());
assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat());
return db;
}
@@ -163,7 +178,7 @@ public class DatabaseTest extends TestCase {
Database db = create(fileFormat);
try {
- db.createTable("test", Collections.<Column>emptyList());
+ ((DatabaseImpl)db).createTable("test", Collections.<ColumnBuilder>emptyList());
fail("created table with no columns?");
} catch(IllegalArgumentException e) {
// success
@@ -231,7 +246,7 @@ public class DatabaseTest extends TestCase {
public void testGetColumns() throws Exception {
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
- List<Column> columns = open(testDB).getTable("Table1").getColumns();
+ List<? extends Column> columns = open(testDB).getTable("Table1").getColumns();
assertEquals(9, columns.size());
checkColumn(columns, 0, "A", DataType.TEXT);
checkColumn(columns, 1, "B", DataType.TEXT);
@@ -245,8 +260,8 @@ public class DatabaseTest extends TestCase {
}
}
- static void checkColumn(List<Column> columns, int columnNumber, String name,
- DataType dataType)
+ static void checkColumn(List<? extends Column> columns, int columnNumber,
+ String name, DataType dataType)
throws Exception
{
Column column = columns.get(columnNumber);
@@ -396,17 +411,19 @@ public class DatabaseTest extends TestCase {
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
createTestTable(db);
- Object[] row1 = createTestRow("Tim1");
- Object[] row2 = createTestRow("Tim2");
- Object[] row3 = createTestRow("Tim3");
+ Map<String,Object> row1 = createTestRowMap("Tim1");
+ Map<String,Object> row2 = createTestRowMap("Tim2");
+ Map<String,Object> row3 = createTestRowMap("Tim3");
Table table = db.getTable("Test");
- table.addRows(Arrays.asList(row1, row2, row3));
+ @SuppressWarnings("unchecked")
+ List<Map<String,Object>> rows = Arrays.asList(row1, row2, row3);
+ table.addRowsFromMaps(rows);
assertRowCount(3, table);
table.reset();
table.getNextRow();
table.getNextRow();
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
table.reset();
@@ -429,17 +446,17 @@ public class DatabaseTest extends TestCase {
assertRowCount(10, table);
table.reset();
table.getNextRow();
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
assertRowCount(9, table);
table.reset();
table.getNextRow();
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
assertRowCount(8, table);
table.reset();
for (int i = 0; i < 8; i++) {
table.getNextRow();
}
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
assertRowCount(7, table);
table.addRow(row);
assertRowCount(8, table);
@@ -447,7 +464,7 @@ public class DatabaseTest extends TestCase {
for (int i = 0; i < 3; i++) {
table.getNextRow();
}
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
assertRowCount(7, table);
table.reset();
assertEquals(2, table.getNextRow().get("D"));
@@ -456,6 +473,38 @@ public class DatabaseTest extends TestCase {
}
}
+ public void testDeleteRow() throws Exception {
+
+ // make sure correct row is deleted
+ for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
+ Database db = create(fileFormat);
+ createTestTable(db);
+ Table table = db.getTable("Test");
+ for(int i = 0; i < 10; ++i) {
+ table.addRowFromMap(createTestRowMap("Tim" + i));
+ }
+ assertRowCount(10, table);
+
+ table.reset();
+
+ List<Row> rows = RowFilterTest.toList(table);
+
+ Row r1 = rows.remove(7);
+ Row r2 = rows.remove(3);
+ assertEquals(8, rows.size());
+
+ assertSame(r2, table.deleteRow(r2));
+ assertSame(r1, table.deleteRow(r1));
+
+ assertTable(rows, table);
+
+ table.deleteRow(r2);
+ table.deleteRow(r1);
+
+ assertTable(rows, table);
+ }
+ }
+
public void testReadLongValue() throws Exception {
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.TEST2, true)) {
@@ -711,9 +760,9 @@ public class DatabaseTest extends TestCase {
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
- Column col = new ColumnBuilder("A", DataType.NUMERIC)
+ ColumnBuilder col = new ColumnBuilder("A", DataType.NUMERIC)
.setScale(4).setPrecision(8).toColumn();
- assertTrue(col.isVariableLength());
+ assertTrue(col.getType().isVariableLength());
Table table = new TableBuilder("test")
.addColumn(col)
@@ -809,7 +858,7 @@ public class DatabaseTest extends TestCase {
public void testMultiPageTableDef() throws Exception
{
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
- List<Column> columns = open(testDB).getTable("Table2").getColumns();
+ List<? extends Column> columns = open(testDB).getTable("Table2").getColumns();
assertEquals(89, columns.size());
}
}
@@ -875,7 +924,7 @@ public class DatabaseTest extends TestCase {
Database db = openCopy(testDB);
Table t = db.getTable("jobDB1");
- assertTrue(t.getOwnedPagesCursor().getUsageMap().toString()
+ assertTrue(((TableImpl)t).getOwnedPagesCursor().getUsageMap().toString()
.startsWith("(InlineHandler)"));
String lval = createNonAsciiString(255); // "--255 chars long text--";
@@ -890,7 +939,7 @@ public class DatabaseTest extends TestCase {
}
assertEquals(1000, ids.size());
- assertTrue(t.getOwnedPagesCursor().getUsageMap().toString()
+ assertTrue(((TableImpl)t).getOwnedPagesCursor().getUsageMap().toString()
.startsWith("(ReferenceHandler)"));
db.close();
@@ -904,7 +953,7 @@ public class DatabaseTest extends TestCase {
final int numColumns = 90;
- List<Column> columns = new ArrayList<Column>();
+ List<ColumnBuilder> columns = new ArrayList<ColumnBuilder>();
List<String> colNames = new ArrayList<String>();
for(int i = 0; i < numColumns; ++i) {
String colName = "MyColumnName" + i;
@@ -912,7 +961,7 @@ public class DatabaseTest extends TestCase {
columns.add(new ColumnBuilder(colName, DataType.TEXT).toColumn());
}
- db.createTable("test", columns);
+ ((DatabaseImpl)db).createTable("test", columns);
Table t = db.getTable("test");
@@ -963,18 +1012,29 @@ public class DatabaseTest extends TestCase {
private void doTestAutoNumber(Table table) throws Exception
{
- table.addRow(null, "row1");
- table.addRow(13, "row2");
- table.addRow("flubber", "row3");
+ Object[] row = {null, "row1"};
+ assertSame(row, table.addRow(row));
+ assertEquals(1, ((Integer)row[0]).intValue());
+ row = table.addRow(13, "row2");
+ assertEquals(2, ((Integer)row[0]).intValue());
+ row = table.addRow("flubber", "row3");
+ assertEquals(3, ((Integer)row[0]).intValue());
table.reset();
- table.addRow(Column.AUTO_NUMBER, "row4");
- table.addRow(Column.AUTO_NUMBER, "row5");
+ row = table.addRow(Column.AUTO_NUMBER, "row4");
+ assertEquals(4, ((Integer)row[0]).intValue());
+ row = table.addRow(Column.AUTO_NUMBER, "row5");
+ assertEquals(5, ((Integer)row[0]).intValue());
+
+ Object[] smallRow = {Column.AUTO_NUMBER};
+ row = table.addRow(smallRow);
+ assertNotSame(row, smallRow);
+ assertEquals(6, ((Integer)row[0]).intValue());
table.reset();
- List<Map<String, Object>> expectedRows =
+ List<? extends Map<String, Object>> expectedRows =
createExpectedTable(
createExpectedRow(
"a", 1,
@@ -990,7 +1050,10 @@ public class DatabaseTest extends TestCase {
"b", "row4"),
createExpectedRow(
"a", 5,
- "b", "row5"));
+ "b", "row5"),
+ createExpectedRow(
+ "a", 6,
+ "b", null));
assertTable(expectedRows, table);
}
@@ -1119,7 +1182,7 @@ public class DatabaseTest extends TestCase {
t.addRow("row" + i, Column.AUTO_NUMBER, "initial data");
}
- Cursor c = Cursor.createCursor(t);
+ Cursor c = CursorBuilder.createCursor(t);
c.reset();
c.moveNextRows(2);
Map<String,Object> row = c.getCurrentRow();
@@ -1129,7 +1192,15 @@ public class DatabaseTest extends TestCase {
"data", "initial data"),
row);
- c.updateCurrentRow(Column.KEEP_VALUE, Column.AUTO_NUMBER, "new data");
+ Map<String,Object> newRow = createExpectedRow(
+ "name", Column.KEEP_VALUE,
+ "id", Column.AUTO_NUMBER,
+ "data", "new data");
+ assertSame(newRow, c.updateCurrentRowFromMap(newRow));
+ assertEquals(createExpectedRow("name", "row1",
+ "id", 2,
+ "data", "new data"),
+ newRow);
c.moveNextRows(3);
row = c.getCurrentRow();
@@ -1187,6 +1258,23 @@ public class DatabaseTest extends TestCase {
"data", newText),
row);
+ List<Row> rows = RowFilterTest.toList(t);
+ assertEquals(50, rows.size());
+
+ for(Row r : rows) {
+ r.put("data", "final data " + r.get("id"));
+ }
+
+ for(Row r : rows) {
+ assertSame(r, t.updateRow(r));
+ }
+
+ t.reset();
+
+ for(Row r : t) {
+ assertEquals("final data " + r.get("id"), r.get("data"));
+ }
+
db.close();
}
}
@@ -1222,8 +1310,8 @@ public class DatabaseTest extends TestCase {
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
Database db = open(testDB);
- assertEquals(db.getFormat().DEFAULT_SORT_ORDER,
- db.getDefaultSortOrder());
+ assertEquals(((DatabaseImpl)db).getFormat().DEFAULT_SORT_ORDER,
+ ((DatabaseImpl)db).getDefaultSortOrder());
db.close();
}
}
@@ -1275,7 +1363,7 @@ public class DatabaseTest extends TestCase {
public Database resolveLinkedDatabase(Database linkerdb, String dbName)
throws IOException {
assertEquals(linkeeDbName, dbName);
- return Database.open(linkeeFile);
+ return DatabaseBuilder.open(linkeeFile);
}
});
@@ -1286,7 +1374,7 @@ public class DatabaseTest extends TestCase {
assertNotNull(linkeeDb);
assertEquals(linkeeFile, linkeeDb.getFile());
- List<Map<String, Object>> expectedRows =
+ List<? extends Map<String, Object>> expectedRows =
createExpectedTable(
createExpectedRow(
"ID", 1,
@@ -1323,9 +1411,9 @@ public class DatabaseTest extends TestCase {
private static void doTestTimeZone(final TimeZone tz) throws Exception
{
- Column col = new Column(true, null) {
+ ColumnImpl col = new ColumnImpl(null, DataType.SHORT_DATE_TIME, 0, 0, 0) {
@Override
- Calendar getCalendar() { return Calendar.getInstance(tz); }
+ protected Calendar getCalendar() { return Calendar.getInstance(tz); }
};
SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");
@@ -1353,7 +1441,7 @@ public class DatabaseTest extends TestCase {
private void checkRawValue(String expected, Object val)
{
if(expected != null) {
- assertTrue(Column.isRawData(val));
+ assertTrue(ColumnImpl.isRawData(val));
assertEquals(expected, val.toString());
} else {
assertNull(val);
@@ -1369,6 +1457,12 @@ public class DatabaseTest extends TestCase {
return createTestRow("Tim");
}
+ static Map<String,Object> createTestRowMap(String col1Val) {
+ return createExpectedRow("A", col1Val, "B", "R", "C", "McCune",
+ "D", 1234, "E", (byte) 0xad, "F", 555.66d,
+ "G", 777.88f, "H", (short) 999, "I", new Date());
+ }
+
static void createTestTable(Database db) throws Exception {
new TableBuilder("test")
.addColumn(new ColumnBuilder("A", DataType.TEXT))
@@ -1383,7 +1477,7 @@ public class DatabaseTest extends TestCase {
.toTable(db);
}
- static String createString(int len) {
+ public static String createString(int len) {
return createString(len, 'a');
}
@@ -1406,21 +1500,25 @@ public class DatabaseTest extends TestCase {
assertEquals(expectedRowCount, table.getRowCount());
}
- static int countRows(Table table) throws Exception {
+ public static int countRows(Table table) throws Exception {
int rtn = 0;
- for(Map<String, Object> row : Cursor.createCursor(table)) {
+ for(Map<String, Object> row : CursorBuilder.createCursor(table)) {
rtn++;
}
return rtn;
}
- static void assertTable(List<Map<String, Object>> expectedTable, Table table)
+ public static void assertTable(
+ List<? extends Map<String, Object>> expectedTable,
+ Table table)
+ throws IOException
{
- assertCursor(expectedTable, Cursor.createCursor(table));
+ assertCursor(expectedTable, CursorBuilder.createCursor(table));
}
- static void assertCursor(List<Map<String, Object>> expectedTable,
- Cursor cursor)
+ public static void assertCursor(
+ List<? extends Map<String, Object>> expectedTable,
+ Cursor cursor)
{
List<Map<String, Object>> foundTable =
new ArrayList<Map<String, Object>>();
@@ -1430,8 +1528,8 @@ public class DatabaseTest extends TestCase {
assertEquals(expectedTable, foundTable);
}
- static Map<String, Object> createExpectedRow(Object... rowElements) {
- Map<String, Object> row = new LinkedHashMap<String, Object>();
+ public static RowImpl createExpectedRow(Object... rowElements) {
+ RowImpl row = new RowImpl((RowIdImpl)null);
for(int i = 0; i < rowElements.length; i += 2) {
row.put((String)rowElements[i],
rowElements[i + 1]);
@@ -1440,8 +1538,8 @@ public class DatabaseTest extends TestCase {
}
@SuppressWarnings("unchecked")
- static List<Map<String, Object>> createExpectedTable(Map... rows) {
- return Arrays.<Map<String, Object>>asList(rows);
+ public static List<Row> createExpectedTable(Row... rows) {
+ return Arrays.<Row>asList(rows);
}
static void dumpDatabase(Database mdb) throws Exception {
@@ -1475,7 +1573,7 @@ public class DatabaseTest extends TestCase {
static void dumpTable(Table table, PrintWriter writer) throws Exception {
// make sure all indexes are read
for(Index index : table.getIndexes()) {
- index.initialize();
+ ((IndexImpl)index).initialize();
}
writer.println("TABLE: " + table.getName());
@@ -1484,7 +1582,7 @@ public class DatabaseTest extends TestCase {
colNames.add(col.getName());
}
writer.println("COLUMNS: " + colNames);
- for(Map<String, Object> row : Cursor.createCursor(table)) {
+ for(Map<String, Object> row : CursorBuilder.createCursor(table)) {
writer.println(massageRow(row));
}
}
@@ -1515,7 +1613,7 @@ public class DatabaseTest extends TestCase {
static void dumpIndex(Index index, PrintWriter writer) throws Exception {
writer.println("INDEX: " + index);
- IndexData.EntryCursor ec = index.cursor();
+ IndexData.EntryCursor ec = ((IndexImpl)index).cursor();
IndexData.Entry lastE = ec.getLastEntry();
IndexData.Entry e = null;
while((e = ec.getNextEntry()) != lastE) {
@@ -1570,7 +1668,7 @@ public class DatabaseTest extends TestCase {
return tmp;
}
- static byte[] toByteArray(File file)
+ public static byte[] toByteArray(File file)
throws IOException
{
// FIXME should really be using commons io IOUtils here, but don't want
diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
index 8f078f6..8c6284a 100644
--- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
@@ -36,11 +36,16 @@ import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
-import junit.framework.TestCase;
-
import static com.healthmarketscience.jackcess.Database.*;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.ByteUtil;
+import com.healthmarketscience.jackcess.impl.IndexCodesTest;
+import com.healthmarketscience.jackcess.impl.IndexData;
+import com.healthmarketscience.jackcess.impl.IndexImpl;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.RowIdImpl;
+import com.healthmarketscience.jackcess.impl.TableImpl;
+import junit.framework.TestCase;
/**
* @author James Ahlborn
@@ -110,8 +115,8 @@ public class IndexTest extends TestCase {
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) {
Database mdb = open(testDB);
- Table table = mdb.getTable("Table1");
- for(Index idx : table.getIndexes()) {
+ TableImpl table = (TableImpl)mdb.getTable("Table1");
+ for(IndexImpl idx : table.getIndexes()) {
idx.initialize();
}
assertEquals(4, table.getIndexes().size());
@@ -122,8 +127,8 @@ public class IndexTest extends TestCase {
"Table2Table1", "otherfk1",
"Table3Table1", "otherfk2");
- table = mdb.getTable("Table2");
- for(Index idx : table.getIndexes()) {
+ table = (TableImpl)mdb.getTable("Table2");
+ for(IndexImpl idx : table.getIndexes()) {
idx.initialize();
}
assertEquals(3, table.getIndexes().size());
@@ -134,8 +139,8 @@ public class IndexTest extends TestCase {
"PrimaryKey", "id",
".rC", "id");
- Index pkIdx = table.getIndex("PrimaryKey");
- Index fkIdx = table.getIndex(".rC");
+ IndexImpl pkIdx = table.getIndex("PrimaryKey");
+ IndexImpl fkIdx = table.getIndex(".rC");
assertNotSame(pkIdx, fkIdx);
assertTrue(fkIdx.isForeignKey());
assertSame(pkIdx.getIndexData(), fkIdx.getIndexData());
@@ -143,8 +148,8 @@ public class IndexTest extends TestCase {
assertEquals(Arrays.asList(pkIdx, fkIdx), indexData.getIndexes());
assertSame(pkIdx, indexData.getPrimaryIndex());
- table = mdb.getTable("Table3");
- for(Index idx : table.getIndexes()) {
+ table = (TableImpl)mdb.getTable("Table3");
+ for(IndexImpl idx : table.getIndexes()) {
idx.initialize();
}
assertEquals(3, table.getIndexes().size());
@@ -171,8 +176,8 @@ public class IndexTest extends TestCase {
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX)) {
// this file has an index with "compressed" entries and node pages
Database db = open(testDB);
- Table t = db.getTable("Table1");
- Index index = t.getIndexes().get(0);
+ TableImpl t = (TableImpl)db.getTable("Table1");
+ IndexImpl index = t.getIndexes().get(0);
assertFalse(index.isInitialized());
assertEquals(512, countRows(t));
assertEquals(512, index.getIndexData().getEntryCount());
@@ -180,23 +185,12 @@ public class IndexTest extends TestCase {
// copy to temp file and attempt to edit
db = openCopy(testDB);
- t = db.getTable("Table1");
+ t = (TableImpl)db.getTable("Table1");
index = t.getIndexes().get(0);
System.out.println("IndexTest: Index type: " +
index.getIndexData().getClass());
- try {
- t.addRow(99, "abc", "def");
- if(index.getIndexData() instanceof SimpleIndexData) {
- // SimpleIndex doesn't support writing these indexes
- fail("Should have thrown UnsupportedOperationException");
- }
- } catch(UnsupportedOperationException e) {
- // success
- if(index.getIndexData() instanceof BigIndexData) {
- throw e;
- }
- }
+ t.addRow(99, "abc", "def");
}
}
@@ -212,28 +206,28 @@ public class IndexTest extends TestCase {
assertRowCount(12, table);
for(Index index : table.getIndexes()) {
- assertEquals(12, index.getIndexData().getEntryCount());
+ assertEquals(12, ((IndexImpl)index).getIndexData().getEntryCount());
}
table.reset();
table.getNextRow();
table.getNextRow();
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
table.getNextRow();
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
table.getNextRow();
table.getNextRow();
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
table.getNextRow();
table.getNextRow();
table.getNextRow();
- table.deleteCurrentRow();
+ table.getDefaultCursor().deleteCurrentRow();
table.reset();
assertRowCount(8, table);
for(Index index : table.getIndexes()) {
- assertEquals(8, index.getIndexData().getEntryCount());
+ assertEquals(8, ((IndexImpl)index).getIndexData().getEntryCount());
}
}
}
@@ -254,9 +248,9 @@ public class IndexTest extends TestCase {
throws Exception
{
Table orig = db.getTable(tableName);
- Index origI = orig.getIndex("DataIndex");
+ IndexImpl origI = (IndexImpl)orig.getIndex("DataIndex");
Table temp = db.getTable(tableName + "_temp");
- Index tempI = temp.getIndex("DataIndex");
+ IndexImpl tempI = (IndexImpl)temp.getIndex("DataIndex");
// copy from orig table to temp table
for(Map<String,Object> row : orig) {
@@ -266,8 +260,8 @@ public class IndexTest extends TestCase {
assertEquals(origI.getIndexData().getEntryCount(),
tempI.getIndexData().getEntryCount());
- Cursor origC = Cursor.createIndexCursor(orig, origI);
- Cursor tempC = Cursor.createIndexCursor(temp, tempI);
+ Cursor origC = CursorBuilder.createCursor(orig, origI);
+ Cursor tempC = CursorBuilder.createCursor(temp, tempI);
while(true) {
boolean origHasNext = origC.moveToNextRow();
@@ -340,7 +334,7 @@ public class IndexTest extends TestCase {
IOException failure = null;
try {
- index.addRow(row, new RowId(400 + i, 0));
+ ((IndexImpl)index).addRow(row, new RowIdImpl(400 + i, 0));
} catch(IOException e) {
failure = e;
}
@@ -357,8 +351,8 @@ public class IndexTest extends TestCase {
for (final TestDB testDB : SUPPORTED_DBS_TEST) {
Database db = openCopy(testDB);
Table table = db.getTable("Table1");
- Index indA = table.getIndex("PrimaryKey");
- Index indB = table.getIndex("B");
+ IndexImpl indA = (IndexImpl)table.getIndex("PrimaryKey");
+ IndexImpl indB = (IndexImpl)table.getIndex("B");
assertEquals(2, indA.getUniqueEntryCount());
assertEquals(2, indB.getUniqueEntryCount());
@@ -382,8 +376,8 @@ public class IndexTest extends TestCase {
indB = null;
table = db.getTable("Table1");
- indA = table.getIndex("PrimaryKey");
- indB = table.getIndex("B");
+ indA = (IndexImpl)table.getIndex("PrimaryKey");
+ indB = (IndexImpl)table.getIndex("B");
assertEquals(12, indA.getIndexData().getEntryCount());
assertEquals(12, indB.getIndexData().getEntryCount());
@@ -391,7 +385,7 @@ public class IndexTest extends TestCase {
assertEquals(12, indA.getUniqueEntryCount());
assertEquals(8, indB.getUniqueEntryCount());
- Cursor c = Cursor.createCursor(table);
+ Cursor c = CursorBuilder.createCursor(table);
assertTrue(c.moveToNextRow());
final Map<String,Object> row = c.getCurrentRow();
@@ -443,7 +437,7 @@ public class IndexTest extends TestCase {
.toTable(db);
assertEquals(1, t.getIndexes().size());
- Index idx = t.getIndexes().get(0);
+ IndexImpl idx = (IndexImpl)t.getIndexes().get(0);
assertEquals(IndexBuilder.PRIMARY_KEY_NAME, idx.getName());
assertEquals(1, idx.getColumns().size());
@@ -458,7 +452,7 @@ public class IndexTest extends TestCase {
t.addRow(1, "row1");
t.addRow(3, "row3");
- Cursor c = new CursorBuilder(t)
+ Cursor c = t.newCursor()
.setIndexByName(IndexBuilder.PRIMARY_KEY_NAME).toCursor();
for(int i = 1; i <= 3; ++i) {
@@ -478,8 +472,8 @@ public class IndexTest extends TestCase {
Table t2 = db.getTable("Table2");
Table t3 = db.getTable("Table3");
- Index t2t1 = t1.getIndex("Table2Table1");
- Index t3t1 = t1.getIndex("Table3Table1");
+ IndexImpl t2t1 = (IndexImpl)t1.getIndex("Table2Table1");
+ IndexImpl t3t1 = (IndexImpl)t1.getIndex("Table3Table1");
assertTrue(t2t1.isForeignKey());
@@ -498,7 +492,7 @@ public class IndexTest extends TestCase {
Index t1pk = t1.getIndex(IndexBuilder.PRIMARY_KEY_NAME);
assertNotNull(t1pk);
- assertNull(t1pk.getReference());
+ assertNull(((IndexImpl)t1pk).getReference());
assertNull(t1pk.getReferencedIndex());
}
}
@@ -506,7 +500,7 @@ public class IndexTest extends TestCase {
private void doCheckForeignKeyIndex(Table ta, Index ia, Table tb)
throws Exception
{
- Index ib = ia.getReferencedIndex();
+ IndexImpl ib = (IndexImpl)ia.getReferencedIndex();
assertNotNull(ib);
assertSame(tb, ib.getTable());
diff --git a/test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java b/test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java
index fccbc67..8cd5a55 100644
--- a/test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java
@@ -26,10 +26,13 @@ import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
-
+import com.healthmarketscience.jackcess.impl.PropertyMapImpl;
+import com.healthmarketscience.jackcess.impl.PropertyMaps;
import static com.healthmarketscience.jackcess.Database.*;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.TableImpl;
+import com.healthmarketscience.jackcess.impl.DatabaseImpl;
/**
* @author James Ahlborn
@@ -49,12 +52,12 @@ public class PropertiesTest extends TestCase
assertFalse(maps.iterator().hasNext());
assertEquals(10, maps.getObjectId());
- PropertyMap defMap = maps.getDefault();
+ PropertyMapImpl defMap = maps.getDefault();
assertTrue(defMap.isEmpty());
assertEquals(0, defMap.getSize());
assertFalse(defMap.iterator().hasNext());
- PropertyMap colMap = maps.get("testcol");
+ PropertyMapImpl colMap = maps.get("testcol");
assertTrue(colMap.isEmpty());
assertEquals(0, colMap.getSize());
assertFalse(colMap.iterator().hasNext());
@@ -105,7 +108,7 @@ public class PropertiesTest extends TestCase
for(TestDB testDb : SUPPORTED_DBS_TEST_FOR_READ) {
Database db = open(testDb);
- Table t = db.getTable("Table1");
+ TableImpl t = (TableImpl)db.getTable("Table1");
assertEquals(t.getTableDefPageNumber(),
t.getPropertyMaps().getObjectId());
PropertyMap tProps = t.getProperties();
@@ -186,10 +189,10 @@ public class PropertiesTest extends TestCase
assertTrue(((String)dbProps.getValue(PropertyMap.ACCESS_VERSION_PROP))
.matches("[0-9]{2}[.][0-9]{2}"));
- for(Map<String,Object> row : db.getSystemCatalog()) {
+ for(Map<String,Object> row : ((DatabaseImpl)db).getSystemCatalog()) {
int id = (Integer)row.get("Id");
byte[] propBytes = (byte[])row.get("LvProp");
- PropertyMaps propMaps = db.getPropertiesForObject(id);
+ PropertyMaps propMaps = ((DatabaseImpl)db).getPropertiesForObject(id);
int byteLen = ((propBytes != null) ? propBytes.length : 0);
if(byteLen == 0) {
assertTrue(propMaps.isEmpty());
diff --git a/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java b/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java
index e49b9bb..e2162c3 100644
--- a/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java
@@ -34,7 +34,8 @@ import java.util.Comparator;
import java.util.List;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import com.healthmarketscience.jackcess.impl.RelationshipImpl;
import junit.framework.TestCase;
/**
@@ -47,7 +48,7 @@ public class RelationshipTest extends TestCase {
return String.CASE_INSENSITIVE_ORDER.compare(r1.getName(), r2.getName());
}
};
-
+
public RelationshipTest(String name) throws Exception {
super(name);
}
@@ -70,7 +71,7 @@ public class RelationshipTest extends TestCase {
assertEquals(Arrays.asList(t1.getColumn("otherfk1")),
rel.getToColumns());
assertTrue(rel.hasReferentialIntegrity());
- assertEquals(4096, rel.getFlags());
+ assertEquals(4096, ((RelationshipImpl)rel).getFlags());
assertTrue(rel.cascadeDeletes());
assertSameRelationships(rels, db.getRelationships(t2, t1), true);
@@ -89,7 +90,7 @@ public class RelationshipTest extends TestCase {
assertEquals(Arrays.asList(t1.getColumn("otherfk2")),
rel.getToColumns());
assertTrue(rel.hasReferentialIntegrity());
- assertEquals(256, rel.getFlags());
+ assertEquals(256, ((RelationshipImpl)rel).getFlags());
assertTrue(rel.cascadeUpdates());
assertSameRelationships(rels, db.getRelationships(t3, t1), true);
diff --git a/test/src/java/com/healthmarketscience/jackcess/TableTest.java b/test/src/java/com/healthmarketscience/jackcess/TableTest.java
index 146d42d..b70c045 100644
--- a/test/src/java/com/healthmarketscience/jackcess/TableTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/TableTest.java
@@ -36,6 +36,10 @@ import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;
+import com.healthmarketscience.jackcess.impl.ColumnImpl;
+import com.healthmarketscience.jackcess.impl.JetFormat;
+import com.healthmarketscience.jackcess.impl.PageChannel;
+import com.healthmarketscience.jackcess.impl.TableImpl;
import junit.framework.TestCase;
/**
@@ -43,24 +47,29 @@ import junit.framework.TestCase;
*/
public class TableTest extends TestCase {
- private final PageChannel _pageChannel = new PageChannel(true);
- private List<Column> _columns = new ArrayList<Column>();
- private Table _testTable;
+ private final PageChannel _pageChannel = new PageChannel(true) {};
+ private List<ColumnImpl> _columns = new ArrayList<ColumnImpl>();
+ private TableImpl _testTable;
+ private int _varLenIdx;
+ private int _fixedOffset;
+
public TableTest(String name) {
super(name);
}
+
+ private void reset() {
+ _testTable = null;
+ _columns = new ArrayList<ColumnImpl>();
+ _varLenIdx = 0;
+ _fixedOffset = 0;
+ }
public void testCreateRow() throws Exception {
- Column col = newTestColumn();
- col.setType(DataType.INT);
- _columns.add(col);
- col = newTestColumn();
- col.setType(DataType.TEXT);
- _columns.add(col);
- col = newTestColumn();
- col.setType(DataType.TEXT);
- _columns.add(col);
+ reset();
+ newTestColumn(DataType.INT, false);
+ newTestColumn(DataType.TEXT, false);
+ newTestColumn(DataType.TEXT, false);
newTestTable();
int colCount = _columns.size();
@@ -77,13 +86,9 @@ public class TableTest extends TestCase {
}
public void testUnicodeCompression() throws Exception {
- Column col = newTestColumn();
- col = newTestColumn();
- col.setType(DataType.TEXT);
- _columns.add(col);
- col = newTestColumn();
- col.setType(DataType.MEMO);
- _columns.add(col);
+ reset();
+ newTestColumn(DataType.TEXT, false);
+ newTestColumn(DataType.MEMO, false);
newTestTable();
String small = "this is a string";
@@ -94,9 +99,10 @@ public class TableTest extends TestCase {
ByteBuffer[] buf1 = encodeColumns(small, large);
ByteBuffer[] buf2 = encodeColumns(smallNotAscii, largeNotAscii);
- for(Column tmp : _columns) {
- tmp.setCompressedUnicode(true);
- }
+ reset();
+ newTestColumn(DataType.TEXT, true);
+ newTestColumn(DataType.MEMO, true);
+ newTestTable();
ByteBuffer[] bufCmp1 = encodeColumns(small, large);
ByteBuffer[] bufCmp2 = encodeColumns(smallNotAscii, largeNotAscii);
@@ -129,7 +135,7 @@ public class TableTest extends TestCase {
{
ByteBuffer[] result = new ByteBuffer[_columns.size()];
for(int i = 0; i < _columns.size(); ++i) {
- Column col = _columns.get(i);
+ ColumnImpl col = _columns.get(i);
result[i] = col.write(row[i], _testTable.getFormat().MAX_ROW_SIZE);
}
return result;
@@ -140,7 +146,7 @@ public class TableTest extends TestCase {
{
Object[] result = new Object[_columns.size()];
for(int i = 0; i < _columns.size(); ++i) {
- Column col = _columns.get(i);
+ ColumnImpl col = _columns.get(i);
result[i] = col.read(toBytes(buffers[i]));
}
return result;
@@ -153,10 +159,10 @@ public class TableTest extends TestCase {
return b;
}
- private Table newTestTable()
+ private TableImpl newTestTable()
throws Exception
{
- _testTable = new Table(true, _columns) {
+ _testTable = new TableImpl(true, _columns) {
@Override
public PageChannel getPageChannel() {
return _pageChannel;
@@ -169,10 +175,22 @@ public class TableTest extends TestCase {
return _testTable;
}
- private Column newTestColumn() {
- return new Column(true, null) {
+ private void newTestColumn(DataType type, final boolean compressedUnicode) {
+
+ int nextColIdx = _columns.size();
+ int nextVarLenIdx = 0;
+ int nextFixedOff = 0;
+
+ if(type.isVariableLength()) {
+ nextVarLenIdx = _varLenIdx++;
+ } else {
+ nextFixedOff = _fixedOffset;
+ _fixedOffset += type.getFixedSize();
+ }
+
+ ColumnImpl col = new ColumnImpl(null, type, nextColIdx, nextFixedOff, nextVarLenIdx) {
@Override
- public Table getTable() {
+ public TableImpl getTable() {
return _testTable;
}
@Override
@@ -184,14 +202,20 @@ public class TableTest extends TestCase {
return getTable().getPageChannel();
}
@Override
- Charset getCharset() {
+ protected Charset getCharset() {
return getFormat().CHARSET;
}
@Override
- Calendar getCalendar() {
+ protected Calendar getCalendar() {
return Calendar.getInstance();
}
+ @Override
+ public boolean isCompressedUnicode() {
+ return compressedUnicode;
+ }
};
+
+ _columns.add(col);
}
}
diff --git a/test/src/java/com/healthmarketscience/jackcess/CodecHandlerTest.java b/test/src/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java
index edcbf09..47a832a 100644
--- a/test/src/java/com/healthmarketscience/jackcess/CodecHandlerTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java
@@ -25,7 +25,7 @@ Suite 200
King of Prussia, PA 19406
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.impl;
import java.io.File;
import java.io.IOException;
@@ -36,7 +36,18 @@ import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import com.healthmarketscience.jackcess.ColumnBuilder;
+import com.healthmarketscience.jackcess.Cursor;
+import com.healthmarketscience.jackcess.CursorBuilder;
+import com.healthmarketscience.jackcess.DataType;
+import com.healthmarketscience.jackcess.Database;
+import com.healthmarketscience.jackcess.DatabaseBuilder;
+import com.healthmarketscience.jackcess.DatabaseTest;
+import com.healthmarketscience.jackcess.DatabaseTest;
+import com.healthmarketscience.jackcess.IndexBuilder;
+import com.healthmarketscience.jackcess.Table;
+import com.healthmarketscience.jackcess.TableBuilder;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
import junit.framework.TestCase;
/**
@@ -75,7 +86,7 @@ public class CodecHandlerTest extends TestCase
{
for(Database.FileFormat ff : SUPPORTED_FILEFORMATS) {
Database db = DatabaseTest.create(ff);
- int pageSize = db.getFormat().PAGE_SIZE;
+ int pageSize = ((DatabaseImpl)db).getFormat().PAGE_SIZE;
File dbFile = db.getFile();
db.close();
@@ -118,13 +129,13 @@ public class CodecHandlerTest extends TestCase
t2.addRow(null, "rowdata-" + i + DatabaseTest.createString(100));
}
- Cursor c1 = new CursorBuilder(t1).setIndex(t1.getPrimaryKeyIndex())
+ Cursor c1 = t1.newCursor().setIndex(t1.getPrimaryKeyIndex())
.toCursor();
- Cursor c2 = new CursorBuilder(t2).setIndex(t2.getPrimaryKeyIndex())
+ Cursor c2 = t2.newCursor().setIndex(t2.getPrimaryKeyIndex())
.toCursor();
- Iterator<Map<String,Object>> i1 = c1.iterator();
- Iterator<Map<String,Object>> i2 = c2.reverseIterable().iterator();
+ Iterator<? extends Map<String,Object>> i1 = c1.iterator();
+ Iterator<? extends Map<String,Object>> i2 = c2.newIterable().reverse().iterator();
int t1rows = 0;
int t2rows = 0;
@@ -225,9 +236,16 @@ public class CodecHandlerTest extends TestCase
public boolean canEncodePartialPage() {
return true;
}
+
+ public boolean canDecodeInline() {
+ return true;
+ }
- public void decodePage(ByteBuffer page, int pageNumber) throws IOException {
- byte[] arr = page.array();
+ public void decodePage(ByteBuffer inPage, ByteBuffer outPage,
+ int pageNumber)
+ throws IOException
+ {
+ byte[] arr = inPage.array();
simpleDecode(arr, arr, pageNumber);
}
@@ -256,9 +274,16 @@ public class CodecHandlerTest extends TestCase
public boolean canEncodePartialPage() {
return false;
}
+
+ public boolean canDecodeInline() {
+ return true;
+ }
- public void decodePage(ByteBuffer page, int pageNumber) throws IOException {
- byte[] arr = page.array();
+ public void decodePage(ByteBuffer inPage, ByteBuffer outPage,
+ int pageNumber)
+ throws IOException
+ {
+ byte[] arr = inPage.array();
fullDecode(arr, arr, pageNumber);
}
diff --git a/test/src/java/com/healthmarketscience/jackcess/FKEnforcerTest.java b/test/src/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java
index 9dd0c88..7ea3123 100644
--- a/test/src/java/com/healthmarketscience/jackcess/FKEnforcerTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java
@@ -17,15 +17,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.impl;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import com.healthmarketscience.jackcess.Column;
+import com.healthmarketscience.jackcess.Cursor;
+import com.healthmarketscience.jackcess.CursorBuilder;
+import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import com.healthmarketscience.jackcess.Row;
+import com.healthmarketscience.jackcess.Table;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
import junit.framework.TestCase;
/**
@@ -43,17 +49,18 @@ public class FKEnforcerTest extends TestCase
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {
Database db = openCopy(testDB);
+ db.setEnforceForeignKeys(false);
Table t1 = db.getTable("Table1");
Table t2 = db.getTable("Table2");
Table t3 = db.getTable("Table3");
t1.addRow(20, 0, 20, "some data", 20);
- Cursor c = Cursor.createCursor(t2);
+ Cursor c = CursorBuilder.createCursor(t2);
c.moveToNextRow();
c.updateCurrentRow(30, "foo30");
- c = Cursor.createCursor(t3);
+ c = CursorBuilder.createCursor(t3);
c.moveToNextRow();
c.deleteCurrentRow();
@@ -66,7 +73,6 @@ public class FKEnforcerTest extends TestCase
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {
Database db = openCopy(testDB);
- db.setEnforceForeignKeys(true);
Table t1 = db.getTable("Table1");
Table t2 = db.getTable("Table2");
Table t3 = db.getTable("Table3");
@@ -80,7 +86,7 @@ public class FKEnforcerTest extends TestCase
}
try {
- Cursor c = Cursor.createCursor(t2);
+ Cursor c = CursorBuilder.createCursor(t2);
c.moveToNextRow();
c.updateCurrentRow(30, "foo30");
fail("IOException should have been thrown");
@@ -90,7 +96,7 @@ public class FKEnforcerTest extends TestCase
}
try {
- Cursor c = Cursor.createCursor(t3);
+ Cursor c = CursorBuilder.createCursor(t3);
c.moveToNextRow();
c.deleteCurrentRow();
fail("IOException should have been thrown");
@@ -99,7 +105,7 @@ public class FKEnforcerTest extends TestCase
assertTrue(ignored.getMessage().contains("Table3[id]"));
}
- Cursor c = Cursor.createCursor(t3);
+ Cursor c = CursorBuilder.createCursor(t3);
Column col = t3.getColumn("id");
for(Map<String,Object> row : c) {
int id = (Integer)row.get("id");
@@ -107,7 +113,7 @@ public class FKEnforcerTest extends TestCase
c.setCurrentRowValue(col, id);
}
- List<Map<String, Object>> expectedRows =
+ List<? extends Map<String, Object>> expectedRows =
createExpectedTable(
createT1Row(0, 0, 30, "baz0", 0),
createT1Row(1, 1, 31, "baz11", 0),
@@ -116,7 +122,7 @@ public class FKEnforcerTest extends TestCase
assertTable(expectedRows, t1);
- c = Cursor.createCursor(t2);
+ c = CursorBuilder.createCursor(t2);
for(Iterator<?> iter = c.iterator(); iter.hasNext(); ) {
iter.next();
iter.remove();
@@ -129,7 +135,7 @@ public class FKEnforcerTest extends TestCase
}
- private static Map<String,Object> createT1Row(
+ private static Row createT1Row(
int id1, int fk1, int fk2, String data, int fk3)
{
return createExpectedRow("id", id1, "otherfk1", fk1, "otherfk2", fk2,
diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexCodesTest.java b/test/src/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java
index ed71ebe..56f9096 100644
--- a/test/src/java/com/healthmarketscience/jackcess/IndexCodesTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java
@@ -25,7 +25,7 @@ Suite 200
King of Prussia, PA 19406
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.impl;
import java.io.File;
import java.lang.reflect.Field;
@@ -37,11 +37,17 @@ import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import junit.framework.TestCase;
-
+import com.healthmarketscience.jackcess.ColumnBuilder;
+import com.healthmarketscience.jackcess.Cursor;
+import com.healthmarketscience.jackcess.CursorBuilder;
+import com.healthmarketscience.jackcess.DataType;
+import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
-
+import com.healthmarketscience.jackcess.Index;
+import com.healthmarketscience.jackcess.Table;
+import com.healthmarketscience.jackcess.TableBuilder;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import junit.framework.TestCase;
/**
* @author James Ahlborn
@@ -86,7 +92,7 @@ public class IndexCodesTest extends TestCase {
// index.initialize();
// System.out.println("Ind " + index);
- Cursor cursor = Cursor.createIndexCursor(t, index);
+ Cursor cursor = CursorBuilder.createCursor(t, index);
while(cursor.moveToNextRow()) {
Map<String,Object> row = cursor.getCurrentRow();
@@ -111,8 +117,8 @@ public class IndexCodesTest extends TestCase {
Cursor.Position expectedPos)
throws Exception
{
- Object[] idxRow = index.constructIndexRow(expectedRow);
- Cursor cursor = Cursor.createIndexCursor(t, index, idxRow, idxRow);
+ Object[] idxRow = ((IndexImpl)index).constructIndexRow(expectedRow);
+ Cursor cursor = CursorBuilder.createCursor(t, index, idxRow, idxRow);
Cursor.Position startPos = cursor.getSavepoint().getCurrentPosition();
@@ -258,11 +264,11 @@ public class IndexCodesTest extends TestCase {
Table t = db.getTable("Table5");
Index ind = t.getIndexes().iterator().next();
- ind.initialize();
+ ((IndexImpl)ind).initialize();
System.out.println("Ind " + ind);
- Cursor cursor = Cursor.createIndexCursor(t, ind);
+ Cursor cursor = CursorBuilder.createCursor(t, ind);
while(cursor.moveToNextRow()) {
System.out.println("=======");
String entryStr =
@@ -311,10 +317,10 @@ public class IndexCodesTest extends TestCase {
Table t = db.getTable("Table1");
Index index = t.getIndex("B");
- index.initialize();
+ ((IndexImpl)index).initialize();
System.out.println("Ind " + index);
- Cursor cursor = Cursor.createIndexCursor(t, index);
+ Cursor cursor = CursorBuilder.createCursor(t, index);
while(cursor.moveToNextRow()) {
System.out.println("=======");
System.out.println("Savepoint: " + cursor.getSavepoint());
@@ -330,7 +336,7 @@ public class IndexCodesTest extends TestCase {
Table t = db.getTable("Table1");
Index index = t.getIndexes().iterator().next();
- index.initialize();
+ ((IndexImpl)index).initialize();
System.out.println("Ind " + index);
Pattern inlinePat = Pattern.compile("7F 0E 02 0E 02 (.*)0E 02 0E 02 01 00");
@@ -349,7 +355,7 @@ public class IndexCodesTest extends TestCase {
Map<Character,String[]> inat2CrazyCodes = new TreeMap<Character,String[]>();
- Cursor cursor = Cursor.createIndexCursor(t, index);
+ Cursor cursor = CursorBuilder.createCursor(t, index);
while(cursor.moveToNextRow()) {
// System.out.println("=======");
// System.out.println("Savepoint: " + cursor.getSavepoint());
@@ -509,7 +515,7 @@ public class IndexCodesTest extends TestCase {
Table t = db.getTable("Table1");
Index index = t.getIndexes().iterator().next();
- index.initialize();
+ ((IndexImpl)index).initialize();
System.out.println("Ind " + index);
Pattern inlinePat = Pattern.compile("7F 4A 4A (.*)4A 4A 01 00");
@@ -528,7 +534,7 @@ public class IndexCodesTest extends TestCase {
Map<Character,String[]> inat2CrazyCodes = new TreeMap<Character,String[]>();
- Cursor cursor = Cursor.createIndexCursor(t, index);
+ Cursor cursor = CursorBuilder.createCursor(t, index);
while(cursor.moveToNextRow()) {
// System.out.println("=======");
// System.out.println("Savepoint: " + cursor.getSavepoint());
@@ -774,7 +780,7 @@ public class IndexCodesTest extends TestCase {
return builder.toString();
}
- static String entryToString(Cursor.Position curPos)
+ public static String entryToString(Cursor.Position curPos)
throws Exception
{
Field eField = curPos.getClass().getDeclaredField("_entry");
diff --git a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java b/test/src/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
index 9c75b6d..962a6f0 100644
--- a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
@@ -1,4 +1,4 @@
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.impl;
import java.io.File;
import java.io.IOException;
@@ -8,10 +8,12 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Set;
-import junit.framework.TestCase;
-
+import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.Database.*;
+import com.healthmarketscience.jackcess.DatabaseBuilder;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
+import junit.framework.TestCase;
+
/**
* @author Dan Rollo
@@ -20,7 +22,7 @@ import static com.healthmarketscience.jackcess.DatabaseTest.*;
*/
public class JetFormatTest extends TestCase {
- static final File DIR_TEST_DATA = new File("test/data");
+ public static final File DIR_TEST_DATA = new File("test/data");
/**
* Defines known valid db test file base names.
@@ -59,8 +61,8 @@ public class JetFormatTest extends TestCase {
/** Defines currently supported db file formats. (can be modified at
runtime via the system property
"com.healthmarketscience.jackcess.testFormats") */
- final static FileFormat[] SUPPORTED_FILEFORMATS;
- final static FileFormat[] SUPPORTED_FILEFORMATS_FOR_READ;
+ public final static FileFormat[] SUPPORTED_FILEFORMATS;
+ public final static FileFormat[] SUPPORTED_FILEFORMATS_FOR_READ;
static {
String testFormatStr = System.getProperty("com.healthmarketscience.jackcess.testFormats");
@@ -79,7 +81,8 @@ public class JetFormatTest extends TestCase {
continue;
}
supportedForRead.add(ff);
- if(ff.getJetFormat().READ_ONLY || (ff == FileFormat.MSISAM)) {
+ if(DatabaseImpl.getFileFormatDetails(ff).getFormat().READ_ONLY ||
+ (ff == FileFormat.MSISAM)) {
continue;
}
supported.add(ff);
@@ -112,7 +115,7 @@ public class JetFormatTest extends TestCase {
}
public final JetFormat getExpectedFormat() {
- return expectedFileFormat.getJetFormat();
+ return DatabaseImpl.getFileFormatDetails(expectedFileFormat).getFormat();
}
@Override
@@ -139,7 +142,7 @@ public class JetFormatTest extends TestCase {
// verify that the db is the file format expected
try {
- Database db = Database.open(testFile, true);
+ Database db = new DatabaseBuilder(testFile).setReadOnly(true).open();
FileFormat dbFileFormat = db.getFileFormat();
db.close();
if(dbFileFormat != fileFormat) {
@@ -165,9 +168,9 @@ public class JetFormatTest extends TestCase {
}
}
- static final List<TestDB> SUPPORTED_DBS_TEST =
+ public static final List<TestDB> SUPPORTED_DBS_TEST =
TestDB.getSupportedForBasename(Basename.TEST);
- static final List<TestDB> SUPPORTED_DBS_TEST_FOR_READ =
+ public static final List<TestDB> SUPPORTED_DBS_TEST_FOR_READ =
TestDB.getSupportedForBasename(Basename.TEST, true);
@@ -181,13 +184,13 @@ public class JetFormatTest extends TestCase {
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
- final FileChannel channel = Database.openChannel(testDB.dbFile, false);
+ final FileChannel channel = DatabaseImpl.openChannel(testDB.dbFile, false);
try {
JetFormat fmtActual = JetFormat.getFormat(channel);
assertEquals("Unexpected JetFormat for dbFile: " +
testDB.dbFile.getAbsolutePath(),
- testDB.expectedFileFormat.getJetFormat(), fmtActual);
+ testDB.getExpectedFormat(), fmtActual);
} finally {
channel.close();
diff --git a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java b/test/src/java/com/healthmarketscience/jackcess/impl/UsageMapTest.java
index 87fa5c3..aad1ddf 100644
--- a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/impl/UsageMapTest.java
@@ -1,11 +1,12 @@
-package com.healthmarketscience.jackcess;
-
-import junit.framework.TestCase;
+package com.healthmarketscience.jackcess.impl;
import java.io.File;
import java.io.IOException;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import com.healthmarketscience.jackcess.Database;
+import com.healthmarketscience.jackcess.DatabaseBuilder;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
+import junit.framework.TestCase;
/**
* @author Dan Rollo
@@ -42,8 +43,8 @@ public final class UsageMapTest extends TestCase {
final int expectedFirstPage, final int expectedLastPage)
throws IOException {
- final Database db = Database.open(dbFile);
- final UsageMap usageMap = UsageMap.read(db,
+ final Database db = DatabaseBuilder.open(dbFile);
+ final UsageMap usageMap = UsageMap.read((DatabaseImpl)db,
PageChannel.PAGE_GLOBAL_USAGE_MAP,
PageChannel.ROW_GLOBAL_USAGE_MAP,
true);
diff --git a/test/src/java/com/healthmarketscience/jackcess/scsu/CompressMain.java b/test/src/java/com/healthmarketscience/jackcess/impl/scsu/CompressMain.java
index af3063d..52b9e86 100644
--- a/test/src/java/com/healthmarketscience/jackcess/scsu/CompressMain.java
+++ b/test/src/java/com/healthmarketscience/jackcess/impl/scsu/CompressMain.java
@@ -1,4 +1,4 @@
-package com.healthmarketscience.jackcess.scsu;
+package com.healthmarketscience.jackcess.impl.scsu;
import java.io.*;
import java.util.*;
diff --git a/test/src/java/com/healthmarketscience/jackcess/scsu/CompressTest.java b/test/src/java/com/healthmarketscience/jackcess/impl/scsu/CompressTest.java
index 0f17e6c..b9dc13a 100644
--- a/test/src/java/com/healthmarketscience/jackcess/scsu/CompressTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/impl/scsu/CompressTest.java
@@ -25,7 +25,7 @@ Suite 200
King of Prussia, PA 19406
*/
-package com.healthmarketscience.jackcess.scsu;
+package com.healthmarketscience.jackcess.impl.scsu;
import junit.framework.TestCase;
diff --git a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
index 73d91b7..015f2fc 100644
--- a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
@@ -37,14 +37,15 @@ import java.util.Map;
import com.healthmarketscience.jackcess.DataType;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseTest;
-import com.healthmarketscience.jackcess.query.Query.Row;
+import com.healthmarketscience.jackcess.impl.query.QueryImpl;
+import com.healthmarketscience.jackcess.impl.query.QueryImpl.Row;
import junit.framework.TestCase;
import org.apache.commons.lang.StringUtils;
import static org.apache.commons.lang.SystemUtils.LINE_SEPARATOR;
-import static com.healthmarketscience.jackcess.query.QueryFormat.*;
+import static com.healthmarketscience.jackcess.impl.query.QueryFormat.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
/**
@@ -169,7 +170,7 @@ public class QueryTest extends TestCase
{
List<Row> rowList = new ArrayList<Row>();
rowList.add(newRow(TYPE_ATTRIBUTE, null, -1, null, null));
- Query query = Query.create(-1, "TestQuery", rowList, 13);
+ QueryImpl query = QueryImpl.create(-1, "TestQuery", rowList, 13);
try {
query.toSQLString();
fail("UnsupportedOperationException should have been thrown");
@@ -187,7 +188,7 @@ public class QueryTest extends TestCase
}
try {
- new Query("TestQuery", rowList, 13, Query.Type.UNION) {
+ new QueryImpl("TestQuery", rowList, 13, Query.Type.UNION) {
@Override protected void toSQLString(StringBuilder builder) {
throw new UnsupportedOperationException();
}};
@@ -468,7 +469,7 @@ public class QueryTest extends TestCase
rowList.add(newRow(TYPE_ATTRIBUTE, typeExpr, type.getValue(),
null, typeName1, null));
rowList.addAll(Arrays.asList(rows));
- return Query.create(type.getObjectFlag(), "TestQuery", rowList, 13);
+ return QueryImpl.create(type.getObjectFlag(), "TestQuery", rowList, 13);
}
private static Row newRow(Byte attr, String expr, String name1, String name2)
@@ -487,7 +488,7 @@ public class QueryTest extends TestCase
{
Short flag = ((flagNum != null) ? flagNum.shortValue() : null);
Integer extra = ((extraNum != null) ? extraNum.intValue() : null);
- return new Row(attr, expr, flag, extra, name1, name2, null, null);
+ return new Row(null, attr, expr, flag, extra, name1, name2, null, null);
}
private static void setFlag(Query query, Number newFlagNum)
@@ -498,7 +499,7 @@ public class QueryTest extends TestCase
private static void addRows(Query query, Row... rows)
{
- query.getRows().addAll(Arrays.asList(rows));
+ ((QueryImpl)query).getRows().addAll(Arrays.asList(rows));
}
private static void replaceRows(Query query, Row... rows)
@@ -509,7 +510,7 @@ public class QueryTest extends TestCase
private static void removeRows(Query query, Byte attr)
{
- for(Iterator<Row> iter = query.getRows().iterator(); iter.hasNext(); ) {
+ for(Iterator<Row> iter = ((QueryImpl)query).getRows().iterator(); iter.hasNext(); ) {
if(attr.equals(iter.next().attribute)) {
iter.remove();
}
@@ -518,7 +519,7 @@ public class QueryTest extends TestCase
private static void removeLastRows(Query query, int num)
{
- List<Row> rows = query.getRows();
+ List<Row> rows = ((QueryImpl)query).getRows();
int size = rows.size();
rows.subList(size - num, size).clear();
}
diff --git a/test/src/java/com/healthmarketscience/jackcess/ErrorHandlerTest.java b/test/src/java/com/healthmarketscience/jackcess/util/ErrorHandlerTest.java
index afffdd5..6431ad8 100644
--- a/test/src/java/com/healthmarketscience/jackcess/ErrorHandlerTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/util/ErrorHandlerTest.java
@@ -25,7 +25,7 @@ Suite 200
King of Prussia, PA 19406
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.util;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -33,10 +33,20 @@ import java.lang.reflect.Modifier;
import java.nio.ByteOrder;
import java.util.List;
-import junit.framework.TestCase;
-
+import com.healthmarketscience.jackcess.Column;
+import com.healthmarketscience.jackcess.ColumnBuilder;
+import com.healthmarketscience.jackcess.Cursor;
+import com.healthmarketscience.jackcess.CursorBuilder;
+import com.healthmarketscience.jackcess.DataType;
+import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.Database.*;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
+import com.healthmarketscience.jackcess.Table;
+import com.healthmarketscience.jackcess.TableBuilder;
+import com.healthmarketscience.jackcess.impl.ColumnImpl;
+import com.healthmarketscience.jackcess.impl.JetFormatTest;
+import com.healthmarketscience.jackcess.impl.TableImpl;
+import junit.framework.TestCase;
/**
* @author James Ahlborn
@@ -95,12 +105,12 @@ public class ErrorHandlerTest extends TestCase
"val", null)),
table);
- Cursor c1 = Cursor.createCursor(table);
- Cursor c2 = Cursor.createCursor(table);
- Cursor c3 = Cursor.createCursor(table);
+ Cursor c1 = CursorBuilder.createCursor(table);
+ Cursor c2 = CursorBuilder.createCursor(table);
+ Cursor c3 = CursorBuilder.createCursor(table);
c2.setErrorHandler(new DebugErrorHandler("#error"));
- c3.setErrorHandler(Database.DEFAULT_ERROR_HANDLER);
+ c3.setErrorHandler(ErrorHandler.DEFAULT);
assertCursor(createExpectedTable(
createExpectedRow("col", "row1",
@@ -143,14 +153,15 @@ public class ErrorHandlerTest extends TestCase
}
@SuppressWarnings("unchecked")
- private void replaceColumn(Table t, String colName) throws Exception
+ private static void replaceColumn(Table t, String colName) throws Exception
{
- Field colsField = Table.class.getDeclaredField("_columns");
+ Field colsField = TableImpl.class.getDeclaredField("_columns");
colsField.setAccessible(true);
List<Column> cols = (List<Column>)colsField.get(t);
Column srcCol = null;
- Column destCol = new BogusColumn(t);
+ ColumnImpl destCol = new BogusColumn(t);
+ destCol.setName(colName);
for(int i = 0; i < cols.size(); ++i) {
srcCol = cols.get(i);
if(srcCol.getName().equals(colName)) {
@@ -169,10 +180,10 @@ public class ErrorHandlerTest extends TestCase
}
- private static class BogusColumn extends Column
+ private static class BogusColumn extends ColumnImpl
{
private BogusColumn(Table table) {
- super(true, table);
+ super((TableImpl)table, DataType.LONG, 1, 0, 0);
}
@Override
diff --git a/test/src/java/com/healthmarketscience/jackcess/ExportTest.java b/test/src/java/com/healthmarketscience/jackcess/util/ExportTest.java
index 7046b8b..a271771 100644
--- a/test/src/java/com/healthmarketscience/jackcess/ExportTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/util/ExportTest.java
@@ -25,19 +25,24 @@ Suite 200
King of Prussia, PA 19406
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.util;
import java.io.BufferedWriter;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-
-import junit.framework.TestCase;
-import org.apache.commons.lang.SystemUtils;
import java.util.Date;
+import com.healthmarketscience.jackcess.ColumnBuilder;
+import com.healthmarketscience.jackcess.DataType;
+import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.Database.*;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
+import com.healthmarketscience.jackcess.Table;
+import com.healthmarketscience.jackcess.TableBuilder;
+import com.healthmarketscience.jackcess.impl.JetFormatTest;
+import junit.framework.TestCase;
+import org.apache.commons.lang.SystemUtils;
/**
*
diff --git a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java b/test/src/java/com/healthmarketscience/jackcess/util/ImportTest.java
index 0be36e1..49be97c 100644
--- a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/util/ImportTest.java
@@ -25,7 +25,7 @@ Suite 200
King of Prussia, PA 19406
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.util;
import java.io.File;
import java.lang.reflect.InvocationHandler;
@@ -39,10 +39,16 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
+import com.healthmarketscience.jackcess.Column;
+import com.healthmarketscience.jackcess.ColumnBuilder;
+import com.healthmarketscience.jackcess.DataType;
+import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.Database.*;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
+import com.healthmarketscience.jackcess.Table;
+import com.healthmarketscience.jackcess.TableBuilder;
+import com.healthmarketscience.jackcess.impl.JetFormatTest;
+import junit.framework.TestCase;
/**
* @author Rob Di Marco
@@ -69,7 +75,7 @@ public class ImportTest extends TestCase
}
assertEquals(Arrays.asList("Test1", "Test2", "Test3"), colNames);
- List<Map<String, Object>> expectedRows =
+ List<? extends Map<String, Object>> expectedRows =
createExpectedTable(
createExpectedRow(
"Test1", "Foo",
@@ -221,13 +227,13 @@ public class ImportTest extends TestCase
rs.addColumn(Types.VARCHAR, "col7", Integer.MAX_VALUE, 0, 0);
Database db = create(fileFormat);
- db.copyTable("Test1", (ResultSet)Proxy.newProxyInstance(
+ ImportUtil.importResultSet((ResultSet)Proxy.newProxyInstance(
Thread.currentThread().getContextClassLoader(),
new Class[]{ResultSet.class},
- rs));
+ rs), db, "Test1");
Table t = db.getTable("Test1");
- List<Column> columns = t.getColumns();
+ List<? extends Column> columns = t.getColumns();
assertEquals(7, columns.size());
Column c = columns.get(0);
diff --git a/test/src/java/com/healthmarketscience/jackcess/JoinerTest.java b/test/src/java/com/healthmarketscience/jackcess/util/JoinerTest.java
index d2049c3..975b4fb 100644
--- a/test/src/java/com/healthmarketscience/jackcess/JoinerTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/util/JoinerTest.java
@@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.util;
import java.util.ArrayList;
import java.util.Arrays;
@@ -27,8 +27,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
-import static com.healthmarketscience.jackcess.JetFormatTest.*;
+import com.healthmarketscience.jackcess.Index;
+import com.healthmarketscience.jackcess.Row;
+import com.healthmarketscience.jackcess.Table;
+import com.healthmarketscience.jackcess.impl.RowImpl;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
import junit.framework.TestCase;
/**
@@ -80,23 +85,23 @@ public class JoinerTest extends TestCase {
}
private static void doTestJoiner(
- Joiner join, Map<Integer,List<Map<String,Object>>> expectedData)
+ Joiner join, Map<Integer,List<Row>> expectedData)
throws Exception
{
final Set<String> colNames = new HashSet<String>(
Arrays.asList("id", "data"));
Joiner revJoin = join.createReverse();
- for(Map<String,Object> row : join.getFromTable()) {
+ for(Row row : join.getFromTable()) {
Integer id = (Integer)row.get("id");
- List<Map<String,Object>> joinedRows =
- new ArrayList<Map<String,Object>>();
- for(Map<String,Object> t1Row : join.findRowsIterable(row)) {
+ List<Row> joinedRows =
+ new ArrayList<Row>();
+ for(Row t1Row : join.findRowsIterable(row)) {
joinedRows.add(t1Row);
}
- List<Map<String,Object>> expectedRows = expectedData.get(id);
+ List<Row> expectedRows = expectedData.get(id);
assertEquals(expectedData.get(id), joinedRows);
if(!expectedRows.isEmpty()) {
@@ -109,16 +114,15 @@ public class JoinerTest extends TestCase {
assertNull(join.findFirstRow(row));
}
- List<Map<String,Object>> expectedRows2 = new
- ArrayList<Map<String,Object>>();
- for(Map<String,Object> tmpRow : expectedRows) {
- Map<String,Object> tmpRow2 = new HashMap<String,Object>(tmpRow);
+ List<Row> expectedRows2 = new ArrayList<Row>();
+ for(Row tmpRow : expectedRows) {
+ Row tmpRow2 = new RowImpl(tmpRow);
tmpRow2.keySet().retainAll(colNames);
expectedRows2.add(tmpRow2);
}
- joinedRows = new ArrayList<Map<String,Object>>();
- for(Map<String,Object> t1Row : join.findRowsIterable(row, colNames)) {
+ joinedRows = new ArrayList<Row>();
+ for(Row t1Row : join.findRowsIterable(row, colNames)) {
joinedRows.add(t1Row);
}
@@ -136,7 +140,7 @@ public class JoinerTest extends TestCase {
{
assertEquals(4, countRows(t2t1Join.getToTable()));
- Map<String,Object> row = createExpectedRow("id", 1);
+ Row row = createExpectedRow("id", 1);
assertTrue(t2t1Join.hasRows(row));
assertTrue(t2t1Join.deleteRows(row));
@@ -145,15 +149,15 @@ public class JoinerTest extends TestCase {
assertFalse(t2t1Join.deleteRows(row));
assertEquals(2, countRows(t2t1Join.getToTable()));
- for(Map<String,Object> t1Row : t2t1Join.getToTable()) {
+ for(Row t1Row : t2t1Join.getToTable()) {
assertFalse(t1Row.get("otherfk1").equals(1));
}
}
- private static Map<Integer,List<Map<String,Object>>> createT2T1Data()
+ private static Map<Integer,List<Row>> createT2T1Data()
{
- Map<Integer,List<Map<String,Object>>> data = new
- HashMap<Integer,List<Map<String,Object>>>();
+ Map<Integer,List<Row>> data = new
+ HashMap<Integer,List<Row>>();
data.put(0,
createExpectedTable(
@@ -175,10 +179,9 @@ public class JoinerTest extends TestCase {
return data;
}
- private static Map<Integer,List<Map<String,Object>>> createT3T1Data()
+ private static Map<Integer,List<Row>> createT3T1Data()
{
- Map<Integer,List<Map<String,Object>>> data = new
- HashMap<Integer,List<Map<String,Object>>>();
+ Map<Integer,List<Row>> data = new HashMap<Integer,List<Row>>();
data.put(10,
createExpectedTable(
diff --git a/test/src/java/com/healthmarketscience/jackcess/MemFileChannelTest.java b/test/src/java/com/healthmarketscience/jackcess/util/MemFileChannelTest.java
index f84f0ab..3e78a2c 100644
--- a/test/src/java/com/healthmarketscience/jackcess/MemFileChannelTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/util/MemFileChannelTest.java
@@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.util;
import java.io.File;
import java.io.FileOutputStream;
@@ -30,6 +30,8 @@ import java.util.Arrays;
import junit.framework.TestCase;
+import com.healthmarketscience.jackcess.DatabaseTest;
+
/**
*
* @author James Ahlborn
diff --git a/test/src/java/com/healthmarketscience/jackcess/RowFilterTest.java b/test/src/java/com/healthmarketscience/jackcess/util/RowFilterTest.java
index 586ad9a..7808a08 100644
--- a/test/src/java/com/healthmarketscience/jackcess/RowFilterTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/util/RowFilterTest.java
@@ -25,16 +25,17 @@ Suite 200
King of Prussia, PA 19406
*/
-package com.healthmarketscience.jackcess;
+package com.healthmarketscience.jackcess.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
+import com.healthmarketscience.jackcess.DataType;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
+import com.healthmarketscience.jackcess.Row;
+import com.healthmarketscience.jackcess.impl.ColumnImpl;
+import junit.framework.TestCase;
/**
* @author James Ahlborn
@@ -54,24 +55,25 @@ public class RowFilterTest extends TestCase
@SuppressWarnings("unchecked")
public void testFilter() throws Exception
{
- Map<String,Object> row0 = createExpectedRow(ID_COL, 0, COL1, "foo", COL2, 13, COL3, "bar");
- Map<String,Object> row1 = createExpectedRow(ID_COL, 1, COL1, "bar", COL2, 42, COL3, null);
- Map<String,Object> row2 = createExpectedRow(ID_COL, 2, COL1, "foo", COL2, 55, COL3, "bar");
- Map<String,Object> row3 = createExpectedRow(ID_COL, 3, COL1, "baz", COL2, 42, COL3, "bar");
- Map<String,Object> row4 = createExpectedRow(ID_COL, 4, COL1, "foo", COL2, 13, COL3, null);
- Map<String,Object> row5 = createExpectedRow(ID_COL, 5, COL1, "bla", COL2, 13, COL3, "bar");
+ Row row0 = createExpectedRow(ID_COL, 0, COL1, "foo", COL2, 13, COL3, "bar");
+ Row row1 = createExpectedRow(ID_COL, 1, COL1, "bar", COL2, 42, COL3, null);
+ Row row2 = createExpectedRow(ID_COL, 2, COL1, "foo", COL2, 55, COL3, "bar");
+ Row row3 = createExpectedRow(ID_COL, 3, COL1, "baz", COL2, 42, COL3, "bar");
+ Row row4 = createExpectedRow(ID_COL, 4, COL1, "foo", COL2, 13, COL3, null);
+ Row row5 = createExpectedRow(ID_COL, 5, COL1, "bla", COL2, 13, COL3, "bar");
- List<Map<String,Object>> rows = Arrays.asList(row0, row1, row2, row3, row4, row5);
+ List<Row> rows = Arrays.asList(row0, row1, row2, row3, row4, row5);
+ ColumnImpl testCol = new ColumnImpl(null, DataType.TEXT, 0, 0, 0) {};
+ testCol.setName(COL1);
assertEquals(Arrays.asList(row0, row2, row4),
- toList(RowFilter.matchPattern(
- new ColumnBuilder(COL1, DataType.TEXT).toColumn(),
+ toList(RowFilter.matchPattern(testCol,
"foo").apply(rows)));
assertEquals(Arrays.asList(row1, row3, row5),
toList(RowFilter.invert(
RowFilter.matchPattern(
- new ColumnBuilder(COL1, DataType.TEXT).toColumn(),
+ testCol,
"foo")).apply(rows)));
assertEquals(Arrays.asList(row0, row2, row4),
@@ -100,10 +102,10 @@ public class RowFilterTest extends TestCase
rows)));
}
- static List<Map<String,Object>> toList(Iterable<Map<String,Object>> rows)
+ public static List<Row> toList(Iterable<Row> rows)
{
- List<Map<String,Object>> rowList = new ArrayList<Map<String,Object>>();
- for(Map<String,Object> row : rows) {
+ List<Row> rowList = new ArrayList<Row>();
+ for(Row row : rows) {
rowList.add(row);
}
return rowList;