This template has the duty to be a bridge between the entity model and Diana to a column family. It has two classes ColumnTemplate and ColumnTemplateAsync, one for the synchronous and the other for the asynchronous work.
ColumnTemplate
The ColumnTemplate is the column template for the synchronous tasks. It has three components:
ColumnEntityConverter: That converts an entity to communication API, e.g., The Person to ColumnFamilyEntity.
ColumnCollectionManager: The Diana column famiy entity manager.
ColumnWorkflow: The workflow to update and save methods.
ColumnTemplate template =//instancePerson person =newPerson();person.setAddress("Olympus");person.setName("Artemis Good");person.setPhones(Arrays.asList("55 11 94320121","55 11 94320121"));person.setNickname("artemis");List<Person> people =Collections.singletonList(person);Person personUpdated =template.insert(person);template.insert(people);template.insert(person,Duration.ofHours(1L));template.update(person);template.update(people);
For information removal and retrieval are used the same classes from Diana for documents, ColumnQuery and ColumnDeleteQuery, respectively, also the callback method can be used.
The ColumnTemplateAsync is the document template for the asynchronous tasks. It has two components:
ColumnEntityConverter: That converts an entity to communication API, e.g., The Person to ColumnFamilyEntity.
ColumnFamilyManagerAsync: The Diana column family entity manager asynchronous.
ColumnTemplateAsync templateAsync =//instancePerson person =newPerson();person.setAddress("Olympus");person.setName("Artemis Good");person.setPhones(Arrays.asList("55 11 94320121","55 11 94320121"));person.setNickname("artemis");List<Person> people =Collections.singletonList(person);Consumer<Person> callback = p -> {};templateAsync.insert(person);templateAsync.insert(person,Duration.ofHours(1L));templateAsync.insert(person, callback);templateAsync.insert(people);templateAsync.update(person);templateAsync.update(person, callback);templateAsync.update(people);
For information removal and retrieval are used the same classes from Diana for documents, ColumnQuery and ColumnDeleteQuery, respectively, also the callback method can be used.
Consumer<List<Person>> callBackPeople = p -> {};Consumer<Void> voidCallBack = v ->{};templateAsync.select(query, callBackPeople);templateAsync.delete(deleteQuery);templateAsync.delete(deleteQuery, voidCallBack);
To use a column template just follow the CDI style and put an @Inject on the field.
@InjectprivateColumnTemplateAsync template;
The next step is to produce a ColumnFamilyManagerAsync: