Voyage by example 
tips and tricks on persisting object models
Esteban Lorenzano 
Pharo core developer 
INRIA - RMoD 
http://smallworks.eu
Why? 
• You already know about Voyage 
• You already attended to a tutorial last year 
• But there are some recurrent prob...
What is Voyage? (1) 
• Simple abstraction layer to map objects into a database 
- Very well suited for document databases,...
What is Voyage? (2) 
• Did I said is simple? 
• it ensures object identity 
• it provides error handling 
• it implements ...
Voyage principles 
• Behavioural complete (for common usage), but 
decoupled approach also possible. 
• Same design for di...
Voyage ultimate goal 
To be the GLORP for NoSQL databases
The problem to solve
Impedance mistmatch 
Class A Class B Class C 
Table A Table B Table C 
1..* 
*..* 
Ideal relational model
Impedance mistmatch 
aColection 
anObject otherObject 
firstObject 
secondObject 
thirdObject 
Real object model
Impedance mistmatch 
aColection 
anObject otherObject 
Real object model 
firstObject 
secondObject 
thirdObject
Impedance mistmatch 
aColection 
anObject otherObject 
Real object model 
firstObject 
secondObject 
thirdObject
So, what about those tips?
Think in objects
A simple model 
*..* 
Hero Power
Persist 
(Hero named: ‘Groot’) 
addPower: ((Power named: ‘Plant Control’) 
level: #epic; 
yourself); 
save.
Persist 
{ 
_id: OID(…), 
#version: …, 
#instanceOf: ‘Hero’, 
name: ‘Groot’, 
powers: [ { #collection: ‘Power’, __id: OID(...
Take control
A simple model 
(a bit more complete) 
*..* 
Hero Power 
1..* 
Equipment 
Container Pistol 
1..*
Persist 
(Hero named: ‘Star-lord’) 
addEquipment: (Container 
addItem: Pistol new; 
yourself); 
save.
Persist (1) 
{ 
_id: OID(…), 
#version: …, 
#instanceOf: ‘Hero’, 
name: ‘Star-lord’, 
powers: [], 
equipment: [ { 
#instan...
Persist (2) 
{ 
_id: OID(1), 
#version: …, 
#instanceOf: ‘Hero’, 
name: ‘Star-lord’, 
powers: [], 
equipment: [ { #collect...
Integrity is a 
consequence
Allowing missing content 
• We do not have foreign keys 
- So we cannot do things like “ON DELETE 
CASCADE” 
- Even delete...
Persist 
mongoContainer 
<mongoContainer> 
! 
^ VOMongoContainer new 
collectionName: ‘powers’; 
enableMissingContent; 
yo...
Querying smart
Query (1) 
Hero 
selectMany: [ :each | … ] 
sortBy: { #name -> VOOrder ascending } asDictionary 
limit: 100 
offset: 100
Query (2) 
Hero 
selectMany: { 
‘name’ -> { 
‘$regexp’ -> ‘^G.*’. 
‘$options’ -> ‘i’ 
} asDictionary 
} asDictionary
Adapt schemes
The “scheme is not mine” 
problem 
• You can move meta-information to your program 
• Magritte-Voyage gives you a lot of p...
Meta-information 
{ 
_id: OID(…), 
#version: …, 
#instanceOf: ‘Hero’, 
name: ‘Star-lord’, 
powers: [], 
equipment: [ { 
#i...
Meta-information 
{ 
_id: OID(…), 
#version: …, 
#instanceOf: ‘Hero’, 
name: ‘Star-lord’, 
powers: [], 
equipment: [ { 
#i...
Meta-information 
{ 
_id: OID(…), 
name: ‘Star-lord’, 
powers: [], 
equipment: [ { 
‘items’, [ {} ] } ] 
}
Voyage 2.0 
• Root detection (enhance save & update) 
• Cyclic detection 
- Add strategy to persist cycles even without ro...
Use it today! 
Gofer it 
smalltalkhubUser: ‘Pharo’ project: ’MetaRepoForPharo30’; 
configurationOf: ‘VoyageMongo’; 
loadSt...
Upcoming SlideShare
Loading in …5
×

Voyage by example

561 views
392 views

Published on

Title: Voyage by example
Speaker: Esteban Lorenzano
Thu, August 21, 11:00am – 11:30am

Video Part1: https://www.youtube.com/watch?v=1szVgKQm474
Video Part2: https://www.youtube.com/watch?v=vxork8Kckh8

Description
Voyage is a framework to abstract over NoSQL databases and provides nice object-oriented features to save objects.

Bio: Esteban Lorenzano, 42 years. Programmer since ever, Full-time Smalltalker since 2007 and Pharo enthusiast since almost its every beginning, after owning his own company and spend some years teaching at different universities in Argentina, he currently works de development of Pharo itself, at the RMoD team of INRIA (France)

Published in: Software
1 Comment
1 Like
Statistics
Notes
  • Video Part1: https://www.youtube.com/watch?v=1szVgKQm474
    Video Part2: https://www.youtube.com/watch?v=vxork8Kckh8
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
561
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Voyage by example

  1. 1. Voyage by example tips and tricks on persisting object models
  2. 2. Esteban Lorenzano Pharo core developer INRIA - RMoD http://smallworks.eu
  3. 3. Why? • You already know about Voyage • You already attended to a tutorial last year • But there are some recurrent problems people find when trying to use it • And I’m still seeing a lot of people that could be using it and they chose other solutions
  4. 4. What is Voyage? (1) • Simple abstraction layer to map objects into a database - Very well suited for document databases, but in theory, the approach will work for other kind of repositories ‣ There was (long time ago) a Voyage-GLORP backend ‣ There was (even more time ago) a Voyage- ImageSegment backend - Voyage-Memory, Voyage-Mongo
  5. 5. What is Voyage? (2) • Did I said is simple? • it ensures object identity • it provides error handling • it implements a connection pool
  6. 6. Voyage principles • Behavioural complete (for common usage), but decoupled approach also possible. • Same design for different backends, but not a common abstraction - There is no such thing as a “voyage query language”, etc. - is a bit more work for users who want to switch, but a lot more happiness for the program itself
  7. 7. Voyage ultimate goal To be the GLORP for NoSQL databases
  8. 8. The problem to solve
  9. 9. Impedance mistmatch Class A Class B Class C Table A Table B Table C 1..* *..* Ideal relational model
  10. 10. Impedance mistmatch aColection anObject otherObject firstObject secondObject thirdObject Real object model
  11. 11. Impedance mistmatch aColection anObject otherObject Real object model firstObject secondObject thirdObject
  12. 12. Impedance mistmatch aColection anObject otherObject Real object model firstObject secondObject thirdObject
  13. 13. So, what about those tips?
  14. 14. Think in objects
  15. 15. A simple model *..* Hero Power
  16. 16. Persist (Hero named: ‘Groot’) addPower: ((Power named: ‘Plant Control’) level: #epic; yourself); save.
  17. 17. Persist { _id: OID(…), #version: …, #instanceOf: ‘Hero’, name: ‘Groot’, powers: [ { #collection: ‘Power’, __id: OID(…) } ] } ! { _id: OID(…), #version: …, #instanceOf: ‘Power’, name: ‘Plant Control’, level: #epic, heroes: [ #collection: ‘Hero’, __id: OID(…) ] }
  18. 18. Take control
  19. 19. A simple model (a bit more complete) *..* Hero Power 1..* Equipment Container Pistol 1..*
  20. 20. Persist (Hero named: ‘Star-lord’) addEquipment: (Container addItem: Pistol new; yourself); save.
  21. 21. Persist (1) { _id: OID(…), #version: …, #instanceOf: ‘Hero’, name: ‘Star-lord’, powers: [], equipment: [ { #instanceOf: ‘Container’, ‘items’, [ { #instanceOf: ‘Pistol’ } ] } ] }
  22. 22. Persist (2) { _id: OID(1), #version: …, #instanceOf: ‘Hero’, name: ‘Star-lord’, powers: [], equipment: [ { #collection: ‘Equipment’, __id: OID(2) } ] } ! { _id: OID(2), #version: …, #instanceOf: ‘Container’, items: [ { #collection: ‘Equipment’, __id: OID(3) } ] } ! { _id: OID(3), #version: …, #instanceOf: ‘Pistol’, }
  23. 23. Integrity is a consequence
  24. 24. Allowing missing content • We do not have foreign keys - So we cannot do things like “ON DELETE CASCADE” - Even delete validations are difficult ‣ Imagine “hero” has a “power”,and I remove the “power”. How can the hero notice it?
  25. 25. Persist mongoContainer <mongoContainer> ! ^ VOMongoContainer new collectionName: ‘powers’; enableMissingContent; yourself
  26. 26. Querying smart
  27. 27. Query (1) Hero selectMany: [ :each | … ] sortBy: { #name -> VOOrder ascending } asDictionary limit: 100 offset: 100
  28. 28. Query (2) Hero selectMany: { ‘name’ -> { ‘$regexp’ -> ‘^G.*’. ‘$options’ -> ‘i’ } asDictionary } asDictionary
  29. 29. Adapt schemes
  30. 30. The “scheme is not mine” problem • You can move meta-information to your program • Magritte-Voyage gives you a lot of power • You can extend/modify parts of the updating system too (like versioning)
  31. 31. Meta-information { _id: OID(…), #version: …, #instanceOf: ‘Hero’, name: ‘Star-lord’, powers: [], equipment: [ { #instanceOf: ‘Container’, ‘items’, [ { #instanceOf: ‘Pistol’ } ] } ] }
  32. 32. Meta-information { _id: OID(…), #version: …, #instanceOf: ‘Hero’, name: ‘Star-lord’, powers: [], equipment: [ { #instanceOf: ‘Container’, ‘items’, [ { #instanceOf: ‘Pistol’ } ] } ] }
  33. 33. Meta-information { _id: OID(…), name: ‘Star-lord’, powers: [], equipment: [ { ‘items’, [ {} ] } ] }
  34. 34. Voyage 2.0 • Root detection (enhance save & update) • Cyclic detection - Add strategy to persist cycles even without roots (It has some consequences (in querying, etc.), so it will be optional) • integrity validations - #removeWithDependencies • Materialisation customisations - #readRaw • Add backend: Riak
  35. 35. Use it today! Gofer it smalltalkhubUser: ‘Pharo’ project: ’MetaRepoForPharo30’; configurationOf: ‘VoyageMongo’; loadStable. Thanks!! Esteban Lorenzano - 2014

×