From f8212d111e3975c643bcd92c7bc8dfa5c4fd2261 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sun, 11 Sep 2016 01:29:49 +0000 Subject: [PATCH] misc cleanups; doc updates git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1034 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/RelationshipBuilder.java | 14 ++++++- src/site/xdoc/cookbook.xml | 38 +++++++++---------- .../jackcess/TableUpdaterTest.java | 10 ++++- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java b/src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java index 8ba9bb1..e52ea80 100644 --- a/src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java +++ b/src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java @@ -59,8 +59,11 @@ public class RelationshipBuilder private List _fromCols = new ArrayList(); private List _toCols = new ArrayList(); - public RelationshipBuilder(String fromTable, String toTable) - { + public RelationshipBuilder(Table fromTable, Table toTable) { + this(fromTable.getName(), toTable.getName()); + } + + public RelationshipBuilder(String fromTable, String toTable) { _fromTable = fromTable; _toTable = toTable; } @@ -74,6 +77,13 @@ public class RelationshipBuilder return this; } + /** + * Adds a pair of columns to the relationship. + */ + public RelationshipBuilder addColumns(Column fromCol, Column toCol) { + return addColumns(fromCol.getName(), toCol.getName()); + } + /** * Enables referential integrity enforcement for this relationship. * diff --git a/src/site/xdoc/cookbook.xml b/src/site/xdoc/cookbook.xml index 4ad5649..fca2519 100644 --- a/src/site/xdoc/cookbook.xml +++ b/src/site/xdoc/cookbook.xml @@ -243,13 +243,12 @@ .addColumn(new ColumnBuilder("StartDate", DataType.SHORT_DATE_TIME)) .toTable(db); - -

- That is a very simple Table. In the real world, we often need Indexes - to speed up lookups and enforce uniqueness constraints. Adding the - following to the previous example will make the "ID" column a primary - key and enable speedier lookups on the "Name" column. -

+

+ That is a very simple Table. In the real world, we often need Indexes + to speed up lookups and enforce uniqueness constraints. Adding the + following to the previous example will make the "ID" column a primary + key and enable speedier lookups on the "Name" column. +

// ... new TableBuilder( ... .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME) @@ -258,11 +257,12 @@ .addColumns("Name")) // ... .toTable( ... -

- Don't forget to close the Database when you are finished building it - and now you have a fresh, new Database on which to test some more - recipes. -

+

+ Don't forget to close the Database when you are finished building it + and now you have a fresh, new Database on which to test some more + recipes. +

+
@@ -363,17 +363,13 @@ } - -

- FIXME, writeme -

-
-

- FIXME, writeme -

-
+ + + + + diff --git a/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java b/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java index 2f3a1a8..564c334 100644 --- a/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java @@ -195,10 +195,18 @@ public class TableUpdaterTest extends TestCase // success } - new TableBuilder("TestTable2") + Table t2 = new TableBuilder("TestTable2") .addColumn(new ColumnBuilder("id2", DataType.LONG)) .toTable(db); + try { + new RelationshipBuilder(t1, t2) + .toRelationship(db); + fail("created rel with no columns?"); + } catch(IllegalArgumentException e) { + // success + } + try { new RelationshipBuilder("TestTable", "TestTable2") .addColumns("id", "id") -- 2.39.5