@Test(expected = IllegalArgumentException.class) public void testThatRemoveColumnMethodThrowsExceptionOnNullInput() { Table table = new Table("users"); table.removeColumn(null); }
public Column removeColumn(String columnName) { checkArgument(!Strings.isNullOrEmpty(columnName), "You must specify a 'name'."); checkState(containsColumn(columnName), "You cannot remove a column which does not exist: " + columnName); Column column = getColumn(columnName); checkState(column.getIncomingForeignKeys().isEmpty(), "You cannot remove a column that is still referenced by foreign keys."); List<Column> identityColumns = getIdentityColumns(); identityColumns.remove(column); checkState(!identityColumns.isEmpty(), "You drop the last remaining identity column of a table."); if (column.getOutgoingForeignKey() != null) { column.getOutgoingForeignKey().drop(); } column.setParent(null); columns.remove(column); return column; }
Table implements Copyable<Table>, Comparable<Table> { public Column removeColumn(String columnName) { checkArgument(!Strings.isNullOrEmpty(columnName), "You must specify a 'name'."); checkState(containsColumn(columnName), "You cannot remove a column which does not exist: " + columnName); Column column = getColumn(columnName); checkState(column.getIncomingForeignKeys().isEmpty(), "You cannot remove a column that is still referenced by foreign keys."); List<Column> identityColumns = getIdentityColumns(); identityColumns.remove(column); checkState(!identityColumns.isEmpty(), "You drop the last remaining identity column of a table."); if (column.getOutgoingForeignKey() != null) { column.getOutgoingForeignKey().drop(); } column.setParent(null); columns.remove(column); return column; } }
Table implements Copyable<Table>, Comparable<Table> { public Column removeColumn(String columnName) { checkArgument(!Strings.isNullOrEmpty(columnName), "You must specify a 'name'."); checkState(containsColumn(columnName), "You cannot remove a column which does not exist: " + columnName); Column column = getColumn(columnName); checkState(column.getIncomingForeignKeys().isEmpty(), "You cannot remove a column that is still referenced by foreign keys."); List<Column> identityColumns = getIdentityColumns(); identityColumns.remove(column); checkState(!identityColumns.isEmpty(), "You drop the last remaining identity column of a table."); if (column.getOutgoingForeignKey() != null) { column.getOutgoingForeignKey().drop(); } column.setParent(null); columns.remove(column); return column; } Table(String name); }
Table implements Copyable<Table>, Comparable<Table> { public Column removeColumn(String columnName) { checkArgument(!Strings.isNullOrEmpty(columnName), "You must specify a 'name'."); checkState(containsColumn(columnName), "You cannot remove a column which does not exist: " + columnName); Column column = getColumn(columnName); checkState(column.getIncomingForeignKeys().isEmpty(), "You cannot remove a column that is still referenced by foreign keys."); List<Column> identityColumns = getIdentityColumns(); identityColumns.remove(column); checkState(!identityColumns.isEmpty(), "You drop the last remaining identity column of a table."); if (column.getOutgoingForeignKey() != null) { column.getOutgoingForeignKey().drop(); } column.setParent(null); columns.remove(column); return column; } Table(String name); Table addIndex(Index index); boolean containsIndex(String... columns); boolean containsIndex(Collection<String> columns); Index removeIndex(String... columns); Index removeIndex(Collection<String> columns); Index getIndex(String... columns); Index getIndex(Collection<String> columns); ImmutableList<Index> getIndexes(); Table addColumn(Column column); Table addColumns(Collection<Column> newColumns); Column getColumn(String columnName); List<Column> getIdentityColumns(); boolean containsColumn(String columnName); Column removeColumn(String columnName); ImmutableList<Column> getColumns(); ForeignKeyBuilder addForeignKey(String... referringColumns); ForeignKeyBuilder addForeignKey(List<String> referringColumns); Table rename(String newName); boolean referencesTable(String tableName); Set<String> enumerateReferencedByTables(); @Override Table copy(); @Override int compareTo(Table o); @Override String toString(); }
Table implements Copyable<Table>, Comparable<Table> { public Column removeColumn(String columnName) { checkArgument(!Strings.isNullOrEmpty(columnName), "You must specify a 'name'."); checkState(containsColumn(columnName), "You cannot remove a column which does not exist: " + columnName); Column column = getColumn(columnName); checkState(column.getIncomingForeignKeys().isEmpty(), "You cannot remove a column that is still referenced by foreign keys."); List<Column> identityColumns = getIdentityColumns(); identityColumns.remove(column); checkState(!identityColumns.isEmpty(), "You drop the last remaining identity column of a table."); if (column.getOutgoingForeignKey() != null) { column.getOutgoingForeignKey().drop(); } column.setParent(null); columns.remove(column); return column; } Table(String name); Table addIndex(Index index); boolean containsIndex(String... columns); boolean containsIndex(Collection<String> columns); Index removeIndex(String... columns); Index removeIndex(Collection<String> columns); Index getIndex(String... columns); Index getIndex(Collection<String> columns); ImmutableList<Index> getIndexes(); Table addColumn(Column column); Table addColumns(Collection<Column> newColumns); Column getColumn(String columnName); List<Column> getIdentityColumns(); boolean containsColumn(String columnName); Column removeColumn(String columnName); ImmutableList<Column> getColumns(); ForeignKeyBuilder addForeignKey(String... referringColumns); ForeignKeyBuilder addForeignKey(List<String> referringColumns); Table rename(String newName); boolean referencesTable(String tableName); Set<String> enumerateReferencedByTables(); @Override Table copy(); @Override int compareTo(Table o); @Override String toString();  }