Helma Logo
main list history

Version 4 by simono on 02. April 2009, 12:25

12 definePrototype("Page", 
15  
20  
34  
36        object: "Page", local: "parent_id", foreign: "id"
37        local: "parent_id",
38        foreign: "id"
38  
46        cachemode: "aggressive" 
48  
50        collection: "Page", local: "id", foreign: "parent_id",
51        local: "id",
52        foreign: "parent_id",
52        order: "createtime" 
54  
56        collection: "Page", local: "id", foreign: "parent_id",
57        local: "id",
58        foreign: "parent_id",
58        order: "createtime" 
60  
62        collection: "Page", local: "id", foreign: "parent_id",
63        local: "id",
64        foreign: "parent_id",
64        order: "createtime" 
66  
68        collection: "Link", local: "id", foreign: "target_id",
69        local: "id",
70        foreign: "target_id",
74        loadmode: "aggressive" 
76  
78        collection: "Link", local: "id", foreign: "source_id",
79        local: "id",
80        foreign: "source_id",
84        loadmode: "aggressive" 
86  
88        object: "Type", local: "form_id", foreign: "id"
89        local: "form_id",
90        foreign: "id"
90  
92        object: "Type", local: "childform_id", foreign: "id"
93        local: "childform_id",
94        foreign: "id"
94  
96        object: "Page", local: "creator_id", foreign: "id"
97        local: "creator_id",
98        foreign: "id"
98  
100        object: "Page", local: "modifier_id", foreign: "id"
101        local: "modifier_id",
102        foreign: "id"
115  
117  
125  
127        object: "Page", local: "source_id", foreign: "id"
128        local: "source_id",
129        foreign: "id"
129  
131        object: "Page", local: "target_id", foreign: "id"
132        local: "target_id",
133        foreign: "id"
134    }

Version 3 by hannes on 02. April 2009, 12:01

7* Defining a new (previously not existing) prototype via definePrototype() from the code in another prototype directory (except Global) other than Global will likely throw an exception.

Version 2 by hannes on 02. April 2009, 11:59

7* Defining a new (previously not existing) prototype via definePrototype() from the code in another prototype directory (except Global) will likely throw an exception.
8* definePrototype() currently has very limited support for dependency tracking. If the type mapping refers to another prototype that hasn't been defined yet, that mapping will probably throw an exception or be borked. It is therefore advisable to define all prototypes in one place/file.

Version 1 by hannes on 02. April 2009, 11:55

1Helma svn trunk has a new global function called definePrototype that allows to define Hopobject database mappings from JavaScript:
3A 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
8A 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  });