JNoSQL Book
  • Eclipse JNoSQL
  • LANGS
  • Eclipse JNoSQL one API to many NoSQL databases
    • About me
    • A principal ideia atrás da AP
    • Por que Diana?
    • Bibliografia
    • Credits
    • Introdução ao Diana
      • Value
      • Criando o seu próprio Writer and Reader
      • Element Entity
      • Document
      • Column
      • Entidade
      • ColumnFamilyEntity
      • DocumentEntity
      • KeyValueEntity
      • Manager
      • Column Manage
      • Document Manage
      • Bucket Manager
      • Factory
      • Column Family Manager Factory
      • Document Family Manager Factory
      • Bucket Manager Factory
      • Configuration
      • Document Configuration
      • Column Configuration
      • Key Value Configuration
    • Diversidade nos Bancos não relacionais
      • Utilizando drivers para com o Diana
    • Introdução ao Artemis
      • Anotações para o Modelo
      • Classes templates
      • Template de Documentos
      • Template de Família de Colunas
      • Template de Chave valor
      • CrudRepository
      • Lidando com os eventos da persistência
      • Bean Validation
    • Componentes do Artemis
      • Workflow
      • EventManager
      • Converter
      • As classes respositórios
    • SUMMARY
    • introduction
  • Eclipse JNoSQL one API para vários bancos NoSQL
    • introduction
    • The main idea behind the API
      • Why Diana?
    • Diana Introduction
      • Value
      • Make custom Writer and Reader
      • Element Entity
      • Document
      • Column
      • Entity
      • ColumnFamilyEntity
      • DocumentEntity
      • KeyValueEntity
      • Manager
      • Document Manager
      • Column Manager
      • Bucket Manager
      • Factory
      • [[Column Family Manager Factory](en/part2/chapter2_5_1.md)
      • Document Collection Factory
      • Bucket Manager Factory
      • Configuration
      • Document Configuration
      • Column Configuration
      • Key Value Configuration
    • The diversity on NoSQL databases
      • Using Diana drivers
      • Implementing a Document Driver
    • Artemis introduction
      • Models Annotation
      • Template classes
      • Document Template
      • Column Family Template
      • Key-value Template
      • Repository
      • Persistence events
      • Bean Validation
    • Artemis components
      • Workflow
      • EventManager
      • Converter
      • The repository class
    • SUMMARY
    • README
    • credits
    • About me
  • LICENSE
Powered by GitBook
On this page
  1. Eclipse JNoSQL one API para vários bancos NoSQL
  2. Artemis components

The repository class

The "maestro" persistence class has synchronous and asynchronous. These interfaces are extended mainly to add a feature that has a Diana driver, but the Artemis API does not support, eg., the live query at OrientDB, consistency level. To make secure an extension there is template method class.

  • AbstractKeyValueRepository

  • AbstractColumnRepository

  • AbstractColumnRepositoryAsync

  • AbstractDocumentRepository

  • AbstractDocumentRepositoryAsync

To demonstrate, it will create a ColumnRepository extension to supports a Cassandra methods that do exists on diana-driver: Cassandra Query Language and consistency level.

public class CassandraColumnRepository extends AbstractColumnRepository {

    @Inject
    private ColumnEntityConverter converter;

    @Inject
    private CassandraColumnFamilyManager manager;

    @Inject
    private ColumnWorkflow workflow;

    @Inject
    private ColumnEventPersistManager eventManager;

    @Override
    protected ColumnEntityConverter getConverter() {
        return converter;
    }

    @Override
    protected ColumnFamilyManager getManager() {
        return manager;
    }

    @Override
    protected ColumnWorkflow getFlow() {
        return workflow;
    }

    @Override
    protected ColumnEventPersistManager getEventManager() {
        return eventManager;
    }

    public <T> T save(T entity, ConsistencyLevel level) {
        Objects.requireNonNull(entity, "entity is required");
        Objects.requireNonNull(level, "level is required");
        UnaryOperator<ColumnEntity> save = e -> manager.save(e, level);
        return workflow.flow(entity, save);
    }

    public <T> T save(T entity, Duration ttl, ConsistencyLevel level) throws NullPointerException {
        Objects.requireNonNull(entity, "entity is required");
        Objects.requireNonNull(level, "level is required");
        UnaryOperator<ColumnEntity> save = e -> manager.save(e, ttl, level);
        return workflow.flow(entity, save);
    }

    public <T> List<T> cql(String query) throws NullPointerException {
        Objects.requireNonNull(query, "query is required");
        List<ColumnEntity> entities = manager.cql(query);
        return entities.stream().map(converter::toEntity).map(c -> (T) c)
                .collect(Collectors.toList());
    }

    public void delete(ColumnDeleteQuery query, ConsistencyLevel level) throws NullPointerException {
        manager.delete(query, level);
    }

}

To conclude, extending the AbstractColumnRepository the CassandraColumnRepository will have support to the methods on Artemis interface and also append the Cassandra resources.

PreviousConverterNextSUMMARY

Last updated 7 years ago