Package io.debezium.relational
Class TableEditorImpl
- java.lang.Object
-
- io.debezium.relational.TableEditorImpl
-
- All Implemented Interfaces:
TableEditor
class TableEditorImpl extends Object implements TableEditor
-
-
Field Summary
Fields Modifier and Type Field Description private StringdefaultCharsetNameprivate TableIdidprivate List<String>pkColumnNamesprivate LinkedHashMap<String,Column>sortedColumnsprivate booleanuniqueValues
-
Constructor Summary
Constructors Modifier Constructor Description protectedTableEditorImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidadd(Column defn)TableEditoraddColumns(Column... columns)Add one or more columns to this table, regardless of thepositionof the supplied columns.TableEditoraddColumns(Iterable<Column> columns)Add one or more columns to the end of this table's list of columns, regardless of thepositionof the supplied columns.List<Column>columns()Get the definitions for the columns in this table.ColumncolumnWithName(String name)Get the definition for the column in this table with the supplied name.Tablecreate()Obtain an immutable table definition representing the current state of this editor.protected booleanhasColumnWithName(String name)booleanhasDefaultCharsetName()Determine if adefault character sethas been set on this table.booleanhasUniqueValues()Determine whether this table's primary key contains all columns (viaTableEditor.setUniqueValues()) such that all rows within the table are unique.protected booleanpositionsAreValid()List<String>primaryKeyColumnNames()The list of column names that make up the primary key for this table.TableEditorremoveColumn(String columnName)Remove the column with the given name.TableEditorrenameColumn(String existingName, String newName)Rename the column with the given name to the new specified name.TableEditorreorderColumn(String columnName, String afterColumnName)Reorder the column with the given name to be positioned after the designated column.TableEditorsetColumns(Column... columns)Set this table's column definitions.TableEditorsetColumns(Iterable<Column> columns)Set this table's column definitions.TableEditorsetDefaultCharsetName(String charsetName)Set the name of the character set that should be used by default in the columns that require a character set but have not defined one.TableEditorsetPrimaryKeyNames(String... pkColumnNames)Set the columns that make up this table's primary key.TableEditorsetPrimaryKeyNames(List<String> pkColumnNames)Set the columns that make up this table's primary key.TableEditorsetUniqueValues()Sets this table's primary key to contain all columns, ensuring that all values are unique within the table.TableIdtableId()Get the identifier for this table.TableEditortableId(TableId id)Set the table identifier.StringtoString()TableEditorupdateColumn(Column newColumn)Update the column with the given name.protected voidupdatePositions()protected voidupdatePrimaryKeys()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.debezium.relational.TableEditor
addColumn, columnNames, hasPrimaryKey
-
-
-
-
Method Detail
-
tableId
public TableId tableId()
Description copied from interface:TableEditorGet the identifier for this table.- Specified by:
tableIdin interfaceTableEditor- Returns:
- the table identifier; may be null if not set
-
tableId
public TableEditor tableId(TableId id)
Description copied from interface:TableEditorSet the table identifier.- Specified by:
tableIdin interfaceTableEditor- Parameters:
id- the table identifier- Returns:
- this editor so callers can chain methods together
-
columns
public List<Column> columns()
Description copied from interface:TableEditorGet the definitions for the columns in this table. The resulting list should not be modified directly; instead, the column definitions should be defined withTableEditor.addColumns(Column...),TableEditor.addColumns(Iterable),TableEditor.setColumns(Column...),TableEditor.setColumns(Iterable), orTableEditor.removeColumn(String).- Specified by:
columnsin interfaceTableEditor- Returns:
- the ordered list of definitions; never null
-
columnWithName
public Column columnWithName(String name)
Description copied from interface:TableEditorGet the definition for the column in this table with the supplied name. The case of the supplied name does not matter.- Specified by:
columnWithNamein interfaceTableEditor- Parameters:
name- the case-insensitive name of the column- Returns:
- the column definition, or null if there is no column with the given name
-
hasColumnWithName
protected boolean hasColumnWithName(String name)
-
primaryKeyColumnNames
public List<String> primaryKeyColumnNames()
Description copied from interface:TableEditorThe list of column names that make up the primary key for this table. The resulting list should not be modified directly; instead, the set of primary key names should be defined withTableEditor.setPrimaryKeyNames(String...).- Specified by:
primaryKeyColumnNamesin interfaceTableEditor- Returns:
- the list of column names that make up the primary key; never null but possibly empty
-
addColumns
public TableEditor addColumns(Column... columns)
Description copied from interface:TableEditorAdd one or more columns to this table, regardless of thepositionof the supplied columns. However, if an existing column definition matches a supplied column, the new column definition will replace the existing column definition.- Specified by:
addColumnsin interfaceTableEditor- Parameters:
columns- the definitions for the columns to be added- Returns:
- this editor so callers can chain methods together
-
addColumns
public TableEditor addColumns(Iterable<Column> columns)
Description copied from interface:TableEditorAdd one or more columns to the end of this table's list of columns, regardless of thepositionof the supplied columns. However, if an existing column definition matches a supplied column, the new column definition will replace the existing column definition.- Specified by:
addColumnsin interfaceTableEditor- Parameters:
columns- the definitions for the columns to be added- Returns:
- this editor so callers can chain methods together
-
add
protected void add(Column defn)
-
setColumns
public TableEditor setColumns(Column... columns)
Description copied from interface:TableEditorSet this table's column definitions. The table's primary key columns may be removed as a result of this method if they refer to columns that are not in the supplied list of column definitions.- Specified by:
setColumnsin interfaceTableEditor- Parameters:
columns- the definitions for the columns to be added- Returns:
- this editor so callers can chain methods together
-
setColumns
public TableEditor setColumns(Iterable<Column> columns)
Description copied from interface:TableEditorSet this table's column definitions. The table's primary key columns may be removed as a result of this method if they refer to columns that are not in the supplied list of column definitions.- Specified by:
setColumnsin interfaceTableEditor- Parameters:
columns- the definitions for the columns to be added- Returns:
- this editor so callers can chain methods together
-
updatePrimaryKeys
protected void updatePrimaryKeys()
-
setPrimaryKeyNames
public TableEditor setPrimaryKeyNames(String... pkColumnNames)
Description copied from interface:TableEditorSet the columns that make up this table's primary key.- Specified by:
setPrimaryKeyNamesin interfaceTableEditor- Parameters:
pkColumnNames- the names of this tables columns that make up the primary key- Returns:
- this editor so callers can chain methods together
-
setPrimaryKeyNames
public TableEditor setPrimaryKeyNames(List<String> pkColumnNames)
Description copied from interface:TableEditorSet the columns that make up this table's primary key.- Specified by:
setPrimaryKeyNamesin interfaceTableEditor- Parameters:
pkColumnNames- the names of this tables columns that make up the primary key- Returns:
- this editor so callers can chain methods together
-
setUniqueValues
public TableEditor setUniqueValues()
Description copied from interface:TableEditorSets this table's primary key to contain all columns, ensuring that all values are unique within the table. This is analogous to callingsetPrimaryKeyNames(columnNames())except that the primary key is updated when columns are added or removed.- Specified by:
setUniqueValuesin interfaceTableEditor- Returns:
- this editor so callers can chain methods together
-
hasUniqueValues
public boolean hasUniqueValues()
Description copied from interface:TableEditorDetermine whether this table's primary key contains all columns (viaTableEditor.setUniqueValues()) such that all rows within the table are unique.- Specified by:
hasUniqueValuesin interfaceTableEditor- Returns:
trueifTableEditor.setUniqueValues()was last called on this table, orfalseotherwise
-
setDefaultCharsetName
public TableEditor setDefaultCharsetName(String charsetName)
Description copied from interface:TableEditorSet the name of the character set that should be used by default in the columns that require a character set but have not defined one.- Specified by:
setDefaultCharsetNamein interfaceTableEditor- Parameters:
charsetName- the name of the character set that should be used by default- Returns:
- this editor so callers can chain methods together
-
hasDefaultCharsetName
public boolean hasDefaultCharsetName()
Description copied from interface:TableEditorDetermine if adefault character sethas been set on this table.- Specified by:
hasDefaultCharsetNamein interfaceTableEditor- Returns:
trueif this has a default character set, orfalseif one has not yet been set
-
removeColumn
public TableEditor removeColumn(String columnName)
Description copied from interface:TableEditorRemove the column with the given name. This method does nothing if no such column exists.- Specified by:
removeColumnin interfaceTableEditor- Parameters:
columnName- the name of the column to be removed- Returns:
- this editor so callers can chain methods together
-
updateColumn
public TableEditor updateColumn(Column newColumn)
Description copied from interface:TableEditorUpdate the column with the given name. The existing column definition with the name as the column provided is replaced with the new one.- Specified by:
updateColumnin interfaceTableEditor- Parameters:
newColumn- the new column definition- Returns:
- this editor so callers can chain methods together
-
reorderColumn
public TableEditor reorderColumn(String columnName, String afterColumnName)
Description copied from interface:TableEditorReorder the column with the given name to be positioned after the designated column. IfafterColumnNameis null, the column will be moved to the first column.- Specified by:
reorderColumnin interfaceTableEditor- Parameters:
columnName- the name of the column to be removedafterColumnName- the name of the column after which the moved column is to be positioned; may be null if the column is to be moved to the first column- Returns:
- this editor so callers can chain methods together
-
renameColumn
public TableEditor renameColumn(String existingName, String newName)
Description copied from interface:TableEditorRename the column with the given name to the new specified name.- Specified by:
renameColumnin interfaceTableEditor- Parameters:
existingName- the existing name of the column to be renamed; may not be nullnewName- the new name of the column; may not be null- Returns:
- this editor so callers can chain methods together
-
updatePositions
protected void updatePositions()
-
positionsAreValid
protected boolean positionsAreValid()
-
create
public Table create()
Description copied from interface:TableEditorObtain an immutable table definition representing the current state of this editor. This editor can be reused after this method, since the resulting table definition no longer refers to any of the data used in this editor.- Specified by:
createin interfaceTableEditor- Returns:
- the immutable table definition; never null
-
-