protected void updatePrimaryKeys() { Iterator<String> nameIter = primaryKeyColumnNames().iterator(); while (nameIter.hasNext()) { String pkColumnName = nameIter.next(); if (!hasColumnWithName(pkColumnName)) nameIter.remove(); } }
@Override public Table create() { if (id == null) throw new IllegalStateException("Unable to create a table from an editor that has no table ID"); List<Column> columns = new ArrayList<>(); sortedColumns.values().forEach(column->{ column = column.edit().charsetNameOfTable(defaultCharsetName).create(); columns.add(column); }); return new TableImpl(id, columns, primaryKeyColumnNames(), defaultCharsetName); } }
@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; }
protected void updatePrimaryKeys() { Iterator<String> nameIter = primaryKeyColumnNames().iterator(); while (nameIter.hasNext()) { String pkColumnName = nameIter.next(); if (!hasColumnWithName(pkColumnName)) nameIter.remove(); } }
@Override public Table create() { if (id == null) throw new IllegalStateException("Unable to create a table from an editor that has no table ID"); List<Column> columns = new ArrayList<>(); sortedColumns.values().forEach(column->{ column = column.edit().charsetNameOfTable(defaultCharsetName).create(); columns.add(column); }); return new TableImpl(id, columns, primaryKeyColumnNames(), defaultCharsetName); } }
@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; }