// can only alter tables we created
if (!manager.hasCreateTable(tableName)) {
return;
}
JDBCFunctionMappingMetaData fkConstraint = manager.getMetaData().getTypeMapping().getFkConstraintTemplate();
if (fkConstraint == null) {
throw new IllegalStateException("Foreign key constraint is not allowed for this type of datastore");
}
String a = SQLUtil.getColumnNamesClause(fields, new StringBuffer(50)).toString();
String b = SQLUtil.getColumnNamesClause(referencesFields, new StringBuffer(50)).toString();
String[] args = new String[]{
tableName,
SQLUtil.fixConstraintName("fk_" + tableName + "_" + cmrFieldName, dataSource),
a,
referencesTableName,
b};
String sql = fkConstraint.getFunctionSql(args, new StringBuffer(100)).toString();
// since we use the pools, we have to do this within a transaction
// suspend the current transaction
TransactionManager tm = manager.getComponent().getTransactionManager();
Transaction oldTransaction;