| 1 | Helma svn trunk has a new global function called definePrototype that allows to define Hopobject database mappings from JavaScript: |
| 3 | A few notes/caveats: |
| 4 | |
| 5 | * You can call definePrototype() on existing prototypes, and you can update an existing prototype's mapping at runtime. |
| 6 | * Defining database mappings via properties files and JavaScript code is mutually exclusive. In other words, if you use definePrototype() on a prototype that also has one or more type.properties files, those properties files will be ignored. This is intentional. |
| 7 | |
| 8 | A working mapping for Gobi looks like this: |
| 9 | |
| 10 | definePrototype("Page", { |
| 11 | _db: "gobi", |
| 12 | _table: "page", |
| 13 | |
| 14 | _id: "id", |
| 15 | _name: "name", |
| 16 | _parent: "parent, parent.version_history, parent.comment_pages, parent.embedded_pages", |
| 17 | _prototype: "prototype", |
| 18 | |
| 19 | name: "name", |
| 20 | body: "body", |
| 21 | prototype: "prototype", |
| 22 | weight: "weight", |
| 23 | groupname: "groupname", |
| 24 | formdata: "formdata", |
| 25 | permissions: "permissions", |
| 26 | attachments: "attachments", |
| 27 | childtype: "childtype", |
| 28 | collection: "collection", |
| 29 | createtime: "createtime", |
| 30 | modifytime: "modifytime", |
| 31 | serialId: "serialId", |
| 32 | |
| 33 | parent: { |
| 34 | object: "Page", local: "parent_id", foreign: "id" |
| 35 | }, |
| 36 | |
| 37 | _children: { |
| 38 | collection: "Page", |
| 39 | accessname: "name", |
| 40 | local: "id", |
| 41 | foreign: "parent_id", |
| 42 | filter: "collection = 'main'", |
| 43 | order: "weight, createtime", |
| 44 | cachemode: "aggressive" |
| 45 | }, |
| 46 | |
| 47 | version_history: { |
| 48 | collection: "Page", local: "id", foreign: "parent_id", |
| 49 | filter: "collection = 'history'", |
| 50 | order: "createtime" |
| 51 | }, |
| 52 | |
| 53 | comment_pages: { |
| 54 | collection: "Page", local: "id", foreign: "parent_id", |
| 55 | filter: "collection = 'comment'", |
| 56 | order: "createtime" |
| 57 | }, |
| 58 | |
| 59 | embedded_pages: { |
| 60 | collection: "Page", local: "id", foreign: "parent_id", |
| 61 | filter: "collection = 'embedded'", |
| 62 | order: "createtime" |
| 63 | }, |
| 64 | |
| 65 | links_in: { |
| 66 | collection: "Link", local: "id", foreign: "target_id", |
| 67 | group: "type", |
| 68 | "group.order": "id, createtime", |
| 69 | order: "id, createtime", |
| 70 | accessname: "sourceId", |
| 71 | cachemode: "aggressive", |
| 72 | loadmode: "aggressive" |
| 73 | }, |
| 74 | |
| 75 | links_out: { |
| 76 | collection: "Link", local: "id", foreign: "source_id", |
| 77 | group: "type", |
| 78 | "group.order": "id, createtime", |
| 79 | order: "id, createtime", |
| 80 | accessname: "targetId", |
| 81 | cachemode: "aggressive", |
| 82 | loadmode: "aggressive" |
| 83 | }, |
| 84 | |
| 85 | form: { |
| 86 | object: "Type", local: "form_id", foreign: "id" |
| 87 | }, |
| 88 | |
| 89 | childform: { |
| 90 | object: "Type", local: "childform_id", foreign: "id" |
| 91 | }, |
| 92 | |
| 93 | creator: { |
| 94 | object: "Page", local: "creator_id", foreign: "id" |
| 95 | }, |
| 96 | |
| 97 | modifier: { |
| 98 | object: "Page", local: "modifier_id", foreign: "id" |
| 99 | } |
| 100 | }); |
| 101 | |
| 102 | definePrototype("AdminPage", { |
| 103 | _extends: "Page" |
| 104 | }); |
| 105 | |
| 106 | definePrototype("Type", { |
| 107 | _extends: "AdminPage" |
| 108 | }); |
| 109 | |
| 110 | definePrototype("Link", { |
| 111 | _db: "gobi", |
| 112 | _table: "link", |
| 113 | |
| 114 | _id: "id", |
| 115 | |
| 116 | sourceId: "source_id", |
| 117 | targetId: "target_id", |
| 118 | createtime: "createtime", |
| 119 | modifytime: "modifytime", |
| 120 | type: "type", |
| 121 | info: "info", |
| 122 | serialId: "serial_id", |
| 123 | |
| 124 | source: { |
| 125 | object: "Page", local: "source_id", foreign: "id" |
| 126 | }, |
| 127 | |
| 128 | target: { |
| 129 | object: "Page", local: "target_id", foreign: "id" |
| 130 | } |
| 131 | }); |