This commit is contained in:
王帅 2024-11-17 21:47:51 +08:00
parent be8ca9a572
commit e234a818f8
2 changed files with 32 additions and 22 deletions

View File

@ -107,12 +107,16 @@ public class Table {
this.comment = comment;
}
/**
* 默认主键
*/
private Column defaultPrimaryKey;
public Column getPrimaryKey() {
// 这里默认表中一定会有字段就不做空判断了
return columns.stream()
.filter(Column::isPrimaryKey)
.findFirst()
.orElseThrow(() -> new NullPointerException("PrimaryKey can't be null"));
if (defaultPrimaryKey == null) {
throw new NullPointerException("PrimaryKey can't be null");
}
return defaultPrimaryKey;
}
public Set<String> getPrimaryKeys() {
@ -176,6 +180,7 @@ public class Table {
}
return false;
}
List<String> superColumns = null;
public void addColumn(Column column) {
@ -193,15 +198,20 @@ public class Table {
}
}
}
if (superColumns.contains(column.getProperty())){
return;
}
// 主键
if (primaryKeys != null && primaryKeys.contains(column.getName())) {
column.setPrimaryKey(true);
if (column.getAutoIncrement() == null && (column.getPropertyType().equals(Integer.class.getName()) || column.getPropertyType().equals(BigInteger.class.getName()))) {
column.setAutoIncrement(true);
}
if (defaultPrimaryKey == null) {
defaultPrimaryKey = column;
}
}
if (superColumns.contains(column.getProperty())) {
return;
}
if (column.getAutoIncrement() == null) {
@ -386,6 +396,7 @@ public class Table {
return "";
}
}
/**
* 构建 kt 继承
*/

View File

@ -18,7 +18,6 @@ package com.mybatisflex.test;
import com.alibaba.druid.pool.DruidDataSource;
import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.datasource.DataSourceDecipher;
import com.mybatisflex.core.datasource.DataSourceManager;
import com.mybatisflex.core.datasource.DataSourceProperty;
import com.mybatisflex.core.row.Db;