javaone 2017 - jnosql: the definitive solution for java and nosql database [con4954]
TRANSCRIPT
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
JNoSQLThe Definitive Solution for Java
and NoSQL Database
Leonardo Lima Otávio Santana
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
About the Speakers
Leonardo Lima
• Computer engineer, server & embedded sw developer
• From São Paulo, Brasil, currently in Austin, TX
• CTO at V2COM
• Spec Lead – JSR363 – Units of Measurement
• V2COM’s Representative at JCP Executive Committee
[about.me/leomrlima]
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Otávio Santana
• Software engineer, Tomitribe
• From Salvador, Brazil
• Java Champion, SouJava JUG Leader
• Apache, Eclipse and OpenJDK Committer
• Expert Group member in many JSRs
• Representative at JCP EC for SouJava
About the Speakers
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
What defines NoSQL databases?
� No fixed data structure
� Not an ACID, but a BASE
� Five different types
◦ Key/Value
◦ Column Family
◦ Document
◦ Graph
◦ Multi-Model
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
ACID x BASE
Basically Available,Soft State,Eventual consistency
Atomicity,Consistency,Isolation,Durability
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Key/Value
� AmazonDynamo� AmazonS3
� Redis� Scalaris� Voldemort
� Couchbase� Hazelcast
Apollo Sun
Aphrodite Love
Ares War
Light Music
Beauty
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Row key
Column Family
� Hbase� Cassandra� Scylla� Clouddata� SimpleDb
� DynamoDB
Apollo
Ares
Kratos
Duty
{”Sun”, “Light”, ”Music”}
Duty“War”
SlainGods13
Weapon“Sword”
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Document
� AmazonSimpleD� Apache CouchDB
� Couchbase� MongoDB� Riak
{”name”:”Diana”,”father”:”Jupiter”,”mother”:”Latona”,”siblings”:{
”name”: ”Apollo”},”godOf”: {”Hunt”}
}
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Graph
� Neo4J� InfoGrid
� Sones� HyperGraphDB
Apollo
Ares
Kratos
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Multi-model
� OrientDB◦ graph, document
� Couchbase◦ key-value, document
� Elasticsearch◦ document, graph
� ArangoDB◦ column family, graph, key-value
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
SQL -> NoSQL
SQL Key-Value Column Family
Document Graph
Table Bucket ColumnFamily
Collection
Row Key/Value pair
Column Document Vertex
Column Key/Value Pair
Key/Value Pair
Vertex/Edgeproperties
Relationship Link Edge
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Scalability x Complexity
Scal
abili
ty
Complexity
Key/Value
Document
Column Family
Graph
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
How Java application interact with…
SQL NoSQLLogic
DAO
JPA
JDBC
JPA
JDBC
JPA
JDBC
Logic
DAO
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
For example: for a Document DB…BaseDocument baseDocument = new BaseDocument();
baseDocument.addAttribute(name, value);
JsonObject jsonObject = JsonObject.create();
jsonObject.put(name, value);
Document document = new Document();
document.append(name, value);
ODocument document = new ODocument(“collection”);
document.field(name, value);
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
A first attempt on independence…
Logic
DAO
JPA
� Hibernate OGM� Eclipse TopLink
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
… brings a bunch of issues!
� Can’t save asynchronously◦ No callback
� Can’t define a Time to Live (TTL) for stored data� Consistency Level choice on persist� Not all DBs are SQL-based
� There are many NoSQL types
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
What is JNoSQL?
� Mapping API - Artemis
� Communication API - Diana
� No lock-in
� Divide and conquer
DAO
Communication
Mapping
JNoS
QL
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Eclipse JNoSQL
� Eclipse Foundation� Apache v2 + EPL 1.0
� API to each NoSQL type� Configurable� Extensible Communication
Mapping
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
JNoSQL - Diana
� Communication layer API� One API for each DB type◦ Document
◦ Key-value
◦ Column
◦ Graph
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
JNoSQL – Diana APIs
Key/Value Document
Column Family
Graph
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Back to that Document DB…
DocumentEntity entity = DocumentEntity.of("documentCollection");
Document document = Document.of(name, value);
entity.add(document);
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Names & Definitions
� Configuration� Factory� Manager� Entity
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Names & Definitions
ColumnConfiguration<?> condition = new DriverConfiguration();try(ColumnFamilyManagerFactory managerFactory = condition.get()) {
ColumnFamilyManager entityManager = managerFactory.get(KEY_SPACE);entityManager.insert(entity);
ColumnQuery select = select().from(COLUMN_FAMILY).where(eq(id)).build();ColumnDeleteQuery delete = delete().from(COLUMN_FAMILY)
.where(eq(id)).build();
Optional<ColumnEntity> result = entityManager.singleResult(query);entityManager.delete(delete);
}
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Handling diversity (1)
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)));
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Handling diversity (2)
//mutiple implementation
entityManager.insert(entity);
ColumnQuery query = select().from(COLUMN_FAMILY).where(ColumnCondition.eq(id)).build();
Optional<ColumnEntity> result = entityManager.singleResult(query);
//cassandra only
List<ColumnEntity> entities = entityManagerCassandra.cql("select * from newKeySpace.newColumnFamily where id=10;");
entityManagerCassandra.insert(entity, ConsistencyLevel.ALL);
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
JNoSQL - Artemis
� Based on CDI and Diana � Heavy use of Annotations
� Events on Create, Update, Delete� Bean Validation Support� Configurable and Extensible
� “Query by Methods”
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Names & Definitions
� Annotated Entities� Template� Repository� Configuration
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Annotaded Entities
� MappedSuperclass� Entity� Column
@Entity(”god")public class God {
@Columnprivate String name;
@Columnprivate Set<God> siblings;
…}
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Templateimport static DocumentQuery.select;@Inject DocumentTemplate template;
God diana = God.builder().withName(“Diana”);template.insert(diana);template.update(diana);
DocumentQuery query = select().from(“god”).where(“name”).equals(“Diana”).build();List<God> gods = template.select(query);
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Repository
@Inject@Database(DatabaseType.COLUMN)private GodRepository godRepository;
@Inject@Database(DatabaseType.KEY_VALUE)private GodRepository godRepository;
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Configuration
[ {"description": "The couchbase document configuration","name": "document","provider":
"org.jnosql.diana.couchbase.document.CouchbaseDocumentConfiguration","settings": {"couchbase-host-1": "localhost","couchbase-user": "root","couchbase-password": "123456"
}} ]
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Configuration
@Inject@ConfigurationUnitprivate DocumentCollectionManagerFactory<?> entityManager;
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Expansibility
@Entity("person")public class God {
@Columnprivate String name;
@UDT(”weapon")@Columnprivate Weapon weapon;
}
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Expansibility
interface GodRepository extends CassandraRepository<God> {
@CQL("select * from Person")List<Person> findAll();
@CQL("select * from Person where name = ?")List<Person> findByName(String name);
}
JNoSQL
#JavaOne #JNoSQL @JNoSQL @otaviojava @leomrlima
Mailing Listhttps://dev.eclipse.org/mailman/listinfo/jnosql-dev