<?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/"
	>

<channel>
	<title>lstierneyltd</title>
	<atom:link href="http://lstierneyltd.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://lstierneyltd.com/blog</link>
	<description>Yet another development blog</description>
	<lastBuildDate>Wed, 21 Jul 2010 08:49:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dos to Unix (Dos2Unix) with Eclipse</title>
		<link>http://lstierneyltd.com/blog/development/tips/dos-to-unix-dos2unix-with-eclipse/</link>
		<comments>http://lstierneyltd.com/blog/development/tips/dos-to-unix-dos2unix-with-eclipse/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 08:49:20 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[quick tips]]></category>
		<category><![CDATA[dos2unix]]></category>
		<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=175</guid>
		<description><![CDATA[1. Open the file in Eclipse that you wish to &#8220;Dos2Unix&#8221;
2. File -> Convert Line Delimiters To -> Unix
Profit!
]]></description>
			<content:encoded><![CDATA[<p>1. Open the file in Eclipse that you wish to &#8220;Dos2Unix&#8221;<br />
2. File -> Convert Line Delimiters To -> Unix</p>
<p>Profit!</p>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/tips/dos-to-unix-dos2unix-with-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Ibatis Typehandlers to fix Oracle Date &#8220;missing time&#8221;</title>
		<link>http://lstierneyltd.com/blog/development/examples/using-ibatis-typehandlers-to-fix-oracle-date-missing-time/</link>
		<comments>http://lstierneyltd.com/blog/development/examples/using-ibatis-typehandlers-to-fix-oracle-date-missing-time/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 11:25:44 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[ibatis]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=160</guid>
		<description><![CDATA[The Problem
When using Ibatis to retrieve Date type values, on Oracle 10g (some driver versions), the time portion of the value returned from the database is not mapped onto the Java object.
i.e.
In DB: 02-JAN-10 13:30:00
In Java Object after mapping: 02-JAN-10 00:00:00
The Ibatis ResultMapper, snippet, looks like this:

....
&#60;result property="savedDate" column="SAVED_DATE" javaType="java.util.Date" jdbcType="DATE"/&#62;
....


The Solution
1. Implement our old [...]]]></description>
			<content:encoded><![CDATA[<h4>The Problem</h4>
<p>When using Ibatis to retrieve Date type values, on Oracle 10g (some driver versions), the time portion of the value returned from the database is not mapped onto the Java object.</p>
<p>i.e.</p>
<p>In DB: <strong>02-JAN-10 13:30:00</strong><br />
In Java Object after mapping: <strong>02-JAN-10 00:00:00</strong></p>
<p>The Ibatis ResultMapper, snippet, looks like this:</p>
<pre>
....
&lt;result property="savedDate" column="SAVED_DATE" javaType="java.util.Date" jdbcType="DATE"/&gt;
....
</pre>
<p><code><span id="more-160"></span></code></p>
<h4>The Solution</h4>
<p>1. Implement our old friend the Ibatis TypeHandlerCallback.</p>
<pre class="brush: php">
package foo.bar;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;

public class CustomDateHandler implements TypeHandlerCallback {

    public Object getResult(ResultGetter getter) throws SQLException {
        final Object obj = getter.getTimestamp();
        return obj != null ? (Date) obj : null;
    }

    public void setParameter(ParameterSetter setter,Object value) throws SQLException {
        setter.setTimestamp(value != null ? new Timestamp(((Date)value).getTime()) : null);
    }

    public Object valueOf(String datetime) {
        return Timestamp.valueOf(datetime);
    }
}
</pre>
<p>2. Add Typehandlers and TypeAliases to Ibatis config</p>
<pre>
&lt;typeAlias alias="OracleDateHandler" type="foo.bar.CustomDateHandler"/&gt;
&lt;typeHandler callback="OracleDateHandler" jdbcType="DATETIME" javaType="date"/&gt;
</pre>
<p>3. Update resultMap to use new &#8220;type&#8221;</p>
<pre>
....
&lt;result property="savedDate" column="SAVED_DATE" javaType="java.util.Date" jdbcType="DATETIME"/&gt;
....
</pre>
<h4>Important Note!</h4>
<p>This solution deals with issues caused by certain versions of the Oracle JDBC drivers. I believe that the 11g drivers fix this issue. As ever YMMV&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/examples/using-ibatis-typehandlers-to-fix-oracle-date-missing-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing Spring apps with @RunWith(SpringJUnit4ClassRunner.class)</title>
		<link>http://lstierneyltd.com/blog/development/examples/unit-testing-spring-apps-with-runwithspringjunit4classrunner-class/</link>
		<comments>http://lstierneyltd.com/blog/development/examples/unit-testing-spring-apps-with-runwithspringjunit4classrunner-class/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 11:13:15 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=153</guid>
		<description><![CDATA[The Problem
I love Spring, who doesn&#8217;t?
One thing however that I found, until recently, a bit awkward was Unit Testing objects which were constructed and initiated via the Spring context and injected into other objects that consumed them. I have seen and used many and varied &#8220;bespoke&#8221; ways to do this, none of which I found [...]]]></description>
			<content:encoded><![CDATA[<h4>The Problem</h4>
<p>I love <a href="http://www.springsource.org/" target="_blank">Spring</a>, who doesn&#8217;t?</p>
<p>One thing however that I found, until recently, a bit awkward was Unit Testing objects which were constructed and initiated via the Spring context and injected into other objects that consumed them. I have seen and used many and varied &#8220;bespoke&#8221; ways to do this, none of which I found satisfying.</p>
<p>This was until a <a href="http://andrew.montheheids.com" target="_blank">collegue</a> introduced me to the wonder that is <a href="http://static.springsource.org/spring/docs/2.5.x/reference/testing.html" target="_blank">SpringJUnit4ClassRunner</a>. I know, I know, I should have been aware of this ages ago but as they say on millionaire &#8220;it&#8217;s easy if you know the answer&#8221;!<br />
<code><span id="more-153"></span></code></p>
<h4>Solution</h4>
<p>A few lines of code speaks more than a thousand words from me&#8230;&#8230;</p>
<pre class="brush: php">
package foo.bar;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={&quot;daos.xml&quot;})
public final class DaoTests {

    @Autowired
    private MyDao dao;

    @Test
    public void testLoadTitle() throws Exception {
        String result = dao.doSomething();
        assertNotNull(result);
    }
}
</pre>
<h4>Whats going on?</h4>
<p><strong><em>@RunWith(SpringJUnit4ClassRunner.class)</em></strong><br />
Quoting the docs: &#8220;SpringJUnit4ClassRunner is a custom extension of JUnit4ClassRunner which provides functionality of the Spring TestContext Framework to standard JUnit 4.4+ tests by means of the TestContextManager and associated support classes and annotations.&#8221;</p>
<p>Basically this means that tests are going to be able to get hold of instantiated beans as defined in the Spring context files (see below).</p>
<p><strong><em>@ContextConfiguration(locations={&#8220;daos.xml&#8221;})</em></strong><br />
This is telling the test where to get the context files containing the bean definitions. Note that if you do not provide any arguments to the annotation then a default will be looked for.</p>
<p>For example: If your class is named foo.bar.DaoTests, the context loader will attempt to load your application context from &#8220;classpath:/foo/bar/DaoTests-context.xml&#8221;.</p>
<p><strong><em>@Autowired</em></strong><br />
This will autowire BY TYPE, beans found in the context. Alternatively you could use @Resource to inject the dependencies by NAME (useful if several beans are of the same type)</p>
<h4>Conclusion</h4>
<p>Now it&#8217;s simply the case of adding a few annotations and a few imports to be able easily write tests which use Spring beans. All in all, a very unobtrusive (and fast) process.</p>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/examples/unit-testing-spring-apps-with-runwithspringjunit4classrunner-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ibatis TypeHandlerCallback Enum Example</title>
		<link>http://lstierneyltd.com/blog/development/examples/ibatis-typehandlercallback-enum-example/</link>
		<comments>http://lstierneyltd.com/blog/development/examples/ibatis-typehandlercallback-enum-example/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 11:29:53 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[ibatis]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=147</guid>
		<description><![CDATA[Problem
You need Ibatis to perform custom processing before parameters are set on a Prepared Statement or after the results are retrieved from the result set. Maybe to convert Y/N to boolean, map results to custom objects etc
Solution
You probably want to look at implementing Ibatis&#8217; TypeHandlerCallBack, the API docs for which are here

Example
In this example I [...]]]></description>
			<content:encoded><![CDATA[<h4>Problem</h4>
<p>You need Ibatis to perform custom processing before parameters are set on a Prepared Statement or after the results are retrieved from the result set. Maybe to convert Y/N to boolean, map results to custom objects etc</p>
<h4>Solution</h4>
<p>You probably want to look at implementing Ibatis&#8217; TypeHandlerCallBack, the API docs for which are <a target="_blank" href="http://ibatis.apache.org/docs/java/user/com/ibatis/sqlmap/client/extensions/TypeHandlerCallback.html">here</a><br />
<code><span id="more-147"></span></code></p>
<h4>Example</h4>
<p>In this example I map a &#8220;prev&#8221; or &#8220;next&#8221; coming back from the DB (as &#8220;direction&#8221;) to the Enum described in <a href="http://lstierneyltd.com/blog/development/java-5-enum-example/" target="_blank" >this post</a>.</p>
<h4>Ibatis Config</h4>
<pre class="brush: php">
&lt;parameterMap id=&quot;findByCompanyIdParams&quot; class=&quot;map&quot;&gt;
    &lt;parameter mode=&quot;IN&quot; property=&quot;companyId&quot; javaType=&quot;java.lang.String&quot; jdbcType=&quot;VARCHAR&quot;/&gt;
    &lt;parameter mode=&quot;IN&quot; property=&quot;nextKeyId&quot; javaType=&quot;java.lang.String&quot; jdbcType=&quot;VARCHAR&quot;/&gt;
    &lt;parameter mode=&quot;IN&quot; property=&quot;maxOccurs&quot; javaType=&quot;java.lang.Integer&quot; jdbcType=&quot;NUMBER&quot;/&gt;
    &lt;parameter mode=&quot;IN&quot; property=&quot;direction&quot; javaType=&quot;OBJECT&quot;
        typeHandler=&quot;foo.bar.PagingCriteriaDirectionTypeHandlerCallback&quot; jdbcType=&quot;VARCHAR&quot;/&gt;
    &lt;parameter mode=&quot;OUT&quot; property=&quot;outCursor&quot; jdbcType=&quot;ORACLECURSOR&quot; javaType=&quot;java.sql.ResultSet&quot;/&gt;
&lt;/parameterMap&gt;
</pre>
<h4>Java code</h4>
<pre class="brush: php">
package foo.bar;

import java.sql.SQLException;

import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
import foo.bar.MyRuntimeException;

public class PagingCriteriaDirectionTypeHandlerCallback implements TypeHandlerCallback{

	public Object getResult(ResultGetter getter) throws SQLException {
		String s = getter.getString();
		if (PagingCriteriaDirection.NEXT.getDescription().equalsIgnoreCase(s)) {
			return PagingCriteriaDirection.NEXT;
		} else if (PagingCriteriaDirection.PREV.getDescription().equalsIgnoreCase(s)) {
			return PagingCriteriaDirection.PREV;
		} else {
			throw new SQLException(&quot;Unexpected value &quot; + s + &quot; found where &quot;
					+ PagingCriteriaDirection.PREV.getDescription() + &quot; or &quot; + PagingCriteriaDirection.NEXT.getDescription() + &quot; was expected.&quot;);
		}
	}

	public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {
		PagingCriteriaDirection direction = (PagingCriteriaDirection) parameter;

		if (direction.equals(PagingCriteriaDirection.NEXT)) {
			setter.setString(PagingCriteriaDirection.NEXT.getDescription());
		}
		else {
			setter.setString(PagingCriteriaDirection.PREV.getDescription());
		}
	}

	public Object valueOf(String s) {
	    if (PagingCriteriaDirection.NEXT.getDescription().equalsIgnoreCase(s)) {
	        return PagingCriteriaDirection.NEXT;
	    }
	    else if (PagingCriteriaDirection.PREV.getDescription().equalsIgnoreCase(s)) {
	        return PagingCriteriaDirection.PREV;
	    }
	    else {
	    	throw new MyRuntimeException(&quot;Unexpected value &quot; + s + &quot; found where &quot;
					+ PagingCriteriaDirection.PREV.getDescription() + &quot; or &quot; + PagingCriteriaDirection.NEXT.getDescription() + &quot; was expected.&quot;);
	    }
	}

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/examples/ibatis-typehandlercallback-enum-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 5 Enum Example</title>
		<link>http://lstierneyltd.com/blog/development/java-5-enum-example/</link>
		<comments>http://lstierneyltd.com/blog/development/java-5-enum-example/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 10:00:49 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=142</guid>
		<description><![CDATA[Description
This simple example of a Java 5 Enum models a PREV/NEXT you might commonly see in a web app.

package foo.bar;

public enum PagingCriteriaDirection {
    NEXT(&#34;Next&#34;), PREV(&#34;Previous&#34;);

    private String description;

    private PagingCriteriaDirection(String desc){
        description = desc;
    }

  [...]]]></description>
			<content:encoded><![CDATA[<h4>Description</h4>
<p>This simple example of a Java 5 Enum models a PREV/NEXT you might commonly see in a web app.</p>
<pre class="brush: php">
package foo.bar;

public enum PagingCriteriaDirection {
    NEXT(&quot;Next&quot;), PREV(&quot;Previous&quot;);

    private String description;

    private PagingCriteriaDirection(String desc){
        description = desc;
    }

    public String getDescription() {
    	return description;
    }

    @Override
    public String toString() {
    	return description;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/java-5-enum-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JUnit 4 Test Class with annotations</title>
		<link>http://lstierneyltd.com/blog/development/examples/junit-4-test-class-with-annotations/</link>
		<comments>http://lstierneyltd.com/blog/development/examples/junit-4-test-class-with-annotations/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 11:15:05 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=139</guid>
		<description><![CDATA[A simple example of a JUnit 4 Test class marked up with annotations.


import org.junit.*;
import static org.junit.Assert.*; 

public class SampleTest {
    private java.util.List emptyList; 

    /**
     * Sets up the test fixture.
     * (Called before every test case method.)
    [...]]]></description>
			<content:encoded><![CDATA[<p>A simple example of a JUnit 4 Test class marked up with annotations.<br />
<code><span id="more-139"></span></code></p>
<pre class="brush: php">
import org.junit.*;
import static org.junit.Assert.*; 

public class SampleTest {
    private java.util.List emptyList; 

    /**
     * Sets up the test fixture.
     * (Called before every test case method.)
     */
    @Before
    public void setUp() {
        emptyList = new java.util.ArrayList();
    } 

    /**
     * Tears down the test fixture.
     * (Called after every test case method.)
     */
    @After
    public void tearDown() {
        emptyList = null;
    } 

    @Test
    public void testSomeBehavior() {
        assertEquals(&quot;Empty list should have 0 elements&quot;, 0, emptyList.size());
    } 

    @Test(expected=IndexOutOfBoundsException.class)
    public void testForException() {
        Object o = emptyList.get(0);
    }
}
</pre>
<h4>Points of note</h4>
<p>The <em>static</em> import of org.junit.Assert.*</p>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/examples/junit-4-test-class-with-annotations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAXB @XmlAnyElement example</title>
		<link>http://lstierneyltd.com/blog/development/tips/jaxb-xmlanyelement-example/</link>
		<comments>http://lstierneyltd.com/blog/development/tips/jaxb-xmlanyelement-example/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 15:06:52 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[quick tips]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=134</guid>
		<description><![CDATA[The problem
I was recently working on a JAXB centric app which was required to capture &#8220;arbitary&#8221; xml. e.g.

&#60;a&#62;
   &#60;b&#62;&#60;/b&#62;
   &#60;c&#62;&#60;/c&#62;
   &#60;d&#62;
       &#60;!-- &#34;Unknown&#34; XML here --&#62;
       &#60;maybeE&#62;&#60;/maybeE&#62;
       &#60;maybeF&#62;&#60;/maybeF&#62;
    [...]]]></description>
			<content:encoded><![CDATA[<h4>The problem</h4>
<p>I was recently working on a JAXB centric app which was required to capture &#8220;arbitary&#8221; xml. e.g.</p>
<pre class="brush: php">
&lt;a&gt;
   &lt;b&gt;&lt;/b&gt;
   &lt;c&gt;&lt;/c&gt;
   &lt;d&gt;
       &lt;!-- &quot;Unknown&quot; XML here --&gt;
       &lt;maybeE&gt;&lt;/maybeE&gt;
       &lt;maybeF&gt;&lt;/maybeF&gt;
       &lt;!-- etc etc --&gt;
   &lt;d/&gt;
&lt;/a&gt;
</pre>
<p>How could I ever capture the contents of <d> if they could be &#8220;anything&#8221;?<br />
<code><span id="more-134"></span></code></p>
<h4>The solution</h4>
<pre class="brush: php">
@XmlRootElement(name=&quot;a&quot;)
public class A { 

   @XmlElement
   private String b; 

   @XmlElement
   private String c; 

   @XmlAnyElement
   private List&lt;Element&gt; content;
}
</pre>
<h4>What&#8217;s going on?</h4>
<p>The <strong>@XmlAnyElement </strong> annotation instructs JAXB to hoover up any elements which aren&#8217;t already annotated/associated with a field and store their DOM representation in:</p>
<pre>
private List<Element> content;
</pre>
<p>You could then do something like:</p>
<pre class="brush: php">
public String getContentAsString() throws Exception{
    StringBuilder builder = new StringBuilder();
    for (Node node: operations) {
        StringWriter writer = new StringWriter();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, &quot;yes&quot;);
        transformer.transform(new DOMSource(node), new StreamResult(writer));
        builder.append(writer.toString());
    }
    return builder.toString();
}
</pre>
<p>To get the nested XML as String.</p>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/tips/jaxb-xmlanyelement-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to convert a CLOB to an XMLType in Oracle</title>
		<link>http://lstierneyltd.com/blog/development/tips/how-to-convert-a-clob-to-an-xmltype-in-oracle/</link>
		<comments>http://lstierneyltd.com/blog/development/tips/how-to-convert-a-clob-to-an-xmltype-in-oracle/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 13:17:23 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[quick tips]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[plsql]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=125</guid>
		<description><![CDATA[Not much comment to add here; code says it all

PROCEDURE clobToXMLType(myClob IN CLOB)

IS
    l_xmlType XMLTYPE;
    -- do something
BEGIN
    l_xmltype := XMLTYPE.createXML(myClob);

EXCEPTION

    WHEN OTHERS THEN
    	RAISE;

END clobToXMLType;

]]></description>
			<content:encoded><![CDATA[<p>Not much comment to add here; code says it all</p>
<pre>
PROCEDURE clobToXMLType(myClob IN CLOB)

IS
    l_xmlType XMLTYPE;
    -- do something
BEGIN
    l_xmltype := XMLTYPE.createXML(myClob);

EXCEPTION

    WHEN OTHERS THEN
    	RAISE;

END clobToXMLType;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/tips/how-to-convert-a-clob-to-an-xmltype-in-oracle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log4j Nested Diagnostic Contexts (NDC)</title>
		<link>http://lstierneyltd.com/blog/development/log4j-nested-diagnostic-contexts-ndc/</link>
		<comments>http://lstierneyltd.com/blog/development/log4j-nested-diagnostic-contexts-ndc/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 18:31:57 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How to's]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[log4j]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=118</guid>
		<description><![CDATA[Introduction and Problem
Log4j is a brilliant set of libraries which provides good &#8220;out of the box&#8221; logging capabilities.
Sometimes however, in multi-threaded environments (for example web apps), it can be hard to decipher the interleaved messages from the various clients

e.g.
Client A logs something
Client B logs something
Client A logs something
Client C logs something
Client A logs something
Client A [...]]]></description>
			<content:encoded><![CDATA[<h4>Introduction and Problem</h4>
<p>Log4j is a brilliant set of libraries which provides good &#8220;out of the box&#8221; logging capabilities.</p>
<p>Sometimes however, in multi-threaded environments (for example web apps), it can be hard to decipher the interleaved messages from the various clients<br />
<code><span id="more-118"></span></code><br />
e.g.</p>
<p>Client A logs something<br />
Client B logs something<br />
Client A logs something<br />
Client C logs something<br />
Client A logs something<br />
Client A logs something<br />
Client B logs something<br />
Client A logs something</p>
<p>Getting hard to read already!</p>
<h4>Solution</h4>
<p>Luckily for us Log4j has a built in solution to this common problem: Nested Diagnostic Contexts.</p>
<p>To quote the API doc &#8220;A Nested Diagnostic Context, or NDC in short, is an instrument to distinguish interleaved log output from different sources. Log output is typically interleaved when a server handles multiple clients near-simultaneously. </p>
<p>Interleaved log output can still be meaningful if each log entry from different contexts had a distinctive stamp. This is where NDCs come into play&#8230;.&#8221; </p>
<p><a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html">http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html</a></p>
<p>The simple example below applies NDC to a Message Driven Bean (MDB):</p>
<h4>Sample Java Code</h4>
<pre>
package test.controller;

import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.log4j.Logger;
import org.apache.log4j.NDC;

public class Log4jDiagnosticContextSetter implements MessageListener {

    private static final Logger LOG = Logger.getLogger(Log4jDiagnosticContextSetter.class);

    private MessageListener messageListener;

    public void onMessage(Message message) {
        boolean loggingContextIsSet = addLoggingContextData(message);

        try {
            messageListener.onMessage(message); // the bean does its stuff
        }
        finally {
            if (loggingContextIsSet){
                removeLoggingContextData();
            }
        }
    }

    private boolean addLoggingContextData(Message message) {
        if (!LOG.isInfoEnabled())
            return false;

        try {
            NDC.push(getUniqueRef());
        }
        catch (Exception e) {
            LOG.error("Error pushing identifier onto Log4J NDC stack.", e);

            return false;
        }

        return true;
    }

    private void removeLoggingContextData() {
        try {
            while (NDC.getDepth() != 0) {
                NDC.pop();
            }
        }
        catch (Exception e) {
            LOG.error("Error popping message ID off of Log4J NDC stack.", e);
    }

    private String getUniqueRef() {
        // some way to get a unique reference
    }
}
</pre>
<h4>Sample Log Output</h4>
<p>You can see here in the example log output the result of the NDC push code above (in this case &#8220;98765432&#8243; is the unique identifier)</p>
<pre>
[02/06/2010 12:49:34:883 BST] [MessageListenerThreadPool : 0] DEBUG AuditServiceListener [98765432] - Processing message
[02/06/2010 12:49:34:883 BST] [MessageListenerThreadPool : 0] DEBUG ServiceMsgProcessor  [98765432] - Starting processing of XML request. Request=(<someMessage></someMessage>)
[02/06/2010 12:49:34:883 BST] [MessageListenerThreadPool : 0] DEBUG RequestUnmarshaller  [98765432] - Unmarshalling XML request payload to object.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/log4j-nested-diagnostic-contexts-ndc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache Config for reduced bandwidth usage</title>
		<link>http://lstierneyltd.com/blog/development/apache-config-for-reduced-bandwidth-usage/</link>
		<comments>http://lstierneyltd.com/blog/development/apache-config-for-reduced-bandwidth-usage/#comments</comments>
		<pubDate>Sun, 30 May 2010 12:47:48 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=85</guid>
		<description><![CDATA[This snippet of an Apache config (httpd.conf) attempts to implement an intelligent caching policy in order to reduce the amount of files needlessly served. Obviously you would only want to do this once your site has moved into test or production environment. Basic tests using YSlow firefox plugin show bandwidth usage reduced by almost 90%.


&#60;VirtualHost [...]]]></description>
			<content:encoded><![CDATA[<p>This snippet of an Apache config (httpd.conf) attempts to implement an intelligent caching policy in order to reduce the amount of files needlessly served. Obviously you would only want to do this once your site has moved into test or production environment. Basic tests using <a href="https://addons.mozilla.org/en-US/firefox/addon/5369">YSlow firefox plugin</a> show bandwidth usage reduced by almost 90%.<br />
<code><span id="more-85"></span></code></p>
<pre>
&lt;VirtualHost *:80&gt;
    ServerAdmin info@myhost.co.uk
    DocumentRoot /var/www/mysite/public_html/
    ServerName mysite.myhost.co.uk
    ErrorLog logs/mysite.myhost-error_log
    CustomLog logs/mysite.myhost-access_log common
    &lt;Directory /var/www/mysite/&gt;
      Options All
      AllowOverride All
      Order allow,deny
      Allow from all
    &lt;/Directory&gt;
Header unset ETag
FileETag None

# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 year (forever?)
&lt;FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"&gt;
ExpiresDefault A29030400
Header append Cache-Control "public"
&lt;/FilesMatch&gt;

# Set up caching on media files for 1 week
&lt;FilesMatch "\.(gif|jpg|jpeg|png|swf)$"&gt;
ExpiresDefault A604800
Header append Cache-Control "public"
&lt;/FilesMatch&gt;

# Set up 2 Hour caching on commonly updated files
&lt;FilesMatch "\.(xml|txt|html|js|css)$"&gt;
ExpiresDefault A14515200
Header append Cache-Control "proxy-revalidate"
&lt;/FilesMatch&gt;

# Force no caching for dynamic files
&lt;FilesMatch "\.(php|cgi|pl|htm)$"&gt;
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
&lt;/FilesMatch&gt;

&lt;Location /&gt;
# Compress output
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
&lt;/Location&gt;
&lt;/VirtualHost&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/apache-config-for-reduced-bandwidth-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
