diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2011-11-12 02:56:39 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2011-11-12 02:56:39 +0000 |
commit | aafaa8f12793373085d10ffb58664f868fa397d4 (patch) | |
tree | bbb056086efd69245fe59ec18213636b18e05189 | |
parent | 84f12a0fbe85d05dc6d2c67ae937633e9fe36609 (diff) | |
download | jackcess-aafaa8f12793373085d10ffb58664f868fa397d4.tar.gz jackcess-aafaa8f12793373085d10ffb58664f868fa397d4.zip |
some tweaks, fixes, and tests for unsupported values
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@592 f203690c-595d-4dc9-a70b-905162fa7fd2
6 files changed, 118 insertions, 10 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java b/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java index d236afe..ba31a3b 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java +++ b/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java @@ -167,6 +167,16 @@ public class ComplexValueForeignKey extends Number return (List<SingleValue>)getValues(); } + @SuppressWarnings("unchecked") + public List<UnsupportedValue> getUnsupportedValues() + throws IOException + { + if(getComplexType() != ComplexDataType.UNSUPPORTED) { + throw new UnsupportedOperationException(); + } + return (List<UnsupportedValue>)getValues(); + } + public void reset() { // discard any cached values _values = null; @@ -246,7 +256,8 @@ public class ComplexValueForeignKey extends Number return value; } - public UnsupportedValue addUnsupportedValue(Map<String,Object> values) + public UnsupportedValue addUnsupportedValue( + Map<String,? extends Object> values) throws IOException { reset(); diff --git a/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java index 7275511..27ee434 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java +++ b/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java @@ -59,8 +59,10 @@ public class UnsupportedColumnInfo extends ComplexColumnInfo<UnsupportedValue> { int id = (Integer)getPrimaryKeyColumn().getRowValue(rawValue); - Map<String,Object> values = new LinkedHashMap<String,Object>(rawValue); - values.remove(getPrimaryKeyColumn().getName()); + Map<String,Object> values = new LinkedHashMap<String,Object>(); + for(Column col : getValueColumns()) { + col.setRowValue(values, col.getRowValue(rawValue)); + } return new UnsupportedValueImpl(id, complexValueFk, values); } @@ -77,13 +79,15 @@ public class UnsupportedColumnInfo extends ComplexColumnInfo<UnsupportedValue> return row; } - public static UnsupportedValue newValue(Map<String,Object> values) { + public static UnsupportedValue newValue(Map<String,? extends Object> values) { return newValue(INVALID_COMPLEX_VALUE_ID, values); } public static UnsupportedValue newValue( - ComplexValueForeignKey complexValueFk, Map<String,Object> values) { - return new UnsupportedValueImpl(INVALID_ID, complexValueFk, values); + ComplexValueForeignKey complexValueFk, + Map<String,? extends Object> values) { + return new UnsupportedValueImpl(INVALID_ID, complexValueFk, + new LinkedHashMap<String,Object>(values)); } private static class UnsupportedValueImpl extends ComplexValueImpl diff --git a/test/data/V2007/unsupportedFieldsTestV2007.accdb b/test/data/V2007/unsupportedFieldsTestV2007.accdb Binary files differnew file mode 100644 index 0000000..c7b1dea --- /dev/null +++ b/test/data/V2007/unsupportedFieldsTestV2007.accdb diff --git a/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java b/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java index f9f4445..09ec547 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java @@ -24,12 +24,13 @@ import java.util.Date; import java.util.List; import java.util.Map; -import static com.healthmarketscience.jackcess.JetFormatTest.*; 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 junit.framework.TestCase; @@ -155,7 +156,6 @@ public class ComplexColumnTest extends TestCase for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { Database db = openCopy(testDB); - db.setTimeZone(TEST_TZ); Table t1 = db.getTable("Table1"); Column col = t1.getColumn("attach-data"); @@ -231,7 +231,6 @@ public class ComplexColumnTest extends TestCase for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { Database db = openCopy(testDB); - db.setTimeZone(TEST_TZ); Table t1 = db.getTable("Table1"); Column col = t1.getColumn("multi-value-data"); @@ -298,6 +297,38 @@ public class ComplexColumnTest extends TestCase } } + public void testUnsupported() throws Exception + { + for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.UNSUPPORTED)) { + + Database db = openCopy(testDB); + + Table t1 = db.getTable("Test"); + Column col = t1.getColumn("UnknownComplex"); + assertEquals(ComplexDataType.UNSUPPORTED, + col.getComplexInfo().getType()); + + for(Map<String,Object> row : t1) { + Integer rowId = (Integer)row.get("ID"); + ComplexValueForeignKey complexValueFk = + (ComplexValueForeignKey)col.getRowValue(row); + + if(rowId.equals(1)) { + checkUnsupportedValues(1, complexValueFk, + "RawData: FF FE 62 61 7A"); + } else if(rowId.equals(2)) { + checkUnsupportedValues(2, complexValueFk, "RawData: FF FE 66 6F 6F", "RawData: FF FE 62 61 7A"); + } else if(rowId.equals(3)) { + checkUnsupportedValues(3, complexValueFk); + } else { + assertTrue(false); + } + } + + db.close(); + } + } + private static void checkVersions( int cValId, ComplexValueForeignKey complexValueFk, String curValue, Object... versionInfos) @@ -365,6 +396,29 @@ public class ComplexColumnTest extends TestCase } } + private static void checkUnsupportedValues( + int cValId, ComplexValueForeignKey complexValueFk, + String... expectedValues) + throws Exception + { + assertEquals(cValId, complexValueFk.get()); + + List<UnsupportedValue> values = complexValueFk.getUnsupportedValues(); + if(expectedValues.length == 0) { + assertTrue(values.isEmpty()); + } else { + assertEquals(expectedValues.length, values.size()); + for(int i = 0; i < expectedValues.length; ++i) { + String value = expectedValues[i]; + UnsupportedValue v = values.get(i); + assertEquals(1, v.getValues().size()); + Object rv = v.get("Value"); + assertTrue(Column.isRawData(rv)); + assertEquals(value, rv.toString()); + } + } + } + private static byte[] getFileBytes(String fname) throws Exception { if("test_data.txt".equals(fname)) { diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index 1f118ca..2c70a19 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -1157,6 +1157,44 @@ public class DatabaseTest extends TestCase { db.close(); } } + + public void testUnsupportedColumns() throws Exception { + for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.UNSUPPORTED)) { + + Database db = open(testDB); + Table t = db.getTable("Test"); + Column varCol = t.getColumn("UnknownVar"); + assertEquals(DataType.UNSUPPORTED_VARLEN, varCol.getType()); + Column fixCol = t.getColumn("UnknownFix"); + assertEquals(DataType.UNSUPPORTED_FIXEDLEN, fixCol.getType()); + + List<String> varVals = Arrays.asList( + "RawData: FF FE 73 6F 6D 65 64 61 74 61", + "RawData: FF FE 6F 74 68 65 72 20 64 61 74 61", + null); + List<String> fixVals = Arrays.asList("RawData: 37 00 00 00", + "RawData: F3 FF FF FF", + "RawData: 02 00 00 00"); + + int idx = 0; + for(Map<String,Object> row : t) { + checkRawValue(varVals.get(idx), varCol.getRowValue(row)); + checkRawValue(fixVals.get(idx), fixCol.getRowValue(row)); + ++idx; + } + db.close(); + } + } + + private void checkRawValue(String expected, Object val) + { + if(expected != null) { + assertTrue(Column.isRawData(val)); + assertEquals(expected, val.toString()); + } else { + assertNull(val); + } + } static Object[] createTestRow(String col1Val) { return new Object[] {col1Val, "R", "McCune", 1234, (byte) 0xad, 555.66d, diff --git a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java index 22dff2d..ec11dce 100644 --- a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java @@ -42,7 +42,8 @@ public class JetFormatTest extends TestCase { INDEX_CODES("testIndexCodes"), INDEX_PROPERTIES("testIndexProperties"), PROMOTION("testPromotion"), - COMPLEX("complexDataTest"); + COMPLEX("complexDataTest"), + UNSUPPORTED("unsupportedFieldsTest"); private final String _basename; |