コード例 #1
0
ファイル: MysqlDialect.java プロジェクト: 4lian/Jfinal-Rapid
 @Override
 public void columnsForTables(Table table, DatabaseMetaData dbmd) {
   try {
     rs = dbmd.getColumns(null, "%", table.getName(), null);
     ResultSet priamryKeyRs = dbmd.getPrimaryKeys(null, null, table.getName());
     String priamryKey = null;
     while (priamryKeyRs.next()) {
       priamryKey = priamryKeyRs.getString("COLUMN_NAME");
     }
     while (rs.next()) {
       Column column = new Column();
       String name = rs.getString("COLUMN_NAME");
       column.setName(name);
       column.setType(rs.getString("TYPE_NAME"));
       int columnSize = rs.getInt("COLUMN_SIZE");
       int nullable = rs.getInt("nullable");
       column.setNullable(nullable == 1);
       column.setDataSize(columnSize);
       if (column.getName().equals(priamryKey)) {
         column.setPrimaryKey(true);
       }
       table.addColumn(column);
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
ファイル: MysqlDialect.java プロジェクト: 4lian/Jfinal-Rapid
 @Override
 public void commentForColumns(Table table, Connection connection) {
   try {
     String sql = "show full columns from" + " " + table.getName();
     pstmt = connection.prepareStatement(sql);
     rs = pstmt.executeQuery();
     Map<String, String> val = new HashMap<String, String>();
     while (rs.next()) {
       val.put(rs.getString("Field"), rs.getString("COMMENT"));
     }
     List<Column> columns = table.getColumns();
     for (Column column : columns) {
       column.setComment(column.getName());
       String comment = val.get(column.getName());
       if (StringKit.notBlank(comment)) {
         column.setComment(comment);
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
コード例 #3
0
ファイル: OracleDialect.java プロジェクト: 4lian/Jfinal-Rapid
 @Override
 public void commentForColumns(Table table, Connection connection) {
   try {
     String sql = "select * from user_col_comments where TABLE_NAME = ?";
     pstmt = connection.prepareStatement(sql);
     pstmt.setString(1, table.getName());
     rs = pstmt.executeQuery();
     List<Column> columns = table.getColumns();
     for (Column column : columns) {
       column.setComment(column.getName());
       while (rs.next()) {
         if (column.getName().equals(rs.getString("COLUMN_NAME"))) {
           String comment = rs.getString("COMMENTS");
           if (StringKit.notBlank(comment)) {
             column.setComment(comment);
             continue;
           }
         }
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }