Browse Source

DEC-15106 fix: mysql有些小版本(如5.5.46)不支持创建key的同时自动创建前缀索引,此处手动指定

release/10.0
lidongy 4 years ago
parent
commit
986e749924
  1. 9
      fine-hibernate/src/main/java/com/fr/third/org/hibernate/dialect/Dialect.java
  2. 7
      fine-hibernate/src/main/java/com/fr/third/org/hibernate/dialect/MySQL5Dialect.java
  3. 4
      fine-hibernate/src/main/java/com/fr/third/org/hibernate/dialect/MySQL8Dialect.java
  4. 4
      fine-hibernate/src/main/java/com/fr/third/org/hibernate/mapping/PrimaryKey.java

9
fine-hibernate/src/main/java/com/fr/third/org/hibernate/dialect/Dialect.java

@ -2788,7 +2788,14 @@ public abstract class Dialect implements ConversionContext {
* 获取主键sql字符串
*
* @param columnList 主键列集合
* @return int
* @return String
*/
public String getPrimaryKeyString(List<Column> columnList) { return "primary key";}
/**
* 获取主键sql后缀
*
* @return String
*/
public String getPrimaryKeyPostfix(Column column) { return "";}
}

7
fine-hibernate/src/main/java/com/fr/third/org/hibernate/dialect/MySQL5Dialect.java

@ -49,6 +49,13 @@ public class MySQL5Dialect extends MySQLDialect {
return "primary key";
}
// 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;
}

4
fine-hibernate/src/main/java/com/fr/third/org/hibernate/dialect/MySQL8Dialect.java

@ -14,4 +14,8 @@ public class MySQL8Dialect extends MySQL5Dialect {
public String getPrimaryKeyString(List<Column> columnList) {
return "primary key";
}
@Override
public String getPrimaryKeyPostfix(Column column) { return "";}
}

4
fine-hibernate/src/main/java/com/fr/third/org/hibernate/mapping/PrimaryKey.java

@ -63,7 +63,9 @@ public class PrimaryKey extends Constraint {
StringBuilder buf = new StringBuilder(dialect.getPrimaryKeyString(columnList)).append(" (");
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
Column column = (Column) iter.next();
buf.append( column.getQuotedName(dialect) );
buf.append( dialect.getPrimaryKeyPostfix(column) );
if ( iter.hasNext() ) {
buf.append(", ");
}

Loading…
Cancel
Save