]> source.dussan.org Git - jackcess.git/commitdiff
some tweaks, fixes, and tests for unsupported values
authorJames Ahlborn <jtahlborn@yahoo.com>
Sat, 12 Nov 2011 02:56:39 +0000 (02:56 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Sat, 12 Nov 2011 02:56:39 +0000 (02:56 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@592 f203690c-595d-4dc9-a70b-905162fa7fd2

src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java
src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java
test/data/V2007/unsupportedFieldsTestV2007.accdb [new file with mode: 0644]
test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java
test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java

index d236afed1cb984eed1de9099b59fd427914950da..ba31a3b557dbb079eb8f19ff0aa5129fd4d0696b 100644 (file)
@@ -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();
index 727551137b3101619777197ed5cb45019d50b71c..27ee43449308b525200cdd459ff76365ec545721 100644 (file)
@@ -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
new file mode 100644 (file)
index 0000000..c7b1dea
Binary files /dev/null and b/test/data/V2007/unsupportedFieldsTestV2007.accdb differ
index f9f4445f44f7b443d1cfc132a22533971596078c..09ec547b8a2d872b3f850f711837b3667d4248cd 100644 (file)
@@ -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)) {
index 1f118ca01551c3ded2df03faf9f7b792f3fbf73c..2c70a19cb50f0a64198281a963673f80bbf7dfd7 100644 (file)
@@ -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,
index 22dff2deca7294f3bd4c0d766f7aea4a5d6f23a5..ec11dce4273cf1dbd5bcccb867fb9a7c8597d1f4 100644 (file)
@@ -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;