SlideShare a Scribd company logo
1 of 24
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Eclipse JNoSQL
Eclipse NoSQL
good practices at OxM
Rafael Del Nero Otávio Santana
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
About the Speakers
Rafael Del Nero
• Creator of NoBugsProject
• #JavaChallenges
• Created the #JavaChallengers Series in Java World
• Java Developer, Equifax
• SouJava member
• Wrote the book “No Bugs, No Stress - Create a Life Changing
Software Without Destroying Your Life”
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Otávio Santana
• Software engineer, Tomitribe
• 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
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
NoSQL
(Not Only SQL)
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
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
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
DAO
Mapping
Communication
Document
Key
Column Graph
DIANA
ARTEMIS
JNoSQL
Data Tier
● Mapping API
● Communication API
● No lock-in
● Divide and conquer
JNoSQL
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Annotated Entities
@Entity("god")
public class God {
@Column
private String name;
@Column
private long age;
@Column
private Set<String> powers;
● MappedSuperclass
● Entity
● Column
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Template
God artemis = ...;
DocumentTemplate template = …
template.insert(artemis);
template.update(artemis);
DocumentQuery query = ...
List<God> gods = template.select(query);
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Repository
interface GodRepository extends Repository<God, String> {
Optional<God> findByName(String name);
Stream<God> findByNameAndAgeOrderByName
(String name, Integer age);
}
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Repository
@Inject
@Database(DatabaseType.COLUMN)
private GodRepository godRepository;
@Inject
@Database(DatabaseType.KEY_VALUE)
private GodRepository godRepository;
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Diversity
@Entity("god")
public class God {
@Column
private String name;
@UDT("weapon")
@Column
private Weapon weapon;
}
interface GodRepository extends
CassandraRepository<God, String> {
@CQL("select * from God where name = ?")
List<God> findByName(String name);
}
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Relational Application
DAO
API API API
Data Tier
Logic Tier
DAO
Logic Tier
Data Tier
JPA
JDBC
JPA
JDBC
JPA
JDBC
NoSQL Application
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
https://dzone.com/refcardz/getting-started-domain-driven
● Entity
● Repository
● Rich Model
● Solid
Domain Driven Design
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
The issue with ORM
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Object-mapping impedance mismatch
● Encapsulation
● Interface, class, inheritance, and
polymorphism
● Mapping to relational concepts
● Data type differences
● Structural and integrity differences
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
1. OxM can do
2. OxM cannot do
Boundaries
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Clean Architecture
● The business matter in your code
● They do not need to know
● Business is OO, but the data…
● Boundaries
● Object-relational impedance
mismatch
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Demo JNoSQL
JNoSQL
With MongoDB
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Manager Factory
@ApplicationScoped
public class MongoDBProducer {
private static final String COLLECTION = "developers";
private MongoDBDocumentConfiguration configuration;
private DocumentCollectionManagerFactory managerFactory;
@PostConstruct
public void init() {
configuration = new MongoDBDocumentConfiguration();
managerFactory = configuration.get();
}
@Produces
public DocumentCollectionManager getManager() {
return managerFactory.get(COLLECTION);
}
}
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Entity Mapping
@Entity
public class Person {
@Id
private Long id;
@Column
private String name;
@Column
private List<String> phones;
@Column
private Address address;
private String ignore;
// Getters and setters
// Constructor
public static PersonBuilder builder() {
return new PersonBuilder();
}
}
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Repository
public interface PersonRepository extends Repository<Person, Long> {
List<Person> findByName(String name);
Stream<Person> findByPhones(List<String> phone);
}
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Insert
public class MongoDBInsert {
public static void main(String[] args) {
Random random = new Random();
Long id = random.nextLong();
try (SeContainer container =
SeContainerInitializer.newInstance().initialize()) {
Person person = Person.builder().
withPhones(Arrays.asList("234", "432"))
.withName("Name")
.withId(id)
.withIgnore("Just Ignore").build();
DocumentTemplate documentTemplate =
container.select(DocumentTemplate.class).get();
Person saved = documentTemplate.insert(person);
System.out.println("Person saved" + saved);
}
}
}
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Query
public class MongoDBQuery{
public static void main(String[] args) {
Random random = new Random();
Long id = 1L;
try (SeContainer container =
SeContainerInitializer.newInstance().initialize()) {
DocumentTemplate documentTemplate =
container.select(DocumentTemplate.class).get();
DocumentQuery query = select().from("Person")
.where("_id").eq(id).build();
Optional<Person> personOptional =
documentTemplate.singleResult(query);
System.out.println("Entity found: " + personOptional);
}
}
}
JNoSQL
#EclipseCon @JNoSQL @otavioJava @rafaDelNero
Otávio Santana Rafael Del Nero
Start using JNoSQL:
https://projects.eclipse.org/projects/technology.jnosql
Start contributing with JNoSQL
https://github.com/JNOSQL
Get the No Bugs No Stress ebook for free:
nobugsproject.com
Thank you!

More Related Content

Similar to Eclipse JNoSQL Good Practices at OXM

Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesHenrik Olsson
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer ToolsWO Community
 
Responsive testing in Drupal - Drupal Developer Days
Responsive testing in Drupal - Drupal Developer DaysResponsive testing in Drupal - Drupal Developer Days
Responsive testing in Drupal - Drupal Developer DaysLa Drupalera
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaWO Community
 
Modern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsModern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsRobert Glaser
 
Functional Patterns with Java8 at Devoxx UK - Slides
Functional Patterns with Java8 at Devoxx UK - SlidesFunctional Patterns with Java8 at Devoxx UK - Slides
Functional Patterns with Java8 at Devoxx UK - SlidesVictor Rentea
 
The JAVA Training Workshop in Ahmedabad
The JAVA Training Workshop in AhmedabadThe JAVA Training Workshop in Ahmedabad
The JAVA Training Workshop in AhmedabadTOPS Technologies
 
Deep Learning for Java Developer - Getting Started
Deep Learning for Java Developer - Getting StartedDeep Learning for Java Developer - Getting Started
Deep Learning for Java Developer - Getting StartedSuyash Joshi
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?Balajihope
 
Architecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsArchitecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsRasheed Waraich
 
Come and Play! with Java EE 7
Come and Play! with Java EE 7Come and Play! with Java EE 7
Come and Play! with Java EE 7Antonio Goncalves
 
Bringing Java into the Open
Bringing Java into the Open Bringing Java into the Open
Bringing Java into the Open Heather VanCura
 
Java days Lviv 2015
Java days Lviv 2015Java days Lviv 2015
Java days Lviv 2015Alex Theedom
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedElizabeth Quinn-Woods
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedMadeline Gauthier
 

Similar to Eclipse JNoSQL Good Practices at OXM (20)

Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project Experiences
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer Tools
 
Advanced JavaScript techniques
Advanced JavaScript techniquesAdvanced JavaScript techniques
Advanced JavaScript techniques
 
Responsive testing in Drupal - Drupal Developer Days
Responsive testing in Drupal - Drupal Developer DaysResponsive testing in Drupal - Drupal Developer Days
Responsive testing in Drupal - Drupal Developer Days
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Modern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsModern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On Rails
 
slides-students-C03.pdf
slides-students-C03.pdfslides-students-C03.pdf
slides-students-C03.pdf
 
Java training in ahmedabad
Java training in ahmedabadJava training in ahmedabad
Java training in ahmedabad
 
Functional Patterns with Java8 at Devoxx UK - Slides
Functional Patterns with Java8 at Devoxx UK - SlidesFunctional Patterns with Java8 at Devoxx UK - Slides
Functional Patterns with Java8 at Devoxx UK - Slides
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 
The JAVA Training Workshop in Ahmedabad
The JAVA Training Workshop in AhmedabadThe JAVA Training Workshop in Ahmedabad
The JAVA Training Workshop in Ahmedabad
 
Deep Learning for Java Developer - Getting Started
Deep Learning for Java Developer - Getting StartedDeep Learning for Java Developer - Getting Started
Deep Learning for Java Developer - Getting Started
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
 
Architecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsArchitecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web Apps
 
Come and Play! with Java EE 7
Come and Play! with Java EE 7Come and Play! with Java EE 7
Come and Play! with Java EE 7
 
Node.js vs. java
Node.js vs. javaNode.js vs. java
Node.js vs. java
 
Bringing Java into the Open
Bringing Java into the Open Bringing Java into the Open
Bringing Java into the Open
 
Java days Lviv 2015
Java days Lviv 2015Java days Lviv 2015
Java days Lviv 2015
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever Changed
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever Changed
 

Recently uploaded

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 

Recently uploaded (20)

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

Eclipse JNoSQL Good Practices at OXM

  • 1. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Eclipse JNoSQL Eclipse NoSQL good practices at OxM Rafael Del Nero Otávio Santana
  • 2. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero About the Speakers Rafael Del Nero • Creator of NoBugsProject • #JavaChallenges • Created the #JavaChallengers Series in Java World • Java Developer, Equifax • SouJava member • Wrote the book “No Bugs, No Stress - Create a Life Changing Software Without Destroying Your Life”
  • 3. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Otávio Santana • Software engineer, Tomitribe • 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
  • 4. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero NoSQL (Not Only SQL)
  • 5. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero 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
  • 6. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero DAO Mapping Communication Document Key Column Graph DIANA ARTEMIS JNoSQL Data Tier ● Mapping API ● Communication API ● No lock-in ● Divide and conquer JNoSQL
  • 7. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Annotated Entities @Entity("god") public class God { @Column private String name; @Column private long age; @Column private Set<String> powers; ● MappedSuperclass ● Entity ● Column
  • 8. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Template God artemis = ...; DocumentTemplate template = … template.insert(artemis); template.update(artemis); DocumentQuery query = ... List<God> gods = template.select(query);
  • 9. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Repository interface GodRepository extends Repository<God, String> { Optional<God> findByName(String name); Stream<God> findByNameAndAgeOrderByName (String name, Integer age); }
  • 10. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Repository @Inject @Database(DatabaseType.COLUMN) private GodRepository godRepository; @Inject @Database(DatabaseType.KEY_VALUE) private GodRepository godRepository;
  • 11. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Diversity @Entity("god") public class God { @Column private String name; @UDT("weapon") @Column private Weapon weapon; } interface GodRepository extends CassandraRepository<God, String> { @CQL("select * from God where name = ?") List<God> findByName(String name); }
  • 12. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Relational Application DAO API API API Data Tier Logic Tier DAO Logic Tier Data Tier JPA JDBC JPA JDBC JPA JDBC NoSQL Application
  • 13. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero https://dzone.com/refcardz/getting-started-domain-driven ● Entity ● Repository ● Rich Model ● Solid Domain Driven Design
  • 14. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero The issue with ORM
  • 15. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Object-mapping impedance mismatch ● Encapsulation ● Interface, class, inheritance, and polymorphism ● Mapping to relational concepts ● Data type differences ● Structural and integrity differences
  • 16. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero 1. OxM can do 2. OxM cannot do Boundaries
  • 17. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Clean Architecture ● The business matter in your code ● They do not need to know ● Business is OO, but the data… ● Boundaries ● Object-relational impedance mismatch
  • 18. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Demo JNoSQL JNoSQL With MongoDB
  • 19. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Manager Factory @ApplicationScoped public class MongoDBProducer { private static final String COLLECTION = "developers"; private MongoDBDocumentConfiguration configuration; private DocumentCollectionManagerFactory managerFactory; @PostConstruct public void init() { configuration = new MongoDBDocumentConfiguration(); managerFactory = configuration.get(); } @Produces public DocumentCollectionManager getManager() { return managerFactory.get(COLLECTION); } }
  • 20. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Entity Mapping @Entity public class Person { @Id private Long id; @Column private String name; @Column private List<String> phones; @Column private Address address; private String ignore; // Getters and setters // Constructor public static PersonBuilder builder() { return new PersonBuilder(); } }
  • 21. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Repository public interface PersonRepository extends Repository<Person, Long> { List<Person> findByName(String name); Stream<Person> findByPhones(List<String> phone); }
  • 22. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Insert public class MongoDBInsert { public static void main(String[] args) { Random random = new Random(); Long id = random.nextLong(); try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { Person person = Person.builder(). withPhones(Arrays.asList("234", "432")) .withName("Name") .withId(id) .withIgnore("Just Ignore").build(); DocumentTemplate documentTemplate = container.select(DocumentTemplate.class).get(); Person saved = documentTemplate.insert(person); System.out.println("Person saved" + saved); } } }
  • 23. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Query public class MongoDBQuery{ public static void main(String[] args) { Random random = new Random(); Long id = 1L; try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { DocumentTemplate documentTemplate = container.select(DocumentTemplate.class).get(); DocumentQuery query = select().from("Person") .where("_id").eq(id).build(); Optional<Person> personOptional = documentTemplate.singleResult(query); System.out.println("Entity found: " + personOptional); } } }
  • 24. JNoSQL #EclipseCon @JNoSQL @otavioJava @rafaDelNero Otávio Santana Rafael Del Nero Start using JNoSQL: https://projects.eclipse.org/projects/technology.jnosql Start contributing with JNoSQL https://github.com/JNOSQL Get the No Bugs No Stress ebook for free: nobugsproject.com Thank you!