<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Groovy Sql Closure Examples</title>
	<atom:link href="http://joeygibson.com/2008/10/19/groovy-sql-closure-examples/feed/" rel="self" type="application/rss+xml" />
	<link>http://joeygibson.com/2008/10/19/groovy-sql-closure-examples/</link>
	<description>Java, Scala, Groovy, Ruby, Python, Lisp, Objective-C, OSX, politics, religion, Koine Greek, Tae Kwon Do, Spanish and much more!</description>
	<lastBuildDate>Wed, 17 Mar 2010 22:18:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rick</title>
		<link>http://joeygibson.com/2008/10/19/groovy-sql-closure-examples/comment-page-1/#comment-830</link>
		<dc:creator>Rick</dc:creator>
		<pubDate>Sat, 21 Mar 2009 18:00:02 +0000</pubDate>
		<guid isPermaLink="false">http://joeygibson.com/?p=829#comment-830</guid>
		<description>I&#039;m also curious. I&#039;m using groovy.sql.Sql but passing a datasource(dbcp basicdatasource) into the constructor instead of passing passing in connection info through newInstance. I haven&#039;t looked at the groovy Sql source code, but do you know if there are still issues closing connections (returning them to the pool) if using a Datasource instead?</description>
		<content:encoded><![CDATA[<p>I&#8217;m also curious. I&#8217;m using groovy.sql.Sql but passing a datasource(dbcp basicdatasource) into the constructor instead of passing passing in connection info through newInstance. I haven&#8217;t looked at the groovy Sql source code, but do you know if there are still issues closing connections (returning them to the pool) if using a Datasource instead?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick</title>
		<link>http://joeygibson.com/2008/10/19/groovy-sql-closure-examples/comment-page-1/#comment-829</link>
		<dc:creator>Rick</dc:creator>
		<pubDate>Sat, 21 Mar 2009 17:50:59 +0000</pubDate>
		<guid isPermaLink="false">http://joeygibson.com/?p=829#comment-829</guid>
		<description>Nice article. I&#039;m surprised this isn&#039;t implemented by default either (maybe it is now?) 

Off topic a bit: I actually found this article while searching for a SqlBuilder... this surprises that one doesn&#039;t exist already? In other words a builder that lets you pass in dynamic sql. For example, you&#039;d pass in several WHERE clause conditions and the fields, and if the fields passed in aren&#039;t null it correctly builds the where clause and prepends the AND or ORs (if needed.) Same thing for IN lists etc when you pass in a collection. Also for ORDER BY (proper comma placements.) You could do similar things for dynamic 

I&#039;ll probably go ahead and write one, but just wondering if any of you know of one that someone has written already. Thanks.

I&#039;m new to groovy, but as an idea..

sql.build {
	Select( expr: &quot;SELECT * FROM FOOBAR&quot;)
	Where{
		AND( prop: foo, expr: &quot;animalType = &#039;${foo}&#039;&quot;)
		AND( prop: bar, expr: &quot;birthDate &gt; &#039;${bar}&#039;&quot;)
		AND( prop: sizes, in: &quot;animalSize&quot;)
	}
	 
}

foo = null, bar = null, sizes =[]:
Select * from foobar

foo = &#039;dog&#039;, bar= null, sizes =[]:
Select * from foobar WHERE animalType = &#039;dog&#039;
 
foo = &#039;dog&#039;, bar= &#039;2009-02-21&#039;, sizes =[4,5,6]:
Select * from foobar WHERE animalType = &#039;dog&#039; AND bithDate &gt; &#039;2009-02-21&#039; AND animalSize in (4,5,6)</description>
		<content:encoded><![CDATA[<p>Nice article. I&#8217;m surprised this isn&#8217;t implemented by default either (maybe it is now?) </p>
<p>Off topic a bit: I actually found this article while searching for a SqlBuilder&#8230; this surprises that one doesn&#8217;t exist already? In other words a builder that lets you pass in dynamic sql. For example, you&#8217;d pass in several WHERE clause conditions and the fields, and if the fields passed in aren&#8217;t null it correctly builds the where clause and prepends the AND or ORs (if needed.) Same thing for IN lists etc when you pass in a collection. Also for ORDER BY (proper comma placements.) You could do similar things for dynamic </p>
<p>I&#8217;ll probably go ahead and write one, but just wondering if any of you know of one that someone has written already. Thanks.</p>
<p>I&#8217;m new to groovy, but as an idea..</p>
<p>sql.build {<br />
	Select( expr: &#8220;SELECT * FROM FOOBAR&#8221;)<br />
	Where{<br />
		AND( prop: foo, expr: &#8220;animalType = &#8216;${foo}&#8217;&#8221;)<br />
		AND( prop: bar, expr: &#8220;birthDate &gt; &#8216;${bar}&#8217;&#8221;)<br />
		AND( prop: sizes, in: &#8220;animalSize&#8221;)<br />
	}</p>
<p>}</p>
<p>foo = null, bar = null, sizes =[]:<br />
Select * from foobar</p>
<p>foo = &#8216;dog&#8217;, bar= null, sizes =[]:<br />
Select * from foobar WHERE animalType = &#8216;dog&#8217;</p>
<p>foo = &#8216;dog&#8217;, bar= &#8216;2009-02-21&#8242;, sizes =[4,5,6]:<br />
Select * from foobar WHERE animalType = &#8216;dog&#8217; AND bithDate &gt; &#8216;2009-02-21&#8242; AND animalSize in (4,5,6)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Coleman</title>
		<link>http://joeygibson.com/2008/10/19/groovy-sql-closure-examples/comment-page-1/#comment-664</link>
		<dc:creator>Bill Coleman</dc:creator>
		<pubDate>Sat, 08 Nov 2008 16:40:25 +0000</pubDate>
		<guid isPermaLink="false">http://joeygibson.com/?p=829#comment-664</guid>
		<description>Categories really rock. Smalltalk started them, Objective-C has them, and even C# 3.0 has them (Of course, they call them &quot;Extension Methods&quot;)

Categories are a really excellent way to extend an existing framework class without having to resort to subclassing -- which is really useful when you don&#039;t always control the creation of instances.</description>
		<content:encoded><![CDATA[<p>Categories really rock. Smalltalk started them, Objective-C has them, and even C# 3.0 has them (Of course, they call them &#8220;Extension Methods&#8221;)</p>
<p>Categories are a really excellent way to extend an existing framework class without having to resort to subclassing &#8212; which is really useful when you don&#8217;t always control the creation of instances.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Flinchbaugh</title>
		<link>http://joeygibson.com/2008/10/19/groovy-sql-closure-examples/comment-page-1/#comment-656</link>
		<dc:creator>John Flinchbaugh</dc:creator>
		<pubDate>Mon, 03 Nov 2008 17:15:02 +0000</pubDate>
		<guid isPermaLink="false">http://joeygibson.com/?p=829#comment-656</guid>
		<description>Using the untyped category selector self has a strange side-effect of adding your newInstance method to *every* class, so I can say String.newInstance(&quot;url&quot;, &quot;login&quot;, &quot;password&quot;, &quot;driver&quot;) {con -&gt; } and your category method will be run.  Trying to define the method as newInstance(Sql self, url, login, password, closure) doesn&#039;t seem to add the *static* method.

You seem to have added a static method to Object, but I can&#039;t figure out how to add a static method to just Sql.

Anyone have any ideas?</description>
		<content:encoded><![CDATA[<p>Using the untyped category selector self has a strange side-effect of adding your newInstance method to *every* class, so I can say String.newInstance(&#8220;url&#8221;, &#8220;login&#8221;, &#8220;password&#8221;, &#8220;driver&#8221;) {con -&gt; } and your category method will be run.  Trying to define the method as newInstance(Sql self, url, login, password, closure) doesn&#8217;t seem to add the *static* method.</p>
<p>You seem to have added a static method to Object, but I can&#8217;t figure out how to add a static method to just Sql.</p>
<p>Anyone have any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joeygibson</title>
		<link>http://joeygibson.com/2008/10/19/groovy-sql-closure-examples/comment-page-1/#comment-611</link>
		<dc:creator>joeygibson</dc:creator>
		<pubDate>Tue, 21 Oct 2008 14:01:25 +0000</pubDate>
		<guid isPermaLink="false">http://joeygibson.com/?p=829#comment-611</guid>
		<description>Thanks, Egon. I should have remembered the ? operator. That&#039;s actually what piqued my interest in Groovy. I can&#039;t believe I forgot to include it.</description>
		<content:encoded><![CDATA[<p>Thanks, Egon. I should have remembered the ? operator. That&#8217;s actually what piqued my interest in Groovy. I can&#8217;t believe I forgot to include it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Egon</title>
		<link>http://joeygibson.com/2008/10/19/groovy-sql-closure-examples/comment-page-1/#comment-610</link>
		<dc:creator>Egon</dc:creator>
		<pubDate>Tue, 21 Oct 2008 12:18:37 +0000</pubDate>
		<guid isPermaLink="false">http://joeygibson.com/?p=829#comment-610</guid>
		<description>Great article, I really enjoyed it :-)

If con is null (i.e. Sql.newInstance throws an exception) con.close() will fail.
Just make it save: con?.close()

Likewise the lines
      if (closure)
      {
        closure.call(con)
      }
can be shortened to
      closure?.call(con)</description>
		<content:encoded><![CDATA[<p>Great article, I really enjoyed it :-)</p>
<p>If con is null (i.e. Sql.newInstance throws an exception) con.close() will fail.<br />
Just make it save: con?.close()</p>
<p>Likewise the lines<br />
      if (closure)<br />
      {<br />
        closure.call(con)<br />
      }<br />
can be shortened to<br />
      closure?.call(con)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
