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
  • DocumentCollectionManager
  • DocumentCollectionManagerAsync
  • Search information on a document collection
  • Removing information from Document Collection
  1. Eclipse JNoSQL one API para vários bancos NoSQL
  2. Diana Introduction

Document Manager

The manager class to a document type can be synchronous or asynchronous:

  • DocumentCollectionManager: To do synchronous operations.

  • DocumentCollectionManagerAsync: To do asynchronous operations.

DocumentCollectionManager

The DocumentCollectionManager is the class that manages the persistence on the synchronous way to document collection.

        DocumentEntity entity = DocumentEntity.of("collection");
        Document diana = Document.of("name", "Diana");
        entity.add(diana);

        List<DocumentEntity> entities = Collections.singletonList(entity);
        DocumentCollectionManager manager = //instance;

        //insert operations
        manager.insert(entity);
        manager.insert(entity, Duration.ofHours(2L));//inserts with 2 hours of TTL
        manager.insert(entities, Duration.ofHours(2L));//inserts with 2 hours of TTL
        //updates operations
        manager.update(entity);
        manager.update(entities);

DocumentCollectionManagerAsync

The DocumentCollectionManagerAsync is the class that manages the persistence on an asynchronous way to document collection.

        DocumentEntity entity = DocumentEntity.of("collection");
        Document diana = Document.of("name", "Diana");
        entity.add(diana);

        List<DocumentEntity> entities = Collections.singletonList(entity);
         DocumentCollectionManagerAsync managerAsync = //instance

        //insert operations
        managerAsync.insert(entity);
        managerAsync.insert(entity, Duration.ofHours(2L));//inserts with 2 hours of TTL
        managerAsync.insert(entities, Duration.ofHours(2L));//inserts with 2 hours of TTL
        //updates operations
        managerAsync.update(entity);
        managerAsync.update(entities);

Sometimes on an asynchronous process, is important to know when this process is over, so the DocumentCollectionManagerAsync also has callback support.

        Consumer<DocumentEntity> callBack = e -> {};
        managerAsync.insert(entity, callBack);
        managerAsync.update(entity, callBack);

Search information on a document collection

Diana has support to retrieve information from both ways synchronous and asynchronous from the DocumentQuery class. The DocumentQuery has information such as sort type, document and also the condition to retrieve information.

The condition on DocumentQuery is given from DocumentCondition, which has the status and the document. Eg. The condition behind is to find a name equal "Ada".

DocumentCondition nameEqualsAda = DocumentCondition.eq(Document.of("name", “Ada”));

Also, the developer can use the aggregators such as AND, OR e NOT.

DocumentCondition nameEqualsAda = DocumentCondition.eq(Document.of("name", "Ada"));
DocumentCondition youngerThan2Years = DocumentCondition.lt(Document.of("age", 2));
DocumentCondition condition = nameEqualsAda.and(youngerThan2Years);
DocumentCondition nameNotEqualsAda = nameEqualsAda.negate();

If there isn't a condition in the query that means the query will try to retrieve all information from the database, similar to a “select * from database” in a relational database, just remembering that the return depends on the driver. It is important to say that not all NoSQL databases have support for this resource.

DocumentQuery also has pagination feature to define where the data start, and it limits.

DocumentCollectionManager manager = //instance;
DocumentCollectionManagerAsync managerAsync = //instance;
DocumentQuery query = DocumentQueryBuilder.select().from("collection").where("age")
                .lt(10).and("name").eq("Ada").orderBy(Sort.of("name", ASC)).limit(10).start(2).build();
List<DocumentEntity> entities = manager.select(query);
Optional<DocumentEntity> entity = manager.singleResult(query);
Consumer<List<DocumentEntity>> callback = e -> {};
managerAsync.select(query, callback);

Removing information from Document Collection

Such as DocumentQuery there is a class to remove information from the document database type: A DocumentDeleteQuery type.

It is smoother than DocumentQuery because there isn't pagination and sort feature, once this information is unnecessary to remove information from database.

        DocumentCollectionManager manager = //instance;
        DocumentCollectionManagerAsync managerAsync = //instance;

        DocumentDeleteQuery query = DocumentQueryBuilder.delete().from("collection").where("age").gt(10)
                .build();


        manager.delete(query);

        managerAsync.delete(query);
        managerAsync.delete(query, v -> {});
PreviousManagerNextColumn Manager

Last updated 6 years ago