I'm using Play framework 1.2.5 and I would like to optimize my SQL queries by creating stored procedures and using them but I don't know how to do.
To create the stored procedure via the Java code how should I do ? Also, should I do it in an @OnApplicationStart job so that I'm sure the procedures are created and stored when the application starts ?
After, how can I use my stored procedures ? Using which function ? How can I pass the parameters to my procedure ? How can I retrieve the result of my procedure ? (generally the result will be a SELECT query) And finally, is it possible to bind the result of my procedure to a model in the play framework ?
I have a lot of questions but I'm new to stored procedures with play framework and JPA and I would like to be sure I'm using them correctly
Thank you for your help
Take a look at evolutions (http://www.playframework.com/documentation/1.2.7/evolutions) for creating your stored procedures.
I don't know how you should create them. Perhaps the OnApplicationStart method is what you need. In my environment the procedures are already in place. We just use Play to invoke them. To invoke stored procedures, you should take a look at the
Work
interface. By implementing this you can execute statements in the database.We've created a basic OracleProcedure class:
For each specific stored procedure you can extend this class and pass the name and parameters to the constructor via
super()
:In your code you can then call it like this:
If you need to call a procedure and retrieve a return value you can use a
CallableStatement
in theexecute()
method: