<?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>Ron's Weblog</title>
	<atom:link href="http://ronfrancis.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ronfrancis.wordpress.com</link>
	<description>Mostly related to java, javascript and web development.</description>
	<lastBuildDate>Thu, 08 May 2008 18:20:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ronfrancis.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ron's Weblog</title>
		<link>http://ronfrancis.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ronfrancis.wordpress.com/osd.xml" title="Ron&#039;s Weblog" />
	<atom:link rel='hub' href='http://ronfrancis.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Java to Scala- some links</title>
		<link>http://ronfrancis.wordpress.com/2008/05/08/java-to-scala-some-links/</link>
		<comments>http://ronfrancis.wordpress.com/2008/05/08/java-to-scala-some-links/#comments</comments>
		<pubDate>Thu, 08 May 2008 17:56:29 +0000</pubDate>
		<dc:creator>Ron Francis</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[Scala Java]]></category>

		<guid isPermaLink="false">http://ronfrancis.wordpress.com/?p=11</guid>
		<description><![CDATA[Over the last few months, I’ve been trying to take out time to learn more about Scala – finding documentation and tutorials is hard ( specially if like me, you&#8217;ve 15 minutes a day to bite through your lunch when reading ). Wouldn’t a “Thinking in Scala” be nice? Before diving into Scala, I would [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=11&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Over the last few months, I’ve been trying to take out time to learn more about Scala – finding documentation and tutorials is hard ( specially if like me, you&#8217;ve 15 minutes a day to bite through  your lunch when reading ). Wouldn’t a “Thinking in Scala” be nice?</p>
<p>Before diving into Scala, I would highly recommend learning more about functional programming. A great read is <a href="http://www.defmacro.org/ramblings/fp.html">Functional Programming For The Rest of Us</a>. This is a great introduction to functional programming, and IMO, a good place to start for those of us new to FP.<br />
After this I&#8217;d recommend <a href="http://www.codecommit.com/blog/scala/roundup-scala-for-java-refugees">Roundup:Scala for Java Refugees</a>.<br />
This is a six-part series and I would read through all of them.It has great side-by-side examples of both Scala and equivalent(if any) Java code.</p>
<p>What&#8217;s great about Scala is the flexibility to structure your code intuitively. Reading an introductory article might not always make this obvious.  As a quick example, (based on a similar one in Part 6), you could add a method to any class to save itself to the database (as opposed to looking up a DAO in your service code).</p>
<pre class="brush: java;">
class Person(firstName: String, lastName: String) {
//simple person class
}
//define a Persistent Object
class PersistentObject(obj:Object) {
def save() {
// call a DAO etc println(&quot;Saving : &quot;+obj)
}
}

//implicitly convert a POJO to a PersistentObject
implicit def pojo2persistent(obj:Object) = new PersistentObject(obj)
new Person(&quot;Ron&quot;,&quot;Francis&quot;).save()
</pre>
<p>Next on my list: Actors-The other concept probably new to Java programmers are Scala Actors. Actors provide Erlang style concurrency( or Message Passing concurrency, as opposed to Java’s shared state concurrency). Here is an <a href="http://lamp.epfl.ch/~phaller/doc/ActorsTutorial.html">actor tutorial</a> . I haven&#8217;t explored this yet &#8211; but sounds promising. For example, here is an interesting blog about <a href="http://scala-blogs.org/2007/12/dynamic-web-applications-with-lift-and.html">Scala Actors and comet </a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ronfrancis.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ronfrancis.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ronfrancis.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ronfrancis.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ronfrancis.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ronfrancis.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ronfrancis.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ronfrancis.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ronfrancis.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ronfrancis.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ronfrancis.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ronfrancis.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ronfrancis.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ronfrancis.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ronfrancis.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ronfrancis.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=11&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ronfrancis.wordpress.com/2008/05/08/java-to-scala-some-links/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3eef9344a78bb7d70a1a3df65929f83d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ron Francis</media:title>
		</media:content>
	</item>
		<item>
		<title>Integration Testing Queries</title>
		<link>http://ronfrancis.wordpress.com/2008/01/10/integration-testing-queries/</link>
		<comments>http://ronfrancis.wordpress.com/2008/01/10/integration-testing-queries/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 20:39:00 +0000</pubDate>
		<dc:creator>Ron Francis</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[Integration test]]></category>

		<guid isPermaLink="false">http://ronfrancis.wordpress.com/2008/01/10/integration-testing-queries/</guid>
		<description><![CDATA[When you&#8217;re developing with databases, you will likely come across the need to test queries that insert, update or delete data. This usually creates a problem because the database tables quickly fill up with test data. In one of my earlier engagements, we were using Hibernate to map a complex graph of objects. Not only [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=10&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re developing with databases, you will likely come across the need to test queries that insert, update or delete data. This usually creates a problem because the database tables quickly fill up with test data.</p>
<p>In one of my earlier engagements, we were using Hibernate to map a complex graph of objects. Not only did we need to test whether the usual CRUD operations worked with one object in isolation, but  with entire graphs of objects. For example, deleting a customer record should delete all records from customer_orders, customer_contacts etc.</p>
<p>We wrote our integration tests using JUnit. To avoid cluttering the database, we used a strategy where we explicitly started a transaction in our setUp() method and rolled it back in tearDown(). The code was (somewhat) like this:</p>
<pre class="brush: java;">
 protected void setUp() throws Exception {
    session = HibernateSessionFactory.newSession();
    transaction = session.beginTransaction();
 }
 protected void tearDown() throws Exception {
    session.flush();//fire all sql updates..
    transaction.rollback();
    HibernateSessionFactory.endSession(session);
}
</pre>
<p>In a later engagement, we came across the same problem. However, this time we were using the spring framework. The spring framework provides a class named  <b>AbstractTransactionalDataSourceSpringContextTests</b> (Yes, the name is a mouthful).  As the name suggests, this is a abstract class you can extend your (JUnit) test case from. It comes with all the usual spring auto-wiring capabilities, in addition, it automatically rolls-back the transaction at the end of each test. Regardless of the approach, integration test are a big time saver. I usually advocate integration tests for all methods invoked from a Controller (e.g.Struts Action). Having tests such as these in place makes it possible to test and debug almost all bugs right from the IDE. And thanks to the auto-rollbacks &#8211; without making a mess of test data.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ronfrancis.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ronfrancis.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ronfrancis.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ronfrancis.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ronfrancis.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ronfrancis.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ronfrancis.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ronfrancis.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ronfrancis.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ronfrancis.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ronfrancis.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ronfrancis.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ronfrancis.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ronfrancis.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ronfrancis.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ronfrancis.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=10&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ronfrancis.wordpress.com/2008/01/10/integration-testing-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3eef9344a78bb7d70a1a3df65929f83d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ron Francis</media:title>
		</media:content>
	</item>
		<item>
		<title>WebLogic Init SQL and Oracle OPTIMIZER_MODE</title>
		<link>http://ronfrancis.wordpress.com/2007/10/16/weblogic-init-sql-and-oracle-optimizer_mode/</link>
		<comments>http://ronfrancis.wordpress.com/2007/10/16/weblogic-init-sql-and-oracle-optimizer_mode/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 20:50:00 +0000</pubDate>
		<dc:creator>Ron Francis</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[WebLogic]]></category>

		<guid isPermaLink="false">http://ronfrancis.wordpress.com/2007/10/16/weblogic-init-sql-and-oracle-optimizer_mode/</guid>
		<description><![CDATA[While tuning some SQL queries in one of my applications, we encountered query plans that, at first glance, seemed to be plain wrong. Having recently upgraded to Oracle 10g, we found that many of our queries worked better in 9i. We tracked it down to a difference in how the new CBO (Cost Based Optimizer) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=6&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While tuning some SQL queries in one of my applications, we encountered query plans that, at first glance, seemed to be plain wrong. Having recently upgraded to Oracle 10g, we found that many of our queries worked better in 9i. We tracked it down to a difference in how the new CBO (Cost Based Optimizer) works in 10g.</p>
<p>The OPTIMIZER_MODE initialization parameter in Oracle 10g influences whether the query is optimized to retrieve the first rows as soon as possible (<i>first_rows</i>) or all rows (<i>all_rows</i>). The default in 10g is <i>all_rows.</i></p>
<p>For OLTP systems (most web applications I worked with have fallen under this category), &#8220;<span style="font-style:italic;">first_rows</span>&#8221; usually makes sense.  For example, displaying paginated results like the first 10 of a 1000 records.</p>
<p>However, if your database is used by clients other than your application(for example a  reporting client)<i>, </i>changing the default<i> </i> OPTIMIZER_MODE might not be a good option.</p>
<p>This was the case with our application where we needed both:</p>
<ul>
<li>A paginated RIA grid where <span style="font-style:italic;">first_rows</span> made sense.</li>
<li>An offline reporting server where <span style="font-style:italic;">all_rows</span> made more sense.</li>
</ul>
<p>One option was to go back to every query that needed &#8220;quick results&#8221; and add the SQL hint <span style="font-family:courier new;">/* first_rows(n)*/</span>. For example,</p>
<pre class="brush: sql;">select /*+first_rows*/ last_name, first_name from Customer...</pre>
<p>This seemed like a lot of work. Also, if you&#8217;re using Hibernate HQL, you cannot insert hints into the generated SQL.The other option is to execute the following statement prior to running the query(s).</p>
<pre class="brush: sql;">ALTER SESSION SET OPTIMIZER_MODE='FIRST_ROWS';</pre>
<p>However, this would also mean a lot of changes to existing code. Also, because we were using connection pooling, I&#8217;d rather execute this only once when a connection is established, and not with every query.Since we were using WebLogic Server 9.2 , we were able to take advantage of a connection pool  property called &#8220;Init SQL&#8221;.(Under  DataSource&gt;Connection Pool&gt;Advanced in the WebLogic console). This property can be set to a SQL statement that would be executed by WebLogic when the connection is initialized.  We set this to :</p>
<pre class="brush: sql;">SQL ALTER SESSION SET OPTIMIZER_MODE='FIRST_ROWS';</pre>
<p>This way, regardless of the Oracle defaults, we were able to customize the <span style="font-family:courier new;">OPTIMIZER_MODE </span>without having to tweak the application code or the database. <span style="font-family:courier new;"><br />
</span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ronfrancis.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ronfrancis.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ronfrancis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ronfrancis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ronfrancis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ronfrancis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ronfrancis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ronfrancis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ronfrancis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ronfrancis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ronfrancis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ronfrancis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ronfrancis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ronfrancis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ronfrancis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ronfrancis.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=6&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ronfrancis.wordpress.com/2007/10/16/weblogic-init-sql-and-oracle-optimizer_mode/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3eef9344a78bb7d70a1a3df65929f83d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ron Francis</media:title>
		</media:content>
	</item>
		<item>
		<title>Don&#8217;t forget an &quot;order by&quot; for pagination queries</title>
		<link>http://ronfrancis.wordpress.com/2007/10/16/dont-forget-an-order-by-for-pagination-queries/</link>
		<comments>http://ronfrancis.wordpress.com/2007/10/16/dont-forget-an-order-by-for-pagination-queries/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 19:25:00 +0000</pubDate>
		<dc:creator>Ron Francis</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[HQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Pagination]]></category>

		<guid isPermaLink="false">http://ronfrancis.wordpress.com/2007/10/16/dont-forget-an-order-by-for-pagination-queries/</guid>
		<description><![CDATA[I&#8217;ve seen this many times in web-based applications that use paginated results. If you&#8217;re using Oracle, the general form of such a query is : select * from ( select /*+ FIRST_ROWS(n) */ a.*, ROWNUM rnum from (your_query_goes_here) a where ROWNUM &#60;=:MAX_ROW_TO_FETCH ) where rnum &#62;= :MIN_ROW_TO_FETCH; While doing this with JDBC/SQL is easy enough-if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=5&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen this many times in web-based applications that use paginated results.</p>
<p>If you&#8217;re using Oracle, the general form of such a query is :</p>
<pre class="brush: sql;">
   select * from
   (
      select /*+ FIRST_ROWS(n) */ a.*, ROWNUM rnum from
          (your_query_goes_here) a
      where  ROWNUM &lt;=:MAX_ROW_TO_FETCH
   )
  where rnum  &gt;= :MIN_ROW_TO_FETCH;
</pre>
<p>While doing this with JDBC/SQL is easy enough-if you&#8217;re using Hibernate HQL (with the appropriate Oracle Dialect), you can also take advantage of this feature. For example:</p>
<pre class="brush: java;">
Query q = &quot;from Customer c order by c.lastName&quot;;
q.setFirstResult(10);
q.setMaxResults(30);
List results = q.list();
</pre>
<p>For this query to work correctly, all the time, it is important to <span style="font-weight:bold;font-style:italic;">always sort by a unique column</span>. In the example above, &#8220;lastName&#8221; will likely have duplicate values. There is no way to guarantee the order of the returned rows unless we include a unique  &#8216;order by&#8217; clause. If a unique column is not available, in many cases, you can just sort by ROWID.  See this article <a href="http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html">here</a> for more on rownum.The modified HQL would look like</p>
<pre class="brush: java;">
&quot;from Customer c
order by c.lastName, c.rowId&quot;</pre>
<p>Of course, you would have to map a java property &#8220;rowId&#8221; to the  pseudo-column &#8220;ROWID&#8221;.<br />
While mapping it in hibernate, be sure to mark it as update=&#8221;false&#8221; and insert=&#8221;false&#8221;, since you cannot update the ROWID column.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ronfrancis.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ronfrancis.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ronfrancis.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ronfrancis.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ronfrancis.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ronfrancis.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ronfrancis.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ronfrancis.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ronfrancis.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ronfrancis.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ronfrancis.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ronfrancis.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ronfrancis.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ronfrancis.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ronfrancis.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ronfrancis.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=5&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ronfrancis.wordpress.com/2007/10/16/dont-forget-an-order-by-for-pagination-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3eef9344a78bb7d70a1a3df65929f83d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ron Francis</media:title>
		</media:content>
	</item>
		<item>
		<title>On Commons Lang</title>
		<link>http://ronfrancis.wordpress.com/2007/03/16/on-commons-lang/</link>
		<comments>http://ronfrancis.wordpress.com/2007/03/16/on-commons-lang/#comments</comments>
		<pubDate>Fri, 16 Mar 2007 15:06:00 +0000</pubDate>
		<dc:creator>Ron Francis</dc:creator>
				<category><![CDATA[Jakarta Commons]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://ronfrancis.wordpress.com/2007/03/16/on-commons-lang/</guid>
		<description><![CDATA[One of my favorite open source libraries is the Jakarta commons. I find myself using some methods and classes all the time. The top few, based on how often they appear in my code, are: StringUtils (org.apache.commons.lang) StringUtils.isNotEmpty(str): Sure beats having to do the following: if(str!= null &#38;&#38; str.length() &#62;0) { ---- } This can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=4&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of my favorite open source libraries is the Jakarta commons. I find myself using some methods and classes all the time. The top few, based on how often they appear in my code, are:</p>
<ol>
<li>
<h3><code>StringUtils (org.apache.commons.lang)</code></h3>
<p><code>StringUtils.isNotEmpty(str)</code>: Sure beats having to do the following:</p>
<pre class="brush: java;">
if(str!= null &amp;&amp; str.length() &gt;0) {
     ----
}</pre>
<p>This can be expressed simply as:</p>
<pre class="brush: java;">
if(StringUtils.isNotEmpty(str)){
   ----
}</pre>
<p><code>StringUtils.isEmpty(str)</code>, <code>StringUtils.isBlank(str)</code>, <code>StringUtils.isNotBlank (str)</code> have similar semantics, with intuitive handling of &#8220;null&#8221; variables.<br />
Check out the API docs for more time-savers.</li>
<li>
<h3><code>ToStringBuilder (org.apache.commons.lang.builder)</code></h3>
<p>Like most others, I find it invaluable to have a well defined toString method in every class I write. This is especially true of stateful classes(domain objects, DTOs etc).<br />
It is painful to write code like:</p>
<pre class="brush: java;">
public String toString() {
    StringBuffer buffer = new StringBuffer();
    buffer.append(&quot;Last Name=&quot;).append(lastName);
    buffer.append(&quot;First Name=&quot;).append(firstName);
}</pre>
<p>The quick and easy:</p>
<pre class="brush: java;">
   return ToStringBuilder.reflectionToString(this);</pre>
<p>If you want to customize which fields are included/excluded, it&#8217;s still simpler than using StringBuffer:</p>
<pre class="brush: java;">
   return new ToStringBuilder(this).
       append(&quot;firstName&quot;,this.firstName).
       append(&quot;lastName&quot;,this.lastName).toString();</pre>
<p>Note: There are many options available like changing the default output format, including the superclass etc. Check out the API for more details.</li>
<li>
<h3><code>EqualsBuilder and HashCodeBuilder (org.apache.commons.lang.builder)</code></h3>
<p>Again, a really simple way to write good <code>equals</code> and<code>hashCode</code> methods:</p>
<pre class="brush: java;">
public boolean equals(Object other) {
   return EqualsBuilder.reflectionEquals(this, other);
}
public int hashCode() {
    return HashCodeBuilder.reflectionHashCode(17,37,this);
}</pre>
<p>See Also: <code>CompareToBuilder </code></li>
<li>
<h3><code>Validate (org.apache.commons.lang)</code></h3>
<p>A good practice is to always ensure that arguments to a method call are correct. For example,</p>
<pre class="brush: java;">
   public void doSomething(Long aLong, Collection aCollection){
      if(aLong == null) {
          throw new IllegalArgumentException(&quot;aLong is null&quot;);
   }

   if(aCollection == null  || aCollection.isEmpty()) {
      throw new IllegalArgumentException(  &quot;aCollection is null or empty&quot;);
   }
   ---
}</pre>
<p>This can be expressed more concisely:</p>
<pre class="brush: java;">
public void doSomething(Long aLong, Collection aCollection){
  Validate.notNull(aLong, &quot;aLong is null&quot;);
  Validate.notEmpty(aCollection, &quot;aCollection is null or empty&quot;);
   -----
}</pre>
</li>
</ol>
<p>The above mentioned are but a few of the useful and elegant methods on the commons lang API. The web site is <a href="http://jakarta.apache.org/commons/lang/">http://jakarta.apache.org/commons/lang/</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ronfrancis.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ronfrancis.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ronfrancis.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ronfrancis.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ronfrancis.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ronfrancis.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ronfrancis.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ronfrancis.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ronfrancis.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ronfrancis.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ronfrancis.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ronfrancis.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ronfrancis.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ronfrancis.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ronfrancis.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ronfrancis.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ronfrancis.wordpress.com&amp;blog=2500403&amp;post=4&amp;subd=ronfrancis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ronfrancis.wordpress.com/2007/03/16/on-commons-lang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3eef9344a78bb7d70a1a3df65929f83d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ron Francis</media:title>
		</media:content>
	</item>
	</channel>
</rss>
