public class DBMetaData extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends DBObject> |
createTable(Connection conn,
Class<T> clz)
创建表
|
static boolean |
createTable(Connection conn,
TableMapping meta)
创建表
|
static boolean |
createTable(Connection conn,
TableMapping meta,
String tablename)
创建表
|
boolean |
existsFunction(Connection conn,
String schema,
String name)
返回指定名称的函数是否存在(需要支持JDBC 4.0的驱动才可执行)
|
boolean |
existsInSchema(Connection conn,
ObjectType type,
String schema,
String objectName)
判断对象是否存在于指定的schema下
|
boolean |
existsProcdure(Connection conn,
String schema,
String objectName)
检查是否存在指定的存储过程
|
boolean |
existTable(Connection conn,
String tableName) |
DatabaseMetaData |
get(Connection conn)
Deprecated.
not recommended
|
String |
getCatalog(Connection conn)
获取当前连接的catalog
|
String[] |
getCatalogs(Connection conn)
获取数据库中所有的catalog
|
ColumnInfo |
getColumn(Connection conn,
String tableName,
String column)
返回指定的列的信息,如果没有找到该列返回null
|
Map<DBField,ColumnMapping> |
getColumnMap(TableMapping meta) |
List<ColumnInfo> |
getColumns(Connection conn,
String tableName)
得到指定表的所有列
|
List<TableInfo> |
getDatabaseObject(Connection conn,
ObjectType type,
String catalog,
String schema,
String matchName,
Operator oper) |
String |
getExists(Connection conn,
ObjectType type,
String objectName)
判断对象是否存在
|
String |
getExistTable(Connection conn,
String tableName)
判断一张表是否存在
|
List<Function> |
getFunctions(Connection conn,
String schema)
返回所有自定义数据库函数
|
Collection<Index> |
getIndexes(Connection conn,
String tableName)
得到指定表的所有索引
|
static DBMetaData |
getInstance() |
MetadataFeature |
getMetadataFeature(Connection conn) |
List<Function> |
getProcedures(Connection conn,
String schema)
得到数据库中的当前用户的存储过程
|
String[] |
getSchemas(Connection conn)
获得所有的Schema
|
String |
getSQLKeywords(Connection conn)
得到由JDBC驱动提供的所有数据库关键字
|
String |
getSystemFunctions(Connection conn)
得到内建其他函数名
|
List<String> |
getTableNames(Connection conn,
String catalog,
String schema,
ObjectType... types)
返回当前schema下的所有数据库表名
|
static void |
refreshTable(Connection conn,
Class<?> clz)
检查并修改数据库中的表,使其和传入的实体模型保持一致。
|
static void |
refreshTable(Connection conn,
TableMapping meta,
MetadataEventListener event)
检查并修改数据库中的表,使其和传入的实体模型保持一致。
|
static void |
refreshTable(Connection conn,
TableMapping meta,
MetadataEventListener event,
boolean modifyConstraint,
boolean modifyIndexes)
检查并修改数据库中的表,使其和传入的实体模型保持一致。
|
static void |
refreshTable(Connection conn,
TableMapping meta,
String tablename,
MetadataEventListener event,
boolean modifyConstraint,
boolean modifyIndex)
更新表。此操作核对输入的元模型和数据库中表的差异,并且通过create table或alter table等语句尽可能将其修改得和元模型一直。
|
boolean |
supportsTransactionIsolationLevel(Connection conn,
int level)
判断,是否支持指定的事务隔离级别
|
void |
truncate(Connection conn,
TableMapping meta,
List<String> tablename)
清除表中的所有数据。truncate是DDL不能回滚。
|
public static DBMetaData getInstance()
public Map<DBField,ColumnMapping> getColumnMap(TableMapping meta)
public MetadataFeature getMetadataFeature(Connection conn)
public ColumnInfo getColumn(Connection conn, String tableName, String column) throws SQLException
tableName
- 表名column
- 列名SQLException
public boolean existsInSchema(Connection conn, ObjectType type, String schema, String objectName) throws SQLException
type
- 要查找的对象类型schema
- 所属schemaobjectName
- 对象名称SQLException
ObjectType
public List<ColumnInfo> getColumns(Connection conn, String tableName) throws SQLException
tableName
- 表名SQLException
ColumnInfo
public Collection<Index> getIndexes(Connection conn, String tableName) throws SQLException
tableName
- 表名SQLException
Index
public List<TableInfo> getDatabaseObject(Connection conn, ObjectType type, String catalog, String schema, String matchName, Operator oper) throws SQLException
type
- 要查询的对象类型 "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
"LOCAL TEMPORARY", "ALIAS", "SYNONYM".schema
- SchemamatchName
- 匹配名称oper
- 操作符,可以为null,为null时表示等于条件SQLException
Operator
public List<String> getTableNames(Connection conn, String catalog, String schema, ObjectType... types) throws SQLException
types
- 取以下参数ObjectType
。可以省略,省略的情况下取TableSQLException
public boolean existTable(Connection conn, String tableName) throws SQLException
SQLException
public String getExistTable(Connection conn, String tableName) throws SQLException
tableName
- 表名SQLException
public String getExists(Connection conn, ObjectType type, String objectName) throws SQLException
type
- 要查找的对象类型objectName
- 对象名称SQLException
ObjectType
public String getCatalog(Connection conn) throws SQLException
conn
- SQLException
public String[] getCatalogs(Connection conn) throws SQLException
SQLException
public String[] getSchemas(Connection conn) throws SQLException
SQLException
public DatabaseMetaData get(Connection conn) throws SQLException
SQLException
public boolean existsProcdure(Connection conn, String schema, String objectName) throws SQLException
schema
- 所在schemaobjectName
- 存储过程名SQLException
public boolean existsFunction(Connection conn, String schema, String name) throws SQLException
schema
- 所在schemaname
- 函数名SQLException
- 检测用户函数功能在 JDBC 4.0 (JDK 6)中定义,很多旧版本驱动都不支持,会抛出此异常public List<Function> getProcedures(Connection conn, String schema) throws SQLException
schema
- 数据库schema,传入null表示当前schemaSQLException
public List<Function> getFunctions(Connection conn, String schema) throws SQLException
schema
- 数据库schema,传入null表示当前schemaSQLException
public String getSystemFunctions(Connection conn) throws SQLException
SQLException
public String getSQLKeywords(Connection conn) throws SQLException
SQLException
public boolean supportsTransactionIsolationLevel(Connection conn, int level) throws SQLException
level
- SQLException
public static void refreshTable(Connection conn, Class<?> clz) throws SQLException
clz
- 要更新的表对应的类SQLException
public static void refreshTable(Connection conn, TableMapping meta, MetadataEventListener event) throws SQLException
meta
- 要更新的表的元数据event
- 事件监听器,可以监听刷新过程的事件SQLException
public static void refreshTable(Connection conn, TableMapping meta, MetadataEventListener event, boolean modifyConstraint, boolean modifyIndexes) throws SQLException
meta
- 要更新的表的元数据event
- 事件监听器,可以监听刷新过程的事件modifyConstraint
- 更改约束modifyIndexes
- 更改索引SQLException
MetadataEventListener
public static void refreshTable(Connection conn, TableMapping meta, String tablename, MetadataEventListener event, boolean modifyConstraint, boolean modifyIndex) throws SQLException
此外,由于ALTER TABLE语句是DDL,因此多个DDL执行中出现错误时,已经执行过的语句将不会被回滚。所以请尽可能通过 监听器 的监听事件来把握表变更的进度情况。
meta
- 元模型tablename
- 表名event
- 事件监听器,可以捕捉表对比、SQL语句执行前后等事件SQLException
- 修改表失败时抛出变更监听器
public void truncate(Connection conn, TableMapping meta, List<String> tablename) throws SQLException
meta
- 要清除的表的元数据tablename
- 表名SQLException
public static <T extends DBObject> boolean createTable(Connection conn, Class<T> clz) throws SQLException
clz
- 建表的CLassSQLException
public static boolean createTable(Connection conn, TableMapping meta) throws SQLException
meta
- 表结构描述。 The metadata of the table.SQLException
public static boolean createTable(Connection conn, TableMapping meta, String tablename) throws SQLException
meta
- 表结构描述。 The metadata of the table.tablename
- 表名。 The name of the table.SQLException
TableMapping}
Copyright © 2020. All rights reserved.