What is an OR/M?

Object relational mapping (OR/M) is a software layer that developers employ to fill the gap between object oriented programming and managing relational data. You see object-oriented programming and relational databases are two worlds that represent the same thing. Many experts from the past have predicted the rise of object oriented databases and that it will rule the world. Well, it’s 2010 now and relational database rules!

Relational database systems (RDBMS) are very good at handling large volumes of data. Even with the worst database design, searching and storing data in a relational database system is very efficient but that’s it. That unfortunately is the extent of it. Relational databases are good with data but business applications need that intelligence built into it in order for it to become an business-enabler. So what’s wrong with databases? Real-life objects are modeled differently in databases especially when foreign keys are introduced.

Allow me to give an example.  If I have a table called Parents and another called Children, to establish a relationship between the two tables, I would have to have a column, ParentID in the Children table. Surely kids don’t walk around with ParentID inscribed on their foreheads, well not yet at least. In an object-oriented world, real-life objects are modeled more closer.

public class Parent { }

public class Children {
public Parent parents;
}

By looking at the code we can say that Children has parents, which in real-life is exactly a true statement. Storing this relationship in a database violates some of the database rules because it potentially stores the same information, representing the same object, twice. Of course if Object-oriented database systems (OODBMS) were popular it would have worked out the relationship and would have efficiently stored the data. We have not even touched on inheritance and polymorphism.

OR/M tools manifested and evolved as a need to fill in the void between the object-oriented world and the relational database world. It is a mapping tool because it maps objects and tables. The tool sets available both commercially and open source is plenty. Although a recent stock take indicated that some of the open source projects have died (one reason why I’m not entirely sold on open source). Think of an OR/M as a translator that interprets object speak into relational speak and vice versa.

In closing, let’s side track for a moment and  draw an analogy using the ancient greek and modern english. In english we have the word LOVE. In ancient greek this can be translated into three possible words; EROS, AGAPE and PHILIA. There’s no direct translation from english, one has to read the context of the sentence and how the word LOVE is used.

A word of caution, beware of an OR/M that claims to be solve all.

Posted by jose on July 10th, 2010 under C# and .NET, Software Development • No Comments

Workshop: jQuery and Forms

In the context of a web application, Forms are a way for users to enter information and submit it to the server for validation and action. An example of a commonly used form in web sites and shopping carts is the customer registration. A user enters some personal details and then submits it to the server. The server checks if the username selected already exists and rejects the user action.

Client-side Validation
jQuery can perform basic client-side validation. This gives the added advantage of capturing errors as early as possible and does not require a trip to the server for validation. To perform a jQuery form validation, there are basically two options; (1) write your own pluggable validation code or (2) use one of the plugins available.

Many developers on the Internet comment that form validation should be made part of the jQuery UI core.

Here’s an example of a plugin called Bassistance.


$(document).ready(function() {
$("#form1").validate({
rules: {
username: "required",

email: {
required: true,
email: true
},

url: {
url: true
},

feedback: {
required: true
}
},
messages: {
comment: "Please enter a comment."
}
});
});

And the matching <form> code is as follows:


<form id="form1" method="post" action="">
<div class="form-row"><span class="label">Username *</span><input type="text" name="username" /></div>
<div class="form-row"><span class="label">Email *</span><input type="text" name="email" /></div>
<div class="form-row"><span class="label">URL</span><input type="text" name="url" /></div>
<div class="form-row"><span class="label">Feedback *</span><textarea name="feedback" ></textarea></div>
<div class="form-row"><input class="submit" type="submit" value="Submit"></div>
</form>

It’s a simple form that takes four inputs from the user. The validation rules are defined in jQuery and the plugin is called through the validate() method passing it data in an array. All the fields in the form have been marked as required hence when the user hits the submit button, the validation routine ensures that all fields are filled in before submitting the form to the server.

In just a few lines, we are able to validate a form.

Posted by jose on May 26th, 2010 under CSU:Workshops • No Comments

Workshop: jQuery and Plug-ins

The jQuery team had extensibility in mind when the Core of jQuery was put together. The jQuery team made sure that the essentials are included in the core, making it small and fast to load. One of jQuery’s feature is the ability to include plugins and even create one. The jQuery framework allows for such choices.

Creating a jQuery Plugin
It is standard practice in the jQuery community to store plugins in the following format:

jquery.<pluginname>.js

The next step is to write a shell with the following format:

(function($) {
// Shell plugin
})(jQuery);

All jQuery plugins will have to start from this shell. However, there’s no plugin code yet. To give jQuery an indication of what the plugin is going to be we first need to give it a name. The following format is the starting point of a jQuery plugin development.


(function($) {
$.fn.myNewPlugin = function() {
// plugin code goes here
};
})(jQuery);

The following is an example of using the plugin:

$(‘p’).myNewPlugin();

Posted by jose on May 20th, 2010 under CSU:Workshops • No Comments

 

Switch to our mobile site