use of com.github.drinkjava2.jdialects.model.ColumnModel in project jDialects by drinkjava2.
the class DDLCreateUtils method buildUniqueDLL.
private static void buildUniqueDLL(Dialect dialect, List<Object> objectResultList, TableModel t) {
List<UniqueModel> l = t.getUniqueConsts();
if (l == null || l.isEmpty())
return;
String dialectName = "" + dialect;
for (UniqueModel unique : l) {
boolean nullable = false;
String[] columns = unique.getColumnList();
for (String colNames : columns) {
ColumnModel vc = t.getColumn(colNames.toLowerCase());
if (vc != null && vc.getNullable())
nullable = true;
}
String uniqueName = unique.getName();
if (StrUtils.isEmpty(uniqueName))
uniqueName = "UK_" + t.getTableName() + "_" + StrUtils.arrayToString(unique.getColumnList(), "_");
String template = "alter table $TABLE add constraint $UKNAME unique ($COLUMNS)";
if ((// DB2 and
StrUtils.startsWithIgnoreCase(dialectName, "DB2") || // DERBY
StrUtils.startsWithIgnoreCase(dialectName, "DERBY")) && nullable)
template = "create unique index $UKNAME on $TABLE ($COLUMNS)";
else if (StrUtils.startsWithIgnoreCase(dialectName, "Informix"))
template = "alter table $TABLE add constraint unique ($COLUMNS) constraint $UKNAME";
String result = StrUtils.replace(template, "$TABLE", t.getTableName());
result = StrUtils.replace(result, "$UKNAME", uniqueName);
result = StrUtils.replace(result, "$COLUMNS", StrUtils.arrayToString(unique.getColumnList()));
objectResultList.add(result);
}
}
Aggregations