Browse Source

misc cleanups; doc updates

git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1034 f203690c-595d-4dc9-a70b-905162fa7fd2
tags/jackcess-2.1.5
James Ahlborn 7 years ago
parent
commit
f8212d111e

+ 12
- 2
src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java View 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.
*

+ 17
- 21
src/site/xdoc/cookbook.xml View File

@@ -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>

+ 9
- 1
src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java View 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")

Loading…
Cancel
Save