Mule with stored procedure

14
By Anirban Sen Chowdhary

Transcript of Mule with stored procedure

Page 1: Mule with stored procedure

By Anirban Sen Chowdhary

Page 2: Mule with stored procedure

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

Page 3: Mule with stored procedure

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.

Page 4: Mule with stored procedure

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

Page 5: Mule with stored procedure

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

Page 6: Mule with stored procedure

Yes, Mule Database component supports executing Stored procedure

Page 7: Mule with stored procedure

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

Page 8: Mule with stored procedure

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:-

Page 9: Mule with stored procedure

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

Page 10: Mule with stored procedure

So, our Mule flow will be following :-

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

Page 11: Mule with stored procedure

Our Mule config will be following :-

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

Page 12: Mule with stored procedure

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

Page 13: Mule with stored procedure

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

Page 14: Mule with stored procedure