public class MetaUtil extends Object
需要注意的是,此工具类在某些数据库(比如Oracle)下无效,此时需要手动在数据库配置中增加:
remarks = true useInformationSchema = true
Constructor and Description |
---|
MetaUtil() |
Modifier and Type | Method and Description |
---|---|
static Entity |
createLimitedEntity(DataSource ds,
String tableName)
创建带有字段限制的Entity对象
此方法读取数据库中对应表的字段列表,加入到Entity中,当Entity被设置内容时,会忽略对应表字段外的所有KEY |
static String |
getCatalog(Connection conn)
获取catalog,获取失败返回
null |
static String |
getCataLog(Connection conn)
Deprecated.
拼写错误,请使用
getCatalog(Connection) |
static String[] |
getColumnNames(DataSource ds,
String tableName)
获得表的所有列名
|
static String[] |
getColumnNames(ResultSet rs)
获得结果集的所有列名
|
static String |
getSchema(Connection conn)
获取schema,获取失败返回
null |
static Table |
getTableMeta(DataSource ds,
String tableName)
获得表的元信息
注意如果需要获取注释,某些数据库如MySQL,需要在配置中添加: |
static Table |
getTableMeta(DataSource ds,
String catalog,
String schema,
String tableName)
获得表的元信息
注意如果需要获取注释,某些数据库如MySQL,需要在配置中添加: |
static List<String> |
getTables(DataSource ds)
获得所有表名
|
static List<String> |
getTables(DataSource ds,
String schema,
String tableName,
TableType... types)
获得所有表名
|
static List<String> |
getTables(DataSource ds,
String schema,
TableType... types)
获得所有表名
|
static List<String> |
getTables(DataSource ds,
TableType... types)
获得所有表名
|
public static List<String> getTables(DataSource ds)
ds
- 数据源public static List<String> getTables(DataSource ds, TableType... types)
ds
- 数据源types
- 表类型public static List<String> getTables(DataSource ds, String schema, TableType... types)
ds
- 数据源schema
- 表数据库名,对于Oracle为用户名types
- 表类型public static List<String> getTables(DataSource ds, String schema, String tableName, TableType... types)
ds
- 数据源schema
- 表数据库名,对于Oracle为用户名tableName
- 表名types
- 表类型public static String[] getColumnNames(ResultSet rs) throws DbRuntimeException
rs
- 结果集DbRuntimeException
- SQL执行异常public static String[] getColumnNames(DataSource ds, String tableName)
ds
- 数据源tableName
- 表名DbRuntimeException
- SQL执行异常public static Entity createLimitedEntity(DataSource ds, String tableName)
ds
- 数据源tableName
- 表名public static Table getTableMeta(DataSource ds, String tableName)
remarks = true useInformationSchema = true
ds
- 数据源tableName
- 表名public static Table getTableMeta(DataSource ds, String catalog, String schema, String tableName)
remarks = true useInformationSchema = true
ds
- 数据源tableName
- 表名catalog
- catalog name,null
表示自动获取,见:getCatalog(Connection)
schema
- a schema name pattern,null
表示自动获取,见:getSchema(Connection)
@Deprecated public static String getCataLog(Connection conn)
getCatalog(Connection)
null
conn
- Connection
数据库连接,null
时返回nullnull
public static String getCatalog(Connection conn)
null
conn
- Connection
数据库连接,null
时返回nullnull
public static String getSchema(Connection conn)
null
conn
- Connection
数据库连接,null
时返回nullnull
Copyright © 2024. All rights reserved.