mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add field
This commit is contained in:
parent
13431497ae
commit
37b051a46c
@ -12,6 +12,8 @@
|
|||||||
* 【core 】 扩充Console功能,支持可变参数(issue#1077@Github)
|
* 【core 】 扩充Console功能,支持可变参数(issue#1077@Github)
|
||||||
* 【crypto 】 增加ECKeyUtil(issue#I1UOF5@Gitee)
|
* 【crypto 】 增加ECKeyUtil(issue#I1UOF5@Gitee)
|
||||||
* 【core 】 增加TransXXX(issue#I1TU1Y@Gitee)
|
* 【core 】 增加TransXXX(issue#I1TU1Y@Gitee)
|
||||||
|
* 【core 】 增加Generator
|
||||||
|
* 【db 】 Column增加是否主键、保留位数等字段
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复Dict.of错误(issue#I1UUO5@Gitee)
|
* 【core 】 修复Dict.of错误(issue#I1UUO5@Gitee)
|
||||||
|
@ -1005,20 +1005,14 @@ public class FileUtil extends PathUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改文件或目录的文件名,不变更路径,只是简单修改文件名<br>
|
* 修改文件或目录的文件名,不变更路径,只是简单修改文件名,不保留扩展名。<br>
|
||||||
* 重命名有两种模式:<br>
|
|
||||||
* 1、isRetainExt为true时,保留原扩展名:
|
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* FileUtil.rename(file, "aaa", true) xx/xx.png =》xx/aaa.png
|
* FileUtil.rename(file, "aaa.png", true) xx/xx.png =》xx/aaa.png
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* FileUtil.rename(file, "aaa.jpg", false) xx/xx.png =》xx/aaa.jpg
|
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param file 被修改的文件
|
* @param file 被修改的文件
|
||||||
* @param newName 新的文件名,包括扩展名
|
* @param newName 新的文件名,如需扩展名,需自行在此参数加上,原文件名的扩展名不会被保留
|
||||||
* @param isOverride 是否覆盖目标文件
|
* @param isOverride 是否覆盖目标文件
|
||||||
* @return 目标文件
|
* @return 目标文件
|
||||||
* @since 5.3.6
|
* @since 5.3.6
|
||||||
@ -1035,6 +1029,7 @@ public class FileUtil extends PathUtil {
|
|||||||
* <pre>
|
* <pre>
|
||||||
* FileUtil.rename(file, "aaa", true) xx/xx.png =》xx/aaa.png
|
* FileUtil.rename(file, "aaa", true) xx/xx.png =》xx/aaa.png
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 2、isRetainExt为false时,不保留原扩展名,需要在newName中
|
* 2、isRetainExt为false时,不保留原扩展名,需要在newName中
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package cn.hutool.core.lang.generator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成器泛型接口<br>
|
||||||
|
* 通过实现此接口可以自定义生成对象的策略
|
||||||
|
*
|
||||||
|
* @param <T> 生成对象类型
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public interface Generator<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成新的对象
|
||||||
|
*
|
||||||
|
* @return 新的对象
|
||||||
|
*/
|
||||||
|
T next();
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package cn.hutool.core.lang.generator;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象生成器,通过指定对象的Class类型,调用next方法时生成新的对象。
|
||||||
|
*
|
||||||
|
* @param <T> 对象类型
|
||||||
|
* @author looly
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public class ObjectGenerator<T> implements Generator<T> {
|
||||||
|
|
||||||
|
private final Class<T> clazz;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
* @param clazz 对象类型
|
||||||
|
*/
|
||||||
|
public ObjectGenerator(Class<T> clazz) {
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
return ReflectUtil.newInstanceIfPossible(this.clazz);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cn.hutool.core.lang.generator;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.ObjectId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ObjectId生成器
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public class ObjectIdGenerator implements Generator<String> {
|
||||||
|
@Override
|
||||||
|
public String next() {
|
||||||
|
return ObjectId.next();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package cn.hutool.core.lang.generator;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Snowflake;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Snowflake生成器<br>
|
||||||
|
* 注意,默认此生成器必须单例使用,否则会有重复<br>
|
||||||
|
* 默认构造的终端ID和数据中心ID都为0,不适用于分布式环境。
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public class SnowflakeGenerator implements Generator<Long> {
|
||||||
|
|
||||||
|
private final Snowflake snowflake;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*/
|
||||||
|
public SnowflakeGenerator() {
|
||||||
|
this(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param workerId 终端ID
|
||||||
|
* @param dataCenterId 数据中心ID
|
||||||
|
*/
|
||||||
|
public SnowflakeGenerator(long workerId, long dataCenterId) {
|
||||||
|
snowflake = new Snowflake(workerId, dataCenterId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long next() {
|
||||||
|
return this.snowflake.nextId();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cn.hutool.core.lang.generator;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UUID生成器
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public class UUIDGenerator implements Generator<String> {
|
||||||
|
@Override
|
||||||
|
public String next() {
|
||||||
|
return IdUtil.fastUUID();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* 提供生成器接口及相关封装
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package cn.hutool.core.lang.generator;
|
@ -1,10 +1,9 @@
|
|||||||
package cn.hutool.core.date;
|
package cn.hutool.core.date;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.BetweenFormater.Level;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import cn.hutool.core.date.BetweenFormater.Level;
|
|
||||||
|
|
||||||
public class BetweenFormaterTest {
|
public class BetweenFormaterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.hutool.db.dialect.impl;
|
package cn.hutool.db.dialect.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.ListUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
@ -10,7 +10,11 @@ import cn.hutool.db.Page;
|
|||||||
import cn.hutool.db.StatementUtil;
|
import cn.hutool.db.StatementUtil;
|
||||||
import cn.hutool.db.dialect.Dialect;
|
import cn.hutool.db.dialect.Dialect;
|
||||||
import cn.hutool.db.dialect.DialectName;
|
import cn.hutool.db.dialect.DialectName;
|
||||||
import cn.hutool.db.sql.*;
|
import cn.hutool.db.sql.Condition;
|
||||||
|
import cn.hutool.db.sql.LogicalOperator;
|
||||||
|
import cn.hutool.db.sql.Query;
|
||||||
|
import cn.hutool.db.sql.SqlBuilder;
|
||||||
|
import cn.hutool.db.sql.Wrapper;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -129,7 +133,7 @@ public class AnsiSqlDialect implements Dialect {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement psForCount(Connection conn, Query query) throws SQLException {
|
public PreparedStatement psForCount(Connection conn, Query query) throws SQLException {
|
||||||
query.setFields(CollectionUtil.newArrayList("count(1)"));
|
query.setFields(ListUtil.toList("count(1)"));
|
||||||
return psForFind(conn, query);
|
return psForFind(conn, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,37 +1,60 @@
|
|||||||
package cn.hutool.db.meta;
|
package cn.hutool.db.meta;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.BooleanUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.db.DbRuntimeException;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.db.DbRuntimeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库表的列信息
|
* 数据库表的列信息
|
||||||
*
|
*
|
||||||
* @author loolly
|
* @author loolly
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Column implements Serializable, Cloneable {
|
public class Column implements Serializable, Cloneable {
|
||||||
private static final long serialVersionUID = 577527740359719367L;
|
private static final long serialVersionUID = 577527740359719367L;
|
||||||
|
|
||||||
// ----------------------------------------------------- Fields start
|
// ----------------------------------------------------- Fields start
|
||||||
/** 表名 */
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
||||||
/** 列名 */
|
/**
|
||||||
|
* 列名
|
||||||
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
/** 类型,对应java.sql.Types中的类型 */
|
/**
|
||||||
|
* 类型,对应java.sql.Types中的类型
|
||||||
|
*/
|
||||||
private int type;
|
private int type;
|
||||||
/** 类型名称 */
|
/**
|
||||||
|
* 类型名称
|
||||||
|
*/
|
||||||
private String typeName;
|
private String typeName;
|
||||||
/** 大小或数据长度 */
|
/**
|
||||||
|
* 大小或数据长度
|
||||||
|
*/
|
||||||
private int size;
|
private int size;
|
||||||
/** 是否为可空 */
|
private Integer digit;
|
||||||
|
/**
|
||||||
|
* 是否为可空
|
||||||
|
*/
|
||||||
private boolean isNullable;
|
private boolean isNullable;
|
||||||
/** 注释 */
|
/**
|
||||||
|
* 注释
|
||||||
|
*/
|
||||||
private String comment;
|
private String comment;
|
||||||
|
/**
|
||||||
|
* 是否自增
|
||||||
|
*/
|
||||||
|
private boolean autoIncrement;
|
||||||
|
/**
|
||||||
|
* 是否为主键
|
||||||
|
*/
|
||||||
|
private boolean isPk;
|
||||||
// ----------------------------------------------------- Fields end
|
// ----------------------------------------------------- Fields end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,12 +63,26 @@ public class Column implements Serializable, Cloneable {
|
|||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param columnMetaRs 列元信息的ResultSet
|
* @param columnMetaRs 列元信息的ResultSet
|
||||||
* @return 列对象
|
* @return 列对象
|
||||||
|
* @deprecated 请使用 {@link #create(Table, ResultSet)}
|
||||||
*/
|
*/
|
||||||
public static Column create(String tableName, ResultSet columnMetaRs) {
|
public static Column create(String tableName, ResultSet columnMetaRs) {
|
||||||
return new Column(tableName, columnMetaRs);
|
return new Column(tableName, columnMetaRs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建列对象
|
||||||
|
*
|
||||||
|
* @param columnMetaRs 列元信息的ResultSet
|
||||||
|
* @param table 表信息
|
||||||
|
* @return 列对象
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public static Column create(Table table, ResultSet columnMetaRs) {
|
||||||
|
return new Column(table, columnMetaRs);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------- Constructor start
|
// ----------------------------------------------------- Constructor start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
*/
|
*/
|
||||||
@ -57,7 +94,9 @@ public class Column implements Serializable, Cloneable {
|
|||||||
*
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param columnMetaRs Meta信息的ResultSet
|
* @param columnMetaRs Meta信息的ResultSet
|
||||||
|
* @deprecated 请使用 {@link #Column(Table, ResultSet)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Column(String tableName, ResultSet columnMetaRs) {
|
public Column(String tableName, ResultSet columnMetaRs) {
|
||||||
try {
|
try {
|
||||||
init(tableName, columnMetaRs);
|
init(tableName, columnMetaRs);
|
||||||
@ -65,6 +104,21 @@ public class Column implements Serializable, Cloneable {
|
|||||||
throw new DbRuntimeException(StrUtil.format("Get table [{}] meta info error!", tableName));
|
throw new DbRuntimeException(StrUtil.format("Get table [{}] meta info error!", tableName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param table 表信息
|
||||||
|
* @param columnMetaRs Meta信息的ResultSet
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public Column(Table table, ResultSet columnMetaRs) {
|
||||||
|
try {
|
||||||
|
init(table, columnMetaRs);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DbRuntimeException(StrUtil.format("Get table [{}] meta info error!", tableName));
|
||||||
|
}
|
||||||
|
}
|
||||||
// ----------------------------------------------------- Constructor end
|
// ----------------------------------------------------- Constructor end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,19 +127,52 @@ public class Column implements Serializable, Cloneable {
|
|||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param columnMetaRs 列的meta ResultSet
|
* @param columnMetaRs 列的meta ResultSet
|
||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
|
* @deprecated 请使用 {@link #init(Table, ResultSet)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void init(String tableName, ResultSet columnMetaRs) throws SQLException {
|
public void init(String tableName, ResultSet columnMetaRs) throws SQLException {
|
||||||
this.tableName = tableName;
|
init(Table.create(tableName), columnMetaRs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*
|
||||||
|
* @param table 表信息
|
||||||
|
* @param columnMetaRs 列的meta ResultSet
|
||||||
|
* @throws SQLException SQL执行异常
|
||||||
|
*/
|
||||||
|
public void init(Table table, ResultSet columnMetaRs) throws SQLException {
|
||||||
|
this.tableName = table.getTableName();
|
||||||
|
|
||||||
this.name = columnMetaRs.getString("COLUMN_NAME");
|
this.name = columnMetaRs.getString("COLUMN_NAME");
|
||||||
|
this.isPk = table.isPk(this.name);
|
||||||
|
|
||||||
this.type = columnMetaRs.getInt("DATA_TYPE");
|
this.type = columnMetaRs.getInt("DATA_TYPE");
|
||||||
this.typeName = columnMetaRs.getString("TYPE_NAME");
|
this.typeName = columnMetaRs.getString("TYPE_NAME");
|
||||||
this.size = columnMetaRs.getInt("COLUMN_SIZE");
|
this.size = columnMetaRs.getInt("COLUMN_SIZE");
|
||||||
this.isNullable = columnMetaRs.getBoolean("NULLABLE");
|
this.isNullable = columnMetaRs.getBoolean("NULLABLE");
|
||||||
this.comment = columnMetaRs.getString("REMARKS");
|
this.comment = columnMetaRs.getString("REMARKS");
|
||||||
|
|
||||||
|
// 保留小数位数
|
||||||
|
try {
|
||||||
|
this.digit = columnMetaRs.getInt("DECIMAL_DIGITS");
|
||||||
|
} catch (SQLException ignore) {
|
||||||
|
//某些驱动可能不支持,跳过
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否自增
|
||||||
|
try {
|
||||||
|
String auto = columnMetaRs.getString("IS_AUTOINCREMENT");
|
||||||
|
if (BooleanUtil.toBoolean(auto)) {
|
||||||
|
this.autoIncrement = true;
|
||||||
|
}
|
||||||
|
} catch (SQLException ignore) {
|
||||||
|
//某些驱动可能不支持,跳过
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------- Getters and Setters start
|
// ----------------------------------------------------- Getters and Setters start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取表名
|
* 获取表名
|
||||||
*
|
*
|
||||||
@ -196,6 +283,26 @@ public class Column implements Serializable, Cloneable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取小数位数
|
||||||
|
*
|
||||||
|
* @return 大小或数据长度
|
||||||
|
*/
|
||||||
|
public int getDigit() {
|
||||||
|
return digit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置小数位数
|
||||||
|
*
|
||||||
|
* @param digit 小数位数
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public Column setDigit(int digit) {
|
||||||
|
this.digit = digit;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为可空
|
* 是否为可空
|
||||||
*
|
*
|
||||||
@ -235,6 +342,50 @@ public class Column implements Serializable, Cloneable {
|
|||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自增
|
||||||
|
*
|
||||||
|
* @return 是否自增
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public boolean isAutoIncrement() {
|
||||||
|
return autoIncrement;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置是否自增
|
||||||
|
*
|
||||||
|
* @param autoIncrement 是否自增
|
||||||
|
* @return this
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public Column setAutoIncrement(boolean autoIncrement) {
|
||||||
|
this.autoIncrement = autoIncrement;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否主键
|
||||||
|
*
|
||||||
|
* @return 是否主键
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public boolean isPk() {
|
||||||
|
return isPk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置是否主键
|
||||||
|
*
|
||||||
|
* @param isPk 是否主键
|
||||||
|
* @return this
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public Column setPk(boolean isPk) {
|
||||||
|
this.isPk = isPk;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
// ----------------------------------------------------- Getters and Setters end
|
// ----------------------------------------------------- Getters and Setters end
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -186,8 +186,10 @@ public class MetaUtil {
|
|||||||
conn = ds.getConnection();
|
conn = ds.getConnection();
|
||||||
|
|
||||||
// catalog和schema获取失败默认使用null代替
|
// catalog和schema获取失败默认使用null代替
|
||||||
String catalog = getCataLog(conn);
|
final String catalog = getCataLog(conn);
|
||||||
String schema = getSchema(conn);
|
table.setCatalog(catalog);
|
||||||
|
final String schema = getSchema(conn);
|
||||||
|
table.setSchema(schema);
|
||||||
|
|
||||||
final DatabaseMetaData metaData = conn.getMetaData();
|
final DatabaseMetaData metaData = conn.getMetaData();
|
||||||
|
|
||||||
@ -213,7 +215,7 @@ public class MetaUtil {
|
|||||||
try (ResultSet rs = metaData.getColumns(catalog, schema, tableName, null)) {
|
try (ResultSet rs = metaData.getColumns(catalog, schema, tableName, null)) {
|
||||||
if (null != rs) {
|
if (null != rs) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
table.setColumn(Column.create(tableName, rs));
|
table.setColumn(Column.create(table, rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,29 @@ import java.util.Set;
|
|||||||
* 数据库表信息
|
* 数据库表信息
|
||||||
*
|
*
|
||||||
* @author loolly
|
* @author loolly
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Table implements Serializable, Cloneable {
|
public class Table implements Serializable, Cloneable {
|
||||||
private static final long serialVersionUID = -810699625961392983L;
|
private static final long serialVersionUID = -810699625961392983L;
|
||||||
|
|
||||||
/** 表名 */
|
/**
|
||||||
|
* table所在的schema
|
||||||
|
*/
|
||||||
|
private String schema;
|
||||||
|
/**
|
||||||
|
* tables所在的catalog
|
||||||
|
*/
|
||||||
|
private String catalog;
|
||||||
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
private String tableName;
|
private String tableName;
|
||||||
/** 注释 */
|
/**
|
||||||
|
* 注释
|
||||||
|
*/
|
||||||
private String comment;
|
private String comment;
|
||||||
/** 主键字段名列表 */
|
/**
|
||||||
|
* 主键字段名列表
|
||||||
|
*/
|
||||||
private Set<String> pkNames = new LinkedHashSet<>();
|
private Set<String> pkNames = new LinkedHashSet<>();
|
||||||
private final Map<String, Column> columns = new LinkedHashMap<>();
|
private final Map<String, Column> columns = new LinkedHashMap<>();
|
||||||
|
|
||||||
@ -29,6 +42,7 @@ public class Table implements Serializable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------- Constructor start
|
// ----------------------------------------------------- Constructor start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
*
|
*
|
||||||
@ -40,6 +54,51 @@ public class Table implements Serializable, Cloneable {
|
|||||||
// ----------------------------------------------------- Constructor end
|
// ----------------------------------------------------- Constructor end
|
||||||
|
|
||||||
// ----------------------------------------------------- Getters and Setters start
|
// ----------------------------------------------------- Getters and Setters start
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 schema
|
||||||
|
*
|
||||||
|
* @return schema
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public String getSchema() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置schema
|
||||||
|
*
|
||||||
|
* @param schema schema
|
||||||
|
* @return this
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public Table setSchema(String schema) {
|
||||||
|
this.schema = schema;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取catalog
|
||||||
|
*
|
||||||
|
* @return catalog
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public String getCatalog() {
|
||||||
|
return catalog;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置catalog
|
||||||
|
*
|
||||||
|
* @param catalog catalog
|
||||||
|
* @return this
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public Table setCatalog(String catalog) {
|
||||||
|
this.catalog = catalog;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取表名
|
* 获取表名
|
||||||
*
|
*
|
||||||
@ -87,6 +146,17 @@ public class Table implements Serializable, Cloneable {
|
|||||||
return pkNames;
|
return pkNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给定列名是否为主键
|
||||||
|
*
|
||||||
|
* @param columnName 列名
|
||||||
|
* @return 是否为主键
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public boolean isPk(String columnName){
|
||||||
|
return getPkNames().contains(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置主键列表
|
* 设置主键列表
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user