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;
+ }
}
}
return this;
}
+ /**
+ * 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}.
*/