<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Spikes Of Nothingness - cayenne tag</title>
  <link>http://weblog.flop.ca/tags/cayenne/</link>
  <description>Florin T.PATRASCU&#039;s blog</description>
  <language>en</language>
  <copyright>Florin T.PATRASCU</copyright>
  <lastBuildDate>Sat, 12 May 2012 02:12:08 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Cayenne ORM support for JPublish</title>
    <link>http://weblog.flop.ca/2007/10/12/1192245426029.html</link>
    
      
        <description>
          &lt;img src=&#034;http://objectstyle.com/images/cayenne-logo-small.gif&#034; alt=&#034;&#034; /&gt;&lt;strong&gt;We finally did it :)&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&#034;http://code.google.com/p/jpublish/&#034;&gt;JPublish&lt;/a&gt; applications can now use a very nice ORM support through the beautiful &lt;a href=&#034;http://cayenne.apache.org/&#034;&gt;Cayenne&lt;/a&gt; framework. I have to admit that initially I started to implement the Hibernate support but then I became more and more attracted by the vibrant community of Cayenne.&lt;br /&gt;
&lt;br /&gt;
The implementation is very simple, a JPublish module and a lot of help from Cayenne&#039;s user list and &lt;a href=&#034;http://click.sourceforge.net/&#034;&gt;Click&lt;/a&gt;&#039;s author generous support. Thank you all!&lt;br /&gt;
&lt;br /&gt;
To enable Cayenne in a JPublish application you will have to configure the JPCayenneModule in your JPublish application. This is very simple. Edit the jpublish.xml file and add:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&amp;lt;!--JPublish Cayenne support --&amp;gt;&lt;br /&gt;
&amp;lt;module classname=&amp;quot;org.jpublish.module.cayenne.JPCayenneModule&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cayenne-config-path&amp;gt;/WEB-INF/cayenne&amp;lt;/cayenne-config-path&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;auto-rollback&amp;gt;true&amp;lt;/auto-rollback&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;session-scope&amp;gt;false&amp;lt;/session-scope&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;shared-cache&amp;gt;true&amp;lt;/shared-cache&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~ Http request paths using a per-request or a per-session Cayenne ObjectContext (OC),&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~ the read-only paths will be interpreted first and will use a global OC one defined&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~ per web app instance.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~ --&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cayenne-enabled-urls&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url path=&amp;quot;/info/*&amp;quot; readonly=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url path=&amp;quot;/status/*&amp;quot; readonly=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url path=&amp;quot;/rss/*&amp;quot; readonly=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url path=&amp;quot;/users/*&amp;quot; readonly=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url path=&amp;quot;/companies/*&amp;quot;/&amp;gt; &amp;lt;!-- readonly=&amp;quot;false&amp;quot; by default, if not defined --&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cayenne-enabled-urls&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;debug&amp;gt;true&amp;lt;/debug&amp;gt;&lt;br /&gt;
&amp;lt;/module&amp;gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;font color=&#034;#666699&#034;&gt;(please verify that you have the JPCayenne.jar in your WEB-INF/lib folder. You can build it from our SVN or simply get it from our demo lib folder)&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
In the configuration above we demonstrate how one can enable ORM support for certain URLs. For example, any request for /rss/* will use a read-only Cayenne &lt;a href=&#034;http://cayenne.apache.org/doc20/api/cayenne/index.html&#034;&gt;DataContext&lt;/a&gt;, while the requests coming for /companies/* will use a per-thread DataContext. The Cayenne&#039;s DataContext life-cycle is handled in a before/after advice style, so you don&#039;t have to worry about the internals :)&lt;br /&gt;
&lt;br /&gt;
The Cayenne support is available in the JPublish context, Actions and Pages (Velocity, Freemarker or StringTemplate) being able to access the Cayenne service (JPCayenneModule.JPCAYENNE_SERVICE_NAME).&lt;br /&gt;
&lt;br /&gt;
So for example in our simple demo TODOs app, any Beanshell action can access the Cayenne service like this (excerpt from actions/GetUsers.bsh):&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt; jpCayenneService = context.get( JPCayenneModule.JPCAYENNE_SERVICE_NAME);&lt;br /&gt;
if( jpCayenneService!= null){&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;Expression qual = ExpressionFactory.likeIgnoreCaseExp(&amp;quot;name&amp;quot;, &amp;quot;%&amp;quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;SelectQuery select = new SelectQuery(User.class, qual);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; users = jpCayenneService.performQuery( select);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if( users != null)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.put( &amp;quot;users&amp;quot;, users);&lt;br /&gt;
}&lt;br /&gt;
&lt;/blockquote&gt; &lt;br /&gt;
You can find a very simple demo in our download section: &lt;a href=&#034;http://jpublish.googlecode.com/files/jpcayenne.war.zip&#034;&gt;jpcayenne.war&lt;/a&gt;, basically a simple TODO web application having the following model:&lt;br /&gt;
&lt;img alt=&#034;&#034; src=&#034;http://jpublish.googlecode.com/svn/trunk/modules/cayenne/models/todos_dev-ERD.png&#034; /&gt; &lt;br /&gt;
&lt;br /&gt;
This demo is just scratching the Cayenne framework and I did it in less than three hours, so please be indulgent :) For learning Cayenne I kindly recommend you to visit Cayenne&#039;s web site for updated documentation and more examples.&lt;br /&gt;
&lt;br /&gt;
I am now going to update our &lt;a href=&#034;http://code.google.com/p/jpublish/wiki/OrmSupport&#034;&gt;JPublish Wiki&lt;/a&gt; with more details about this implementation, so ... stay tuned and send us your feedback.&lt;br /&gt;
&lt;br /&gt;
Give it a try and let us know how it goes.&lt;br /&gt;
&lt;br /&gt;
Cheers,
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://weblog.flop.ca/2007/10/12/1192245426029.html#comments</comments>
    <guid isPermaLink="true">http://weblog.flop.ca/2007/10/12/1192245426029.html</guid>
    <pubDate>Sat, 13 Oct 2007 03:17:06 GMT</pubDate>
  </item>
  
  </channel>
</rss>

