|
|
|
@ -37,24 +37,28 @@ public class MySQL5Dialect extends MySQLDialect {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//utf8编码下,mysql5.7以下版本主键长度不能超过255,故特殊处理,去掉它的primary。
|
|
|
|
|
// 它默认会生成一个长度为255的前缀索引
|
|
|
|
|
@Override |
|
|
|
|
public String getPrimaryKeyString(List<Column> columnList) { |
|
|
|
|
for (Column column : columnList) { |
|
|
|
|
if (column.getLength() > INDEX_LENGTH_LIMIT) { |
|
|
|
|
return "key"; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String sqlConstraintString(List<Column> columnList) { |
|
|
|
|
StringBuilder buf = new StringBuilder("key ("); |
|
|
|
|
boolean overLimit = false; |
|
|
|
|
for (int i = 0; i < columnList.size(); i ++) { |
|
|
|
|
if (i != 0) { |
|
|
|
|
buf.append(", "); |
|
|
|
|
} |
|
|
|
|
Column column = columnList.get(i); |
|
|
|
|
buf.append(column.getQuotedName(this)); |
|
|
|
|
if (column.getLength() > INDEX_LENGTH_LIMIT) { |
|
|
|
|
buf.append("(" + INDEX_LENGTH_LIMIT + ")"); |
|
|
|
|
overLimit = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!overLimit) { |
|
|
|
|
buf.insert(0, "primary "); |
|
|
|
|
} |
|
|
|
|
return "primary key"; |
|
|
|
|
} |
|
|
|
|
return buf.append(')').toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// mysql有些小版本(如5.5.46)不支持创建key的同时自动创建前缀索引,此处手动指定
|
|
|
|
|
@Override |
|
|
|
|
public String getPrimaryKeyPostfix(Column column) { |
|
|
|
|
int columnLength = column.getLength(); |
|
|
|
|
return columnLength > INDEX_LENGTH_LIMIT ? "(" + INDEX_LENGTH_LIMIT + ")" : ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() { |
|
|
|
|
return EXTRACTER; |
|
|
|
|