From f3a3751ea49dadc76c9f1544dc17a7dba3b60945 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sat, 23 Feb 2013 15:59:58 +0000 Subject: finish some basic content git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@661 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/site/site.xml | 2 +- src/site/xdoc/cookbook.xml | 61 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/site/site.xml b/src/site/site.xml index b00e488..74db3d1 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -6,7 +6,7 @@ - + diff --git a/src/site/xdoc/cookbook.xml b/src/site/xdoc/cookbook.xml index ec294d3..84ebe94 100644 --- a/src/site/xdoc/cookbook.xml +++ b/src/site/xdoc/cookbook.xml @@ -28,7 +28,7 @@ example.

- + @@ -178,6 +178,7 @@

+

@@ -186,7 +187,7 @@ support everything you may need when creating a new database, it does support a wide range of functionality, and adds more all the time. (If you started using Jackcess a while ago, you should - definitely keep tabs on the release notes, as your knowledge of what + definitely keep tabs on the release notes, as your knowledge of what is possible may be out of date).

@@ -201,20 +202,66 @@ Some notable gaps:

    -
  • Cannot currently create (index backed) foreign-key +
  • Cannot currently create tables with (index backed) foreign-key constraints
  • -
  • Cannot currently create "complex" columns (attachment, - multi-value, versioned memo)
  • +
  • Cannot currently create tables with "complex" columns + (attachment, multi-value, versioned memo)

- As long as your needs fall into the + As long as your needs fall into the aforementioned constraints (or + if you can fake it), then let's get started! +

+

+ The first thing we need to choose is the desired FileFormat + of the new Database. Armed with that information, we can start + putting the pieces together using the appropriate builder classes. + Notice that the result of creating the new Database is an open + Database instance.

+ + File file = new File("test.mdb"); + Database db = new DatabaseBuilder(file) + .setFileFormat(Database.FileFormat.V2000) + .open(); +

- + An empty Database isn't very useful, of course, so we probably want + to add a Table or two. The following code will create the table + that we have used in the above examples. Notice that, like Database + creation, the result of the Table creation is an open Table + instance.

+ + Table table = new TableBuilder("Test") + .addColumn(new ColumnBuilder("ID", DataType.LONG) + .setAutoNumber(true)) + .addColumn(new ColumnBuilder("Name", DataType.TEXT)) + .addColumn(new ColumnBuilder("Salary", DataType.MONEY)) + .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. +

+ + // new TableBuilder(... + .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME) + .addColumns("ID").setPrimaryKey()) + .addIndex(new IndexBuilder("NameIndex") + .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. +

-- cgit v1.2.3