提交 4dd2d02c authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add Constraint.Type.getSqlName()

上级 0ea0365c
......@@ -39,7 +39,23 @@ public abstract class Constraint extends SchemaObjectBase implements
/**
* The constraint type for referential constraints.
*/
REFERENTIAL
REFERENTIAL;
/**
* Get standard SQL type name.
*
* @return standard SQL type name
*/
public String getSqlName() {
if (this == Constraint.Type.PRIMARY_KEY) {
return "PRIMARY KEY";
}
if (this == Constraint.Type.REFERENTIAL) {
return "FOREIGN KEY";
}
return name();
}
}
/**
......
......@@ -54,7 +54,7 @@ public class ConstraintUnique extends Constraint {
if (comment != null) {
buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
}
buff.append(' ').append(getTypeName()).append('(');
buff.append(' ').append(getConstraintType().getSqlName()).append('(');
for (IndexColumn c : columns) {
buff.appendExceptFirst(", ");
buff.append(Parser.quoteIdentifier(c.column.getName()));
......@@ -66,13 +66,6 @@ public class ConstraintUnique extends Constraint {
return buff.toString();
}
private String getTypeName() {
if (primaryKey) {
return "PRIMARY KEY";
}
return "UNIQUE";
}
@Override
public String getCreateSQLWithoutIndexes() {
return getCreateSQLForCopy(table, getSQL(), false);
......
......@@ -1953,14 +1953,6 @@ public class MetaTable extends Table {
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
String constraintTypeAsString;
if (constraintType == Constraint.Type.PRIMARY_KEY) {
constraintTypeAsString = "PRIMARY KEY";
} else if (constraintType == Constraint.Type.REFERENTIAL) {
constraintTypeAsString = "FOREIGN KEY";
} else {
constraintTypeAsString = constraintType.name();
}
add(rows,
// CONSTRAINT_CATALOG
catalog,
......@@ -1969,7 +1961,7 @@ public class MetaTable extends Table {
// CONSTRAINT_NAME
identifier(constraint.getName()),
// CONSTRAINT_TYPE
constraintTypeAsString,
constraintType.getSqlName(),
// TABLE_CATALOG
catalog,
// TABLE_SCHEMA
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论