提交 ad68f1ec authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add ExtTypeInfo.getCreateSQL()

上级 74188a32
...@@ -5027,7 +5027,7 @@ public class Parser { ...@@ -5027,7 +5027,7 @@ public class Parser {
} catch (DbException e) { } catch (DbException e) {
throw e.addSQL(original); throw e.addSQL(original);
} }
original += extTypeInfo.toString(); original += extTypeInfo.getCreateSQL();
} }
} else if (dataType.type == Value.GEOMETRY) { } else if (dataType.type == Value.GEOMETRY) {
if (extTypeInfo == null) { if (extTypeInfo == null) {
...@@ -5051,7 +5051,7 @@ public class Parser { ...@@ -5051,7 +5051,7 @@ public class Parser {
} }
read(CLOSE_PAREN); read(CLOSE_PAREN);
extTypeInfo = new ExtTypeInfoGeometry(type, srid); extTypeInfo = new ExtTypeInfoGeometry(type, srid);
original += extTypeInfo.toString(); original += extTypeInfo.getCreateSQL();
} }
} }
} else if (readIf(OPEN_PAREN)) { } else if (readIf(OPEN_PAREN)) {
......
...@@ -515,7 +515,7 @@ public class Column { ...@@ -515,7 +515,7 @@ public class Column {
} }
//$FALL-THROUGH$ //$FALL-THROUGH$
case Value.ENUM: case Value.ENUM:
buff.append(extTypeInfo.toString()); buff.append(extTypeInfo.getCreateSQL());
break; break;
case Value.BYTES: case Value.BYTES:
case Value.STRING: case Value.STRING:
......
...@@ -19,4 +19,16 @@ public abstract class ExtTypeInfo { ...@@ -19,4 +19,16 @@ public abstract class ExtTypeInfo {
*/ */
public abstract Value cast(Value value); public abstract Value cast(Value value);
/**
* Returns SQL including parentheses that should be appended to a type name.
*
* @return SQL including parentheses that should be appended to a type name
*/
public abstract String getCreateSQL();
@Override
public String toString() {
return getCreateSQL();
}
} }
...@@ -43,7 +43,7 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo { ...@@ -43,7 +43,7 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
return label == null ? null : label.trim().toUpperCase(Locale.ENGLISH); return label == null ? null : label.trim().toUpperCase(Locale.ENGLISH);
} }
private static String toString(String[] enumerators) { private static String toSQL(String[] enumerators) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
result.append('('); result.append('(');
for (int i = 0; i < enumerators.length; i++) { for (int i = 0; i < enumerators.length; i++) {
...@@ -83,7 +83,7 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo { ...@@ -83,7 +83,7 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
} }
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
if (l.equals(cleaned[j])) { if (l.equals(cleaned[j])) {
throw DbException.get(ErrorCode.ENUM_DUPLICATE, toString(enumerators)); throw DbException.get(ErrorCode.ENUM_DUPLICATE, toSQL(enumerators));
} }
} }
cleaned[i] = l; cleaned[i] = l;
...@@ -177,8 +177,8 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo { ...@@ -177,8 +177,8 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
} }
@Override @Override
public String toString() { public String getCreateSQL() {
return toString(enumerators); return toSQL(enumerators);
} }
} }
...@@ -18,7 +18,7 @@ public final class ExtTypeInfoGeometry extends ExtTypeInfo { ...@@ -18,7 +18,7 @@ public final class ExtTypeInfoGeometry extends ExtTypeInfo {
private final Integer srid; private final Integer srid;
private static String toString(int type, Integer srid) { private static String toSQL(int type, Integer srid) {
if (type == 0 && srid == null) { if (type == 0 && srid == null) {
return ""; return "";
} }
...@@ -58,14 +58,14 @@ public final class ExtTypeInfoGeometry extends ExtTypeInfo { ...@@ -58,14 +58,14 @@ public final class ExtTypeInfoGeometry extends ExtTypeInfo {
ValueGeometry g = (ValueGeometry) value; ValueGeometry g = (ValueGeometry) value;
if (type != 0 && g.getTypeAndDimensionSystem() != type || srid != null && g.getSRID() != srid) { if (type != 0 && g.getTypeAndDimensionSystem() != type || srid != null && g.getSRID() != srid) {
throw DbException.get(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, throw DbException.get(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1,
toString(g.getTypeAndDimensionSystem(), g.getSRID()) + " <> " + toString()); toSQL(g.getTypeAndDimensionSystem(), g.getSRID()) + " <> " + toString());
} }
return g; return g;
} }
@Override @Override
public String toString() { public String getCreateSQL() {
return toString(type, srid); return toSQL(type, srid);
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论