Skip to main content

Notice: This Wiki is now read only and edits are no longer 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 17:30, 27 October 2017 by Unnamed Poltroon (Talk)

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.

The API has three modules, document, column, key-value project. The Graph API is the Apache TinkerPop project:

       <dependency>
            <groupId>org.jnosql.diana</groupId>
            <artifactId>diana-key-value</artifactId>
            <version>${project.version}</version>
        </dependency>
       <dependency>
            <groupId>org.jnosql.diana</groupId>
            <artifactId>diana-column</artifactId>
            <version>${project.version}</version>
        </dependency>
       <dependency>
            <groupId>org.jnosql.diana</groupId>
            <artifactId>diana-document</artifactId>
            <version>${project.version}</version>
        </dependency>


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.insert(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.select(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

Diana-databases-min.png



Links

Back to the top