<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Jgoday&#039;s Blog</title>
	<atom:link href="http://jgoday.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jgoday.wordpress.com</link>
	<description>some code stories</description>
	<lastBuildDate>Mon, 07 Nov 2011 18:18:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jgoday.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Jgoday&#039;s Blog</title>
		<link>http://jgoday.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jgoday.wordpress.com/osd.xml" title="Jgoday&#039;s Blog" />
	<atom:link rel='hub' href='http://jgoday.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Scala android and actors</title>
		<link>http://jgoday.wordpress.com/2011/07/07/scala-android-and-actors/</link>
		<comments>http://jgoday.wordpress.com/2011/07/07/scala-android-and-actors/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 18:47:43 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[android]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=214</guid>
		<description><![CDATA[Scala expressiveness strikes back ! &#160; A sample showing iteration between scala actors and android.Activity Extending activity with a trait  to receive events from another actors, services, or any other source ( listeners , as a observer … ) class MainActivity extends Activity with ActivityUtil with Reactive { override def onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) setContentView(R.layout.main) <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=214&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Scala expressiveness strikes back !</strong></p>
<p>&nbsp;</p>
<p>A sample showing iteration between scala actors and <em>android.Activity</em></p>
<p>Extending activity with a trait  to receive events from another actors, services, or any other source ( listeners , as a observer … )</p>
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;color:#000;font-family:'Liberation Mono';padding:5px;">
<pre><code>
class MainActivity extends Activity
                      with ActivityUtil
                      with Reactive { 

    override def onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState) 

        setContentView(R.layout.main) 

        button(R.id.Button01).onClicked {
            app.actor ! Ping(this)
        }
    } 

    onReact {
        case Pong(count) =&gt; onUi {
            textView(R.id.Label1).setText("Pong -&gt; " + count)
        }
    }
} 

</code></pre>
</div>
<p style="text-align:center;"><strong>Isn&#8217;t she pretty ?</strong></p>
<p>&nbsp;</p>
<ol>
<li><strong>ActivityUtil</strong>
<ul>
<li>Allow us to access activity components directly</p>
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;color:#000;padding:5px;">
<pre><code>
button(R.id.Button01)</code></pre>
</div>
</li>
</ul>
</li>
<li><strong>Reactive</strong>
<ul>
<li>Converts the activity into a scala actor</li>
<li>Calling onReact with the desired partialFunctions, allow us to manage the external events
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;color:#000;padding:5px;">
<pre><code>
onReact {
    case Pong(count) =&gt; onUi {
        textView(R.id.Label1).setText("Pong -&gt; " + count)
    }
} </code></pre>
</div>
<p>One problem, onReact resides inside another thread ( the actor one ), so to access components of the view, we must use <em>onUi</em> function
</li>
</ul>
</li>
<li><strong>ViewConversions</strong>
<ul>
<li>With a bunch of implicit conversions, we can implement Listeners directly with functions</p>
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;color:#000;padding:5px;">
<pre><code>
button(R.id.Button01).onClicked {
    app.actor ! Ping(this)
} </code></pre>
</div>
</li>
</ul>
</li>
<li>The application class contains the other actor who returns Pong
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;color:#000;padding:5px;">
<pre><code>

class App extends Application {
    val actor = new SampleActor 

    override def onCreate(): Unit = {
        actor.start
    }
} 

case class Pong(count: Int)
case class Ping(a: Actor) 

class SampleActor extends Actor with L {
    private var count = 0
    def act() {
        loop {
            receive {
                case Ping(a) =&gt; {
                    count = count + 1
                    a ! Pong(count)
                }
            }
        }
    }
}
</code></pre>
</div>
</li>
</ol>
<p style="text-align:center;"><strong><br />
I just remembered why I love scala so much <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></p>
<p>&nbsp;</p>
<p>PD: I used giter8 to get a scala-android template</p>
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;color:#000;padding:5px;">
<pre><code> g8 gseitz/android-sbt-project </code></pre>
</div>
<p>&nbsp;</p>
<ul>
<li><strong>giter8</strong>  <a title="https://github.com/n8han/giter8" href="https://github.com/n8han/giter8">https://github.com/n8han/giter8</a></li>
<li><strong>template home</strong> <a title="https://github.com/gseitz/android-sbt-project.g8" href="https://github.com/gseitz/android-sbt-project.g8">https://github.com/gseitz/android-sbt-project.g8</a></li>
<li><strong>scala-home</strong> <a title="http://www.scala-lang.org/" href="http://www.scala-lang.org/">http://www.scala-lang.org/</a></li>
<li><strong>sample-code</strong> <a title="https://github.com/jgoday/sample_android_scala_actor" href="https://github.com/jgoday/sample_android_scala_actor">https://github.com/jgoday/sample_android_scala_actor</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/214/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=214&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2011/07/07/scala-android-and-actors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>42.441540 -8.863144</georss:point>
		<geo:lat>42.441540</geo:lat>
		<geo:long>-8.863144</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>
	</item>
		<item>
		<title>Gnome shell extension wallpaper</title>
		<link>http://jgoday.wordpress.com/2011/06/18/gnome-shell-extension-wallpaper/</link>
		<comments>http://jgoday.wordpress.com/2011/06/18/gnome-shell-extension-wallpaper/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 18:47:42 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[gnome]]></category>
		<category><![CDATA[gnome gnome-shell]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=195</guid>
		<description><![CDATA[Simple gnome-shell extension to change the wallpaper from the overview. Get it from : github source sample snapshot To change where to search wallpapers edit src/extension.js and set const DIRECTORIES = [ "/usr/share/backgrounds", GLib.get_home_dir() + "/Pictures", "another_directory" ]; with the image directories that you want. By default it searchs in /usr/share/backgrounds AND $HOME/Pictures<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=195&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Simple gnome-shell extension to change the wallpaper from the overview.</p>
</p>
<p>Get it from : </p>
<ul>
<li>
<a href="https://github.com/jgoday/gnome-shell-extension-wallpapers">github source</a>
</li>
<li>
<a href="https://github.com/jgoday/gnome-shell-extension-wallpapers/raw/master/snapshot.png" title="sample snapshot">sample snapshot</a>
      </li>
</ul>
<p>To change where to search wallpapers edit <strong>src/extension.js</strong> and set<br />
<code>
<pre>
const DIRECTORIES = [
       "/usr/share/backgrounds",
       GLib.get_home_dir() + "/Pictures",
       "another_directory"
];
</pre>
<p></code><br />
with the image directories that you want.</p>
<p>
By default it searchs in <em>/usr/share/backgrounds</em> AND <em>$HOME/Pictures</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=195&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2011/06/18/gnome-shell-extension-wallpaper/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>
	</item>
		<item>
		<title>Kate plugin experiment</title>
		<link>http://jgoday.wordpress.com/2010/10/07/kate-plugin-experiment/</link>
		<comments>http://jgoday.wordpress.com/2010/10/07/kate-plugin-experiment/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 19:34:37 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[kde4]]></category>
		<category><![CDATA[qt4]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=184</guid>
		<description><![CDATA[Just a nasty experiment, a kate plugin to open and visualize open files. Open a new file (win + O) View open files (win + B) i haven&#8217;t had much time to refactor code so &#8230; http://github.com/jgoday/newkateplugin<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=184&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just a nasty experiment,</p>
<p>a kate plugin to open and visualize open files.</p>
<ul>
<li> <b>Open a new file (win + O)</b><br />
<a href="http://jgoday.files.wordpress.com/2010/10/snapshot22.png"><img src="http://jgoday.files.wordpress.com/2010/10/snapshot22.png?w=300&#038;h=221" alt="" title="Open new file" width="300" height="221" class=" wp-image-186" style="display:block;" /></a><br />

  </li>
<li><b>View open files (win + B)</b><br />
<a href="http://jgoday.files.wordpress.com/2010/10/snapshot23.png"><img src="http://jgoday.files.wordpress.com/2010/10/snapshot23.png?w=300&#038;h=221" alt="" title="Browe open files " width="300" height="221" class=" wp-image-187" style="display:block;" /></a><br />

   </li>
</ul>
<div>
i haven&#8217;t had much time to refactor code so &#8230;<br />
<a href="http://github.com/jgoday/newkateplugin">http://github.com/jgoday/newkateplugin</a>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=184&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2010/10/07/kate-plugin-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>

		<media:content url="http://jgoday.files.wordpress.com/2010/10/snapshot22.png?w=300" medium="image">
			<media:title type="html">Open new file</media:title>
		</media:content>

		<media:content url="http://jgoday.files.wordpress.com/2010/10/snapshot23.png?w=300" medium="image">
			<media:title type="html">Browe open files </media:title>
		</media:content>
	</item>
		<item>
		<title>Sample OpenOffice 3 extension with scala 2.8 and sbt</title>
		<link>http://jgoday.wordpress.com/2010/08/30/sample-openoffice-3-extension-with-scala-2-8-and-sbt/</link>
		<comments>http://jgoday.wordpress.com/2010/08/30/sample-openoffice-3-extension-with-scala-2-8-and-sbt/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 19:47:18 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[openoffice]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=169</guid>
		<description><![CDATA[Sample OpenOffice 3 extension with scala and sbt Here&#8217;s a small sample of a openoffice 3 extension using scala and sbt Project link: sample scala addon Openoffice devel documentation: DevGuide and sdk samples : folder examples/ on openoffice sdk (usually located in /usr/lib/openoffice-dev) I just ported ProtocolHandlerAddon_java to scala and sbt under examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java using sbt, <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=169&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Sample OpenOffice 3 extension with scala and sbt</h2>
<ul>
<li>
    Here&#8217;s a small sample of a openoffice 3 extension using scala and sbt
</li>
<li>
   <b>Project link</b>: <a href="http://github.com/jgoday/sample_scala_ooaddon">sample scala addon</a>
</li>
<li>
Openoffice devel documentation: <a href="http://wiki.services.openoffice.org/wiki/Documentation/DevGuide">DevGuide</a> and sdk samples :</p>
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;padding:5px;">
    folder examples/ on openoffice sdk (usually located in /usr/lib/openoffice-dev)
    </div>
</li>
<li>
    I just ported ProtocolHandlerAddon_java to scala and sbt</p>
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;padding:5px;">
        under examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java
    </div>
</li>
<li>
    using <b>sbt</b>,<br />
    a little task (create_extension) will help to create the oxt file (with the .xcu files, scala-library jar, manifest &#8230;)</p>
<div style="border:1px solid #444;background-color:#f2f2f2;font-size:small;margin-bottom:5px;box-shadow:.3px .3px 7px #505050;-moz-box-shadow:.3px .3px 4px #505050;padding:5px;">
<pre>
$&gt; sbt
   :&gt; update
   :&gt; compile
   :&gt; package
   :&gt; create_extension
</pre>
</p></div>
</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/169/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=169&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2010/08/30/sample-openoffice-3-extension-with-scala-2-8-and-sbt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>
	</item>
		<item>
		<title>Fun with liftweb and jquery dialogs</title>
		<link>http://jgoday.wordpress.com/2010/03/18/fun-with-liftweb-and-jquery-dialogs/</link>
		<comments>http://jgoday.wordpress.com/2010/03/18/fun-with-liftweb-and-jquery-dialogs/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 13:18:38 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[lift]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=160</guid>
		<description><![CDATA[Here&#8217;s a sample of jquery-ui (version 1.8) dialogs in lift, the code (a little ugly) can be found here : http://github.com/jgoday/liftweb-jquery-dialogs-sample The sample has two main classes 1: JQueryDialog Allow create generic dialogs from templates or with explicit content We can create a dialog like this : new JQueryDialog(&#60;div&#62;Dialog content&#60;/div&#62;) { override def elementId = <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=160&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a sample of jquery-ui (version 1.8) dialogs in lift,<br />
the code (a little ugly) can be found here : <a href="http://github.com/jgoday/liftweb-jquery-dialogs-sample">http://github.com/jgoday/liftweb-jquery-dialogs-sample</a></p>
<p>The sample has two main classes</p>
<ul>
<li>
        1: JQueryDialog</p>
<p>Allow create generic dialogs from templates or with explicit content<br />
We can create a dialog like this :</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
new JQueryDialog(&lt;div&gt;Dialog content&lt;/div&gt;) {
    override def elementId = "dialog_id"
    override def options = "modal:true" ::
                           "title:'dialog title!'" ::
                           "open: function (event, ui) {alert('dialog is opening!');}" ::
                            super.options
}
</code>
</pre>
</div>
</li>
<li>
        2: FormDialog<br />
To create generic dialogs from templates and with default actions (close)</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
val item = new Item
def _template: NodeSeq = bind("item",
            TemplateFinder.findAnyTemplate("templates-hidden/item" :: Nil) openOr
                                           &lt;div&gt;{"Cannot find template"}&lt;/div&gt;,
            "name" -&gt; item.name.toForm)

val dialog = new FormDialog(true) {
    override def getFormContent = _template
    override def confirmDialog: NodeSeq = SHtml.ajaxSubmit("save",
            () =&gt; {println(item);this.closeCmd}) ++ super.confirmDialog
}
</code>
</pre>
</div>
</li>
</ul>

<a href='http://jgoday.wordpress.com/2010/03/18/fun-with-liftweb-and-jquery-dialogs/snapshot2/' title='snapshot2'><img width="150" height="92" src="http://jgoday.files.wordpress.com/2010/03/snapshot2.png?w=150&#038;h=92" class="attachment-thumbnail" alt="snapshot2" title="snapshot2" /></a>
<a href='http://jgoday.wordpress.com/2010/03/18/fun-with-liftweb-and-jquery-dialogs/snapshot3-2/' title='snapshot3'><img width="150" height="19" src="http://jgoday.files.wordpress.com/2010/03/snapshot3.png?w=150&#038;h=19" class="attachment-thumbnail" alt="snapshot3" title="snapshot3" /></a>

<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=160&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2010/03/18/fun-with-liftweb-and-jquery-dialogs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>

		<media:content url="http://jgoday.files.wordpress.com/2010/03/snapshot2.png?w=150" medium="image">
			<media:title type="html">snapshot2</media:title>
		</media:content>

		<media:content url="http://jgoday.files.wordpress.com/2010/03/snapshot3.png?w=150" medium="image">
			<media:title type="html">snapshot3</media:title>
		</media:content>
	</item>
		<item>
		<title>Scala traits</title>
		<link>http://jgoday.wordpress.com/2010/02/16/scala-traits/</link>
		<comments>http://jgoday.wordpress.com/2010/02/16/scala-traits/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 21:42:23 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=155</guid>
		<description><![CDATA[Really love scala, traits and the ability of define custom types as interfaces. type ObjectWithName = { def getName: String } trait NicePerson[T &#60;: ObjectWithName] { def greet: String = { "Hello ! My name is %s".format(this.asInstanceOf[ObjectWithName].getName) } } class Person(name: String) { def getName: String = name } val peter = new Person("Peter") with <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=155&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Really love scala,<br />
traits and the ability of define custom types as interfaces.</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
type ObjectWithName = {
    def getName: String
}

trait NicePerson[T &lt;: ObjectWithName] {
    def greet: String = {
        "Hello ! My name is %s".format(this.asInstanceOf[ObjectWithName].getName)
    }
}

class Person(name: String) {
    def getName: String = name
}

val peter = new Person("Peter") with NicePerson[Person]
println(peter.greet) // = Hello ! My name is Peter

</code>
</pre>
</div>
<p>How nice it is ?</p>
<p>Some references:<br />
<a href="http://markthomas.info/blog/?p=92">http://markthomas.info/blog/?p=92</a><br />
<a href="http://codemonkeyism.com/scala-goodness-structural-typing/">http://codemonkeyism.com/scala-goodness-structural-typing/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=155&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2010/02/16/scala-traits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>
	</item>
		<item>
		<title>scala dsl to perform sql searches: part 1</title>
		<link>http://jgoday.wordpress.com/2010/01/20/scala-dsl-to-perform-sql-searches-part-1/</link>
		<comments>http://jgoday.wordpress.com/2010/01/20/scala-dsl-to-perform-sql-searches-part-1/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 18:45:08 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=147</guid>
		<description><![CDATA[Reading designing-internal-dsls-in-scala.html(recommended!) I come up with the idea of doing some simple scala DSL, to write and perform SQL searchs using lift-mapper objects. The result would be something like that: var find = FIND(Item) WITH(ItemType.name AS type_name, ItemResponsible.name as responsible) WHEN ( "type_name" ILIKE _nameVariable, "cancelled" IS_NULL, OR ( "responsible" IS_NULL, "ItemResponsible.id" EQUALS _getLoggedUserID() ) <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=147&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Reading <a href="http://debasishg.blogspot.com/2008/05/designing-internal-dsls-in-scala.html">designing-internal-dsls-in-scala.html</a>(recommended!)<br />
I come up with the idea of doing some simple scala DSL,<br />
to write and perform SQL searchs using lift-mapper objects.</p>
<p>The result would be something like that:</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
var find = FIND(Item)
    WITH(ItemType.name AS type_name, ItemResponsible.name as responsible)
    WHEN (
        "type_name" ILIKE _nameVariable,
        "cancelled" IS_NULL,
        OR (
            "responsible" IS_NULL,
            "ItemResponsible.id" EQUALS _getLoggedUserID()
        )
    )
    LIMIT 100 OFFSET 20

...
performSearch(find)
</code>
</pre>
</div>
<p>Here&#8217;s a sample code</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>

// types
type Condition = (() =&gt; Boolean, () =&gt; String)
type Operator  = (String, List[Condition])    

def _mergeConditions(operator: Operator): String = {
    var shouldApplyAndOperator = false // ????      

    var sql = ""
    var operatorFilters = ""
    val (operatorSQL, conditions) = operator

    var shouldApplyOperatorFilters = false

    conditions.foreach(cdt =&gt; {
        val (condition, filter) = cdt

        if (condition()) {
            val filterValue = shouldApplyOperatorFilters match {
                case true  =&gt; " %s (%s) ".format(operatorSQL, filter())
                case _ =&gt; " %s ".format(filter())
            }                                                          

            operatorFilters += filterValue
            shouldApplyOperatorFilters = true
        }
    })                                       

    if (shouldApplyOperatorFilters) {
        val filterValue = shouldApplyAndOperator match {
            case true  =&gt; " %s (%s) ".format("AND", operatorFilters)         

            case _ =&gt; " %s ".format(operatorFilters)                         

        }                                                                       

        sql += filterValue
        shouldApplyAndOperator = true
    }                                                                           

    sql
}                                                                               

// Base class to search objects
class Find(obj: String) {
    private var fields: List[Any]         = List()
    private var operators: List[Operator] = List()

    def toSQL: String = {
        def _getFieldsAsSQL = this.fields.reduceLeft(_ + "," + _)
        def _getTableName = this.obj
        def _getOperatorsAsSQL = {
            var sql = ""                                         

            this.operators.foreach(op =&gt; {
                sql += _mergeConditions(op)
            })                             

            if (sql != "") sql = " WHERE " + sql
            sql
        }                                       

        "SELECT %s FROM %s %s".format(
                _getFieldsAsSQL,
                _getTableName,
                _getOperatorsAsSQL)
    }                                 

    /**
     * Adds a list of conditions around a sql AND operator
     */
    def AND(conditions: Condition*): Find = {
        this.operators = ("AND", conditions.toList) :: this.operators
        this
    }                                                                

    /**
     * Adds a list of conditions around a sql OR operator
     */
    def OR(conditions: Condition*): Find = {
        this.operators = ("OR",  conditions.toList) :: this.operators
        this
    }                                                                

    /**
     * Selects the object with custom fields
     */
    def WITH(fields: Any*): Find = {
        this.fields = fields.toList ::: this.fields
        this
    }
}                                                  

/** Global operator methods to composite conditions around a find object **/
def AND(conditions: Condition*): Condition = {
    (() =&gt; true, () =&gt; _mergeConditions("AND", conditions.toList))        

}                                                                           

def OR(conditions: Condition*): Condition = {
    (() =&gt; true, () =&gt; _mergeConditions("OR", conditions.toList))
}                                                                

// CONDITIONS AND WRAPPERS

class StaticConditionWrapper(filter: String) extends FunctionConditionWrapper(()
=&gt; filter)
class FunctionConditionWrapper(filter: () =&gt; String) {                       

    def ALWAYS: Condition = {
        (() =&gt; true, filter)
    }
    def IF(condition: () =&gt; Boolean): Condition = {
        (condition, filter)
    }
    def IF(value: Boolean): Condition = {
        (() =&gt; value, filter)
    }
    def ILIKE(value: String): Condition = {
        (() =&gt; value != "", () =&gt; " %s ILIKE '%%%s%%' ".format(filter(),
value))
    }
    def IS_NULL: Condition = {
        (() =&gt; true, () =&gt; " %s IS NULL ".format(filter()))
    }
    def NOT_NULL: Condition = {
        (() =&gt; true, () =&gt; " %s IS NOT NULL ".format(filter()))
    }
}

implicit def IF(filter: String) = new StaticConditionWrapper(filter)
implicit def IF(filter: () =&gt; String) = new FunctionConditionWrapper(filter)

// Object FIND to easy create find objects (FIND("object_name"))
object FIND {
    def apply(obj: String): Find = new Find(obj)
}

</code>
</pre>
</div>
<p>The result of evaluting</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
// TEST
def checkCondition: () =&gt;&gt; Boolean = () =&gt; true
def someFilter: () =&gt; String = () =&gt; " something true"

val f = (
    FIND("ObjectName") WITH(1,2,3,4,5)
    AND (
        someFilter ALWAYS,
        "A" IF true,
        "B" IF checkCondition,
        OR (
            "C" ALWAYS,
            AND (
                "NAME" ILIKE "Pepe",
                "CANCELLED" IS_NULL
            )
        )
    )
)

println(f.toSQL)
</code></pre>
</div>
<p>is </p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
SELECT 1,2,3,4,5 FROM ObjectName
    WHERE
    something true AND (A)  AND (B)  AND
        (  C  OR (   NAME ILIKE '%Pepe%'   AND ( CANCELLED IS NULL )  )  )
</code></pre>
</div>
<p>really nice <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>All filtering is based on</p>
<ul>
<li><b>Conditions :</b>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
type Condition = (() =&gt; Boolean, () =&gt; String)

sample : (() =&gt; {result_of_checking_condition()),
          () =&gt; {create_some_sql_filter()})
</code></pre>
</div>
<p>A couple, containing a function that will decide if the filter applies or not,<br />
and a function that makes the filter
    </li>
<li><b>Operators  :    </b>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
type Operator = (String, List[Condition])
</code></pre>
</div>
<p>Allows to composite conditions and envolves them with a SQL Operator (And/Or)</p>
</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/147/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=147&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2010/01/20/scala-dsl-to-perform-sql-searches-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>
	</item>
		<item>
		<title>Logging database changes in lift-mapper</title>
		<link>http://jgoday.wordpress.com/2010/01/11/logging-database-changes-in-lift-mapper/</link>
		<comments>http://jgoday.wordpress.com/2010/01/11/logging-database-changes-in-lift-mapper/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 19:24:01 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[lift]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=142</guid>
		<description><![CDATA[Here is a little trick to log the changed properties on the lift-mapper objets. First we define a changeLogger trait that extends Mapper trait ChangeLogger[T &#60;: Mapper[T] ] { def checkChanges(obj: T): Unit = { if (obj.dirty_?) { Log.debug("Object " + obj.getSingleton.dbTableName + " has changed") obj.formFields.foreach(f =&#62; { f.dirty_? match { case true =&#62; <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=142&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a little trick to log the changed properties<br />
on the lift-mapper objets.</p>
<ul>
<li>
    <b>First we define a changeLogger trait that extends <a href="http://scala-tools.org/mvnsites/liftweb-1.1-M6/lift-mapper/scaladocs/net/liftweb/mapper/Mapper.html">Mapper</a></p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
trait ChangeLogger[T &lt;: Mapper[T] ] {
    def checkChanges(obj: T): Unit = {
        if (obj.dirty_?) {

            Log.debug("Object " + obj.getSingleton.dbTableName + " has changed")

            obj.formFields.foreach(f =&gt; {
                f.dirty_? match {
                    case true =&gt; Log.debug(" ---&gt; Property %s was='%s' and now is = '%s'".format(f.name, f.is.toString, f.was.toString))
                }
            })
        }
    }
}
</code>
</pre>
</div>
<p>    </b></li>
<li>
        <b>Extend LongKeyedMetaMapper</b> (or any other MetaMapper class) to call ChangeLogger checkChanges method after save (or after delete &#8230;)</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
trait ChangeLoggerMetaMapper[T &lt;: LongKeyedMapper[T]] extends LongKeyedMetaMapper[T]
                                                with ChangeLogger[T] { self : T =&gt;
    override def afterSave: List[(T) =&gt; Unit] = checkChanges _ :: super.afterSave
}

</code>
</pre>
</div>
</li>
<li>
        <b>Model object</b></p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
class Item extends LongKeyedMapper[Item] with IdPK
                                         with ChangeLogger[Item] {
    def getSingleton = Item

    object name extends MappedString(this, 100) {
        override def validations = valMinLen(1, "Must be not empty") _ ::
                                   valUnique("Name must be unique") _ ::
                                   super.validations
    }
}

object Item extends Item with ChangeLoggerMetaMapper[Item] {
    def findByName(name: String): List[Item] = {
        Item.findAll(By(Item.name, name))
    }
}

</code>
</pre>
</div>
</li>
</ul>
<p><a href="http://jgoday.files.wordpress.com/2010/01/snapshot1.png"><img src="http://jgoday.files.wordpress.com/2010/01/snapshot1.png?w=570&#038;h=190" alt="" title="snapshot1" width="570" height="190" class="aligncenter size-full wp-image-144" /></a><br />
<br />
The code can be found on <a href="http://github.com/jgoday/sample_lift_testing">http://github.com/jgoday/sample_lift_testing</a></p>
<p>Documentation for lift-mapper (version lift-1.1-M6) <a href="http://scala-tools.org/mvnsites/liftweb-1.1-M6/lift-mapper/scaladocs/index.html">http://scala-tools.org/mvnsites/liftweb-1.1-M6/lift-mapper/scaladocs/index.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=142&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2010/01/11/logging-database-changes-in-lift-mapper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>

		<media:content url="http://jgoday.files.wordpress.com/2010/01/snapshot1.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>
	</item>
		<item>
		<title>Sample list items with lift</title>
		<link>http://jgoday.wordpress.com/2009/12/27/sample-list-items-with-lift/</link>
		<comments>http://jgoday.wordpress.com/2009/12/27/sample-list-items-with-lift/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 18:19:43 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[lift]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=136</guid>
		<description><![CDATA[Add/Edit/Remove items in lift sample 1- Create the menu in boot in src/main/scala/bootstrap/liftweb/Boot.scala // List items menu val itemsMenu = Menu(Loc("Items", "items" :: "index" :: Nil, "List items")) // Build SiteMap val entries = Menu(Loc("Home", List("index"), "Home")) :: itemsMenu :: Nil 2- Define the default database The properties in src/main/resources/props/default.props with the connection url db.driver <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=136&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Add/Edit/Remove items in lift sample</p>
<ul>
<li>
        <b>1- Create the menu in boot</b></p>
<p>in src/main/scala/bootstrap/liftweb/Boot.scala</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
// List items menu
val itemsMenu = Menu(Loc("Items", "items" :: "index" :: Nil, "List items"))

// Build SiteMap
val entries = Menu(Loc("Home", List("index"), "Home")) :: itemsMenu :: Nil
</code></pre>
</div>
</li>
<li>
        <b>2- Define the default database</b><br />
The properties in src/main/resources/props/default.props with the connection url</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
db.driver   = org.h2.Driver
db.url      = jdbc:h2:~/hello_db
db.user     =
db.password =
</code></pre>
</div>
<p>in src/main/scala/bootstrap/liftweb/Boot.scala</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>

DB.defineConnectionManager(DefaultConnectionIdentifier, DefaultDBVendor)
Schemifier.schemify(true, Log.infoF _, Item)

...

object DefaultDBVendor extends ConnectionManager {
    def newConnection(name: ConnectionIdentifier): Box[Connection] = {
        try {
            val connectionUrl = Props.get("db.url").openOr("") + "?user=" +
                                Props.get("db.username").openOr("") + "&amp;password=" +
                                Props.get("db.password").openOr("")

            Class.forName(Props.get("db.driver").open_!)
            val dm = DriverManager.getConnection(connectionUrl)
            return Full(dm)
        }
        catch {
            case e: Exception =&gt; {
                Log.error(e.getMessage);
                return Empty
            }
        }
    }

    def releaseConnection(conn: Connection) = conn.close
}

</code></pre>
</div>
</li>
<li>
        <b>3- Create items/index.html</b><br />
in src/main/webapp/items/index.html</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
&lt;lift:surround with="default" at="content"&gt;
    &lt;ul&gt;
        &lt;lift:adminItems.list&gt;
            &lt;li&gt;
                &lt;item:name /&gt;
            &lt;/li&gt;
        &lt;/lift:adminItems.list&gt;
    &lt;/ul&gt;
&lt;/lift:surround&gt;

</code></pre>
</div>
<p>and snippet in src/main/scala/com/sample/snippet/AdminItems.scala</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
package com.sample.snippet

import scala.xml.{NodeSeq, Text}

import net.liftweb.util.{Helpers, Log}
import Helpers._

import com.sample.model.Item

class AdminItems {

    def list(node: NodeSeq): NodeSeq = {
        Item.findAll match {
            case Nil   =&gt; Text("There is no items in db")
            case items =&gt; items.flatMap(i =&gt; bind("item", node, "name" -&gt; {i.name}))
        }
    }
...
}
</code></pre>
</div>
</li>
<li>
        <b>4- Add item form</b></p>
<p>create a template for add/edit items in src/main/webapp/templates-hidden/item_form.html,<br />
we are going to use the same template for edit and add items,<br />
using <a href="http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/http/TemplateFinder$object.html">TemplateFinder</a> in AdminItems snippet</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
&lt;fieldset&gt;
    &lt;legend&gt;&lt;itemForm:title /&gt;&lt;/legend&gt;
    &lt;label for="name"&gt;Name&lt;/label&gt;

    &lt;itemForm:name /&gt;
    &lt;itemForm:id /&gt;

    &lt;itemForm:submit /&gt;
&lt;/fieldset&gt;

</code></pre>
</div>
<p>we are going to use two <a href="http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/http/RequestVar.html">requestvars</a> to decide when to display the edit form or the add form</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
    private object ShowAddItem  extends RequestVar[Int](0)
    private object SelectedItem extends RequestVar[Long](0)
</code></pre>
</div>
<p>declare a showAddItem and showEditItem function in adminItems snippet</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
    def clear = {
        ShowAddItem(0)
        SelectedItem(0)
    }                  

    def showAddItem(node: NodeSeq): NodeSeq = {
        ShowAddItem.get match {
            case 1 =&gt; {
                var name = ""
                val template: NodeSeq = TemplateFinder.findAnyTemplate(ITEM_TEMPLATE :: Nil).openOr(&lt;p&gt;&lt;/p&gt;)
                val content = bind("itemForm", template, "title"  -&gt; Text("New item"),
                                                          "name"   -&gt; SHtml.text(name, name = _),
                                                          "id"     -&gt; Text(""),
                                                          "submit" -&gt; SHtml.submit("save", () =&gt; addItem(name)),
                                                          "close"  -&gt; SHtml.link("index", () =&gt; clear, Text("close")))                                                              

                &lt;div&gt;{content}&lt;/div&gt;
            }
            case _ =&gt; SHtml.link("index", () =&gt; ShowAddItem(1), &lt;p&gt;Add&lt;/p&gt;)
        }
    }                                                                      

    def showEditItem(node: NodeSeq): NodeSeq = {
        if (SelectedItem.get &gt; 0) {
            var id = SelectedItem.get
            val item = Item.find(id).open_!     

            var name = item.name.is

            val template = TemplateFinder.findAnyTemplate(ITEM_TEMPLATE :: Nil).openOr(&lt;p&gt;&lt;/p&gt;)
            val content  = bind("itemForm", template, "title"  -&gt; Text("Edit item"),
                                                      "name"   -&gt; SHtml.text(name, name = _),
                                                      "id"     -&gt; Html.hidden(() =&gt; {id = id}),
                                                      "submit" -&gt; SHtml.submit("save", () =&gt; saveItem(id, name)),
                                                      "close"  -&gt; SHtml.link("index", () =&gt; clear, Text("close")))                                                                  

            &lt;div&gt;{content}&lt;/div&gt;
        }
        else {
            &lt;div&gt;&lt;/div&gt;
        }
    }
</code></pre>
</div>
<p>Now we can call the showEditItem and showAddItem snippets functions in items/index view</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
&lt;lift:surround with="default" at="content"&gt;
    &lt;ul&gt;
        &lt;lift:adminItems.list&gt;
            &lt;li&gt;
                &lt;item:name /&gt;

                &lt;item:edit /&gt;
                &lt;item:remove /&gt;
            &lt;/li&gt;
        &lt;/lift:adminItems.list&gt;
    &lt;/ul&gt;

    &lt;lift:adminItems.showAddItem  form="POST" /&gt;
    &lt;lift:adminItems.showEditItem form="POST" /&gt;
&lt;/lift:surround&gt;

</code></pre>
</div>
<p>The attribute form=&#8221;POST&#8221; on the snippet will create a form with method=&#8221;POST&#8221; automatically arround the snippet content.</p>
<p>And that&#8217;s it, a simple list with liftweb.<br />
The code can be found on <a href="http://github.com/jgoday/sample_lift_testing">http://github.com/jgoday/sample_lift_testing</a>
</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/136/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=136&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2009/12/27/sample-list-items-with-lift/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>
	</item>
		<item>
		<title>Lift testing with dbunit and specs</title>
		<link>http://jgoday.wordpress.com/2009/12/25/lift-testing-with-dbunit-and-specs/</link>
		<comments>http://jgoday.wordpress.com/2009/12/25/lift-testing-with-dbunit-and-specs/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 19:27:42 +0000</pubDate>
		<dc:creator>jgoday</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[lift]]></category>

		<guid isPermaLink="false">http://jgoday.wordpress.com/?p=129</guid>
		<description><![CDATA[Here&#8217;s a post about Lift and testing, using scala specs and dbunit. We can use dbunit to populate a sample database for testing purposes, in this example we are going to use the embedded h2 database. 1. Create a sample liftweb (1.1-M8) application using maven 2.2 mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate \ -DarchetypeGroupId=net.liftweb \ -DarchetypeArtifactId=lift-archetype-blank \ -DarchetypeVersion=1.1-M8 \ <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=129&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a post about <a href="http://liftweb.net/">Lift</a> and testing,<br />
using <a href="http://code.google.com/p/specs/">scala specs</a> and <a href="http://www.dbunit.org/">dbunit</a>.</p>
<p>We can use dbunit to populate a sample database for testing purposes,<br />
in this example we are going to use the  <a href="http://www.h2database.com/html/main.html">embedded h2 database</a>.</p>
<ul>
<li>
        <b>1. Create a sample liftweb (1.1-M8) application using maven 2.2</b></p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate        \
    -DarchetypeGroupId=net.liftweb        \
    -DarchetypeArtifactId=lift-archetype-blank        \
    -DarchetypeVersion=1.1-M8        \
    -DremoteRepositories=http://scala-tools.org/repo-releases        \
    -DgroupId=com.sample -DartifactId=hello
</code>
</pre>
</div>
<p>And add the testing dependencies to pom.xml (specs, h2database and dbunit)</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>

&lt;dependency&gt;
    &lt;groupId&gt;org.scala-tools.testing&lt;/groupId&gt;
    &lt;artifactId&gt;specs&lt;/artifactId&gt;
    &lt;version&gt;1.4.4&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;                                 

&lt;dependency&gt;
    &lt;groupId&gt;com.h2database&lt;/groupId&gt;
    &lt;artifactId&gt;h2&lt;/artifactId&gt;
    &lt;version&gt;1.2.125&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;                     

&lt;dependency&gt;
    &lt;groupId&gt;org.dbunit&lt;/groupId&gt;
    &lt;artifactId&gt;dbunit&lt;/artifactId&gt;
    &lt;version&gt;2.4.7&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
</code>
</pre>
</div>
</li>
<li>
        <b>2. Create a sample model vo (Item with name and id)</b></p>
<p>in src/main/scala/com/sample/model/Item.scala,<br />
a sample object with a string attribute name that cannot be empty.</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
package com.sample.model

import net.liftweb.mapper.{By, IdPK,
                           LongKeyedMapper, LongKeyedMetaMapper,
                           MappedString}

class Item extends LongKeyedMapper[Item] with IdPK {
    def getSingleton = Item

    object name extends MappedString(this, 100) {
        override def validations = valMinLen(1, "Must be not empty") _ ::
                                   super.validations
    }
}

object Item extends Item with LongKeyedMetaMapper[Item] {
    def findByName(name: String): List[Item] = {
        Item.findAll(By(Item.name, name))
    }
}
</code>
</pre>
</div>
<p>We can test the compilation to let maven download the dependencies<br />
without testing : <b>mvn package -Dmaven.test.skip=true</b>
    </li>
<li>
        <b>3. Create a sample Specs test file for item</b></p>
<p>in src/test/scala/com/sample/model/ItemSpecs.scala,</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
package com.sample.model

import org.specs.Specification
import org.specs.runner.JUnit4

class ItemSpecsAsTest extends JUnit4(ItemSpecs)

object ItemSpecs extends Specification {
    "Item" should {
        "do nothing wrong" in {
            true must beTrue
        }
    }
}
</code>
</pre>
</div>
</li>
<li>
        <b>4. Create a database util class to initialize database and populate data</b></p>
<p>in src/test/scala/com/sample/utils/DBUtil.scala,</p>
<p>it will initialize the default <i>database connection identifier</i> using the properties file in<br />
src/test/resources <b>(by default src/test/resources/props/test.default.props)</b></p>
<p>and will let us choose a dbunit dataset file to populate the test data using<br />
<b>DBUtil.setupDB(&#8220;dbunit_database_file.xml&#8221;)</b></p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
package com.sample.utils                                                     

import net.liftweb.mapper.{DB,
                          ConnectionIdentifier, DefaultConnectionIdentifier,
                          StandardDBVendor}
import net.liftweb.util.{Log, Props}                                        

import org.dbunit.dataset.{IDataSet}
import org.dbunit.dataset.xml.{XmlDataSet}
import org.dbunit.database.{DatabaseConfig, DatabaseConnection}
import org.dbunit.operation.{DatabaseOperation}                

object DBUtil {
    private var dataset: IDataSet      = null
    private var dbunitConnection: DatabaseConnection = null

    lazy val connectionIdentifier: () =&gt; ConnectionIdentifier = {
        () =&gt; DefaultConnectionIdentifier
    }                                                            

    def initialize = {
        DB.defineConnectionManager(connectionIdentifier(),
                                  new StandardDBVendor(Props.get("db.driver").openOr(""),
                                                       Props.get("db.url").openOr(""),
                                                       Props.get("db.user"),
                                                       Props.get("db.password")))
    }                                                                                    

    def setupDB(filename: String) = {
        this.dataset = new XmlDataSet(this.getClass().getClassLoader().getResourceAsStream(filename))

        DB.use(connectionIdentifier()) {
            conn =&gt; {
                this.dbunitConnection = new DatabaseConnection(conn)
                DatabaseOperation.CLEAN_INSERT.execute(this.dbunitConnection, this.dataset)
            }
        }
    }

    def shutdownDB = {
        DB.use(connectionIdentifier()) {
            conn =&gt; {
                try {
                    DatabaseOperation.DELETE.execute(this.dbunitConnection, this.dataset)
                }
                catch {
                    case e: Exception =&gt; Log.error(e.getMessage)
                }
            }
        }

    }
}
</code>
</pre>
</div>
</li>
<li>
        <b>5. Now we can do some more interesting test</b></p>
<p>using a sample dataset in src/test/resources/dbunit/item_test.xml,<br />
the lift <a href="http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/Schemifier$object.html">Shemifier</a> class will create the database table on the beggining of the test<br />
and destroy it at the end.</p>
<div style="border:1px dotted #909090;background-color:#f7f7f7;overflow:auto;padding:4px;">
<pre>
<code>
package com.sample.model                                                        

import net.liftweb.mapper.{Schemifier}
import net.liftweb.util.{Log}         

import com.sample.utils.DBUtil

import org.specs.Specification
import org.specs.runner.JUnit4

class ItemSpecsAsTest extends JUnit4(ItemSpecs)

object ItemSpecs extends Specification {
    "Item" should {
        doFirst {
            DBUtil.initialize
            Schemifier.schemify(true, Log.infoF _ , Item)
            DBUtil.setupDB("dbunit/item_test.xml")
        }                                                

        "save without problem" in {
            val item = new Item
            item.name("item name")

            item.save must beTrue
            (Item.findAll.length == 3) must beTrue
        }

        "find by name" in {
            val items = Item.findByName("Item 1")
            items.length must_== 1
        }

        "delete without problem" in {
            val items = Item.findByName("item name")

            items.length must_== 1
            items(0).delete_! must beTrue
            Item.findAll.length must_== 2
        }

        doLast {
            DBUtil.shutdownDB
            Schemifier.destroyTables_!!(Log.infoF _, Item)
        }
    }
}

</code>
</pre>
</div>
</li>
</ul>
<p>Simple and funny <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The sample code can be found in <a href="http://github.com/jgoday/sample_lift_testing"></p>
<p>http://github.com/jgoday/sample_lift_testing</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgoday.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgoday.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgoday.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgoday.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgoday.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgoday.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgoday.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgoday.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgoday.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgoday.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgoday.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgoday.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgoday.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgoday.wordpress.com/129/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgoday.wordpress.com&amp;blog=7273388&amp;post=129&amp;subd=jgoday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jgoday.wordpress.com/2009/12/25/lift-testing-with-dbunit-and-specs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>42.487982 -8.857673</georss:point>
		<geo:lat>42.487982</geo:lat>
		<geo:long>-8.857673</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2bef5dd951eebfef9f36c38af35b9090?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgoday</media:title>
		</media:content>
	</item>
	</channel>
</rss>
