From ae2ffd397026c7eac5210d343934ab15eb00bb4a Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Wed, 1 Feb 2012 04:25:23 +0000 Subject: add initial support for linked tables (fixes issue 3479560) git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@610 f203690c-595d-4dc9-a70b-905162fa7fd2 --- test/data/V2007/linkerTestV2007.accdb | Bin 0 -> 454656 bytes test/data/linkeeTest.accdb | Bin 0 -> 524288 bytes .../healthmarketscience/jackcess/DatabaseTest.java | 56 +++++++++++++++++++++ .../jackcess/JetFormatTest.java | 3 +- 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 test/data/V2007/linkerTestV2007.accdb create mode 100755 test/data/linkeeTest.accdb (limited to 'test') diff --git a/test/data/V2007/linkerTestV2007.accdb b/test/data/V2007/linkerTestV2007.accdb new file mode 100755 index 0000000..57c6b25 Binary files /dev/null and b/test/data/V2007/linkerTestV2007.accdb differ diff --git a/test/data/linkeeTest.accdb b/test/data/linkeeTest.accdb new file mode 100755 index 0000000..a159097 Binary files /dev/null and b/test/data/linkeeTest.accdb differ diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index 4cfd656..efda478 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -1216,6 +1216,62 @@ public class DatabaseTest extends TestCase { } } + public void testLinkedTables() throws Exception { + for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.LINKED)) { + Database db = openCopy(testDB); + + try { + db.getTable("Table2"); + fail("FileNotFoundException should have been thrown"); + } catch(FileNotFoundException e) { + // success + } + + assertTrue(db.getLinkedDatabases().isEmpty()); + + final String linkeeDbName = "Z:\\jackcess_test\\linkeeTest.accdb"; + final File linkeeFile = new File("test/data/linkeeTest.accdb"); + db.setLinkResolver(new LinkResolver() { + public Database resolveLinkedDatabase(Database linkerdb, String dbName) + throws IOException { + assertEquals(linkeeDbName, dbName); + return Database.open(linkeeFile); + } + }); + + Table t2 = db.getTable("Table2"); + + assertEquals(1, db.getLinkedDatabases().size()); + Database linkeeDb = db.getLinkedDatabases().get(linkeeDbName); + assertNotNull(linkeeDb); + assertEquals(linkeeFile, linkeeDb.getFile()); + + List> expectedRows = + createExpectedTable( + createExpectedRow( + "ID", 1, + "Field1", "bar")); + + assertTable(expectedRows, t2); + + db.createLinkedTable("FooTable", linkeeDbName, "Table2"); + + Table t3 = db.getTable("FooTable"); + + assertEquals(1, db.getLinkedDatabases().size()); + + expectedRows = + createExpectedTable( + createExpectedRow( + "ID", 1, + "Field1", "buzz")); + + assertTable(expectedRows, t3); + + db.close(); + } + } + private void checkRawValue(String expected, Object val) { if(expected != null) { diff --git a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java index ec11dce..c5cacfb 100644 --- a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java @@ -43,7 +43,8 @@ public class JetFormatTest extends TestCase { INDEX_PROPERTIES("testIndexProperties"), PROMOTION("testPromotion"), COMPLEX("complexDataTest"), - UNSUPPORTED("unsupportedFieldsTest"); + UNSUPPORTED("unsupportedFieldsTest"), + LINKED("linkerTest"); private final String _basename; -- cgit v1.2.3