/** * Set the value for the field with the given name to be the supplied array. * * @param name The name of the field * @param values the (valid) values for the array * @return The array that was just set as the value for the named field; never null and may or may not be the same * instance as the supplied <code>array</code>. */ default Array setArray(CharSequence name, Object... values) { return setArray(name, Array.create(values)); }
/** * Set the value for the field with the given name to be a new, empty array. * * @param name The name of the field * @return The array that was just created; never null */ default Array setArray(CharSequence name) { return setArray(name, Array.create()); }
/** * Get the existing array value in this document for the given field name, or create a new array if there is no existing array * at this field. * * @param fieldName The name of the field * @return The editable array field value; never null */ default Array getOrCreateArray(CharSequence fieldName) { Value value = get(fieldName); if (value == null || value.isNull()) { return setArray(fieldName, (Array) null); } return value.asArray(); }
private Document toDocument(Table table) { Document document = Document.create(); document.set("defaultCharsetName", table.defaultCharsetName()); document.set("primaryKeyColumnNames", Array.create(table.primaryKeyColumnNames())); List<Document> columns = table.columns() .stream() .map(this::toDocument) .collect(Collectors.toList()); document.setArray("columns", Array.create(columns)); return document; }
public HistoryRecord(Map<String, ?> source, Map<String, ?> position, String databaseName, String schemaName, String ddl, TableChanges changes) { this.doc = Document.create(); Document src = doc.setDocument(Fields.SOURCE); if (source != null) source.forEach(src::set); Document pos = doc.setDocument(Fields.POSITION); if (position != null) { for (Entry<String, ?> positionElement : position.entrySet()) { if (positionElement.getValue() instanceof byte[]) { pos.setBinary(positionElement.getKey(), (byte[]) positionElement.getValue()); } else { pos.set(positionElement.getKey(), positionElement.getValue()); } } } if (databaseName != null) { doc.setString(Fields.DATABASE_NAME, databaseName); } if (schemaName != null) { doc.setString(Fields.SCHEMA_NAME, schemaName); } if (ddl != null) { doc.setString(Fields.DDL_STATEMENTS, ddl); } if (changes != null) { doc.setArray(Fields.TABLE_CHANGES, changes.toArray()); } }
@Test @FixFor("DBZ-759") public void shouldCreateArrayFromValues() { Document document = Document.create(); document.setArray("my_field", 1, 2, 3); assertThat(document.toString()).isEqualTo( "{\n" + " \"my_field\" : [ 1, 2, 3 ]\n" + "}" ); }
/** * Set the value for the field with the given name to be a new, empty array. * * @param name The name of the field * @return The array that was just created; never null */ default Array setArray(CharSequence name) { return setArray(name, Array.create()); }
/** * Set the value for the field with the given name to be the supplied array. * * @param name The name of the field * @param values the (valid) values for the array * @return The array that was just set as the value for the named field; never null and may or may not be the same * instance as the supplied <code>array</code>. */ default Array setArray(CharSequence name, Object... values) { return setArray(name, Array.create(values)); }
private Document toDocument(Table table) { Document document = Document.create(); document.set("defaultCharsetName", table.defaultCharsetName()); document.set("primaryKeyColumnNames", Array.create(table.primaryKeyColumnNames())); List<Document> columns = table.columns() .stream() .map(this::toDocument) .collect(Collectors.toList()); document.setArray("columns", Array.create(columns)); return document; }
/** * Get the existing array value in this document for the given field name, or create a new array if there is no existing array * at this field. * * @param fieldName The name of the field * @return The editable array field value; never null */ default Array getOrCreateArray(CharSequence fieldName) { Value value = get(fieldName); if (value == null || value.isNull()) { return setArray(fieldName, (Array) null); } return value.asArray(); }
public HistoryRecord(Map<String, ?> source, Map<String, ?> position, String databaseName, String schemaName, String ddl, TableChanges changes) { this.doc = Document.create(); Document src = doc.setDocument(Fields.SOURCE); if (source != null) source.forEach(src::set); Document pos = doc.setDocument(Fields.POSITION); if (position != null) { for (Entry<String, ?> positionElement : position.entrySet()) { if (positionElement.getValue() instanceof byte[]) { pos.setBinary(positionElement.getKey(), (byte[]) positionElement.getValue()); } else { pos.set(positionElement.getKey(), positionElement.getValue()); } } } if (databaseName != null) { doc.setString(Fields.DATABASE_NAME, databaseName); } if (schemaName != null) { doc.setString(Fields.SCHEMA_NAME, schemaName); } if (ddl != null) { doc.setString(Fields.DDL_STATEMENTS, ddl); } if (changes != null) { doc.setArray(Fields.TABLE_CHANGES, changes.toArray()); } }