]> source.dussan.org Git - jackcess.git/commitdiff
misc cleanups; doc updates
authorJames Ahlborn <jtahlborn@yahoo.com>
Sun, 11 Sep 2016 01:29:49 +0000 (01:29 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Sun, 11 Sep 2016 01:29:49 +0000 (01:29 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1034 f203690c-595d-4dc9-a70b-905162fa7fd2

src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java
src/site/xdoc/cookbook.xml
src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java

index 8ba9bb1473a889dc2cc05a94935c1bc2e389f7d3..e52ea808257d0827ca6674d7a439fd42548d5026 100644 (file)
@@ -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;
   }
@@ -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.
    *
index 4ad564955a0b00724a5046686516954b022ba429..fca2519a84de5d166e2200b1f636b3a1eba5ebe5 100644 (file)
     .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)
               .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">
   }
 </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>
index 2f3a1a89d7077a4fdfa0045da5867ba92d0388b1..564c334ce789434568e407ddc508436831276b8b 100644 (file)
@@ -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")