void retrieveColumns(final MutableTable table, final InclusionRule columnInclusionRule) throws SQLException { MetadataResultSet results = null; try { results = new MetadataResultSet( getMetaData() .getColumns( unquotedName(table.getSchema().getCatalogName()), unquotedName(table.getSchema().getSchemaName()), unquotedName(table.getName()), null)); while (results.next()) { // Get the "COLUMN_DEF" value first as it the Oracle drivers // don't handle it properly otherwise. // http://issues.apache.org/jira/browse/DDLUTILS-29?page=all final String defaultValue = results.getString("COLUMN_DEF"); // final String columnCatalogName = quotedName(results.getString("TABLE_CAT")); final String schemaName = quotedName(results.getString("TABLE_SCHEM")); final String tableName = quotedName(results.getString("TABLE_NAME")); final String columnName = quotedName(results.getString("COLUMN_NAME")); LOGGER.log(Level.FINER, String.format("Retrieving column: %s.%s", tableName, columnName)); MutableColumn column; column = lookupOrCreateColumn(table, columnName, false /* add */); final String columnFullName = column.getFullName(); // Note: If the table name contains an underscore character, // this is a wildcard character. We need to do another check to // see if the table name matches. if (columnInclusionRule.include(columnFullName) && table.getName().equals(tableName) && belongsToSchema(table, columnCatalogName, schemaName)) { column = lookupOrCreateColumn(table, columnName, true /* add */); final int ordinalPosition = results.getInt("ORDINAL_POSITION", 0); final int dataType = results.getInt("DATA_TYPE", 0); final String typeName = results.getString("TYPE_NAME"); final int size = results.getInt("COLUMN_SIZE", 0); final int decimalDigits = results.getInt("DECIMAL_DIGITS", 0); final boolean isNullable = results.getInt("NULLABLE", DatabaseMetaData.columnNullableUnknown) == DatabaseMetaData.columnNullable; final String remarks = results.getString("REMARKS"); column.setOrdinalPosition(ordinalPosition); column.setType( lookupOrCreateColumnDataType((MutableSchema) table.getSchema(), dataType, typeName)); column.setSize(size); column.setDecimalDigits(decimalDigits); column.setRemarks(remarks); column.setNullable(isNullable); if (defaultValue != null) { column.setDefaultValue(defaultValue); } column.addAttributes(results.getAttributes()); table.addColumn(column); } } } catch (final SQLException e) { throw new SchemaCrawlerSQLException("Could not retrieve columns for table " + table, e); } finally { if (results != null) { results.close(); } } }