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

Add Constraint.Type.getSqlName()

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