Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

EWD 3 Training Course Part 20: The DocumentNode Object

530 views

Published on

This presentation is Part 20 of the EWD 3 Training Course. It begins an in-depth examination of EWD 3's JavaScript abstraction of Global Storage, starting with the underlying concept, and then examining the core part of the abstraction: the DocumentNode Object.

Published in: Software

EWD 3 Training Course Part 20: The DocumentNode Object

  1. 1. Copyright © 2016 M/Gateway Developments Ltd EWD 3 Training Course Part 20 JavaScript Abstraction of Global Storage: (a) The DocumentNode Object Rob Tweed Director, M/Gateway Developments Ltd Twitter: @rtweed
  2. 2. Copyright © 2016 M/Gateway Developments Ltd Underlying Concept
  3. 3. Copyright © 2016 M/Gateway Developments Ltd myGlobal("a")=123 myGlobal("b","c1")="foo" myGlobal("b","c2")="foo2" myGlobal("d","e1","f1")="bar1" myGlobal("d","e1","f2")="bar2" myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" myGlobal "a" 123 "b" "c2" "foo2" "d" "c1" "foo" "e2" "e1" "f2" "bar2" "f1" "bar1" "f2" "bar2" "f1" "bar1" "f3" "bar3" Hierarchical diagram representing a Global
  4. 4. Copyright © 2016 M/Gateway Developments Ltd myGlobal = { a: 123, b: { c1: 'foo', c2: 'foo2' } d: { e1: { f1: 'bar1', f2: 'bar2' }, e2: { f1: 'bar1', f2: 'bar2', f3: 'bar3' } } } myGlobal("a")=123 myGlobal("b","c1")="foo" myGlobal("b","c2")="foo2" myGlobal("d","e1","f1")="bar1" myGlobal("d","e1","f2")="bar2" myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" One to one correspondence between any tree of Global nodes and a Javascript object
  5. 5. Copyright © 2016 M/Gateway Developments Ltd myGlobal = { a: 123, b: { c1: 'foo', c2: 'foo2' } d: { e1: { f1: 'bar1', f2: 'bar2' }, e2: { f1: 'bar1', f2: 'bar2', f3: 'bar3' } } } myGlobal("a")=123 myGlobal("b","c1")="foo" myGlobal("b","c2")="foo2" myGlobal("d","e1","f1")="bar1" myGlobal("d","e1","f2")="bar2" myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" Subscript <=> Property
  6. 6. Copyright © 2016 M/Gateway Developments Ltd myGlobal("d","e2","f3") <=> myGlobal.d.e2.f3 Global Node JavaScript Object
  7. 7. Copyright © 2016 M/Gateway Developments Ltd myGlobal("d","e2","f3") <=> myGlobal.d.e2.f3 Global Node JavaScript Object But… JavaScript Objects are in memory Global Nodes are persistent, on disk
  8. 8. Copyright © 2016 M/Gateway Developments Ltd myGlobal("d","e2","f3") <=> myGlobal.d.e2.f3 Global Node JavaScript Object Could we abstract Global Nodes as Persistent JavaScript Objects?
  9. 9. Copyright © 2016 M/Gateway Developments Ltd ewd-document-store - JavaScript Abstraction of Global Storage https://github.com/robtweed/ewd-document-store Layered on top of the basic cache.node APIs
  10. 10. Copyright © 2016 M/Gateway Developments Ltd ewd-document-store - JavaScript Abstraction of Global Storage https://github.com/robtweed/ewd-document-store Layered on top of the basic cache.node APIs Loaded automatically into QEWD workers
  11. 11. Copyright © 2016 M/Gateway Developments Ltd ewd-document-store - JavaScript Abstraction of Global Storage https://github.com/robtweed/ewd-document-store Layered on top of the basic cache.node APIs Loaded automatically into QEWD workers Made accessible in QEWD by this.documentStore
  12. 12. Copyright © 2016 M/Gateway Developments Ltd ewd-document-store - JavaScript Abstraction of Global Storage https://github.com/robtweed/ewd-document-store Layered on top of the basic cache.node APIs Loaded automatically into QEWD workers Made accessible in QEWD by this.documentStore Can also be used standalone for testing and debugging
  13. 13. Copyright © 2016 M/Gateway Developments Ltd ewd-document-store - JavaScript Abstraction of Global Storage Use in a test harness: See example in: https://github.com/robtweed/ewd-document-store/blob/master/lib/tests/CacheStandalone.js
  14. 14. Copyright © 2016 M/Gateway Developments Ltd Edit CacheStandalone.js var DocumentStore = require('ewd-document-store'); var interface = require('cache'); var db = new interface.Cache(); console.log('db: ' + JSON.stringify(db)); // Change these parameters to match your GlobalsDB or Cache system: var ok = db.open({ path: '/opt/cache/mgr', username: '_SYSTEM', password: 'SYS', namespace: 'USER' }); console.log('ok: ' + JSON.stringify(ok)); var documentStore = new DocumentStore(db); console.log(db.version()); var rob = new documentStore.DocumentNode('rob');
  15. 15. Copyright © 2016 M/Gateway Developments Ltd Edit CacheStandalone.js var DocumentStore = require('ewd-document-store'); var interface = require('cache'); var db = new interface.Cache(); console.log('db: ' + JSON.stringify(db)); // Change these parameters to match your GlobalsDB or Cache system: var ok = db.open({ path: 'C:InterSystemsCache2015-2mgr', username: '_SYSTEM', password: 'SYS', namespace: 'USER' }); console.log('ok: ' + JSON.stringify(ok)); var documentStore = new DocumentStore(db); console.log(db.version()); var rob = new documentStore.DocumentNode('rob');
  16. 16. Copyright © 2016 M/Gateway Developments Ltd Save as C:qewddocStoreTest.js var DocumentStore = require('ewd-document-store'); var interface = require('cache'); var db = new interface.Cache(); console.log('db: ' + JSON.stringify(db)); // Change these parameters to match your GlobalsDB or Cache system: var ok = db.open({ path: 'C:InterSystemsCache2015-2mgr', username: '_SYSTEM', password: 'SYS', namespace: 'USER' }); console.log('ok: ' + JSON.stringify(ok)); var documentStore = new DocumentStore(db); console.log(db.version()); var rob = new documentStore.DocumentNode('rob');
  17. 17. Copyright © 2016 M/Gateway Developments Ltd Version for use with GT.M var DocumentStore = require('ewd-document-store'); var interface = require('nodem'); var db = new interface.Gtm(); console.log('db: ' + JSON.stringify(db)); var ok = db.open(); console.log('ok: ' + JSON.stringify(ok)); var documentStore = new DocumentStore(db); console.log(db.version()); var rob = new documentStore.DocumentNode('rob');
  18. 18. Copyright © 2016 M/Gateway Developments Ltd Version for use with ewd-redis-globals var DocumentStore = require('ewd-document-store'); var interface = require('ewd-redis-globals'); var db = new interface(); console.log('db: ' + JSON.stringify(db)); var ok = db.open(); console.log('ok: ' + JSON.stringify(ok)); var documentStore = new DocumentStore(db); console.log(db.version()); var rob = new documentStore.DocumentNode('rob');
  19. 19. Copyright © 2016 M/Gateway Developments Ltd Run it cd qewd (or cd /qewd ) node docStoreTest
  20. 20. Copyright © 2016 M/Gateway Developments Ltd Run it cd ewd3 node docStoreTest It runs a set of examples using DocumentNode objects You can use it as the basis of your own test harness
  21. 21. Copyright © 2016 M/Gateway Developments Ltd Adapting your own test harness var DocumentStore = require('ewd-document-store'); var interface = require('cache'); var db = new interface.Cache(); var ok = db.open({ path: 'C:InterSystemsCache2015-2mgr', username: '_SYSTEM', password: 'SYS', namespace: 'USER' }); var documentStore = new DocumentStore(db); // delete and replace everything from this point onwards // documentStore provides you with the abstracted interface to your database // use this to try out the following examples for yourself // simply replace this.documentStore with documentStore
  22. 22. Copyright © 2016 M/Gateway Developments Ltd The DocumentNode Object
  23. 23. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new documentStore.DocumentNode(name, subscripts); when using standalone test harness
  24. 24. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode(name, subscripts); when using QEWD
  25. 25. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode(name, subscripts); Represents a node within a document store hierarchy May or may not physically exist at this point ie this does NOT create a node
  26. 26. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode(name, subscripts); Represents a node within a document's hierarchy May or may not physically exist at this point ie this does NOT create a node Creates an instance of an object that represents that node, with a set of methods and properties to manipulate and access that node
  27. 27. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); represents myDoc("d","e2")
  28. 28. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); represents myDoc("d","e2") create: dnode.value = 'foo2';
  29. 29. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); represents myDoc("d","e2") create: dnode.value = 'foo2'; get: var x = dnode.value;
  30. 30. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); represents myDoc("d","e2") create: dnode.value = 'foo2'; get: var x = dnode.value; value is a read/write property
  31. 31. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); represents myDoc("d","e2") create: dnode.value = 'foo2'; get: var x = dnode.value; delete: dnode.delete();
  32. 32. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); represents myDoc("d","e2") create: dnode.value = 'foo2'; get: var x = dnode.value; delete: dnode.delete(); Note: delete will also delete any lower-level DocumentNodes in the underlying Global Storage tree
  33. 33. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); represents myDoc("d","e2") create: dnode.value = 'foo2'; get: var x = dnode.value; delete: dnode.delete(); exists?: var exists = dnode.exists; // true | false
  34. 34. Copyright © 2016 M/Gateway Developments Ltd myDoc("a")=123 myDoc("b","c1")="foo" myDoc("b","c2")="foo2" myDoc("d","e1","f1")="bar1" myDoc("d","e1","f2")="bar2" myDoc("d","e2","f1")="bar1" myDoc("d","e2","f2")="bar2" myDoc("d","e2","f3")="bar3" var dnode = new this.documentStore.DocumentNode('myDoc', ['d']);
  35. 35. Copyright © 2016 M/Gateway Developments Ltd var dnode = new this.documentStore.DocumentNode('myDoc', ['d']); dnode.hasChildren // true dnode.hasValue // false dnode.exists // true myDoc("a")=123 myDoc("b","c1")="foo" myDoc("b","c2")="foo2" myDoc("d","e1","f1")="bar1" myDoc("d","e1","f2")="bar2" myDoc("d","e2","f1")="bar1" myDoc("d","e2","f2")="bar2" myDoc("d","e2","f3")="bar3"
  36. 36. Copyright © 2016 M/Gateway Developments Ltd var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); dnode.hasChildren // true dnode.hasValue // false dnode.exists // true myDoc("a")=123 myDoc("b","c1")="foo" myDoc("b","c2")="foo2" myDoc("d","e1","f1")="bar1" myDoc("d","e1","f2")="bar2" myDoc("d","e2","f1")="bar1" myDoc("d","e2","f2")="bar2" myDoc("d","e2","f3")="bar3"
  37. 37. Copyright © 2016 M/Gateway Developments Ltd var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2', 'f3']); dnode.hasChildren // false dnode.hasValue // true dnode.exists // true myDoc("a")=123 myDoc("b","c1")="foo" myDoc("b","c2")="foo2" myDoc("d","e1","f1")="bar1" myDoc("d","e1","f2")="bar2" myDoc("d","e2","f1")="bar1" myDoc("d","e2","f2")="bar2" myDoc("d","e2","f3")="bar3"
  38. 38. Copyright © 2016 M/Gateway Developments Ltd var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2', 'f4']); dnode.hasChildren // false dnode.hasValue // false dnode.exists // false Even though the node doesn’t physically exist, you can define a DocumentNode Object for it myDoc("a")=123 myDoc("b","c1")="foo" myDoc("b","c2")="foo2" myDoc("d","e1","f1")="bar1" myDoc("d","e1","f2")="bar2" myDoc("d","e2","f1")="bar1" myDoc("d","e2","f2")="bar2" myDoc("d","e2","f3")="bar3"
  39. 39. Copyright © 2016 M/Gateway Developments Ltd var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2', 'f3']); dnode.name // f3 Node Name === last global subscript dnode.parent // myDoc("d","e2") myDoc("a")=123 myDoc("b","c1")="foo" myDoc("b","c2")="foo2" myDoc("d","e1","f1")="bar1" myDoc("d","e1","f2")="bar2" myDoc("d","e2","f1")="bar1" myDoc("d","e2","f2")="bar2" myDoc("d","e2","f3")="bar3" Returns a DocumentNode Object
  40. 40. Copyright © 2016 M/Gateway Developments Ltd var dnode = new this.documentStore.DocumentNode('myDoc', ['d', 'e2']); dnode.firstChild // myDoc("d","e2","f1") dnode.lastChild // myDoc("d","e2","f3") dnode.previousSibling // myDoc("d","e1") dnode.nextSibling // undefined myDoc("a")=123 myDoc("b","c1")="foo" myDoc("b","c2")="foo2" myDoc("d","e1","f1")="bar1" myDoc("d","e1","f2")="bar2" myDoc("d","e2","f1")="bar1" myDoc("d","e2","f2")="bar2" myDoc("d","e2","f3")="bar3" DocumentNode Objects
  41. 41. Copyright © 2016 M/Gateway Developments Ltd DocumentNode Object • We’ll further explore it in subsequent parts of this course • For more / additional information: – http://gradvs1.mgateway.com/download/ewd-document-store.pdf

×