Archive for March, 2012

Why MVC? Simply Explained

March 29, 2012

Disclaimer : I collected this from one support forum. Its not my original post.

MVC (Model – View – Controller) is one of those concepts that only starts to make sense when you’re dealing with larger applications and/or when working on the same application with several developers.

Compare it with tasks, if you’ve got 3 tasks that need to be done on a certain date, you won’t feel the need to have some kind of task organization, but if you have to deal with dozens of different tasks, with various due dates you’ll start using todo-lists. Then when you start working with a team of people and you need to prioritize and sequence tasks, you realize simple todo-lists won’t suffice and you’ll end up with applying SCRUM for instance (it obviously deals with more than task management, but it is one of the core parts of the methodology)

The same applies to MVC. It’s benefits are absolutely not restricted to large-scale, team-based development, but they become most obvious in such situations.

Let’s say you need to make a web application that loads some data in a xml file, lets the user do some operations on that data and saves the users edits in a SharedObject.
Fine. It’s a small application, you can develop it pretty fast and there’s no need to start thinking about using MVC or other patterns for structuring your components (not talking about UI components here, just cogs in the machine).
The application is a huge success and your client is extremely satisfied, they ask you to change the application because they’ll be setting up a back end with which the xml file can be manipulated by them, in fact no, they want to use a database instead of the file. And since it’s 2012 they definitely need an iphone app as well.
You’ll start working on the web application and since the deadline’s not just tight, but completely insane chances are you’ll be modifying it to reflect the use case changes, make a copy of the entire project to create the iphone app and again simply making the iOS required changes in that project directly.
Now repeat this five times. The client keeps on asking modifications. expansions etc. These can be UI related changes, but even complete backend architecture swaps, going from REST to SOAP for instance.
If you didn’t structure your project using MVC, you’ll be in a world of pain. No, you’ll be in a world of pain anyway, but had you used MVC from the start you’d notice that some things would’ve been less painful:

  • 95% of the code for the web application and the iphone app will be the same, but instead of saving the user data to a Shared Object or through a web service, you’d be using a local DB for instance. Due to the separation of concerns as promoted with MVC (and even more specifically with RL) you’d notice that the only thing different in the web app and the iphone app would’ve been a single service class. Without MVC chances are pretty high you’ll be making modifications in a bunch of classes.
  • The same applies to the UI for instance. Again, the heart of the application is the same, only the way it’s presented to the user is different. Due to separation of your app into the various tiers you’ll notice that changing the UI for the iphone app, will only have an impact on view classes and you’ll spent a tremendous amount of time less of searching through your code and finding out where to change what.
  • w/o MVC 95% of both apps would still be the same, but the differences would’ve been scattered in various files, here and there some lines, with MVC the differences will be in using different classes, ie the changes are more compact and overseeable.

All in all using MVC makes your code more structured and far more flexible to accomodate change in size, platform etc. etc.

Courtsey : creynders of Robotlegs Support

Getting Oracle Version Number

March 27, 2012

Ever wondered how to know the version number of the Oracle server you are connected to. You can very well use the v$session table.

Select * from v$session;

This will give you 4-5 rows showing all the version numbers of different tools used in the database. Happy Coding Guys. 🙂

Inserting / Updating NULL values in iBatis

March 1, 2012

Inserting or Updating nulls in iBatis should be done in a crewked way. One obvious fix is to put the isNotNull tag before the fields which can be null. But this will make the sqlmap file cumbersome or hard to read. For eg:, the below insert query will throw error, if you are trying to insert a null value for, say, infoId.

<insert id=”insertInformation” parameterClass=”Information”>
insert into info (Key, Name, InfoId)
values (#key#, #name#, #infoId#)

We can put isNotNull tage like this :

<insert id=”insertInformation” parameterClass=”Information”>
insert into info (Key, Name, InfoId)
values (#key#, #name#
<isNotNull property=”infoId”>
, #infoId#

Now doesn’t that became too much. So here comes the ultimate fix. You just need to put the Oracle datatype of the column separated by a colon in the statment like this :


The complete sql tag will become like this :

<insert id=”insertInformation” parameterClass=”Information”>
insert into info (Key, Name, InfoId)
values (#key#, #name#, #infoId:VARCHAR#)

Similarly the update statement also can be modified like this :

<update id=”updateInformation” parameterClass=”Information”>
update Info set
Key = #key#,
Name = #name#,
infoId = #infoId:VARCHAR#
id = #id#

%d bloggers like this: