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

View File

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