/** * Obtain an editor for the table with the given ID. This method does not lock or modify the set of table definitions, so use * with caution. The resulting editor can be used to modify the table definition, but when completed the new {@link Table} * needs to be added back to this object via {@link #overwriteTable(Table)}. * * @param tableId the identifier of the table * @return the editor for the table, or null if there is no table with the specified ID */ public TableEditor editOrCreateTable(TableId tableId) { Table table = forTable(tableId); return table == null ? Table.editor().tableId(tableId) : table.edit(); }
public Table getTableSchemaFromChangeTable(ChangeTable changeTable) throws SQLException { final DatabaseMetaData metadata = connection().getMetaData(); final TableId changeTableId = changeTable.getChangeTableId(); List<ColumnEditor> columnEditors = new ArrayList<>(); try (ResultSet rs = metadata.getColumns(realDatabaseName, changeTableId.schema(), changeTableId.table(), null)) { while (rs.next()) { readTableColumn(rs, changeTableId, null).ifPresent(columnEditors::add); } } // The first 5 columns and the last column of the change table are CDC metadata final List<Column> columns = columnEditors.subList(CHANGE_TABLE_DATA_COLUMN_OFFSET, columnEditors.size() - 1).stream() .map(c -> c.position(c.position() - CHANGE_TABLE_DATA_COLUMN_OFFSET).create()) .collect(Collectors.toList()); final List<String> pkColumnNames = new ArrayList<>(); prepareQuery(GET_LIST_OF_KEY_COLUMNS, ps -> ps.setInt(1, changeTable.getChangeTableObjectId()), rs -> { while (rs.next()) { pkColumnNames.add(rs.getString(2)); } }); Collections.sort(columns); return Table.editor() .tableId(changeTable.getSourceTableId()) .addColumns(columns) .setPrimaryKeyNames(pkColumnNames) .create(); }
@Before public void beforeEach() { editor = Table.editor(); table = null; columnEditor = Column.editor(); }
public Table getTableSchemaFromTable(ChangeTable changeTable) throws SQLException { final DatabaseMetaData metadata = connection().getMetaData(); List<Column> columns = new ArrayList<>(); try (ResultSet rs = metadata.getColumns( realDatabaseName, changeTable.getSourceTableId().schema(), changeTable.getSourceTableId().table(), null) ) { while (rs.next()) { readTableColumn(rs, changeTable.getSourceTableId(), null).ifPresent(ce -> columns.add(ce.create())); } } final List<String> pkColumnNames = readPrimaryKeyNames(metadata, changeTable.getSourceTableId()); Collections.sort(columns); return Table.editor() .tableId(changeTable.getSourceTableId()) .addColumns(columns) .setPrimaryKeyNames(pkColumnNames) .create(); }
private TableEditor parseSelectElements(MySqlParser.SelectElementsContext ctx) { TableEditor table = Table.editor(); if (ctx.star != null) { tableByAlias.keySet().forEach(tableId -> {
private static Table fromDocument(TableId id, Document document) { TableEditor editor = Table.editor() .tableId(id) .setDefaultCharsetName(document.getString("defaultCharsetName"));
@Before public void beforeEach() { table = Table.editor() .tableId(id) .addColumns(Column.editor().name("C1") .type("VARCHAR").jdbcType(Types.VARCHAR).length(10) .generated(true) .optional(false) .create(), Column.editor().name("C2") .type("NUMBER").jdbcType(Types.NUMERIC).length(5) .optional(false) .create(), Column.editor().name("C3") .type("DATE").jdbcType(Types.DATE).length(4) .optional(true) .create(), Column.editor().name("C4") .type("COUNTER").jdbcType(Types.INTEGER) .autoIncremented(true) .optional(true) .create()) .setPrimaryKeyNames("C1", "C2") .create(); c1 = table.columnWithName("C1"); c2 = table.columnWithName("C2"); c3 = table.columnWithName("C3"); c4 = table.columnWithName("C4"); }
String ddl = "CREATE TABLE foo ( first VARCHAR(22) NOT NULL );"; Table table = Table.editor() .tableId(new TableId(databaseName, schemaName, "foo")) .addColumn(Column.editor()
}); schema = null; table = Table.editor() .tableId(id) .addColumns(Column.editor().name("C1")
/** * Obtain an editor for the table with the given ID. This method does not lock or modify the set of table definitions, so use * with caution. The resulting editor can be used to modify the table definition, but when completed the new {@link Table} * needs to be added back to this object via {@link #overwriteTable(Table)}. * * @param tableId the identifier of the table * @return the editor for the table, or null if there is no table with the specified ID */ public TableEditor editOrCreateTable(TableId tableId) { Table table = forTable(tableId); return table == null ? Table.editor().tableId(tableId) : table.edit(); }
@Override public void enterCreate_table(Create_tableContext ctx) { if (ctx.relational_table() == null) { throw new IllegalArgumentException("Only relational tables are supported"); } editor = Table.editor(); editor.tableId(new TableId(catalogName, schemaName, getTableName(ctx.tableview_name()))); super.enterCreate_table(ctx); }
private static Table fromDocument(TableId id, Document document) { TableEditor editor = Table.editor() .tableId(id) .setDefaultCharsetName(document.getString("defaultCharsetName"));