| | |
| | | System.out.println("conn is null."); |
| | | return; |
| | | } |
| | | Map<String, String> tables = getTables(DB_NAME); |
| | | Map<String, String> tables = getTables(CONN, DB_NAME); |
| | | for (Map.Entry<String, String> table : tables.entrySet()) { |
| | | String tableName = table.getKey(); |
| | | String tableDesc = table.getValue(); |
| | |
| | | if (ONLY_TABLES.size() > 0 && BooleanUtils.isFalse(ONLY_TABLES.contains(tableName))) { |
| | | continue; |
| | | } |
| | | List<Map<String, Object>> columns = getColumns(tableName, DB_NAME); |
| | | List<Map<String, Object>> columns = getColumns(CONN, tableName, DB_NAME); |
| | | genPO(columns, tableDesc); |
| | | genVO(columns, tableDesc); |
| | | genColumnsEnum(columns, tableDesc); |
| | |
| | | //#endregion |
| | | |
| | | |
| | | public static Map<String, String> getTables(String dbSchema) { |
| | | public static Map<String, String> getTables(Connection connect, String dbSchema) { |
| | | Map<String, String> result = new LinkedHashMap<>(); |
| | | String sql = " SELECT TABLE_NAME ,TABLE_COMMENT " + |
| | | " FROM information_schema.`TABLES` " + |
| | | " WHERE TABLE_SCHEMA = ? "; |
| | | try (PreparedStatement pStmt = CONN.prepareStatement(sql)) { |
| | | try (PreparedStatement pStmt = connect.prepareStatement(sql)) { |
| | | pStmt.setString(1, dbSchema); |
| | | try (ResultSet rs = pStmt.executeQuery()) { |
| | | while (rs.next()) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | public static List<Map<String, Object>> getColumns(String tableName, String dbSchema) { |
| | | public static List<Map<String, Object>> getColumns(Connection connect, String tableName, String dbSchema) { |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | String sql = "SELECT `TABLE_NAME` AS'objName', `COLUMN_NAME`AS'name', `DATA_TYPE` AS'type', `CHARACTER_MAXIMUM_LENGTH` AS'length', `COLUMN_COMMENT` AS'description',\n" + |
| | | "`COLUMN_DEFAULT` AS'default',NUMERIC_PRECISION AS'numeric_precision',NUMERIC_SCALE AS'numeric_scale',DATETIME_PRECISION AS'datetime_precision',\n" + |
| | |
| | | "CASE `IS_NULLABLE` WHEN 'YES' THEN CONVERT(1,UNSIGNED) ELSE CONVERT(0,UNSIGNED) END AS'isNullable'\n" + |
| | | "FROM `information_schema`.`COLUMNS`\n" + |
| | | "WHERE `table_name` = ? AND `table_schema` = ?; "; |
| | | try (PreparedStatement pStmt = CONN.prepareStatement(sql)) { |
| | | try (PreparedStatement pStmt = connect.prepareStatement(sql)) { |
| | | pStmt.setString(1, tableName); |
| | | pStmt.setString(2, dbSchema); |
| | | try (ResultSet rs = pStmt.executeQuery()) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | public static List<Map<String, Object>> getListAll(String sql) { |
| | | public static List<Map<String, Object>> getListAll(Connection connect, String sql) { |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | try (PreparedStatement pStmt = CONN.prepareStatement(sql)) { |
| | | try (PreparedStatement pStmt = connect.prepareStatement(sql)) { |
| | | try (ResultSet rs = pStmt.executeQuery()) { |
| | | //获取键名 |
| | | ResultSetMetaData md = rs.getMetaData(); |
| | |
| | | } |
| | | } |
| | | |
| | | public static Map<String, String> getPK(String tableName) { |
| | | public static Map<String, String> getPK(Connection connect, String tableName) { |
| | | Map<String, String> result = new LinkedHashMap<>(); |
| | | String sql = "SHOW INDEX FROM ? WHERE Key_name='PRIMARY'"; |
| | | try (PreparedStatement pStmt = CONN.prepareStatement(sql)) { |
| | | try (PreparedStatement pStmt = connect.prepareStatement(sql)) { |
| | | pStmt.setString(1, tableName); |
| | | try (ResultSet rs = pStmt.executeQuery()) { |
| | | while (rs.next()) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | public static Map<String, String> getIndex(String tableName) { |
| | | public static Map<String, String> getIndex(Connection connect, String tableName) { |
| | | Map<String, String> result = new LinkedHashMap<>(); |
| | | String sql = "SHOW INDEX FROM ? WHERE Key_name!='PRIMARY'"; |
| | | try (PreparedStatement pStmt = CONN.prepareStatement(sql)) { |
| | | try (PreparedStatement pStmt = connect.prepareStatement(sql)) { |
| | | pStmt.setString(1, tableName); |
| | | try (ResultSet rs = pStmt.executeQuery()) { |
| | | while (rs.next()) { |