aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2016-09-11 01:29:49 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2016-09-11 01:29:49 +0000
commitf8212d111e3975c643bcd92c7bc8dfa5c4fd2261 (patch)
treeaf3334bcf7cbbf81c184b053e74a99d2bfc32e62
parent09a70b9f2465c39852784eb1b03049ed73512867 (diff)
downloadjackcess-f8212d111e3975c643bcd92c7bc8dfa5c4fd2261.tar.gz
jackcess-f8212d111e3975c643bcd92c7bc8dfa5c4fd2261.zip
misc cleanups; doc updates
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1034 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java14
-rw-r--r--src/site/xdoc/cookbook.xml38
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java10
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<String> _fromCols = new ArrayList<String>();
private List<String> _toCols = new ArrayList<String>();
- 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;
}
@@ -75,6 +78,13 @@ public class RelationshipBuilder
}
/**
+ * 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.
*
* Note, this requires the "from" table to have an existing unique index on
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);
</source>
- </subsection>
- <p>
- 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.
- </p>
+ <p>
+ 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.
+ </p>
<source>
// ... new TableBuilder( ...
.addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME)
@@ -258,11 +257,12 @@
.addColumns("Name"))
// ... .toTable( ...
</source>
- <p>
- 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.
- </p>
+ <p>
+ 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.
+ </p>
+ </subsection>
</section>
<section name="Finding Stuff">
@@ -363,17 +363,13 @@
}
</source>
</subsection>
-
- <p>
- FIXME, writeme
- </p>
</section>
- <section name="Miscellaneous Examples">
- <p>
- FIXME, writeme
- </p>
- </section>
+ <!-- <section name="Miscellaneous Examples"> -->
+ <!-- <p> -->
+ <!-- FIXME, writeme -->
+ <!-- </p> -->
+ <!-- </section> -->
</body>
</document>
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,11 +195,19 @@ 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")
.toRelationship(db);