40
Otávio Santana @otaviojava Eclipse JNoSQL

Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Otávio Santana @otaviojava

Eclipse JNoSQL

Page 2: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

NoSQL

01 Database

02 Doesn't use structure

03 Not Transaction

04 Base

Five different types05

Page 3: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Key Value

AmazonDynamo

AmazonS3

Redis

Hazelcast

Apollo

Ares

Aphrodite

Sun

War

Love Beauty

Page 4: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Column Family

Apollo

Aphrodite

Ares

Kratos

Duty

Duty

Duty

Dead Gods

Love, happy

Sun

War

13

Color

weaponSword

Row-key ColumnsHBase

Scylla

SimpleDb

Cassandra

DynamoDB

Clouddata

Page 5: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Document{ "name":"Diana", "duty":[ "Hunt", "Moon", "Nature" ], "siblings":{ "Apollo":"brother" }}

ApacheCouchDB

MongoDB

Couchbase

Page 6: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Graph

Apollo Ares

Kratoswas killed by was killed by

killed killed

Neo4j

InfoGrid

Sones

HyperGraphDB

Page 7: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Multi-Model

01

02

03

04

OrientDB (graph, document)

Couchbase (key value, document)

Elasticsearch (document, graph)

ArangoDB (document, graph, key-value)

Page 8: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

SQL vs NoSQL

SQL KEY-VALUE COLUMN DOCUMENTS GRAPH

Table Bucket Column family Collection

Row Key/value pair column Documents Vertex

Column Key/value pair Key/value pair Vertex and Edge property

Relationship Link Edge

Page 9: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

BASE vs ACID

• Basically Available• Soft state• Eventual consistency

• Atomicity• Consistency• Isolation• Durability

Page 10: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

CAP

Page 11: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Scalability vs Complexity

Scal

abili

ty

Complexity

key-valueColumn

DocumentGraph

Page 12: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Relational Application NoSQL Application

Logic Tier Logic Tier

DAO DAO

JPAJPAJPAJPAJDBC JDBCJDBCJDBC

Data Tier

APIAPI API

Data Tier

Page 13: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

The Current Solution

DAO

Solution Solution

Hibernate OGM

TopLink

Page 14: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

JPA problem for NoSQL

01

02

03

04

05

06

Saves Async

Async Callback

Time to Live (TTL)

Consistency Level

SQL based

Diversity in NoSQL

Page 15: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

The Current Solution

DIANA

ARTEMIS

JNoSQL

DAO

Mapping

Communication

Column Documents Key Graph

Data Tier

01

02

03

04

Mapping API

Communication API

No lock-in

Divide and Conquer

Page 16: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Why Diana?

01

02

03

04

Goddess of the hunt, nature and moon

Fought in Troy

Brave warrior and hunter

Diana Rome = Artemis Greek

Page 17: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Diana

API Communication layer

Document, key-value, Colum, Graph (TinkerPop)

Page 18: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Communication Issue

ODocument document = new ODocument(“collection”);document.field(name, value);

JsonObject jsonObject = JsonObject.create();jsonObject.put(name, value);

BaseDocument baseDocument = new BaseDocument();baseDocument.addAttribute(name, value);

Document document = new Document();document.append(name, value);

Page 19: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Eclipse JNoSQL

DocumentEntity entity = DocumentEntity.of("collection");entity.add(name, value);

Page 20: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

01

02

03

04

Configuration

Factory

Manager

Entity

Names & Definitions

Page 21: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Names & DefinitionsColumnConfiguration<?> configuration = new DriverConfiguration();

try(ColumnFamilyManagerFactory managerFactory = configuration.get()) {

ColumnFamilyManager entityManager = managerFactory.get(KEY_SPACE);

entityManager.insert(entity);

ColumnQuery select = select().from(COLUMN_FAMILY)

.where("id").eq("Ada").build();

ColumnDeleteQuery delete = delete().from(COLUMN_FAMILY)

.where("id").eq("Ada").build();

Optional<ColumnEntity> result = entityManager.singleResult(query);

entityManager.delete(delete);

Page 22: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Diversity

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)));

//cassandra onlyList<ColumnEntity> entities = entityManagerCassandra.cql("select * from newKeySpace.newColumnFamily where id=10;");entityManagerCassandra.insert(entity, ConsistencyLevel.ALL);

//mutiple implementationentityManager.insert(entity);ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();Optional<ColumnEntity> result = entityManager.singleResult(query);

Page 23: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

01

02

03

04

05

06

Artemis

CDI Based

Diana Based

Annotation Based

Events to insert, delete, update

Supports to Bean Validation

Configurable and Extensible

07 Query Method

Page 24: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

01

02

03

04

Annotated Entities

Template

Repository

Configuration

Names & Definitions

Page 25: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Annotated Entities

01

02

03

Mapped Superclass

Entity

Column

@Entity("god")public class God {

@Column private String name;

@Column private long age;

@Column private Set<String> powers;}

Page 26: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

TemplateGod artemis = ...;

DocumentTemplate template = …

template.insert(artemis);

template.update(artemis);

DocumentQuery query = ...

List<God> gods = template.select(query);

Page 27: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Repositoryinterface GodRepository extends Repository<God, String> {

Optional<God> findByName(String name);

Stream<God> findByNameAndAgeOrderByName(String name, Integer age);

}

Page 28: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Repository@Inject@Database(DatabaseType.COLUMN)private GodRepository godRepository;

@Inject@Database(DatabaseType.KEY_VALUE)private GodRepository godRepository;

Page 29: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Support to

JSON XML YAML

Page 30: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Configuration@Inject@ConfigurationUnitprivate DocumentCollectionManagerFactory<?> entityManager;

Page 31: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Diversity

@Entity("god")public class God {

@Columnprivate String name;

@UDT("weapon")@Columnprivate Weapon weapon;

}

interface GodRepository extends CassandraRepository<God, String> {

@CQL("select * from God where name = ?") List<God> findByName(String name);

}

Page 32: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

We have Query by TextDocumentTemplate documentTemplate = ...;

ColumnTemplate columnTemplate = ...;

KeyValueTempalte keyValueTemplate =...;

GraphTemplate graphTemplate =...;

List<Movie> movies = documentTemplate.query("select * from Movie where

year > 2012");

List<Person> people = columnTemplate.query("select * from Person where age

= 25");

Optional<God> god = keyValueTemplate.query("get \"Diana\"");

List<City> cities = graphTemplate.query("g.V().hasLabel('City')");

Page 33: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

We have Query by TextPreparedStatement preparedStatement = template.prepare("select * from Person

where name = @name");

preparedStatement.bind("name", "Ada");

List<Person> adas = preparedStatement.getResultList();

//to graph just keep using gremlin

PreparedStatement prepare = graphTemplate().prepare("g.V().hasLabel(param)");

prepare.bind("param", "Person");

List<Person> people = preparedStatement.getResultList();

Page 34: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

We have Query by Textinterface PersonRepository extends Repository<Person, Long> {

@Query("select * from Person")

Optional<Person> findByQuery();

@Query("select * from Person where id = @id")

Optional<Person> findByQuery(@Param("id") String id);

}

Page 35: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Demo

Couchbase + Docker

CDI 2.0 with Java SE

Configuration

JNoSQL

Page 36: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

NoSQL Providers

Page 37: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Draft and code proposal

Community Feedback

Involve NoSQL Vendors

Involve Solution Vendors

Eclipse Project

Road Map

Development

Page 38: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

JUGs/Communities

Page 39: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

References

Communication APISupport to Async operationsAPIs

Mapping APIBean ValidationEventsRepositoryTemplate

Query by textPrepared Statement

http://jnosql.org/https://github.com/eclipse?q=Jnosqlhttps://dev.eclipse.org/mailman/listinfo/jnosql-devhttps://gitter.im/JNOSQL/developershttps://wiki.eclipse.org/JNoSQL

Page 40: Otávio Santana @otaviojava - oraguate.org · 2018-10-04 · NoSQL 01 Database 02 Doesn't use structure 03 Not Transaction 04 Base 05 Five different types

Otávio Santana @otaviojava

Thank you