flack edited this page Dec 8, 2016 · 3 revisions

The Database Abstraction Layer (DBA) is a wrapper around MgdSchema objects which provides MidCOM functionality to Midgard objects. Internally, this is done by the midcom_core_dbaobject baseclass that acts as a decorator.

Another important part of this layer is midcom_core_querybuilder, which provides query access to the storage backend.

Main Features

DBA classes must extend midcom_core_dbaobject, which provides methods like new_query_builder() and integrations with ACL and other Services.

There are also a number of event handlers that are automatically triggered when a DBA object is updated, created or deleted. One of them is called before the operation, another one after it is completed. For deletion, they look like this:

public function _on_deleting()
   //your code here
   return $proceed //false cancels the operation, true causes it to proceed

public function _on_deleted()
   //your code here.

Apart from these methods, the more generic MidCOM Watches allow a component to react to changes done to other objects as well, for example a Midgard Replicator run can be triggered when an object is updated or deleted.


If you have a database table mytable consisting of two columns, mystring and myfloat, and a correctly defined Mgdschema file to go along, the DBA system will provide you with a PHP object with both columns as properties and all the standard methods, so code like this is possible:

//create a new entry in the database:
$object = new mytable_dba_class();
$object->mystring = "something";
$object->myfloat = 2.3456;

//retrieve entries from the db:
$qb = mytable_dba_class::new_query_builder();
$qb->add_constraint('myfloat', '>', 3);
$entries = $qb->execute();

Creating a Component with a Custom Object Schema

A small howto from the midgard-users forum:

  1. create component skeleton using for example the scaffold
  2. create mgdschema.xml
  3. symlink the .xml from MIDGARD_PREFIX/share/midgard/schema/ using the component name as filename.
  4. stop apache
  5. run midgard-schema database_name to get the SQL imported and then metadata etc columns added
  6. start apache
  7. in manifest.inc add
'class_mapping' => array(
    'org_routamc_positioning_location' => 'org_routamc_positioning_location_dba'
  1. in component root create myclass.php, below is a basic example based on the definition above:
class org_routamc_positioning_location_dba extends midcom_core_dbaobject
    public $__midcom_class_name__ = __CLASS__;
    public $__mgdschema_class_name__ = 'org_routamc_positioning_location';
  1. Call /midcom-cache-invalidate to reload the manifest and DBA classes cache.
  2. Create new topic to test your new component.






You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.