private static Table readTable(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { String tableName = (String) values.get("TABLE_NAME"); Table table = null; if ((tableName != null) && (tableName.length() > 0)) { table = new Table(); table.setName(tableName); table.setType((String) values.get("TABLE_TYPE")); table.setCatalog((String) values.get("TABLE_CAT")); table.setSchema((String) values.get("TABLE_SCHEM")); table.setDescription((String) values.get("REMARKS")); table.addColumns(readColumns(metaData, tableName)); Collection<String> primaryKeys = readPrimaryKeyNames(metaData, tableName); for (Object key : primaryKeys) { Column col = table.findColumn((String) key, true); if (col != null) { col.setPrimaryKey(true); } else { throw new NullPointerException(String.format("%s pk %s is null - %s %s", tableName, key, ToStringBuilder.reflectionToString(metaData, ToStringStyle.SIMPLE_STYLE), ToStringBuilder.reflectionToString(values, ToStringStyle.SIMPLE_STYLE))); } } } return table; }
private static Table readTable(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { String tableName = (String) values.get("TABLE_NAME"); Table table = null; if ((tableName != null) && (tableName.length() > 0)) { table = new Table(); table.setName(tableName); table.setType((String) values.get("TABLE_TYPE")); table.setCatalog((String) values.get("TABLE_CAT")); table.setSchema((String) values.get("TABLE_SCHEM")); table.setDescription((String) values.get("REMARKS")); table.addColumns(readColumns(metaData, tableName)); Collection<String> primaryKeys = readPrimaryKeyNames(metaData, tableName); for (Object key : primaryKeys) { Column col = table.findColumn((String) key, true); if (col != null) { col.setPrimaryKey(true); } else { throw new NullPointerException(String.format("%s pk %s is null - %s %s", tableName, key, ToStringBuilder.reflectionToString(metaData, ToStringStyle.SIMPLE_STYLE), ToStringBuilder.reflectionToString(values, ToStringStyle.SIMPLE_STYLE))); } } } return table; }
private static Table generateTable(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { String tableName = (String) values.get("TABLE_NAME"); Table table = null; if ((tableName != null) && (tableName.length() > 0)) { table = new Table(); table.setName(tableName); table.setType((String) values.get("TABLE_TYPE")); table.setCatalog((String) values.get("TABLE_CAT")); table.setSchema((String) values.get("TABLE_SCHEM")); table.setDescription((String) values.get("REMARKS")); table.addColumns(generateColumns(metaData, tableName)); table.addIndices(generateIndices(metaData, tableName)); Collection<String> primaryKeys = readPrimaryKeyNames(metaData, tableName); for (Object key : primaryKeys) { Column col = table.findColumn((String) key, true); if (col != null) { col.setPrimaryKey(true); } else { throw new NullPointerException(String.format("%s pk %s is null - %s %s", tableName, key, ToStringBuilder.reflectionToString(metaData, ToStringStyle.SIMPLE_STYLE), ToStringBuilder.reflectionToString(values, ToStringStyle.SIMPLE_STYLE))); } } } return table; }
/** * {@inheritDoc} */ public void apply(Database database, boolean caseSensitive) { Table table = findChangedTable(database, caseSensitive); ArrayList newColumns = new ArrayList(); for (int idx = 0; idx < table.getColumnCount(); idx++) { newColumns.add(table.getColumn(idx)); } for (int idx = 0; idx < table.getColumnCount(); idx++) { Column column = table.getColumn(idx); int newPos = getNewPosition(column.getName(), caseSensitive); if (newPos >= 0) { newColumns.set(newPos, column); } } table.removeAllColumns(); table.addColumns(newColumns); } }
table.addColumns(readColumns(metaData, tableName)); table.addForeignKeys(readForeignKeys(metaData, tableName)); table.addIndices(readIndices(metaData, tableName));