Browse Source

KERNEL-5345 refactor: 对mysql5数据库特殊处理 改在third

release/10.0
lidongy 4 years ago
parent
commit
9039b3a654
  1. 17
      fine-hibernate/src/main/java/com/fr/third/org/hibernate/dialect/MySQL5Dialect.java
  2. 17
      fine-hibernate/src/main/java/com/fr/third/org/hibernate/dialect/MySQL8Dialect.java

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

@ -9,9 +9,11 @@ package com.fr.third.org.hibernate.dialect;
import com.fr.third.org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; import com.fr.third.org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
import com.fr.third.org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import com.fr.third.org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
import com.fr.third.org.hibernate.internal.util.JdbcExceptionHelper; import com.fr.third.org.hibernate.internal.util.JdbcExceptionHelper;
import com.fr.third.org.hibernate.mapping.Column;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.List;
/** /**
* An SQL dialect for MySQL 5.x specific features. * An SQL dialect for MySQL 5.x specific features.
@ -19,6 +21,9 @@ import java.sql.Types;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class MySQL5Dialect extends MySQLDialect { public class MySQL5Dialect extends MySQLDialect {
private static final int INDEX_LENGTH_LIMIT = 255;
@Override @Override
protected void registerVarcharTypes() { protected void registerVarcharTypes() {
registerColumnType( Types.VARCHAR, "longtext" ); registerColumnType( Types.VARCHAR, "longtext" );
@ -32,6 +37,18 @@ public class MySQL5Dialect extends MySQLDialect {
return false; 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";
}
}
return "primary key";
}
public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() { public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
return EXTRACTER; return EXTRACTER;
} }

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

@ -0,0 +1,17 @@
package com.fr.third.org.hibernate.dialect;
import com.fr.third.org.hibernate.mapping.Column;
import java.util.List;
/**
* @author lidongy
* @version 10.0
* Created by lidongy on 2020/9/18
*/
public class MySQL8Dialect extends MySQL5Dialect {
@Override
public String getPrimaryKeyString(List<Column> columnList) {
return "primary key";
}
}
Loading…
Cancel
Save