<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1691319531198109621</id><updated>2011-12-19T15:02:10.756-08:00</updated><title type='text'>Freedom Consulting Group</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://freedomconsultinggroup.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1691319531198109621/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://freedomconsultinggroup.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Freedom Consulting Group</name><uri>http://www.blogger.com/profile/00675483269860474751</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1691319531198109621.post-7417994823053999754</id><published>2010-05-02T19:50:00.000-07:00</published><updated>2010-05-02T19:52:27.849-07:00</updated><title type='text'>Grails and PL/SQL - how to integrate PL/SQL into Grails</title><content type='html'>My experience has been with data centric applications.  The business logic is typically stored in the database.&lt;br /&gt;&lt;br /&gt;Recently, I have been working with Grails, which is a great Java framework.  But as with most Java frameworks, its support of Oracle is mainly centered around Hibernate.  Hibernate definitely has advantages, but if you're trying to develop a robust Oracle/data centric application using PL/SQL to manage business logic, its not the best solution.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have been working at trying to create a plugin to allow developers to better integrate PL/SQL into Grails.  What I've come up with is to use Grails services to call PL/SQL procedures.  My approach is in its early stages, but I've found its pretty easy to call PL/SQL procedures and functions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first step is to create an 'Oracle' service.&lt;br /&gt;&lt;br /&gt;1) grails create-service Oracle&lt;br /&gt;&lt;br /&gt;This will create a default OracleService in the grails-app/services&lt;br /&gt;&lt;br /&gt;2) In your Oracle schema, add the following test function&lt;br /&gt;&lt;br /&gt;(This is just a test function)&lt;br /&gt;&lt;br /&gt;CREATE FUNCTION getUser&lt;br /&gt;&lt;br /&gt;RETURN VARCHAR2 AS&lt;br /&gt;&lt;br /&gt;v_retval VARCHAR2(255);&lt;br /&gt;&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;   select user into v_retval FROM DUAL;&lt;br /&gt;&lt;br /&gt;END;&lt;br /&gt;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;3) Modify the OracleService.groovy file to look like the following&lt;br /&gt;&lt;br /&gt;import groovy.sql.*&lt;br /&gt;&lt;br /&gt;class OracleService {&lt;br /&gt;&lt;br /&gt;    def dataSource // using the datasource we define in the spring's resources.xml  &lt;br /&gt;&lt;br /&gt;    boolean transactional = true&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    def serviceMethod() {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;    /*Example of Oracle function */&lt;br /&gt;&lt;br /&gt;    def getUser = {&lt;br /&gt;&lt;br /&gt;        def retval&lt;br /&gt;&lt;br /&gt;        Sql sql = new groovy.sql.Sql(dataSource)&lt;br /&gt;&lt;br /&gt;        sql.call("{? =call getUser()}",[Sql.VARCHAR])  { user -&amp;gt;  retval=user}&lt;br /&gt;&lt;br /&gt;        return retval&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;4) Add the following to whatever controller you want to call the Oracle function from&lt;br /&gt;&lt;br /&gt;class OracleController {&lt;br /&gt;&lt;br /&gt;  def oracleService&lt;br /&gt;&lt;br /&gt;  def getUser={&lt;br /&gt;&lt;br /&gt;         def mysid = oracleService.getUser()&lt;br /&gt;&lt;br /&gt;        println "SID="+mysid&lt;br /&gt;&lt;br /&gt;        render("")&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;5) Note there is no view in my example.. but you can test it as follows:&lt;br /&gt;&lt;br /&gt;http://localhost:8080/yourApp/oracle/getUser&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If it works you should see your Oracle login printed to the console&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Obviously this is just an example.  But it demonstrates how easy it is to integrate Oracle packages into a controller.  From here we can write our business logic, and easily call Oracle from our controllers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1691319531198109621-7417994823053999754?l=freedomconsultinggroup.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freedomconsultinggroup.blogspot.com/feeds/7417994823053999754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://freedomconsultinggroup.blogspot.com/2010/05/grails-and-plsql-how-to-integrate-plsql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1691319531198109621/posts/default/7417994823053999754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1691319531198109621/posts/default/7417994823053999754'/><link rel='alternate' type='text/html' href='http://freedomconsultinggroup.blogspot.com/2010/05/grails-and-plsql-how-to-integrate-plsql.html' title='Grails and PL/SQL - how to integrate PL/SQL into Grails'/><author><name>Freedom Consulting Group</name><uri>http://www.blogger.com/profile/00675483269860474751</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
