Browse Source
* commit 'ab3816fa87262d3c0d56c543f292536f16f1377d': DEC-15106 test: 补充单元测试 DEC-15106 fix: 改成统一在方言中实现,方便维护一点 DEC-15106 fix: mysql有些小版本(如5.5.46)不支持创建key的同时自动创建前缀索引,此处手动指定 KERNEL-5345 refactor: 对mysql5数据库特殊处理 改在third KERNEL-5345 refactor: hibernate特殊处理,使其可以扩展建表时的主键设置语句bugfix/10.0
superman
4 years ago
6 changed files with 119 additions and 12 deletions
@ -0,0 +1,24 @@ |
|||||||
|
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 sqlConstraintString(List<Column> columnList) { |
||||||
|
StringBuilder buf = new StringBuilder("primary key ("); |
||||||
|
for (int i = 0; i < columnList.size(); i++) { |
||||||
|
if (i != 0) { |
||||||
|
buf.append(", "); |
||||||
|
} |
||||||
|
buf.append(columnList.get(i).getQuotedName(this)); |
||||||
|
} |
||||||
|
return buf.append(')').toString(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
package com.fr.third.org.hibernate.dialect; |
||||||
|
|
||||||
|
import com.fr.third.org.hibernate.mapping.Column; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author lidongy |
||||||
|
* @version 10.0 |
||||||
|
* Created by lidongy on 2020/9/18 |
||||||
|
*/ |
||||||
|
public class MySQLDialectTest { |
||||||
|
@Test |
||||||
|
public void testSqlConstraintString() { |
||||||
|
List<Column> columnList = new ArrayList<>(); |
||||||
|
Column column1 = new Column(); |
||||||
|
column1.setName("id1"); |
||||||
|
column1.setLength(1000); |
||||||
|
Column column2 = new Column(); |
||||||
|
column2.setName("id2"); |
||||||
|
column2.setLength(200); |
||||||
|
Column column3 = new Column(); |
||||||
|
column3.setName("id3"); |
||||||
|
column3.setLength(255); |
||||||
|
|
||||||
|
columnList.add(column1); |
||||||
|
columnList.add(column2); |
||||||
|
columnList.add(column3); |
||||||
|
|
||||||
|
Assert.assertEquals(new MySQLDialect().sqlConstraintString(columnList), "primary key (id1, id2, id3)"); |
||||||
|
Assert.assertEquals(new MySQL5Dialect().sqlConstraintString(columnList), "key (id1(255), id2, id3)"); |
||||||
|
Assert.assertEquals(new MySQL8Dialect().sqlConstraintString(columnList), "primary key (id1, id2, id3)"); |
||||||
|
|
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue