Helma Logo
main list history
previous version  overview  next version

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

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

A few notes/caveats:

* You can call definePrototype() on existing prototypes, and you can update an existing prototype's mapping at runtime.
* 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.
* 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.
* 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.

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"
    }
  });

     removed
     added