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;
}
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.
*
.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>
// 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")