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;
return value;
}
- public UnsupportedValue addUnsupportedValue(Map<String,Object> values)
+ public UnsupportedValue addUnsupportedValue(
+ Map<String,? extends Object> values)
throws IOException
{
reset();
{
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);
}
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
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;
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");
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");
}
}
+ 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)
}
}
+ 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)) {
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,
INDEX_CODES("testIndexCodes"),
INDEX_PROPERTIES("testIndexProperties"),
PROMOTION("testPromotion"),
- COMPLEX("complexDataTest");
+ COMPLEX("complexDataTest"),
+ UNSUPPORTED("unsupportedFieldsTest");
private final String _basename;