@Override public TableEditor renameColumn(String existingName, String newName) { final Column existing = columnWithName(existingName); if (existing == null) throw new IllegalArgumentException("No column with name '" + existingName + "'"); Column newColumn = existing.edit().name(newName).create(); // Determine the primary key names ... List<String> newPkNames = null; if ( !hasUniqueValues() && primaryKeyColumnNames().contains(existing.name())) { newPkNames = new ArrayList<>(primaryKeyColumnNames()); newPkNames.replaceAll(name->existing.name().equals(name) ? newName : name); } // Add the new column, move it before the existing column, and remove the old column ... addColumn(newColumn); reorderColumn(newColumn.name(), existing.name()); removeColumn(existing.name()); if (newPkNames != null) { setPrimaryKeyNames(newPkNames); } return this; }
@Override public TableEditor renameColumn(String existingName, String newName) { final Column existing = columnWithName(existingName); if (existing == null) throw new IllegalArgumentException("No column with name '" + existingName + "'"); Column newColumn = existing.edit().name(newName).create(); // Determine the primary key names ... List<String> newPkNames = null; if ( !hasUniqueValues() && primaryKeyColumnNames().contains(existing.name())) { newPkNames = new ArrayList<>(primaryKeyColumnNames()); newPkNames.replaceAll(name->existing.name().equals(name) ? newName : name); } // Add the new column, move it before the existing column, and remove the old column ... addColumn(newColumn); reorderColumn(newColumn.name(), existing.name()); removeColumn(existing.name()); if (newPkNames != null) { setPrimaryKeyNames(newPkNames); } return this; }