类 TableBuilder


  • public class TableBuilder
    extends java.lang.Object
    TODO:
    作者:
    王剑洪 on 2020/6/1 16:09
    • 构造器概要

      构造器 
      构造器 说明
      TableBuilder​(javax.sql.DataSource dataSource, DataConfig dataConfig)  
    • 方法概要

      所有方法 静态方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      java.util.List<Table> build()  
      protected TableColumn buildColumn​(Table table, TableColumn cm)  
      protected void buildColumnMetas​(Table table, java.lang.String primaryKey)
      TODO: 文档参考: http://dev.mysql.com/doc/connector-j/en/connector-j-reference-type-conversions.html
      protected java.lang.String buildModelName​(java.lang.String tableName, Table table)
      构造 modelName,mysql 的 tableName 建议使用小写字母,多单词表名使用下划线分隔,不建议使用驼峰命名 oracle 之下的 tableName 建议使用下划线分隔多单词名,无论 mysql还是 oralce,tableName 都不建议使用驼峰命名
      protected java.lang.String buildPrimaryKey​(Table table)  
      protected void buildTableNames​(java.util.List<Table> ret)  
      protected java.sql.ResultSet getTablesResultSet()
      不同数据库 dbMeta.getTables(...)
      protected java.lang.String handleJavaType​(java.sql.ResultSetMetaData rsmd, int i)  
      void setDialect​(com.jfinal.plugin.activerecord.dialect.Dialect dialect)  
      static void setTableTpl​(Table table)  
      void setTypeMapping​(TypeMapping typeMapping)  
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • dataSource

        protected javax.sql.DataSource dataSource
      • dialect

        protected com.jfinal.plugin.activerecord.dialect.Dialect dialect
      • conn

        protected java.sql.Connection conn
      • dbMeta

        protected java.sql.DatabaseMetaData dbMeta
    • 构造器详细资料

      • TableBuilder

        public TableBuilder​(javax.sql.DataSource dataSource,
                            DataConfig dataConfig)
    • 方法详细资料

      • setDialect

        public void setDialect​(com.jfinal.plugin.activerecord.dialect.Dialect dialect)
      • setTypeMapping

        public void setTypeMapping​(TypeMapping typeMapping)
      • build

        public java.util.List<Table> build()
      • buildModelName

        protected java.lang.String buildModelName​(java.lang.String tableName,
                                                  Table table)
        构造 modelName,mysql 的 tableName 建议使用小写字母,多单词表名使用下划线分隔,不建议使用驼峰命名 oracle 之下的 tableName 建议使用下划线分隔多单词名,无论 mysql还是 oralce,tableName 都不建议使用驼峰命名
        参数:
        tableName - tableName
        table - table
        返回:
        String
      • getTablesResultSet

        protected java.sql.ResultSet getTablesResultSet()
                                                 throws java.sql.SQLException
        不同数据库 dbMeta.getTables(...) 的 schemaPattern 参数意义不同 1:oracle 数据库这个参数代表 dbMeta.getUserName() 2:postgresql 数据库中需要在 jdbcUrl中配置 schemaPatter,例如: jdbc:postgresql://localhost:15432/djpt?currentSchema=public,sys,app 最后的参数就是搜索schema的顺序,DruidPlugin 下测试成功 3:开发者若在其它库中发现工作不正常,可通过继承 MetaBuilder并覆盖此方法来实现功能
        返回:
        ResultSet ResultSet
        抛出:
        java.sql.SQLException - SQLException
      • setTableTpl

        public static void setTableTpl​(Table table)
      • buildTableNames

        protected void buildTableNames​(java.util.List<Table> ret)
                                throws java.sql.SQLException
        抛出:
        java.sql.SQLException
      • buildPrimaryKey

        protected java.lang.String buildPrimaryKey​(Table table)
                                            throws java.sql.SQLException
        抛出:
        java.sql.SQLException
      • buildColumnMetas

        protected void buildColumnMetas​(Table table,
                                        java.lang.String primaryKey)
                                 throws java.sql.SQLException
        TODO: 文档参考: http://dev.mysql.com/doc/connector-j/en/connector-j-reference-type-conversions.html

        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 改变此映射规则

        参数:
        table - 表
        primaryKey - 主键
        抛出:
        java.sql.SQLException - 异常
      • handleJavaType

        protected java.lang.String handleJavaType​(java.sql.ResultSetMetaData rsmd,
                                                  int i)
                                           throws java.sql.SQLException
        抛出:
        java.sql.SQLException