I did this by post-processing the DDL.
Here's most of the code, assumes the DDL is in an array of strings. compress method is an exercise for the reader.
If you use this, you owe me a beer :)
Mike
Code:
Pattern createTableP = Pattern.compile("create\\s+table\\s+(\\S+)",Pattern.CASE_INSENSITIVE);
Matcher createTableM = createTableP.matcher("");
Pattern pkP = Pattern.compile("primary\\s+key",Pattern.CASE_INSENSITIVE);
Matcher pkM = pkP.matcher("");
Pattern nnP = Pattern.compile("\\(?(\\S+)\\s+\\S+(\\s+not\\s+null)", Pattern.CASE_INSENSITIVE);
Matcher nnM = nnP.matcher("");
Pattern ciP = Pattern.compile("create\\s+index");
Matcher ciM = ciP.matcher("");
for(int i = 0; i < createSQL.length; ++i) {
// is it a 'create table'?
createTableM.reset(createSQL[i]);
if (createTableM.find()) {
String tableName = createTableM.group(1);
// if there's a 'primary key' clause, add the constraint name
// assumes there isn't a constraint name already
pkM.reset(createSQL[i]);
if (pkM.find()) {
String pkc = "PK_" + compress(tableName, ORACLE_CONSTRAINT_LENGTH - 3);
createSQL[i] = pkM.replaceFirst("constraint " + pkc + " primary key");
}
// for each 'not null' clause add a constraint name
// assumes there isn't a constraint name already
nnM.reset(createSQL[i]);
String updatedSql = "";
int pos = 0;
while (nnM.find()) {
String nnc = "NN_" + compress(tableName + "_" + nnM.group(1), ORACLE_CONSTRAINT_LENGTH - 4);
updatedSql += createSQL[i].substring(pos, nnM.start(2)) + " constraint " + nnc;
pos = nnM.start(2);
}
updatedSql += createSQL[i].substring(pos);
// set tablespace for 'create table'
createSQL[i] = updatedSql + " tablespace my_data";
}
// if this is a 'create index' set the tablespace
ciM.reset(createSQL[i]);
if (ciM.find()) {
createSQL[i] += " tablespace my_index";
}
}
[/code]