MongoDB                      JBoss User Group Brno                                      dagi@gooddata.comThursday 3 May 2012
About me                      •   Roman Pichlík                      •   GoodData                      •   CZJUG          ...
Agenda                      • What’s wrong...                      • Demo                      • Using MongoDB in Java    ...
A typical java app with                             RDBMS                                      Web Layer                  ...
A typical java app with                             RDBMS                                      Web Layer                  ...
A typical java app with                             RDBMS                                                        Web Layer...
A typical java app with                             RDBMS                                                        Web Layer...
A typical java app with                             RDBMS                                                        Web Layer...
Data Access LayerThursday 3 May 2012It’s not only complicated on this picture -> required 3rd party libraries on classpath
Data Access Layer                                   CRUD interfaceThursday 3 May 2012It’s not only complicated on this pic...
Data Access Layer                                   CRUD interface                      Persistence context logic (queries...
Data Access Layer                                   CRUD interface                      Persistence context logic (queries...
Data Access Layer                                   CRUD interface                      Persistence context logic (queries...
Data Access Layer                                   CRUD interface                      Persistence context logic (queries...
Abstraction faux pas                      • We get used to live/think in Object world                      • We store data...
Time for MongoDBThursday 3 May 2012
MongoDB                      • Document oriented database                      • Schema less                      • Driver...
Data organizationThursday 3 May 2012document - JSONschemaless (documents, fields)
Data organization                                   RDBMS                                      table                      ...
Data organization                 MongoDB                RDBMS                      collection           table            ...
Data organization                 MongoDB                RDBMS                      collection           table            ...
Data organization                 MongoDB                                       RDBMS                      collection     ...
Data organization                 MongoDB                                           RDBMS                      collection ...
Data organization                 MongoDB                                           RDBMS                      collection ...
Data organization                 MongoDB                                                  RDBMS                      coll...
Fruit demo :-)Thursday 3 May 2012
> use fruitdb                                    change/create DB  switched to db fruitdb                                 ...
Using MongoDB in Java                  MongoDB                      Java Application                        BSON          ...
Using MongoDB in Java                      Mongo m = new Mongo("localhost" , 27017 );                      DB db = m.getDB...
Sweet MongoDB                      •   Thin Data Access Layer                          •   No magic behind the            ...
Architecture impact                      • No transactions                       • only atomic update on document level   ...
MongoDB cluster in GoodData                                                  Sync. write, Master + Slave                  ...
Thank you                      •   Join us and work with MongoDB ;-)                      •   http://www.gooddata.com/abou...
Upcoming SlideShare
Loading in …5
×

MongoDB for Java Developers

3,773 views

Published on

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,773
On SlideShare
0
From Embeds
0
Number of Embeds
1,922
Actions
Shares
0
Downloads
33
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

MongoDB for Java Developers

  1. 1. MongoDB JBoss User Group Brno dagi@gooddata.comThursday 3 May 2012
  2. 2. About me • Roman Pichlík • GoodData • CZJUG • CZ Podcast • Follow me on Twitter • @_dagiThursday 3 May 2012
  3. 3. Agenda • What’s wrong... • Demo • Using MongoDB in Java • MongoDB deployment in GoodData • Q&AThursday 3 May 2012
  4. 4. A typical java app with RDBMS Web Layer Domain Business Logic Layer model Data Access LayerThursday 3 May 2012
  5. 5. A typical java app with RDBMS Web Layer Domain Business Logic Layer model Data Access LayerThursday 3 May 2012
  6. 6. A typical java app with RDBMS Web Layer Domain Business Logic Layer model am eta dat Data Access Layer a fo rm app ing to RD BM S sc hem aThursday 3 May 2012
  7. 7. A typical java app with RDBMS Web Layer Domain Business Logic Layer model am eta dat Data Access Layer a fo rm app al ing e lation to b ject/R sa RD ic for O ice ver BM k mag on and v S sc hem a blac versi a conThursday 3 May 2012
  8. 8. A typical java app with RDBMS Web Layer Domain Business Logic Layer model am eta dat Data Access Layer a fo rm app al ing e lation to b ject/R sa RD ic for O ice ver BM k mag on and v S sc hem a blac versi a con and transactions...Thursday 3 May 2012
  9. 9. Data Access LayerThursday 3 May 2012It’s not only complicated on this picture -> required 3rd party libraries on classpath
  10. 10. Data Access Layer CRUD interfaceThursday 3 May 2012It’s not only complicated on this picture -> required 3rd party libraries on classpath
  11. 11. Data Access Layer CRUD interface Persistence context logic (queries, merge...)Thursday 3 May 2012It’s not only complicated on this picture -> required 3rd party libraries on classpath
  12. 12. Data Access Layer CRUD interface Persistence context logic (queries, merge...) Spring ORM BridgeThursday 3 May 2012It’s not only complicated on this picture -> required 3rd party libraries on classpath
  13. 13. Data Access Layer CRUD interface Persistence context logic (queries, merge...) Spring ORM Bridge ORM framework (Hibernate/JPA)Thursday 3 May 2012It’s not only complicated on this picture -> required 3rd party libraries on classpath
  14. 14. Data Access Layer CRUD interface Persistence context logic (queries, merge...) Why the hell it’s so complicated?! Spring ORM Bridge ORM framework (Hibernate/JPA)Thursday 3 May 2012It’s not only complicated on this picture -> required 3rd party libraries on classpath
  15. 15. Abstraction faux pas • We get used to live/think in Object world • We store data in RDBMS world • We build a bridge between Object/ RDBMS worlds • The bridge (ORM) is very complicatedThursday 3 May 2012How many of you know patterns like Open Session in View, DTO?How many of you know the difference between first and second level cache?How many of you know the difference between Session#load and Session#get method?
  16. 16. Time for MongoDBThursday 3 May 2012
  17. 17. MongoDB • Document oriented database • Schema less • Driver API • NoSQL but Query friendly • Open source • AGPL server, Apache 2.0 driverThursday 3 May 2012
  18. 18. Data organizationThursday 3 May 2012document - JSONschemaless (documents, fields)
  19. 19. Data organization RDBMS table Fruit id weight color discriminator country curvatureThursday 3 May 2012document - JSONschemaless (documents, fields)
  20. 20. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight color discriminator country curvatureThursday 3 May 2012document - JSONschemaless (documents, fields)
  21. 21. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight color discriminator country curvatureThursday 3 May 2012document - JSONschemaless (documents, fields)
  22. 22. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight color discriminator country curvature id discriminator color weight country curvature row 1 apple red 10 cz null 2 banana null 5.1 br 3Thursday 3 May 2012document - JSONschemaless (documents, fields)
  23. 23. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight document color { discriminator    "_id":"1", country    "apple":{ curvature       "weight":10,       "country":"cz",       "color":"red" id discriminator color weight country curvature    } } row 1 apple red 10 cz null 2 banana null 5.1 br 3 {    "_id":"2",    "banana":{       "weight":5.1,       "country":"br",       "curvature":3    } }Thursday 3 May 2012document - JSONschemaless (documents, fields)
  24. 24. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight document color { discriminator    "_id":"1", country    "apple":{ curvature       "weight":10,       "country":"cz",       "color":"red" id discriminator color weight country curvature    } } row 1 apple red 10 cz null 2 banana null 5.1 br 3 {    "_id":"2",    "banana":{       "weight":5.1,       "country":"br",       "curvature":3    } }Thursday 3 May 2012document - JSONschemaless (documents, fields)
  25. 25. Data organization MongoDB RDBMS collection table Fruit Fruit Document id weight document color { discriminator    "_id":"1", country    "apple":{ curvature       "weight":10,       "country":"cz",       "color":"red" id discriminator color weight country curvature    } } row 1 apple red 10 cz null 2 banana null 5.1 br 3 {    "_id":"2", column    "banana":{       "weight":5.1, field       "country":"br",       "curvature":3    } }Thursday 3 May 2012document - JSONschemaless (documents, fields)
  26. 26. Fruit demo :-)Thursday 3 May 2012
  27. 27. > use fruitdb change/create DB switched to db fruitdb insert document > db.createCollection("fruit"); { "ok" : 1 } > db.fruit.insert({apple:{weight:10, country:"cz", color:"red"}}); > db.fruit.findOne(); get first document { "_id" : ObjectId("4fa0f21591d1fb43c578fa26"), "apple" : { "color" : "red", "country" : "cz", "weight" : 10 } } > db.fruit.insert({banana:{weight:5.1, country: "br", curvature:3}}); > db.fruit.update({"apple.color":"green"}, {$set: {"apple.color":"red"}}); update document > db.fruit.remove({"_id":"4fa0f3a791d1fb43c578fa27"}) > db.fruit.find({"apple.color":"red"}); remove document { "_id" : ObjectId("4fa0f21591d1fb43c578fa26"), "apple" : { "color" : "red", "country" : "cz", "weight" : 10 } } find documentThursday 3 May 2012
  28. 28. Using MongoDB in Java MongoDB Java Application BSON Web Layer Domain JSON document Business Logic Layer { model    "_id":"...",    "apple":{ Data Access Layer       "weight":10,       "country":"cz",       "color":"red" BSON API Auth.    } } MongoDB driver Failover ConnectivityThursday 3 May 2012
  29. 29. Using MongoDB in Java Mongo m = new Mongo("localhost" , 27017 ); DB db = m.getDB( "fruitdb" ); DBCollection coll = db.getCollection("fruit"); BasicDBObject doc = new BasicDBObject(); BasicDBObject apple = new BasicDBObject(); apple.put("weight", 10); apple.put("country", "cz"); apple.put("color", "red"); doc.put("apple", apple); fruit.insert(doc);Thursday 3 May 2012
  30. 30. Sweet MongoDB • Thin Data Access Layer • No magic behind the scene • Flexible • schemaless • new document types • new collections • No Alter DDLThursday 3 May 2012
  31. 31. Architecture impact • No transactions • only atomic update on document level • atomic FindAndUpdate operation • No constraints • application logic handles data inconsistency • Self sufficient documents over JoinsThursday 3 May 2012 • redundancy
  32. 32. MongoDB cluster in GoodData Sync. write, Master + Slave • GoodData platform No slave reads hosted on Amazon WS Client • 3-node • Journal enabled Master • EBS used for data replication • backup/restore Slave Slave • Application specific backup/restoreThursday 3 May 2012* Master elected automatically on start or when the previous one goes down* Master writes to journal -> Ops log replicated to slaves
  33. 33. Thank you • Join us and work with MongoDB ;-) • http://www.gooddata.com/about/careers • Q&AThursday 3 May 2012

×