Mule with stored procedure

Post on 20-Jul-2015

197 views 1 download

Transcript of Mule with stored procedure

By Anirban Sen Chowdhary

Before we start let’s look what actually a stored procedure is.

Stored procedure :- A stored procedure which is also called proc, storp, sproc, StoPro,StoredProc, StoreProc, sp or SP is actually stored in the database data dictionary.

Source:- Wikipidea

The main advantages of Stored procedure are :-Maintainability

It is easier to maintain scripts containing stored procedureTesting

It can be tested independent of the applicationIsolation of Business Rules

Having Stored Procedures in one location means that business rules are separated from disparate code files in the application

Speed / OptimizationStored procedures can be cached on the serverExecution plans for the process are easily reviewable without having to run the application

SecurityIt limit direct access to tables via defined roles in the database and also provide an "interface" to the underlying data structure so that all implementation and even the data itself is shielded.

How are Stored procedure called :-Through CALL procedure(...) orEXECUTE procedure(...)

So, Do Mule Database component supports Stored procedure andhow can we run a Stored procedure from Mule Database component ????

Yes, Mule Database component supports executing Stored procedure

So let us create a Stored Procedure in our database:, I used SQL server in my case-

You can see the how our Stored procedure is created.Let our Stored procedure name be testStoredProccedure , and this Stored procedure will retrieve all the data from Database:-

Now we click execute button as below, our testStoredProccedure is created :-

So, our Mule flow will be following :-

This Mule flow will retrieve all the data from Database using the Stored procedure

Our Mule config will be following :-

You can see the database component is calling the Stored procedure testStoredProccedure

Now, lets hit the url http://localhost:8081 and test our application:-

If you now check the console you will find the Stored procedure is executed and data are retrieved from Database

That’s it … Now you can try this example by your own and can execute your Stored procedure ..

Hope you enjoyed this little trick …

Happy coding and share your knowledge everywhere