Mura ORM

Introduction

Most software applications have to interact with relational databases, such as MySQL, Microsoft SQL Server, and Oracle, to name a few. Many developers have struggled with the complexities of mapping their relational databases to objects. Mura CMS has a custom Object Relational Mapping (ORM) framework to enable developers the ability to define mappings between their object model and the relational database.

Using Mura ORM allows you to access and modify objects quickly and easily, without having to write tons of custom DAOs, relying on class extensions, and maintaining several database-vendor-specific CRUD statements, and more.

If you're familiar with ColdFusion-based Hibernate ORM, then you will be able to jump in rather quickly. If not, then you may want to brush up on at least the basics of CF-ORM. Sam Farmer wrote a nice "Intro to ORM" article with some hands on exercises on the LearnCFInAWeek.com site at www.learncfinaweek.com/week1/Intro_to_ORM/. In addition, Mark Mandel wrote a great article for Adobe at www.adobe.com/devnet/coldfusion/articles/coldfusion9_orm.html.  Finally, there's an excellent book by John Whish available at www.coldfusionormbook.com for those who would like to learn more.

Why Mura ORM?

The CFML-based ORM is great for defining entity properties, CRUD operations, and managing relationships with other ORM entities. However, it's not so good for creating relationships to Mura's core entities or working with DI/1. For example, relationships can't be based on DI/1 BeanName or Alias, because it must be the component path. Not to mention having to deal with sharing hibernate sessions with other applications and/or plugins. Plus, when things go wrong in CFML-based ORM, it's not always easy to troubleshoot.

Basics

Mura ORM entities are accessible via:

$.getBean('entityName');
application.serviceFactory('entityName');

Mura ORM takes avantage of DI/1 dependency injection, and has familiar interactions:

entity.loadBy();
entity.get{relatedEntity}Iterator();
entity.get{relatedEntity}Query();
entity.get{relatedEntity}();
entity.getFeed();
entity.validate();
entity.getError();
entityFeed.addParam();
entityFeed.getQuery();
entityFeed.getIterator();

Other familiar interactions with Mura's objects/beans:

feed = $.getBean('entityName').getFeed();
feed.addParam(column='myColumn', criteria='test');
it = feed.getIterator();
while ( it.hasNext() ) {
  obj = it.next();
  WriteOutput(obj.getMyColumn());
}

Target via Mura Events:

onBeforeMyEntitySave($) {
  var bean = $.event('bean');
  ...
}

They also:

  • Know how to bundle themselves
  • Play well with Mura content versioning
  • Have a very similar implmentation as CFML's ORM

Component (CFC) Attributes

entityName
table
datasource
discriminatorColumn
discriminatorValue
orderby
readonly
// Mura-specific attributes
bundleable
cacheName
dbtype
manageSchema
useTrash

Property Attributes

name
persistent
fieldtype
cfc
fkcolumn
type
cascade
singularName
orderby
lenth
default
ormtype
// Mura-specific attributes
loadkey
dataType
nullable
required
validate
message
regex
comparable

Validation Attributes

minValue
maxValue
minLength
maxLength
minCollection
maxCollection
minList
maxList
inList
method
lte
lt
gte
gt
eq
neq

Support for CFML ORM Events

preLoad();
postLoad();
preUpdate();
postUpdate();
preCreate();
postCreate();
postInsert();
preDelete();
postDelete();