public List<Column> getSelectedColumns() { return selectTableEditor.columns(); }
/** * Get the names of the columns in this table. The resulting list should not be modified directly; * instead, the column definitions should be defined with {@link #addColumns(Column...)}, * {@link #addColumns(Iterable)}, {@link #setColumns(Column...)}, {@link #setColumns(Iterable)}, or * {@link #removeColumn(String)}. * * @return the ordered list of column names; never null */ default List<String> columnNames() { return columns().stream().map(Column::name).collect(Collectors.toList()); }
protected void assertValidPositions(TableEditor editor) { AtomicInteger position = new AtomicInteger(1); assertThat(editor.columns().stream().allMatch(defn -> defn.position() == position.getAndIncrement())).isTrue(); }
if (table.columns().isEmpty()) { selectedColumnsByAlias.forEach((columnName, fromTableColumn) -> { if (fromTableColumn != null && columnName != null) table.addColumn(fromTableColumn.edit().name(columnName).create()); } else { List<Column> changedColumns = new ArrayList<>(); table.columns().forEach(column -> {
protected void parseCreateIndex(Marker start) { boolean unique = tokens.canConsume("UNIQUE"); tokens.canConsumeAnyOf("FULLTEXT", "SPATIAL"); tokens.consume("INDEX"); String indexName = tokens.consume(); // index name if (tokens.matches("USING")) { parseIndexType(start); } TableId tableId = null; if (tokens.canConsume("ON")) { // Usually this is required, but in some cases ON is not required tableId = parseQualifiedTableName(start); } if (unique && tableId != null) { // This is a unique index, and we can mark the index's columns as the primary key iff there is not already // a primary key on the table. (Should a PK be created later via an alter, then it will overwrite this.) TableEditor table = databaseTables.editTable(tableId); if (table != null && !table.hasPrimaryKey()) { List<String> names = parseIndexColumnNames(start); if (table.columns().stream().allMatch(Column::isRequired)) { databaseTables.overwriteTable(table.setPrimaryKeyNames(names).create()); } } } // We don't care about any other statements or the rest of this statement ... consumeRemainingStatement(start); // TODO fix: signal should be send only when some changes on table are made signalCreateIndex(indexName, tableId, start); debugParsed(start); }
@Test public void shouldNotHaveColumnsIfEmpty() { assertThat(editor.columnWithName("any")).isNull(); assertThat(editor.columns()).isEmpty(); assertThat(editor.primaryKeyColumnNames()).isEmpty(); }
@Test public void shouldFindNonExistingColumnByNameIndependentOfCase() { editor.tableId(id); Column c1 = columnEditor.name("C1").type("VARCHAR").jdbcType(Types.VARCHAR).length(10).position(1).create(); Column c2 = columnEditor.name("C2").type("NUMBER").jdbcType(Types.NUMERIC).length(5).position(1).create(); Column c3 = columnEditor.name("C3").type("DATE").jdbcType(Types.DATE).position(1).create(); editor.addColumns(c1, c2, c3); editor.columns().forEach(col -> { assertThat(editor.columnWithName(col.name())).isNotNull(); assertThat(editor.columnWithName(col.name().toUpperCase())).isNotNull(); assertThat(editor.columnWithName(col.name().toLowerCase())).isNotNull(); }); assertThat(editor.columnWithName("WOOPS")).isNull(); }
assertValidPositions(editor); editor.reorderColumn("C1", null); assertThat(editor.columns()).containsExactly(editor.columnWithName("C1"), editor.columnWithName("C2"), editor.columnWithName("C3")); assertValidPositions(editor); editor.reorderColumn("C2", "C1"); assertThat(editor.columns()).containsExactly(editor.columnWithName("C1"), editor.columnWithName("C2"), editor.columnWithName("C3")); assertValidPositions(editor); editor.reorderColumn("C3", "C2"); assertThat(editor.columns()).containsExactly(editor.columnWithName("C1"), editor.columnWithName("C2"), editor.columnWithName("C3")); assertValidPositions(editor); editor.reorderColumn("C3", "C1"); assertThat(editor.columns()).containsExactly(editor.columnWithName("C1"), editor.columnWithName("C3"), editor.columnWithName("C2")); assertValidPositions(editor); editor.reorderColumn("C3", null); assertThat(editor.columns()).containsExactly(editor.columnWithName("C3"), editor.columnWithName("C1"), editor.columnWithName("C2"));
@Test public void shouldRemoveColumnByName() { editor.tableId(id); Column c1 = columnEditor.name("C1").type("VARCHAR").jdbcType(Types.VARCHAR).length(10).position(1).create(); Column c2 = columnEditor.name("C2").type("NUMBER").jdbcType(Types.NUMERIC).length(5).autoIncremented(true).create(); Column c3 = columnEditor.name("C3").type("DATE").jdbcType(Types.DATE).autoIncremented(true).create(); editor.addColumns(c1, c2, c3); editor.removeColumn("C2"); assertThat(editor.columns()).containsExactly(editor.columnWithName("C1"), editor.columnWithName("C3")); assertValidPositions(editor); }
/** * Get the names of the columns in this table. The resulting list should not be modified directly; * instead, the column definitions should be defined with {@link #addColumns(Column...)}, * {@link #addColumns(Iterable)}, {@link #setColumns(Column...)}, {@link #setColumns(Iterable)}, or * {@link #removeColumn(String)}. * * @return the ordered list of column names; never null */ default List<String> columnNames() { return columns().stream().map(Column::name).collect(Collectors.toList()); }