<?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>BitterSweetJaVa</title>
	<atom:link href="http://bittersweetjava.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bittersweetjava.wordpress.com</link>
	<description>Just another IT blog</description>
	<lastBuildDate>Sat, 14 May 2011 10:03:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bittersweetjava.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>BitterSweetJaVa</title>
		<link>http://bittersweetjava.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bittersweetjava.wordpress.com/osd.xml" title="BitterSweetJaVa" />
	<atom:link rel='hub' href='http://bittersweetjava.wordpress.com/?pushpress=hub'/>
		<item>
		<title>New Home&#8230;</title>
		<link>http://bittersweetjava.wordpress.com/2010/02/17/new-home/</link>
		<comments>http://bittersweetjava.wordpress.com/2010/02/17/new-home/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 04:11:21 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=279</guid>
		<description><![CDATA[this blog is now hosted at http://www.bittersweetjava.com.ar/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=279&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>this blog is now hosted at <a href="http://www.bittersweetjava.com.ar/">http://www.bittersweetjava.com.ar/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/279/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=279&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2010/02/17/new-home/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>JEXL Basic Example</title>
		<link>http://bittersweetjava.wordpress.com/2010/01/07/jexl-basic-example/</link>
		<comments>http://bittersweetjava.wordpress.com/2010/01/07/jexl-basic-example/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 17:39:24 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Jexl]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=272</guid>
		<description><![CDATA[&#8220;Java Expression Language (JEXL) is an expression language engine which can be embedded in applications and frameworks&#8221;. Although the last time that the official site was generated was on march 08 (for version 1.1), there is recent activity on JIRA regarding the release of version 2. import org.apache.commons.jexl.Expression; import org.apache.commons.jexl.ExpressionFactory; import org.apache.commons.jexl.JexlContext; import org.apache.commons.jexl.JexlHelper; public [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=272&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8220;<a href='http://commons.apache.org/jexl/index.html'>Java Expression Language (JEXL)</a> is an expression language engine which can be embedded in applications and frameworks&#8221;. </p>
<p>Although the last time that the official site was generated was on march 08 (for version 1.1), there is recent activity on JIRA regarding the release of version 2.</p>
<p><code><br />
import org.apache.commons.jexl.Expression;<br />
import org.apache.commons.jexl.ExpressionFactory;<br />
import org.apache.commons.jexl.JexlContext;<br />
import org.apache.commons.jexl.JexlHelper;<br />
</code><code><br />
public class JEXLExample {<br />
</code><code><br />
	public static void main(String[] args) {<br />
		MyObject myObject = new MyObject();<br />
</code><code><br />
		String expr;<br />
		expr = "(myObject.number1 + myObject.number2) / myObject.number3";<br />
		processExpression(myObject, expr);<br />
		expr = "(N1 + N2) / N3";<br />
		processExpression(myObject, expr);<br />
		expr = "myObject.itsTrue";<br />
		processExpression(myObject, expr);<br />
		expr = "myObject.itsFalse";<br />
		processExpression(myObject, expr);<br />
</code><code><br />
		expr = "myObject.getThePresident().equals('Barack Obama')";<br />
		processExpression(myObject, expr);<br />
		expr = "myObject.thePresident.equals(\"George Bush\")";<br />
		processExpression(myObject, expr);<br />
</code><code><br />
	}<br />
</code><code><br />
	/**<br />
	 * @param containerObject<br />
	 * @param expression<br />
	 */<br />
	private static void processExpression(MyObject containerObject, String expression) {<br />
		try {<br />
			Expression e = ExpressionFactory.createExpression(expression);<br />
			JexlContext jc = JexlHelper.createContext();<br />
			//"myObject" is the alias to be used for expression evaluation<br />
			jc.getVars().put("myObject", containerObject);<br />
			jc.getVars().put("N1", containerObject.getNumber1());<br />
			jc.getVars().put("N2", containerObject.getNumber2());<br />
			jc.getVars().put("N3", containerObject.getNumber3());<br />
			System.out.println("Evaluating: " + expression );<br />
			System.out.println("  \\--------&gt; " + e.evaluate(jc) );<br />
		} catch (Exception e) {<br />
			e.printStackTrace();<br />
		}<br />
	}<br />
}<br />
</code></p>
<p>Notice the method <strong>processExpression</strong>, inside is where our expression is evaluated and the result is printed in the console.<br />
First, we create an Expression object using the ExpressionFactory provided by Jexl, passing our expression as parameter.</p>
<p><code>Expression e = ExpressionFactory.createExpression(expression);</code></p>
<p>Then, we create the context in which our expression is going to be evaluated:</p>
<p><code>JexlContext jc = JexlHelper.createContext();</code></p>
<p>And finally, we add the variables into our context. These are the ones that can be used inside the expression.</p>
<p><code>jc.getVars().put("myObject", containerObject);<br />
jc.getVars().put("N1", containerObject.getNumber1());<br />
jc.getVars().put("N2", containerObject.getNumber2());<br />
jc.getVars().put("N3", containerObject.getNumber3());</code></p>
<p>In the first line, I&#8217;m adding my <strong>containerObject</strong> object using the alias <strong>myObject</strong>.<br />
The last 3 lines just add a different alias for each one of the numbers stored in the containerObject.</p>
<p>Below is the (short) code for the class MyObject:</p>
<p><code><br />
public class MyObject {<br />
	private String thePresident = "Barack Obama";<br />
	private Boolean itsTrue = true;<br />
	private Boolean itsFalse = false;<br />
	private Integer number1 = 15;<br />
	private Integer number2 = 13;<br />
	private Integer number3 = 2;<br />
</code><code><br />
	...Getters &amp; Setters...<br />
}<br />
</code></p>
<p>This should be the output once you execute the example from above:</p>
<p><code><br />
Evaluating: (myObject.number1 + myObject.number2) / myObject.number3<br />
  \--------&gt; 14.0<br />
Evaluating: (N1 + N2) / N3<br />
  \--------&gt; 14.0<br />
Evaluating: myObject.itsTrue<br />
  \--------&gt; true<br />
Evaluating: myObject.itsFalse<br />
  \--------&gt; false<br />
Evaluating: myObject.getThePresident().equals('Barack Obama')<br />
  \--------&gt; true<br />
Evaluating: myObject.thePresident.equals("George Bush")<br />
  \--------&gt; false<br />
</code></p>
<p>I used Jexl in a previous project that I was involved. It&#8217;s very useful when you need to let the users enter expressions for filtering and calculation purposes.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/272/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=272&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2010/01/07/jexl-basic-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring Framework: Reference constants</title>
		<link>http://bittersweetjava.wordpress.com/2009/12/02/spring-framework-reference-constants/</link>
		<comments>http://bittersweetjava.wordpress.com/2009/12/02/spring-framework-reference-constants/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 20:59:28 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Spring Framework]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=251</guid>
		<description><![CDATA[First of all, add the util schema to the spring namespace: &#60;&#160;beans xmlns="http://www.springframework.org/schema/beans" &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;xmlns:util="http://www.springframework.org/schema/util" &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;xsi:schemaLocation=" &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;http://www.springframework.org/schema/beans &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;http://www.springframework.org/schema/beans/spring-beans-2.0.xsd &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;http://www.springframework.org/schema/util &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;http://www.springframework.org/schema/util/spring-util-2.0.xsd"&#62; then, we should be able to use it to bind static fields to a bean property: &#60;util:constant static-field="com.mycompany.myproject.myclass.STATIC_FIELD"/&#62;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=251&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>First of all, add the util schema to the spring namespace:</p>
<p><code>&lt;&nbsp;beans xmlns="http://www.springframework.org/schema/beans"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>xmlns:util="http://www.springframework.org/schema/util</strong>"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xsi:schemaLocation="<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/beans<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/beans/spring-beans-2.0.xsd<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>http://www.springframework.org/schema/util<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/util/spring-util-2.0.xsd</strong>"&gt;</code></p>
<p>then, we should be able to use it to bind static fields to a bean property:<br />
<code><strong>
<pre>&lt;util:constant static-field="com.mycompany.myproject.myclass.STATIC_FIELD"/&gt;</pre>
<p></strong></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/251/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=251&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2009/12/02/spring-framework-reference-constants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>Retrieve DB Objects from a legacy system using Hibernate</title>
		<link>http://bittersweetjava.wordpress.com/2009/11/30/retrieve-db-objects-from-a-legacy-system-using-hibernate/</link>
		<comments>http://bittersweetjava.wordpress.com/2009/11/30/retrieve-db-objects-from-a-legacy-system-using-hibernate/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 21:22:09 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Annotations]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[NamedNativeQueries]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=211</guid>
		<description><![CDATA[Problem: Load data from multiple tables into a single Java entity. Approach 1: Use custom SQL loading @Entity // Class that will store the query result(s). Class field names are the same than database column names. @SqlResultSetMapping(name = "customerMapping", entities = @EntityResult(entityClass = CustomerMapping.class)) // Using hibernate annotation to specify out custom SQL queries @org.hibernate.annotations.NamedNativeQueries( [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=211&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><u>Problem:</u> Load data from multiple tables into a single Java entity.</strong></p>
<p><strong><u>Approach 1:</u> Use custom SQL loading</strong></p>
<p><code><br />
@Entity<br />
// Class that will store the query result(s). Class field names are the same than database column names.<br />
@SqlResultSetMapping(name = "customerMapping", entities = @EntityResult(entityClass = CustomerMapping.class))<br />
// Using hibernate annotation to specify out custom SQL queries<br />
@org.hibernate.annotations.NamedNativeQueries(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@NamedNativeQuery(name = "loadAllCustomers",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;query = "select a.col1,a.col2,b.col1 from table1 a, table2 b where a.col5=b.col5",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resultSetMapping = "customerMapping"),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@NamedNativeQuery(name = "loadByCustNum",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;query = "select a.col1,a.col2,b.col1 from table1 a, table2 b where a.col5=b.col5 and a.col1 = ?",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resultSetMapping = "customerMapping")<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
)<br />
// Default SQL query to be used when loading this entity through Hibernate<br />
@Loader(namedQuery = "loadByCustNum")<br />
public class CustomerMapping implements Serializable {<br />
... class body<br />
}<br />
</code></p>
<p><strong><u>Approach 2:</u> Use one-to-one mapping approach</strong></p>
<p><code><br />
@Entity<br />
@Table(catalog = "myDB", schema = "dbo", name = "customer_mapping")<br />
public class CustomerMapping implements Serializable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@OneToOne<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Foreign Key pointing to the corresponding CustomerMaster data.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@JoinColumn(name = "gte_cust_num", unique = true, nullable = true)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Default hibernate action to be taken when the FK is not null and<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// it's not present in the secondary table.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Hibernate can ignore the error and do nothing or throw an exception.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@NotFound(action=NotFoundAction.IGNORE)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private CustomerMaster masterData;<br />
... class body<br />
}<br />
</code><br />
<code><br />
@Entity<br />
@Table(catalog="myDB", schema="dbo", name="customer_master")<br />
public class CustomerMaster implements Serializable {<br />
... class body<br />
}<br />
</code></p>
<p><u>NOTE:</u> Be careful when trying to retrieve the objects using HQL:</p>
<p><code>hql = "from CustomerMapping cmi where cmi.filterField = 'ABCXXX'";</code></p>
<p>The query above will result in a performance issue if we are retrieving several CustomerMapping objects. This is because hibernate will generate one query to get all the CustomerMapping objects and N queries to get the data to populate each CustomerMaster object (from the one-to-one relation).<br />
<code><br />
SELECT A,B,C FROM CustomerMapping WHERE filterField = 'ABCXXX';<br />
SELECT D,E,F FROM CustomerMaster WHERE id = ?;<br />
SELECT D,E,F FROM CustomerMaster WHERE id = ?;<br />
SELECT D,E,F FROM CustomerMaster WHERE id = ?;<br />
</code><br />
In other words, if we are retrieving <strong>N</strong> objects, then we will have <strong>N+1</strong> database queries.</p>
<p>In order to avoid this, we need to force Hibernate to use <strong>JOIN FETCH</strong> to retrieve the CustomerMaster data:</p>
<p><code>hql = "from CustomerMapping cmi <strong>left join fetch cmi.masterData</strong> where cmi.filterField = 'ABCXXX'";</code></p>
<p>The query above will produce only one sql query to retrieve CustomerMapping and CustomerMaster data using a <strong>join</strong>.<br />
<code><br />
SELECT A,B,C FROM CustomerMapping LEFT JOIN CustomerMaster (....) WHERE filterField = 'ABCXXX';<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/211/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=211&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2009/11/30/retrieve-db-objects-from-a-legacy-system-using-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>Port forwarding in VirtualBox</title>
		<link>http://bittersweetjava.wordpress.com/2009/11/29/port-forwarding-in-virtualbox/</link>
		<comments>http://bittersweetjava.wordpress.com/2009/11/29/port-forwarding-in-virtualbox/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 22:00:38 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Port Forwading]]></category>
		<category><![CDATA[Virtual Box]]></category>
		<category><![CDATA[VM]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=215</guid>
		<description><![CDATA[Here are useful commands to setup the port forwarding in a VirtualBox VM. -- Forward local port 8888 to VM port 80 (Apache httpd) VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/Protocol" TCP VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/GuestPort" 80 VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/HostPort" 8888 -- Forward local port 9090 to VM port 8080 (Apache Tomcat) VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/Protocol" TCP [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=215&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here are useful commands to setup the port forwarding in a VirtualBox VM.<br />
<code><br />
-- Forward local port 8888 to VM port 80 (Apache httpd)<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/Protocol" TCP<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/GuestPort" 80<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpd/HostPort" 8888<br />
</code><code><br />
-- Forward local port 9090 to VM port 8080 (Apache Tomcat)<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/Protocol" TCP<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/GuestPort" 8080<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/HostPort" 9090<br />
</code><code><br />
-- Forward local port 2222 to VM port 22 (SSH)<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22<br />
VBoxManage setextradata "Ubuntu" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222<br />
</code></p>
<ul>
<li><strong>Ubuntu</strong>: Represents the name of the VM.</li>
<li><strong>pcnet</strong>: Represents the driver of the network interface configured in the VM:</li>
<ul>
<li><em>pcnet</em> corresponds to the PCnet FAST II and PCnet FAST III devices</li>
<li><em>e1000</em> corresponds to the Intel PRO/1000 devices</li>
</ul>
<li><strong>0</strong>: Represent the network interface number (you can configure multiple network interfaces.</li>
<li><strong>&#8220;httpd&#8221;, &#8220;tomcat&#8221;, &#8220;ssh&#8221;</strong> are custom (and identifier) names for a particular configuration.</li>
<li><strong>Protocol</strong>: The protocol to be used, can be TCP or UDP</li>
<li><strong>GuessPort</strong>: The target port (in our VM)</li>
<li><strong>HostPort</strong>: The source port (in the PC hosting the VM)</li>
</ul>
<p><u>Note:</u> These commands need to be executed from the command line of the host operating system while the VM is off.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/215/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=215&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2009/11/29/port-forwarding-in-virtualbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>Proxy setup in Java / Maven / SVN project</title>
		<link>http://bittersweetjava.wordpress.com/2009/11/27/proxy-setup-in-java-maven-project/</link>
		<comments>http://bittersweetjava.wordpress.com/2009/11/27/proxy-setup-in-java-maven-project/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 16:59:28 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[S.C.M.]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Subclipse]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=206</guid>
		<description><![CDATA[To setup a proxy to be used by Maven only, you need to have it defined in the settings.xml file. This file is located in [USR_HOME]\.m2 directory (C:\Documents and Settings\[USERNAME]\.m2 for Windows users). Here&#8217;s an example of the file: &#60;settings&#62; &#160;&#160;&#60;proxies&#62; &#160;&#160;&#160;&#60;proxy&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#60;active&#62;true&#60;/active&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#60;protocol&#62;http&#60;/protocol&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#60;host&#62;[PROXY&#160;SERVER]&#60;/host&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#60;port&#62;[PROXY&#160;PORT]&#60;/port&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#60;username&#62;[PROXY&#160;USERNAME]&#60;/username&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#60;password&#62;[PROXY&#160;PASSWORD]&#60;/password&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#60;nonProxyHosts&#62;www.website1.com&#124;*.website2.com&#60;/nonProxyHosts&#62; &#160;&#160;&#160;&#160;&#60;/proxy&#62; &#160;&#160;&#60;/proxies&#62; &#60;/settings&#62; To setup a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=206&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To setup a proxy to be used by Maven only, you need to have it defined in the settings.xml file.<br />
This file is located in [USR_HOME]\.m2 directory (C:\Documents and Settings\[USERNAME]\.m2 for Windows users).<br />
Here&#8217;s an example of the file:</p>
<p><code><br />
&lt;settings&gt;<br />
&nbsp;&nbsp;&lt;proxies&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;proxy&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;active&gt;true&lt;/active&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;protocol&gt;http&lt;/protocol&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;host&gt;[PROXY&nbsp;SERVER]&lt;/host&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;port&gt;[PROXY&nbsp;PORT]&lt;/port&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;username&gt;[PROXY&nbsp;USERNAME]&lt;/username&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;password&gt;[PROXY&nbsp;PASSWORD]&lt;/password&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;nonProxyHosts&gt;www.website1.com|*.website2.com&lt;/nonProxyHosts&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/proxy&gt;<br />
&nbsp;&nbsp;&lt;/proxies&gt;<br />
&lt;/settings&gt;<br />
</code></p>
<p>To setup a proxy to be used for a Java application: </p>
<p><code><br />
System.getProperties().put("http.proxyHost", [PROXY SERVER]);<br />
System.getProperties().put("http.proxyPort", [PROXY PORT]);<br />
System.getProperties().put("http.proxyUser", [PROXY USERNAME]);<br />
System.getProperties().put("http.proxyPassword", [PROXY PASSWORD]);<br />
</code></p>
<p>To display the proxy server used for a particular URL:<br />
<code><br />
URL url = new URL("http://www.treasurydirect.gov/xml/CPI_20090814.xml");<br />
System.out.println(ProxySelector.getDefault().select(url.toURI()));<br />
</code></p>
<p><strong><u>Update Dec. 7, 2009:</u></strong> Proxy setup for Subversion command line and subclipse plugin (eclipse).</p>
<p>You should have a file named &#8216;<strong>servers</strong>&#8216; under <strong>C:\Documents and Settings\[USR_HOME]\Application Data\Subversion</strong>.<br />
The file has pretty good inline documentation.<br />
In my case, at the end of the file, I modified the following lines under <strong>[global]</strong> group:<br />
<code><br />
[global]<br />
http-proxy-host = [PROXY SERVER]<br />
http-proxy-port = [PROXY PORT]<br />
#http-proxy-username = [PROXY USERNAME]<br />
#http-proxy-password = [PROXY PASSWORD]<br />
http-compression = no<br />
http-auth-types = basic;digest;negotiate<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=206&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2009/11/27/proxy-setup-in-java-maven-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>Read metadata information using JDBC</title>
		<link>http://bittersweetjava.wordpress.com/2009/10/30/read-metadata-information-using-jdbc/</link>
		<comments>http://bittersweetjava.wordpress.com/2009/10/30/read-metadata-information-using-jdbc/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:58:37 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Metadata]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=192</guid>
		<description><![CDATA[Small example of how to get DB metadata using JDBC. import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.ResultSet; public class MetadataTest { &#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;public static void main(String args[]) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;try { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Connection conn = getMySQLConnection(); &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DatabaseMetaData md = conn.getMetaData(); &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ResultSet rsCatalogs = md.getCatalogs(); &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println("===================================================================="); &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println("Databases: "); &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;while(rsCatalogs.next()) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println(" * " + rsCatalogs.getString("TABLE_CAT")); &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;// [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=192&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Small example of how to get DB metadata using JDBC.<br />
<code><br />
import java.sql.Connection;<br />
import java.sql.DatabaseMetaData;<br />
import java.sql.DriverManager;<br />
import java.sql.ResultSet;<br />
</code><br />
<code><br />
public class MetadataTest {<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String args[]) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connection conn = getMySQLConnection();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DatabaseMetaData md = conn.getMetaData();<br />
</code><br />
<code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ResultSet rsCatalogs = md.getCatalogs();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("====================================================================");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Databases: ");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(rsCatalogs.next()) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(" * " + rsCatalogs.getString("TABLE_CAT"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</code><br />
<code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// getTables(catalog, schemaPattern, tableNamePattern, types)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ResultSet rsTables = md.getTables("metadata", null, null, null);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("====================================================================");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Tables: ");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print("\n");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(rsTables.next()) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String tableName = rsTables.getString("TABLE_NAME");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(" ** " + tableName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(" || Type: " + rsTables.getString("TABLE_TYPE"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(" || Catalog: " + rsTables.getString("TABLE_CAT"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(" || Scheme: " + rsTables.getString("TABLE_SCHEM"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//getTables(catalog, schemaPattern, tableNamePattern, columnNamePattern)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ResultSet rsColumns = md.getColumns("metadata",null,tableName,null);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(rsColumns.next()) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(" ====&gt; " + rsColumns.getString("COLUMN_NAME"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(", " + rsColumns.getString("TYPE_NAME"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(" (" + rsColumns.getString("COLUMN_SIZE"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("," + rsColumns.getInt("DECIMAL_DIGITS") + ")");<br />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("--------------------------------------------------------------------");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (Exception e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</code><br />
<code><br />
&nbsp;&nbsp;&nbsp;&nbsp;public static Connection getMySQLConnection() throws Exception {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connection conn;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Class.forName("com.mysql.jdbc.Driver").newInstance();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn = DriverManager.getConnection("jdbc:mysql:///metadata", "root",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return conn;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</code></p>
<p>The example above, displays all the databases available, plus tables/columns under database <strong>metadata</strong>. Below is the SQL script you can run (MySQL) to use with this example.<br />
<code><br />
CREATE DATABASE metadata;<br />
USE metadata;<br />
</code><br />
<code><br />
CREATE TABLE customers (<br />
  id                INT   NOT NULL   AUTO_INCREMENT   PRIMARY KEY,<br />
  customerName      VARCHAR(50),<br />
  customerMiddle    VARCHAR(1),<br />
  customerSurname   VARCHAR(50),<br />
  customerAge       TINYINT,<br />
  customerBirthdate DATETIME);<br />
</code><br />
<code><br />
CREATE TABLE stores (<br />
  id             INT   NOT NULL   AUTO_INCREMENT   PRIMARY KEY,<br />
  storeCode      INT,<br />
  storeName      VARCHAR(100),<br />
  storeAvgIncome DECIMAL(26,4));<br />
</code><br />
<code><br />
CREATE TABLE products (<br />
  id           INT   NOT NULL   AUTO_INCREMENT   PRIMARY KEY,<br />
  productCode  INT,<br />
  productName  VARCHAR(100),<br />
  productPrice FLOAT(8,2));<br />
</code><br />
<code><br />
CREATE TABLE stock (<br />
  id          INT   NOT NULL   AUTO_INCREMENT   PRIMARY KEY,<br />
  productCode INT,<br />
  storeCode   INT,<br />
  stock       SMALLINT UNSIGNED);<br />
</code><br />
<code><br />
CREATE VIEW v_Stock AS<br />
SELECT stores.storeCode,stores.storeName,products.productCode,products.productName,stock.stock<br />
FROM stock stock<br />
JOIN stores stores<br />
ON stock.storeCode = stores.storeCode<br />
JOIN products products<br />
ON stock.productCode = products.productCode;<br />
</code></p>
<p>Once you execute the java program, you should get something like this:<br />
<code><br />
====================================================================<br />
Databases:<br />
 * information_schema<br />
 * metadata<br />
 * mysql<br />
 * rbs<br />
 * test<br />
====================================================================<br />
Tables:<br />
</code><code><br />
 ** customers || Type: TABLE || Catalog: metadata || Scheme: null<br />
 ====&gt; id, INT (10,0)<br />
 ====&gt; customerName, VARCHAR (50,0)<br />
 ====&gt; customerMiddle, VARCHAR (1,0)<br />
 ====&gt; customerSurname, VARCHAR (50,0)<br />
 ====&gt; customerAge, INT (10,0)<br />
 ====&gt; customerBirthdate, DATETIME (19,0)<br />
--------------------------------------------------------------------<br />
 ** products || Type: TABLE || Catalog: metadata || Scheme: null<br />
 ====&gt; id, INT (10,0)<br />
 ====&gt; productCode, INT (10,0)<br />
 ====&gt; productName, VARCHAR (100,0)<br />
 ====&gt; productPrice, FLOAT (8,2)<br />
--------------------------------------------------------------------<br />
 ** stock || Type: TABLE || Catalog: metadata || Scheme: null<br />
 ====&gt; id, INT (10,0)<br />
 ====&gt; productCode, INT (10,0)<br />
 ====&gt; storeCode, INT (10,0)<br />
 ====&gt; stock, SMALLINT UNSIGNED (5,0)<br />
--------------------------------------------------------------------<br />
 ** stores || Type: TABLE || Catalog: metadata || Scheme: null<br />
 ====&gt; id, INT (10,0)<br />
 ====&gt; storeCode, INT (10,0)<br />
 ====&gt; storeName, VARCHAR (100,0)<br />
 ====&gt; storeAvgIncome, DECIMAL (26,2)<br />
--------------------------------------------------------------------<br />
 ** v_stock || Type: VIEW || Catalog: metadata || Scheme: null<br />
 ====&gt; storeCode, INT (10,0)<br />
 ====&gt; storeName, VARCHAR (100,0)<br />
 ====&gt; productCode, INT (10,0)<br />
 ====&gt; productName, VARCHAR (100,0)<br />
 ====&gt; stock, SMALLINT UNSIGNED (5,0)<br />
--------------------------------------------------------------------<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=192&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2009/10/30/read-metadata-information-using-jdbc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>Quartz Job</title>
		<link>http://bittersweetjava.wordpress.com/2009/09/23/quartz-job/</link>
		<comments>http://bittersweetjava.wordpress.com/2009/09/23/quartz-job/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 18:32:23 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Job]]></category>
		<category><![CDATA[Quartz]]></category>
		<category><![CDATA[Scheduling]]></category>
		<category><![CDATA[Servlet]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=162</guid>
		<description><![CDATA[For one of the applications that I&#8217;m maintaining, I was performing several manual validations on the tables a few times a day; in order to facilitate this tasks, I created a stored procedure to handle them and then send an email with the results using MSSQL mail service. Also, I wanted this procedure to be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=162&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For one of the applications that I&#8217;m maintaining, I was performing several manual validations on the tables a few times a day; in order to facilitate this tasks, I created a stored procedure to handle them and then send an email with the results using MSSQL mail service.<br />
Also, I wanted this procedure to be executed several times a day, that&#8217;s why I decided to use <a href="http://www.opensymphony.com/quartz/">Quartz</a> in order to create a scheduled job for my web application that will call my recently created procedure.</p>
<p>First, I created the class that will represent the Job I want to execute. This class <em>must</em> implement the class </p>
<p><strong>org.quartz.Job</strong>, overriding the method <em>execute(..)</em></p>
<p><code>package com.dashboard.util;<br />
import org.apache.log4j.Logger;<br />
import org.quartz.Job;<br />
import org.quartz.JobExecutionContext;<br />
import org.quartz.JobExecutionException;<br />
import com.dashboard.forms.DashboardForm;<br />
import com.dashboard.services.IService;<br />
import com.dashboard.services.ValuationHealthCheckService;<br />
</code><code><br />
public class ValuationHealthCheckJob implements Job {<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static final Logger logger = Logger.getLogger(ValuationHealthCheckService.class);<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void execute(JobExecutionContext arg0) throws JobExecutionException {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DashboardForm form = new DashboardForm();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;form.setEmailTo("xxxxx.yyyyy@domain.com");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IService service = new ValuationHealthCheckService();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service.execute(form);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (Exception e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;logger.error(e);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></p>
<p>As you can see, the body of the method execute is really simple. A <strong>DashboardForm</strong> class, which is simply a java bean with a field &#8220;<em>emailTo</em>&#8221; and then the creation and execution of my service class. The service class will take care of connecting to the database and execute the stored procedure that will verify the tables and send an email with the result.<br />
Here&#8217;s the <strong>ValuationHealthCheckService</strong> class:</p>
<p><code><br />
package com.dashboard.services;<br />
</code><code><br />
import java.sql.Connection;<br />
import java.sql.PreparedStatement;<br />
import java.sql.SQLException;<br />
import javax.naming.Context;<br />
import javax.naming.InitialContext;<br />
import javax.naming.NamingException;<br />
import javax.sql.DataSource;<br />
import org.apache.log4j.Logger;<br />
import com.dashboard.forms.DashboardForm;<br />
</code><code><br />
public class ValuationHealthCheckService implements IService {<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;private static final Logger logger = Logger.getLogger(ValuationHealthCheckService.class);<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void execute(Object o) throws NamingException, SQLException {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DashboardForm form = (DashboardForm) o;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connection con = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Context ctx = new InitialContext();<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/MarginDB");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;con = ds.getConnection();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String populateAttrs = "{call p_ValuationHealthCheck(?,?)}";<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;logger.info("{call p_ValuationHealthCheck(?,?)}");<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (form.getEmailTo() == null || form.getEmailTo().equals("")) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new RuntimeException("You must specify at least one email recipient.");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PreparedStatement populateAttrsStmt = con.prepareStatement(populateAttrs);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;populateAttrsStmt.setString(1, form.getEmailTo());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;populateAttrsStmt.setString(2, form.getEmailCC());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;populateAttrsStmt.execute();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;con.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></p>
<p>I&#8217;m retrieving the database connection using the <em>datasource</em> I have defined in <em>Tomcat</em>.<br />
After that, I needed to create the servlet in order to setup the schedule for the job.</p>
<p><code><br />
import java.text.ParseException;<br />
import javax.servlet.http.HttpServlet;<br />
import org.quartz.CronTrigger;<br />
import org.quartz.JobDetail;<br />
import org.quartz.Scheduler;<br />
import org.quartz.SchedulerException;<br />
import org.quartz.SchedulerFactory;<br />
import org.quartz.impl.StdSchedulerFactory;<br />
import com.dashboard.util.ValuationHealthCheckJob;<br />
<code></code><br />
public class QuartzServlet extends HttpServlet {<br />
<code></code><br />
&nbsp;&nbsp;&nbsp;&nbsp;public QuartzServlet() throws SchedulerException, ParseException {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SchedulerFactory sf = new StdSchedulerFactory();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scheduler sched = sf.getScheduler();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Specify the class of the job I want to execute<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JobDetail jd = new JobDetail("ValuationHealthCheck", "AppGroup", ValuationHealthCheckJob.class);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Create a CRON expression<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CronTrigger ct = new CronTrigger("cronTrigger", "cronTrigger", "<strong>0 0 15-19 * * ?</strong>");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Add into the Scheduler the job and the trigger<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sched.scheduleJob(jd, ct);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sched.start();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<code></code><br />
}</code></p>
<p>And as a final step, I needed to define the servlet in the <strong>web.xml</strong> file.<br />
<code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;servlet&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;servlet-name&gt;quartz&lt;/servlet-name&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;servlet-class&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;com.dashboard.servlets.QuartzServlet<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/servlet-class&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/servlet&gt;<br />
</code></p>
<p>Just restart the Tomcat so the servlet (and our job) is loaded. From now on, our job will be executed using the cron expression we defined in the servlet: <strong>0 0 15-19</strong> . This means that the job will be executed everyday, every hour from 15 (3:00 PM) to 19 (7:00PM).</p>
<p>&#8211;</p>
<p><strong><em>Just a note</em></strong>: Make sure you have the JAR file for Quartz in the WEB-INF/lib directory. I&#8217;m using maven for my web project so you just need to include the Quartz dependency in the <em>pom.xml</em>:<br />
<code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;dependency&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;opensymphony&lt;/groupId&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;quartz&lt;/artifactId&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;1.6.0&lt;/version&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;scope&gt;compile&lt;/scope&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/dependency&gt;<br />
</code></p>
<p>&#8211;</p>
<p>That&#8217;s all. This was the simplest solution I found for my problem (due to lack of time). However, I will work on the integration with Spring as soon as I have free time.<br />
<u>For more information on Quartz</u>: <a href="http://www.opensymphony.com/quartz/">http://www.opensymphony.com/quartz/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=162&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2009/09/23/quartz-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple XML parser + SQL Generation</title>
		<link>http://bittersweetjava.wordpress.com/2009/08/25/simple-xml-parser-sql-generation/</link>
		<comments>http://bittersweetjava.wordpress.com/2009/08/25/simple-xml-parser-sql-generation/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 15:18:14 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Financial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[Parser]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=136</guid>
		<description><![CDATA[Problem: Quick way to parse an XML stream from a website and generate a SQL script to populate a MSSQL table. Solution: import java.io.InputStream; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class XMLReader { public static void main(String argv[]) { try { URL url = new URL("http://www.treasurydirect.gov/xml/CPI_20090814.xml"); [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=136&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration:underline;"><strong>Problem:</strong></span> Quick way to parse an XML stream from a website and generate a SQL script to populate a MSSQL table.</p>
<p><strong><span style="text-decoration:underline;">Solution:</span></strong><br />
<code><br />
import java.io.InputStream;<br />
import java.net.URL;<br />
</code><code><br />
import javax.xml.parsers.DocumentBuilder;<br />
import javax.xml.parsers.DocumentBuilderFactory;<br />
</code><code><br />
import org.w3c.dom.Document;<br />
import org.w3c.dom.Element;<br />
import org.w3c.dom.Node;<br />
import org.w3c.dom.NodeList;<br />
</code><code><br />
public class XMLReader {<br />
</code><code><br />
public static void main(String argv[]) {<br />
</code><code><br />
try {<br />
URL url = new URL("http://www.treasurydirect.gov/xml/CPI_20090814.xml");<br />
InputStream is = url.openStream();<br />
</code><code><br />
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();<br />
DocumentBuilder db = dbf.newDocumentBuilder();<br />
Document doc = db.parse(is);<br />
doc.getDocumentElement().normalize();<br />
NodeList dailyIndexes = doc.getElementsByTagName("DailyIndexRatio");<br />
</code><code><br />
/*<br />
* &lt;DailyIndexRatio&gt;<br />
*   &lt;CUSIP&gt;912810FD5&lt;/CUSIP&gt;<br />
*   &lt;IssueDate&gt;1998-04-15&lt;/IssueDate&gt;<br />
*   &lt;Date&gt;2009-09-01&lt;/Date&gt;<br />
*   &lt;RefCPI&gt;215.69300&lt;/RefCPI&gt;<br />
*   &lt;IndexRatio&gt;1.33358&lt;/IndexRatio&gt;<br />
* &lt;/DailyIndexRatio&gt;<br />
*/<br />
</code><code><br />
for (int s = 0; s &lt; dailyIndexes.getLength(); s++) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;Node currentIndexNode = dailyIndexes.item(s);<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (currentIndexNode.getNodeType() == Node.ELEMENT_NODE) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;// DailyIndexRatio Element<br />
&nbsp;&nbsp;&nbsp;&nbsp;Element currentIndexElement = (Element) currentIndexNode;<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;// List of CUSIP Nodes<br />
&nbsp;&nbsp;&nbsp;&nbsp;NodeList cusipNodeList = currentIndexElement.getElementsByTagName("CUSIP");<br />
&nbsp;&nbsp;&nbsp;&nbsp;// CUSIP Element (1st one)<br />
&nbsp;&nbsp;&nbsp;&nbsp;Element cusipElmnt = (Element) cusipNodeList.item(0);<br />
&nbsp;&nbsp;&nbsp;&nbsp;// List of child nodes for CUSIP Element<br />
&nbsp;&nbsp;&nbsp;&nbsp;NodeList cusipChildNodes = cusipElmnt.getChildNodes();<br />
&nbsp;&nbsp;&nbsp;&nbsp;// Get the value of the 1st node (Text of CUSIP Element)<br />
&nbsp;&nbsp;&nbsp;&nbsp;//((Node) cusipChildNodes.item(0)).getNodeValue()<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;NodeList dateNodeList = currentIndexElement.getElementsByTagName("Date");<br />
&nbsp;&nbsp;&nbsp;&nbsp;Element dateElmnt = (Element) dateNodeList.item(0);<br />
&nbsp;&nbsp;&nbsp;&nbsp;NodeList dateChildNodes = dateElmnt.getChildNodes();<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;NodeList indexRatioNodeList = currentIndexElement.getElementsByTagName("IndexRatio");<br />
&nbsp;&nbsp;&nbsp;&nbsp;Element indexRatioElmnt = (Element) indexRatioNodeList.item(0);<br />
&nbsp;&nbsp;&nbsp;&nbsp;NodeList indexRatioChildNodes = indexRatioElmnt.getChildNodes();<br />
</code><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;// SQL SCRIPT GENERATION<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.print("INSERT INTO [CPIData] (Date, CUSIP, CPI) VALUES ('"<br />
&nbsp;&nbsp;&nbsp;&nbsp;+ ((Node) dateChildNodes.item(0)).getNodeValue() + "','");<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(((Node) cusipChildNodes.item(0)).getNodeValue() + "',");<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(((Node) indexRatioChildNodes.item(0)).getNodeValue() + ")");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</code><code><br />
}<br />
} catch (Exception e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
}<br />
}<br />
}<br />
</code><br />
Basically, I just needed the Consumer Price Indexes (CPI) that needs to be applied to a particular security (TIPS).<br />
This simple java app returns (console) the SQL script that we need to execute in order to have the CPI&#8217;s stored in the DB.</p>
<p><em><span style="text-decoration:underline;">Note:</span> This code has been tested using Eclipse 3.3 and JDK 6.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/136/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=136&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2009/08/25/simple-xml-parser-sql-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
		<item>
		<title>Property Reader in Spring Framework</title>
		<link>http://bittersweetjava.wordpress.com/2009/08/11/property-reader-in-spring-framework/</link>
		<comments>http://bittersweetjava.wordpress.com/2009/08/11/property-reader-in-spring-framework/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 14:55:03 +0000</pubDate>
		<dc:creator>.&#124;2ic&#124;K</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Properties]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://bittersweetjava.wordpress.com/?p=130</guid>
		<description><![CDATA[In order to add support to this feature, we must add inside the Spring Context file, the following bean definition: &#60;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&#62; &#160;&#160;&#160;&#160;&#60;property name="location"&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#60;value&#62;/WEB-INF/classes/MyPropertyFile.properties&#60;/value&#62; &#160;&#160;&#160;&#160;&#60;/property&#62; &#60;/bean&#62; Where MyPropertyFile.properties is the file that has stored the properties we need to get. By adding the definition above, we would be able to bind each one [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=130&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In order to add support to this feature, we must add inside the Spring Context file, the following bean definition:</p>
<p><code><br />
&lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;property name="location"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;value&gt;/WEB-INF/classes/MyPropertyFile.properties&lt;/value&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/property&gt;<br />
&lt;/bean&gt;<br />
</code></p>
<p>Where <strong><em>MyPropertyFile.properties</em></strong> is the file that has stored the properties we need to get.<br />
By adding the definition above, we would be able to bind each one of the properties from the file to a particular bean:</p>
<p><code>&lt;bean id="MyAppService" class="com.application.MyAppService"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;property name="fileNameProd"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;value&gt;${application.fileName.prod}&lt;/value&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/property&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;property name="fileNameQA"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;value&gt;${application.fileName.qa}&lt;/value&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/property&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;property name="fileNameUAT"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;value&gt;${application.fileName.uat}&lt;/value&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/property&gt;<br />
&lt;/bean&gt;</code></p>
<p>When we get the <em>MyAppService</em> Bean, the properties will be already loaded from our file.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bittersweetjava.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bittersweetjava.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bittersweetjava.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bittersweetjava.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bittersweetjava.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bittersweetjava.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bittersweetjava.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bittersweetjava.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bittersweetjava.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bittersweetjava.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bittersweetjava.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bittersweetjava.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bittersweetjava.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bittersweetjava.wordpress.com/130/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bittersweetjava.wordpress.com&amp;blog=6391978&amp;post=130&amp;subd=bittersweetjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bittersweetjava.wordpress.com/2009/08/11/property-reader-in-spring-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b2b55564627fccc7f167e8f537929150?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">allgoodthings</media:title>
		</media:content>
	</item>
	</channel>
</rss>
