protected boolean hasColumnWithName(String name) { return columnWithName(name) != null; }
@Override public TableEditor reorderColumn(String columnName, String afterColumnName) { Column columnToMove = columnWithName(columnName); if (columnToMove == null) throw new IllegalArgumentException("No column with name '" + columnName + "'"); Column afterColumn = afterColumnName == null ? null : columnWithName(afterColumnName); if (afterColumn != null && (afterColumn.position() + 1) == columnToMove.position()) {
protected void add(Column defn) { if (defn != null) { Column existing = columnWithName(defn.name()); int position = existing != null ? existing.position() : sortedColumns.size() + 1; sortedColumns.put(defn.name().toLowerCase(), defn.edit().position(position).create()); } assert positionsAreValid(); }
@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 boolean hasColumnWithName(String name) { return columnWithName(name) != null; }
@Override public TableEditor reorderColumn(String columnName, String afterColumnName) { Column columnToMove = columnWithName(columnName); if (columnToMove == null) throw new IllegalArgumentException("No column with name '" + columnName + "'"); Column afterColumn = afterColumnName == null ? null : columnWithName(afterColumnName); if (afterColumn != null && (afterColumn.position() + 1) == columnToMove.position()) {
protected void add(Column defn) { if (defn != null) { Column existing = columnWithName(defn.name()); int position = existing != null ? existing.position() : sortedColumns.size() + 1; sortedColumns.put(defn.name().toLowerCase(), defn.edit().position(position).create()); } assert positionsAreValid(); }
@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; }