Helma Logo
main list history

Defining HopObject mappings programmatically

Helma svn trunk has a new global function called definePrototype that allows to define Hopobject database mappings from JavaScript:

A few notes/caveats:

A working mapping for Gobi looks like this:

 definePrototype("Page",{
    _db: "gobi",
    _table: "page",
    _id: "id",
    _name: "name",
    _parent: "parent, parent.version_history, parent.comment_pages, parent.embedded_pages",
    _prototype: "prototype",
    name: "name",
    body: "body",
    prototype: "prototype",
    weight: "weight",
    groupname: "groupname",
    formdata: "formdata",
    permissions: "permissions",
    attachments: "attachments",
    childtype: "childtype",
    collection: "collection",
    createtime: "createtime",
    modifytime: "modifytime",
    serialId: "serialId",
    parent: {
        object: "Page",
        local: "parent_id",
        foreign: "id" 
    },
    _children: {
        collection: "Page",
        accessname: "name",
        local: "id",
        foreign: "parent_id",
        filter: "collection = 'main'",
        order: "weight, createtime",
        cachemode: "aggressive" 
    },
    version_history: {
        collection: "Page",
        local: "id",
        foreign: "parent_id",
        filter: "collection = 'history'",
        order: "createtime" 
    },
    comment_pages: {
        collection: "Page",
        local: "id",
        foreign: "parent_id",
        filter: "collection = 'comment'",
        order: "createtime" 
    },
    embedded_pages: {
        collection: "Page",
        local: "id",
        foreign: "parent_id",
        filter: "collection = 'embedded'",
        order: "createtime" 
    },
    links_in: {
        collection: "Link",
        local: "id",
        foreign: "target_id",
        group: "type",
        "group.order": "id, createtime",
        order: "id, createtime",
        accessname: "sourceId",
        cachemode: "aggressive",
        loadmode: "aggressive" 
    },
    links_out: {
        collection: "Link",
        local: "id",
        foreign: "source_id",
        group: "type",
        "group.order": "id, createtime",
        order: "id, createtime",
        accessname: "targetId",
        cachemode: "aggressive",
        loadmode: "aggressive" 
    },
    form: {
        object: "Type",
        local: "form_id",
        foreign: "id" 
    },
    childform: {
        object: "Type",
        local: "childform_id",
        foreign: "id" 
    },
    creator: {
        object: "Page",
        local: "creator_id",
        foreign: "id" 
    },
    modifier: {
        object: "Page",
        local: "modifier_id",
        foreign: "id" 
    }
  });
  
  definePrototype("AdminPage", {
    _extends: "Page"
  });
  
  definePrototype("Type", {
    _extends: "AdminPage"
  });
  
  definePrototype("Link", {
    _db: "gobi",
    _table: "link",
    _id: "id",
    sourceId: "source_id",
    targetId: "target_id",
    createtime: "createtime",
    modifytime: "modifytime",
    type: "type",
    info: "info",
    serialId: "serial_id",
    source: {
        object: "Page",
        local: "source_id",
        foreign: "id" 
    },
    target: {
        object: "Page",
        local: "target_id",
        foreign: "id" 
    } 
  });

Links to this page: Helma 1.7 wishlist, Helma 1.7.0 Changelog, Helma 1.7.0 Released