private Table createTable(Connection conn, ResultSet rs) throws SQLException { String realTableName = null; try { ResultSetMetaData rsMetaData = rs.getMetaData(); String schemaName = rs.getString("TABLE_SCHEM") == null ? "" : rs.getString("TABLE_SCHEM"); realTableName = rs.getString("TABLE_NAME"); String tableType = rs.getString("TABLE_TYPE"); String remarks = rs.getString("REMARKS"); if (remarks == null && dbHelper.isOracleDataBase()) { remarks = getOracleTableComments(realTableName); } Table table = new Table(); table.setSqlName(realTableName); table.setRemarks(remarks); if ("SYNONYM".equals(tableType) && dbHelper.isOracleDataBase()) { table.setOwnerSynonymName(getSynonymOwner(realTableName)); } retriveTableColumns(table); table.initExportedKeys(conn.getMetaData()); table.initImportedKeys(conn.getMetaData()); BeanHelper.copyProperties( table, TableOverrideValuesProvider.getTableOverrideValues(table.getSqlName())); return table; } catch (SQLException e) { throw new RuntimeException("create table object error,tableName:" + realTableName, e); } }
private List getTableColumns( Table table, List primaryKeys, List indices, Map uniqueIndices, Map uniqueColumns) throws SQLException { // get the columns List columns = new LinkedList(); ResultSet columnRs = getColumnsResultSet(table); while (columnRs.next()) { int sqlType = columnRs.getInt("DATA_TYPE"); String sqlTypeName = columnRs.getString("TYPE_NAME"); String columnName = columnRs.getString("COLUMN_NAME"); String columnDefaultValue = columnRs.getString("COLUMN_DEF"); String remarks = columnRs.getString("REMARKS"); if (remarks == null && dbHelper.isOracleDataBase()) { remarks = getOracleColumnComments(table.getSqlName(), columnName); } // if columnNoNulls or columnNullableUnknown assume "not nullable" boolean isNullable = (DatabaseMetaData.columnNullable == columnRs.getInt("NULLABLE")); int size = columnRs.getInt("COLUMN_SIZE"); int decimalDigits = columnRs.getInt("DECIMAL_DIGITS"); boolean isPk = primaryKeys.contains(columnName); boolean isIndexed = indices.contains(columnName); String uniqueIndex = (String) uniqueIndices.get(columnName); List columnsInUniqueIndex = null; if (uniqueIndex != null) { columnsInUniqueIndex = (List) uniqueColumns.get(uniqueIndex); } boolean isUnique = columnsInUniqueIndex != null && columnsInUniqueIndex.size() == 1; if (isUnique) { GLogger.trace("unique column:" + columnName); } Column column = new Column( table, sqlType, sqlTypeName, columnName, size, decimalDigits, isPk, isNullable, isIndexed, isUnique, columnDefaultValue, remarks); BeanHelper.copyProperties( column, TableOverrideValuesProvider.getColumnOverrideValues(table, column)); columns.add(column); } columnRs.close(); return columns; }
private Table getTable(String catalog, String schema, String tableName) { Table t = null; try { t = _getTable(catalog, schema, tableName); if (t == null && !tableName.equals(tableName.toUpperCase())) { t = _getTable(catalog, schema, tableName.toUpperCase()); } if (t == null && !tableName.equals(tableName.toLowerCase())) { t = _getTable(catalog, schema, tableName.toLowerCase()); } } catch (Exception e) { throw new RuntimeException(e); } if (t == null) { throw new NotFoundTableException( "not found table with give name:" + tableName + (dbHelper.isOracleDataBase() ? " \n databaseStructureInfo:" + getDatabaseStructureInfo() : "")); } return t; }