1 | Dataset.writerReader returns the required DatasetWriterReader for mutative access. Similarly, Dataset.reader returns a DatasetReader. |
1 | The DatasetWriterReader API provides the add method which takes the specified key of the record, |
2 | And var-args of Cell. Another variant takes an Iterable of cells. |
1 | DatasetReader has a get method which takes a key as the argument. It returns an Optional of record. If the dataset doesn't have a record against the provided key Optional.isPresent will return false. |
1 | The DatasetWriterReader.update method requires the key of the record to be updated along with an UpdateOperation of the cell. The UpdateOperation.write method has overloaded variants which can be used to add/update cells in an existing record. |
2 | For updating multiple cells simultaneously, you can use UpdateOperation.allOf which takes a var-arg. To remove a cell use UpdateOperation.remove. Note that all these updates only happen to an existing record. If the record doesn't exist, an update operation will not result in the addition of a record against the provided key. |
1 | DatasetWriterReader.delete takes key and returns true if the record deletion was successful. |
1 | An accessor for a record can be obtained by calling DatasetWriterReader.on which takes a key as the argument. DatasetReader.on returns a ReadRecordAccessor which has read only access to the record. |
2 | The read method takes a Function as an argument which maps the record to the required output. |
3 | The upsert method is like the same verb in a RDBMS: it will add if the record is absent or update if the record is present. |
4 | There is an advanced update that takes an additional BiFunction as mapper along with an UpdateOperation. The function maps the record that existed before the update and the record that resulted from the update. |
5 | Another variant allows conditional read/writes on the record. ReadWriteRecordAccessor.iff takes a predicate, the operations done on ConditionalReadWriteRecordAccessor are supplied with the same predicate. If the predicate returns true, the operation is executed against the record. |
6 | If the predicate returns true, the read will return a record. |
7 | The record will only be updated if the predicate returns true. |
8 | Similarly, the deletion succeeds if the predicate was true. |