/** * Get the columns that make up the primary key for this table. * @return the list of columns that make up the primary key; never null but possibly empty */ default List<Column> primaryKeyColumns() { return filterColumns(col->isPrimaryKeyColumn(col.name())); }
/** * Get the columns that are not included in the primary key for this table. * @return the list of columns that are not part of the primary key; never null but possibly empty */ default List<Column> nonPrimaryKeyColumns() { return filterColumns(col->!isPrimaryKeyColumn(col.name())); }
@Test public void shouldDetermineIfColumnIsPartOfPrimaryKeyUsingColumnNameWithExactMatch() { assertThat(table.isPrimaryKeyColumn("C1")).isTrue(); assertThat(table.isPrimaryKeyColumn("C2")).isTrue(); assertThat(table.isPrimaryKeyColumn("C3")).isFalse(); assertThat(table.isPrimaryKeyColumn("C4")).isFalse(); assertThat(table.isPrimaryKeyColumn("non-existant")).isFalse(); }
@Test public void shouldDetermineIfColumnIsPartOfPrimaryKeyUsingColumnNameWithWrongCase() { assertThat(table.isPrimaryKeyColumn("c1")).isTrue(); assertThat(table.isPrimaryKeyColumn("c2")).isTrue(); assertThat(table.isPrimaryKeyColumn("c3")).isFalse(); assertThat(table.isPrimaryKeyColumn("c4")).isFalse(); assertThat(table.isPrimaryKeyColumn("non-existant")).isFalse(); }
AtomicBoolean hasPrimaryKey = new AtomicBoolean(false); table.columns().forEach(column -> { if (table.isPrimaryKeyColumn(column.name())) {
private Table tableFromFromMessage(List<ReplicationMessage.Column> columns, Table table) { return table.edit() .setColumns(columns.stream() .map(column -> { final PostgresType type = column.getType(); final ColumnEditor columnEditor = Column.editor() .name(column.getName()) .jdbcType(type.getJdbcId()) .type(type.getName()) .optional(column.isOptional()) .nativeType(type.getOid()); columnEditor.length(column.getTypeMetadata().getLength()); columnEditor.scale(column.getTypeMetadata().getScale()); return columnEditor.create(); }) .collect(Collectors.toList()) ) .setPrimaryKeyNames(table.filterColumnNames(c -> table.isPrimaryKeyColumn(c.name()))).create(); } }
/** * Get the columns that make up the primary key for this table. * @return the list of columns that make up the primary key; never null but possibly empty */ default List<Column> primaryKeyColumns() { return filterColumns(col->isPrimaryKeyColumn(col.name())); }
/** * Get the columns that are not included in the primary key for this table. * @return the list of columns that are not part of the primary key; never null but possibly empty */ default List<Column> nonPrimaryKeyColumns() { return filterColumns(col->!isPrimaryKeyColumn(col.name())); }
AtomicBoolean hasPrimaryKey = new AtomicBoolean(false); table.columns().forEach(column -> { if (table.isPrimaryKeyColumn(column.name())) {
private Table tableFromFromMessage(List<ReplicationMessage.Column> columns, Table table) { return table.edit() .setColumns(columns.stream() .map(column -> { final PostgresType type = column.getType(); final ColumnEditor columnEditor = Column.editor() .name(column.getName()) .jdbcType(type.getJdbcId()) .type(type.getName()) .optional(column.isOptional()) .nativeType(type.getOid()); columnEditor.length(column.getTypeMetadata().getLength()); columnEditor.scale(column.getTypeMetadata().getScale()); return columnEditor.create(); }) .collect(Collectors.toList()) ) .setPrimaryKeyNames(table.filterColumnNames(c -> table.isPrimaryKeyColumn(c.name()))).create(); } }
assertThat(table.isPrimaryKeyColumn("ID"));