Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

JNoSQL/Diana/Start

< JNoSQL‎ | Diana
Revision as of 15:20, 19 March 2017 by Otaviopolianasantana.gmail.com (Talk | contribs) (Created page with " == Getting Start with Diana == <br/> An important thing about Diana is that it is one API divided in four, one for each database flavor. So, just the API is useless withou...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Getting Start with Diana


An important thing about Diana is that it is one API divided in four, one for each database flavor. So, just the API is useless without an implementation. Once the database implements Diana and passes on TCK, it calls him a database driver from a type.


In a multi-model database, that has support for more than one NoSQL kind; the provider must implement more than one API, one to each database that it supports.

        <dependency>
            <groupId>org.jnosql.diana</groupId>
            <artifactId>xxxx-driver</artifactId>
            <version>version</version>
        </dependency>

Where:

  • xxx is a database provider plus a `driver` suffix e.g. cassandra-driver or mongodb-driver
  • version: is the version required

E.g.:

  <dependency>
     <groupId>org.jnosql.diana</groupId>
     <artifactId>mongodb-driver</artifactId>
     <version>0.0.1</version>
  </dependency>


Once the configuration has particular methods, once each database has a different shape. The database might have several behaviors among NoSQL provider.

Column

public class App {

    public static final String KEY_SPACE = "newKeySpace";
    public static final String COLUMN_FAMILY = "newColumnFamily";

    public static void main(String[] args) {

        ColumnConfiguration condition = //instance

        try(ColumnFamilyManagerFactory managerFactory = condition.get()) {
            ColumnFamilyManager columnEntityManager = managerFactory.get(KEY_SPACE);
            ColumnEntity entity = ColumnEntity.of(COLUMN_FAMILY);
            Column id = Column.of("id", 10L);
            entity.add(id);
            entity.add(Column.of("version", 0.001));
            entity.add(Column.of("name", "Diana"));
            entity.add(Column.of("options", Arrays.asList(1, 2, 3)));

            columnEntityManager.save(entity);

            ColumnQuery query = ColumnQuery.of(COLUMN_FAMILY);
            query.and(ColumnCondition.eq(id));
            Optional<ColumnEntity> result = columnEntityManager.singleResult(query);
            System.out.println(result);

        }


    }
}



Document


public class App {

    public static final String DATABASE = "database";
    public static final String DOCUMENT_COLLECTION = "person";

    public static void main(String[] args)  {
        DocumentConfiguration configuration = //instance
        try(DocumentCollectionManagerFactory collectionFactory = configuration.get();) {
            DocumentCollectionManager collectionManager = collectionFactory.get(DATABASE);

            DocumentEntity entity = DocumentEntity.of(DOCUMENT_COLLECTION);
            entity.add(Document.of("name", "Daniel Soro"));
            entity.add(Document.of("age", 26));

            DocumentEntity entitySaved = collectionManager.save(entity);
            Optional<Document> id = entitySaved.find("_id");

            DocumentQuery query = DocumentQuery.of(DOCUMENT_COLLECTION);
            query.and(DocumentCondition.eq(id.get()));
            List<DocumentEntity> documentsFound = collectionManager.find(query);


        }
    }
}

Key Value

public class App {


    public static void main(String[] args) {

        KeyValueConfiguration configuration = //instance
        try (BucketManagerFactory managerFactory = configuration.get()) {
            BucketManager bucket = managerFactory.getBucketManager("bucket");
            List<String> list = managerFactory.getList("bucketList", String.class);
            Set<String> set = managerFactory.getSet("bucketSet", String.class);
            Map<String, Integer> map = managerFactory.getMap("bucketList", String.class, Integer.class);
            Queue<String> queue = managerFactory.getQueue("queueList", String.class);
            bucket.put("key", "value");
            Optional<Value> value = bucket.get("key");
        }


    }
}

Driver Documentation


Links

Back to the top