public class DBInfoBuilder extends Object
Modifier and Type | Field and Description |
---|---|
protected Connection |
conn |
protected DataSource |
dataSource |
protected DatabaseMetaData |
dbMeta |
protected int |
driverMajorVersion |
protected String |
driverName |
protected String |
driverVersion |
protected Set<String> |
excludedTables |
protected String[] |
removedTableNamePrefixes |
Constructor and Description |
---|
DBInfoBuilder(DataSource dataSource) |
Modifier and Type | Method and Description |
---|---|
void |
addExcludedTable(String... excludedTables) |
List<TableInfo> |
build() |
protected void |
buildColumnMetas(TableInfo tableInfo)
文档参考: http://dev.mysql.com/doc/connector-j/en/connector-j-reference-type-
conversions.html
|
protected void |
buildPrimaryKey(TableInfo TableInfo) |
protected void |
buildTableNames(List<TableInfo> ret) |
String |
forTableBuilderDoBuild(String tableName) |
ColumnInfo |
getColumn(TableInfo tableInfo,
String column)
返回指定的列的信息,如果没有找到该列返回null
|
protected ResultSet |
getTablesResultSet()
不同数据库 dbMeta.getTables(...) 的 schemaPattern 参数意义不同
1:oracle 数据库这个参数代表 dbMeta.getUserName() 2:postgresql 数据库中需要在 jdbcUrl中配置 schemaPatter,例如:jdbc:postgresql://localhost:15432/djpt?currentSchema= public,sys,app 最后的参数就是搜索schema的顺序,DruidPlugin 下测试成功 3:开发者若在其它库中发现工作不正常,可通过继承 MetaBuilder并覆盖此方法来实现功能 |
protected boolean |
isSkipTable(String tableName)
通过继承并覆盖此方法,跳过一些不希望处理的 table,定制更加灵活的 table 过滤规则
|
void |
setRemovedTableNamePrefixes(String... removedTableNamePrefixes)
设置需要被移除的表名前缀,仅用于生成 modelName 与 baseModelName 例如表名 "osc_account",移除前缀
"osc_" 后变为 "account"
|
protected DataSource dataSource
protected Connection conn
protected DatabaseMetaData dbMeta
protected String[] removedTableNamePrefixes
protected String driverName
protected String driverVersion
protected int driverMajorVersion
public DBInfoBuilder(DataSource dataSource)
public void addExcludedTable(String... excludedTables)
public void setRemovedTableNamePrefixes(String... removedTableNamePrefixes)
protected boolean isSkipTable(String tableName)
protected ResultSet getTablesResultSet() throws SQLException
SQLException
protected void buildTableNames(List<TableInfo> ret) throws SQLException
SQLException
protected void buildPrimaryKey(TableInfo TableInfo) throws SQLException
SQLException
protected void buildColumnMetas(TableInfo tableInfo) throws SQLException
JDBC 与时间有关类型转换规则,mysql 类型到 java 类型如下对应关系: DATE java.sql.Date DATETIME java.sql.Timestamp TIMESTAMP[(M)] java.sql.Timestamp TIME java.sql.Time
对数据库的 DATE、DATETIME、TIMESTAMP、TIME 四种类型注入 new java.util.Date()对象保存到库以后可以达到“秒精度” 为了便捷性,getter、setter 方法中对上述四种字段类型采用 java.util.Date,可通过定制 TypeMapping 改变此映射规则
SQLException
public ColumnInfo getColumn(TableInfo tableInfo, String column) throws SQLException
tableInfo
- 表名column
- 列名SQLException
Copyright © 2020. All rights reserved.