aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2011-05-15 21:47:53 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2011-05-15 21:47:53 +0000
commit5f93a558aefae1d95fef260240c64fe1011e1e56 (patch)
treeb44be79828101964273da73b74f1fee56cf83328 /src/java/com
parent6f4c1311f0f83a6901c3880538ef710888f3ce5a (diff)
downloadjackcess-5f93a558aefae1d95fef260240c64fe1011e1e56.tar.gz
jackcess-5f93a558aefae1d95fef260240c64fe1011e1e56.zip
check for too many pk indexes on a table; add convenience method to TableBuilder for adding pk index
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@562 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java8
-rw-r--r--src/java/com/healthmarketscience/jackcess/TableBuilder.java10
2 files changed, 18 insertions, 0 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java
index 3029881..96d7aaa 100644
--- a/src/java/com/healthmarketscience/jackcess/Database.java
+++ b/src/java/com/healthmarketscience/jackcess/Database.java
@@ -1145,12 +1145,20 @@ public class Database
if(!indexes.isEmpty()) {
// now, validate the indexes
Set<String> idxNames = new HashSet<String>();
+ boolean foundPk = false;
for(IndexBuilder index : indexes) {
index.validate(colNames);
if(!idxNames.add(index.getName().toUpperCase())) {
throw new IllegalArgumentException("duplicate index name: " +
index.getName());
}
+ if(index.isPrimaryKey()) {
+ if(foundPk) {
+ throw new IllegalArgumentException(
+ "found second primary key index: " + index.getName());
+ }
+ foundPk = true;
+ }
}
}
diff --git a/src/java/com/healthmarketscience/jackcess/TableBuilder.java b/src/java/com/healthmarketscience/jackcess/TableBuilder.java
index 740a684..51e8697 100644
--- a/src/java/com/healthmarketscience/jackcess/TableBuilder.java
+++ b/src/java/com/healthmarketscience/jackcess/TableBuilder.java
@@ -103,6 +103,16 @@ public class TableBuilder {
}
/**
+ * Sets the names of the primary key columns for this table. Convenience
+ * method for creating a primary key index on a table.
+ */
+ public TableBuilder setPrimaryKey(String... colNames) {
+ addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME)
+ .addColumns(colNames).setPrimaryKey());
+ return this;
+ }
+
+ /**
* Escapes the new table's name using {@link Database#escapeIdentifier}.
*/
public TableBuilder escapeName()