diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2014-05-06 04:22:46 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2014-05-06 04:22:46 +0000 |
commit | 840ccbde0f0729e976fde4cec1a2fbfe55559b7b (patch) | |
tree | 9d85ec98f762e817de4cd40175e90898c1fe8a50 /src/test | |
parent | 7fdfea151021252e458426c8f99b73d55486e2f0 (diff) | |
download | jackcess-840ccbde0f0729e976fde4cec1a2fbfe55559b7b.tar.gz jackcess-840ccbde0f0729e976fde4cec1a2fbfe55559b7b.zip |
add convenience methods to Row for getting values cast to specific types
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@859 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test')
11 files changed, 69 insertions, 68 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java b/src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java index 32f228e..0485557 100644 --- a/src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java @@ -125,8 +125,8 @@ public class BigIndexTest extends TestCase { String prevValue = firstValue; int rowCount = 0; List<String> firstTwo = new ArrayList<String>(); - for(Map<String,Object> row : CursorBuilder.createCursor(index)) { - String origVal = (String)row.get("col1"); + for(Row row : CursorBuilder.createCursor(index)) { + String origVal = row.getString("col1"); String val = origVal; if(val == null) { val = firstValue; @@ -162,8 +162,8 @@ public class BigIndexTest extends TestCase { index.getIndexData().validate(); List<String> found = new ArrayList<String>(); - for(Map<String,Object> row : CursorBuilder.createCursor(index)) { - found.add((String)row.get("col1")); + for(Row row : CursorBuilder.createCursor(index)) { + found.add(row.getString("col1")); } assertEquals(firstTwo, found); diff --git a/src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java b/src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java index 8e2ba6d..8aae78c 100644 --- a/src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java @@ -64,8 +64,8 @@ public class ComplexColumnTest extends TestCase assertEquals(ComplexDataType.VERSION_HISTORY, verCol.getComplexInfo().getType()); - for(Map<String,Object> row : t1) { - String rowId = (String)row.get("id"); + for(Row row : t1) { + String rowId = row.getString("id"); ComplexValueForeignKey complexValueFk = (ComplexValueForeignKey)verCol.getRowValue(row); @@ -166,8 +166,8 @@ public class ComplexColumnTest extends TestCase assertEquals(ComplexDataType.ATTACHMENT, col.getComplexInfo().getType()); - for(Map<String,Object> row : t1) { - String rowId = (String)row.get("id"); + for(Row row : t1) { + String rowId = row.getString("id"); ComplexValueForeignKey complexValueFk = (ComplexValueForeignKey)col.getRowValue(row); @@ -251,8 +251,8 @@ public class ComplexColumnTest extends TestCase assertEquals(ComplexDataType.MULTI_VALUE, col.getComplexInfo().getType()); - for(Map<String,Object> row : t1) { - String rowId = (String)row.get("id"); + for(Row row : t1) { + String rowId = row.getString("id"); ComplexValueForeignKey complexValueFk = (ComplexValueForeignKey)col.getRowValue(row); @@ -322,8 +322,8 @@ public class ComplexColumnTest extends TestCase assertEquals(ComplexDataType.UNSUPPORTED, col.getComplexInfo().getType()); - for(Map<String,Object> row : t1) { - Integer rowId = (Integer)row.get("ID"); + for(Row row : t1) { + Integer rowId = row.getInt("ID"); ComplexValueForeignKey complexValueFk = (ComplexValueForeignKey)col.getRowValue(row); diff --git a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java index d10d18b..bafee57 100644 --- a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java @@ -1102,18 +1102,18 @@ public class CursorTest extends TestCase { IndexCursor cursor = CursorBuilder.createCursor(idx); List<String> expectedData = new ArrayList<String>(); - for(Map<String,Object> row : cursor.newEntryIterable(1) + for(Row row : cursor.newEntryIterable(1) .addColumnNames("data")) { - expectedData.add((String)row.get("data")); + expectedData.add(row.getString("data")); } assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData); expectedData = new ArrayList<String>(); - for(Iterator<? extends Map<String,Object>> iter = + for(Iterator<? extends Row> iter = cursor.newEntryIterable(1).iterator(); iter.hasNext(); ) { - expectedData.add((String)iter.next().get("data")); + expectedData.add(iter.next().getString("data")); iter.remove(); try { iter.remove(); @@ -1135,9 +1135,9 @@ public class CursorTest extends TestCase { assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData); expectedData = new ArrayList<String>(); - for(Map<String,Object> row : cursor.newEntryIterable(1) + for(Row row : cursor.newEntryIterable(1) .addColumnNames("data")) { - expectedData.add((String)row.get("data")); + expectedData.add(row.getString("data")); } assertTrue(expectedData.isEmpty()); @@ -1155,21 +1155,21 @@ public class CursorTest extends TestCase { Cursor cursor = CursorBuilder.createCursor(t1); List<String> expectedData = new ArrayList<String>(); - for(Map<String,Object> row : cursor.newIterable().setColumnNames( + for(Row row : cursor.newIterable().setColumnNames( Arrays.asList("otherfk1", "data"))) { if(row.get("otherfk1").equals(1)) { - expectedData.add((String)row.get("data")); + expectedData.add(row.getString("data")); } } assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData); expectedData = new ArrayList<String>(); - for(Iterator<? extends Map<String,Object>> iter = cursor.iterator(); + for(Iterator<? extends Row> iter = cursor.iterator(); iter.hasNext(); ) { - Map<String,Object> row = iter.next(); + Row row = iter.next(); if(row.get("otherfk1").equals(1)) { - expectedData.add((String)row.get("data")); + expectedData.add(row.getString("data")); iter.remove(); try { iter.remove(); @@ -1192,10 +1192,10 @@ public class CursorTest extends TestCase { assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData); expectedData = new ArrayList<String>(); - for(Map<String,Object> row : cursor.newIterable().setColumnNames( + for(Row row : cursor.newIterable().setColumnNames( Arrays.asList("otherfk1", "data"))) { if(row.get("otherfk1").equals(1)) { - expectedData.add((String)row.get("data")); + expectedData.add(row.getString("data")); } } diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index 24fe758..ab80183 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -278,11 +278,11 @@ public class DatabaseTest extends TestCase assertEquals(4, db.getTableNames().size()); final Table table = db.getTable("Table1"); - Map<String, Object> row1 = table.getNextRow(); - Map<String, Object> row2 = table.getNextRow(); + Row row1 = table.getNextRow(); + Row row2 = table.getNextRow(); if(!"abcdefg".equals(row1.get("A"))) { - Map<String, Object> tmpRow = row1; + Row tmpRow = row1; row1 = row2; row2 = tmpRow; } @@ -294,7 +294,7 @@ public class DatabaseTest extends TestCase } } - static void checkTestDBTable1RowABCDEFG(final TestDB testDB, final Table table, final Map<String, Object> row) + static void checkTestDBTable1RowABCDEFG(final TestDB testDB, final Table table, final Row row) throws IOException { assertEquals("testDB: " + testDB + "; table: " + table, "abcdefg", row.get("A")); assertEquals("hijklmnop", row.get("B")); @@ -303,7 +303,7 @@ public class DatabaseTest extends TestCase assertEquals(new Integer(333333333), row.get("E")); assertEquals(new Double(444.555d), row.get("F")); final Calendar cal = Calendar.getInstance(); - cal.setTime((Date) row.get("G")); + cal.setTime(row.getDate("G")); assertEquals(Calendar.SEPTEMBER, cal.get(Calendar.MONTH)); assertEquals(21, cal.get(Calendar.DAY_OF_MONTH)); assertEquals(1974, cal.get(Calendar.YEAR)); @@ -314,7 +314,7 @@ public class DatabaseTest extends TestCase assertEquals(Boolean.TRUE, row.get("I")); } - static void checkTestDBTable1RowA(final TestDB testDB, final Table table, final Map<String, Object> row) + static void checkTestDBTable1RowA(final TestDB testDB, final Table table, final Row row) throws IOException { assertEquals("testDB: " + testDB + "; table: " + table, "a", row.get("A")); assertEquals("b", row.get("B")); @@ -323,7 +323,7 @@ public class DatabaseTest extends TestCase assertEquals(new Integer(0), row.get("E")); assertEquals(new Double(0d), row.get("F")); final Calendar cal = Calendar.getInstance(); - cal.setTime((Date) row.get("G")); + cal.setTime(row.getDate("G")); assertEquals(Calendar.DECEMBER, cal.get(Calendar.MONTH)); assertEquals(12, cal.get(Calendar.DAY_OF_MONTH)); assertEquals(1981, cal.get(Calendar.YEAR)); @@ -513,12 +513,12 @@ public class DatabaseTest extends TestCase for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.TEST2, true)) { Database db = open(testDB); Table table = db.getTable("MSP_PROJECTS"); - Map<String, Object> row = table.getNextRow(); + Row row = table.getNextRow(); assertEquals("Jon Iles this is a a vawesrasoih aksdkl fas dlkjflkasjd flkjaslkdjflkajlksj dfl lkasjdf lkjaskldfj lkas dlk lkjsjdfkl; aslkdf lkasjkldjf lka skldf lka sdkjfl;kasjd falksjdfljaslkdjf laskjdfk jalskjd flkj aslkdjflkjkjasljdflkjas jf;lkasjd fjkas dasdf asd fasdf asdf asdmhf lksaiyudfoi jasodfj902384jsdf9 aw90se fisajldkfj lkasj dlkfslkd jflksjadf as", row.get("PROJ_PROP_AUTHOR")); assertEquals("T", row.get("PROJ_PROP_COMPANY")); assertEquals("Standard", row.get("PROJ_INFO_CAL_NAME")); assertEquals("Project1", row.get("PROJ_PROP_TITLE")); - byte[] foundBinaryData = (byte[])row.get("RESERVED_BINARY_DATA"); + byte[] foundBinaryData = row.getBytes("RESERVED_BINARY_DATA"); byte[] expectedBinaryData = toByteArray(new File("src/test/data/test2BinData.dat")); assertTrue(Arrays.equals(expectedBinaryData, foundBinaryData)); @@ -549,7 +549,7 @@ public class DatabaseTest extends TestCase table.reset(); - Map<String, Object> row = table.getNextRow(); + Row row = table.getNextRow(); assertEquals(testStr, row.get("A")); assertEquals(testStr, row.get("B")); @@ -559,7 +559,7 @@ public class DatabaseTest extends TestCase assertEquals(testStr, row.get("A")); assertEquals(longMemo, row.get("B")); - assertTrue(Arrays.equals(oleValue, (byte[])row.get("C"))); + assertTrue(Arrays.equals(oleValue, row.getBytes("C"))); db.close(); } @@ -937,8 +937,8 @@ public class DatabaseTest extends TestCase } Set<Integer> ids = new HashSet<Integer>(); - for(Map<String,Object> row : t) { - ids.add((Integer)row.get("ID")); + for(Row row : t) { + ids.add(row.getInt("ID")); } assertEquals(1000, ids.size()); @@ -1103,8 +1103,8 @@ public class DatabaseTest extends TestCase } List<Date> foundDates = new ArrayList<Date>(); - for(Map<String,Object> row : table) { - foundDates.add((Date)row.get("date")); + for(Row row : table) { + foundDates.add(row.getDate("date")); } assertEquals(dates.size(), foundDates.size()); diff --git a/src/test/java/com/healthmarketscience/jackcess/IndexTest.java b/src/test/java/com/healthmarketscience/jackcess/IndexTest.java index aad0376..c2d058a 100644 --- a/src/test/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/IndexTest.java @@ -387,7 +387,7 @@ public class IndexTest extends TestCase { Cursor c = CursorBuilder.createCursor(table); assertTrue(c.moveToNextRow()); - final Map<String,Object> row = c.getCurrentRow(); + final Row row = c.getCurrentRow(); // Row order is arbitrary, so v2007 row order difference is valid if (testDB.getExpectedFileFormat().ordinal() >= Database.FileFormat.V2007.ordinal()) { diff --git a/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java b/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java index aa98ce5..182e637 100644 --- a/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java @@ -191,9 +191,9 @@ 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 : ((DatabaseImpl)db).getSystemCatalog()) { - int id = (Integer)row.get("Id"); - byte[] propBytes = (byte[])row.get("LvProp"); + for(Row row : ((DatabaseImpl)db).getSystemCatalog()) { + int id = row.getInt("Id"); + byte[] propBytes = row.getBytes("LvProp"); PropertyMaps propMaps = ((DatabaseImpl)db).getPropertiesForObject(id); int byteLen = ((propBytes != null) ? propBytes.length : 0); if(byteLen == 0) { diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java index 47a832a..e680fd9 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java @@ -45,6 +45,7 @@ import com.healthmarketscience.jackcess.DatabaseBuilder; import com.healthmarketscience.jackcess.DatabaseTest; import com.healthmarketscience.jackcess.DatabaseTest; import com.healthmarketscience.jackcess.IndexBuilder; +import com.healthmarketscience.jackcess.Row; import com.healthmarketscience.jackcess.Table; import com.healthmarketscience.jackcess.TableBuilder; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; @@ -134,8 +135,8 @@ public class CodecHandlerTest extends TestCase Cursor c2 = t2.newCursor().setIndex(t2.getPrimaryKeyIndex()) .toCursor(); - Iterator<? extends Map<String,Object>> i1 = c1.iterator(); - Iterator<? extends Map<String,Object>> i2 = c2.newIterable().reverse().iterator(); + Iterator<? extends Row> i1 = c1.iterator(); + Iterator<? extends Row> i2 = c2.newIterable().reverse().iterator(); int t1rows = 0; int t2rows = 0; @@ -156,10 +157,10 @@ public class CodecHandlerTest extends TestCase assertEquals(100, t2rows); } - private static void checkRow(Map<String,Object> row) + private static void checkRow(Row row) { - int id = (Integer)row.get("id"); - String value = (String)row.get("data"); + int id = row.getInt("id"); + String value = row.getString("data"); String valuePrefix = "rowdata-" + id; assertTrue(value.startsWith(valuePrefix)); assertEquals(valuePrefix.length() + 100, value.length()); diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java index 7ea3123..70c2b94 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java @@ -107,8 +107,8 @@ public class FKEnforcerTest extends TestCase Cursor c = CursorBuilder.createCursor(t3); Column col = t3.getColumn("id"); - for(Map<String,Object> row : c) { - int id = (Integer)row.get("id"); + for(Row row : c) { + int id = row.getInt("id"); id += 20; c.setCurrentRowValue(col, id); } diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java index 62565ac..ddee491 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java @@ -44,6 +44,7 @@ import com.healthmarketscience.jackcess.DataType; import com.healthmarketscience.jackcess.Database; import static com.healthmarketscience.jackcess.DatabaseTest.*; import com.healthmarketscience.jackcess.Index; +import com.healthmarketscience.jackcess.Row; import com.healthmarketscience.jackcess.Table; import com.healthmarketscience.jackcess.TableBuilder; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; @@ -95,7 +96,7 @@ public class IndexCodesTest extends TestCase { Cursor cursor = CursorBuilder.createCursor(index); while(cursor.moveToNextRow()) { - Map<String,Object> row = cursor.getCurrentRow(); + Row row = cursor.getCurrentRow(); Cursor.Position curPos = cursor.getSavepoint().getCurrentPosition(); boolean success = false; try { @@ -113,7 +114,7 @@ public class IndexCodesTest extends TestCase { } private static void findRow(final TestDB testDB, Table t, Index index, - Map<String,Object> expectedRow, + Row expectedRow, Cursor.Position expectedPos) throws Exception { @@ -124,7 +125,7 @@ public class IndexCodesTest extends TestCase { cursor.beforeFirst(); while(cursor.moveToNextRow()) { - Map<String,Object> row = cursor.getCurrentRow(); + Row row = cursor.getCurrentRow(); if(expectedRow.equals(row)) { // verify that the entries are indeed equal Cursor.Position curPos = cursor.getSavepoint().getCurrentPosition(); @@ -136,7 +137,7 @@ public class IndexCodesTest extends TestCase { // TODO long rows not handled completely yet in V2010 // seems to truncate entry at 508 bytes with some trailing 2 byte seq if(testDB.getExpectedFileFormat() == Database.FileFormat.V2010) { - String rowId = (String)expectedRow.get("name"); + String rowId = expectedRow.getString("name"); String tName = t.getName(); if(("Table11".equals(tName) || "Table11_desc".equals(tName)) && ("row10".equals(rowId) || "row11".equals(rowId) || @@ -363,9 +364,9 @@ public class IndexCodesTest extends TestCase { Cursor.Savepoint savepoint = cursor.getSavepoint(); String entryStr = entryToString(savepoint.getCurrentPosition()); - Map<String,Object> row = cursor.getCurrentRow(); - String value = (String)row.get("data"); - String key = (String)row.get("key"); + Row row = cursor.getCurrentRow(); + String value = row.getString("data"); + String key = row.getString("key"); char c = value.charAt(2); System.out.println("======="); @@ -542,9 +543,9 @@ public class IndexCodesTest extends TestCase { Cursor.Savepoint savepoint = cursor.getSavepoint(); String entryStr = entryToString(savepoint.getCurrentPosition()); - Map<String,Object> row = cursor.getCurrentRow(); - String value = (String)row.get("data"); - String key = (String)row.get("key"); + Row row = cursor.getCurrentRow(); + String value = row.getString("data"); + String key = row.getString("key"); char c = value.charAt(2); System.out.println("======="); System.out.println("RowId: " + diff --git a/src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java b/src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java index f6de03b..35feaa0 100644 --- a/src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java @@ -93,7 +93,7 @@ public class JoinerTest extends TestCase { Joiner revJoin = join.createReverse(); for(Row row : join.getFromTable()) { - Integer id = (Integer)row.get("id"); + Integer id = row.getInt("id"); List<Row> joinedRows = new ArrayList<Row>(); diff --git a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java index b519664..3a1cc05 100644 --- a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java @@ -102,12 +102,12 @@ public class OleBlobTest extends TestCase for(Row row : t) { try { blob = OleBlob.Builder.fromInternalData( - (byte[])row.get("ole")); + row.getBytes("ole")); OleBlob.Content content = blob.getContent(); assertSame(blob, content.getBlob()); assertSame(content, blob.getContent()); - switch((Integer)row.get("id")) { + switch(row.getInt("id")) { case 1: assertEquals(OleBlob.ContentType.SIMPLE_PACKAGE, content.getType()); OleBlob.SimplePackageContent spc = (OleBlob.SimplePackageContent)content; @@ -170,13 +170,12 @@ public class OleBlobTest extends TestCase OleBlob oleBlob = null; try { - String name = (String)row.get("name"); - oleBlob = OleBlob.Builder.fromInternalData((byte[])row.get("ole_data")); + String name = row.getString("name"); + oleBlob = OleBlob.Builder.fromInternalData(row.getBytes("ole_data")); OleBlob.Content content = oleBlob.getContent(); Attachment attach = null; if(content.getType() != OleBlob.ContentType.LINK) { - attach = ((ComplexValueForeignKey)row.get("attach_data")) - .getAttachments().get(0); + attach = row.getForeignKey("attach_data").getAttachments().get(0); } switch(content.getType()) { |