Saturday, January 26, 2013

Soundgarden setlist @ Orpheum Theatre, Boston, MA in 2013

Searching With My Good Eye Closed
Spoonman
Jesus Christ Pose
Outshined
By Crooked Steps
Taree
My Wave
Been Away Too Long
The Day I Tried to Live
Blow Up the Outside World
Fell on Black Days
Ugly Truth
Drawing Flies
Hunted Down
Non-State Actor
Blood on the Valley Floor
Mailman
A Thousand Days Before
Burden in My Hand
Head Down
Loud Love
4th of July

Encore:
Incessant Mace
Rusty Cage
Black Hole Sun
Slaves & Bulldozers

source: www.setlist.fm

Saturday, January 12, 2013

Ibatis return custom java object from query as List

Using IBatis if a sql query returns a number of rows and you need to IBatis to convert these rows to a java Object then you need to

1) create a resultMap entry where you map the propery in the java object to a column in a table
2) create a statement which contains the query and specify a resultMap (This is has been defined by above step 1)

using the above two configurations, Ibatis converts each row into a new MyClass() object and then populates it with the data from that row.

java code snippet
Map parameterMap = new HashMap();
parameterMap.put("inputNames", "abc");
      
List nameList = (List) getSqlMapClientTemplate().queryForList("getEmpDetails", parameterMap);
       
 

ibatis config       
<sqlMap namespace="myQueries">

    <resultMap id="idMap" class="com.test.MyClass">
        <result property="myId" column="ID_COLUMN_IN_DATABASE_TABLE"/>
        <result property="name" column="NAME_COLUMN_IN_DATABASE_TABLE"/>
    </resultMap>
   
    <statement id="getEmpDetails" resultMap="idMap"
        parameterClass="java.util.Map">
        select mytable.ID_COLUMN_IN_DATABASE_TABLE, mytable.NAME_COLUMN_IN_DATABASE_TABLE
        from mytable
        where mytable.name = #inputNames#
    </statement>
   
</sqlMap>

Using XStream to set xmlns attribute (xml namespace)

Thoughtworks xstream does not have an API to add xmlns attribute to xml root element. There is a work around to do the same using their useAttributeFor() API. Its a bit of hack but serves the purpose.

java pojo
public class TestXmlns {
    private String name;
    private String address;
    private String xmlns;
   
    ...get/set for above attributes.
   
}

create an instance of xstream and add below configuration
xstream.useAttributeFor(TestXmlns.class, "xmlns");

Example:
TestXmlns x1 = new TestXmlns();
x1.setName("abc");
x1.setAddress("zyx");
z1.setXmlns("http://com.company.mytest");

XStream xstream = new XStream();
xstream.useAttributeFor(TestXmlns.class, "xmlns");

String xmlString = xstream.toXML(x1);

output
<TestXmlns xmlns="http://com.company.mytest">
    <name>abc</name>
    <address>xyz</address>
</TestXmlns>

Convert java.util.Date to xsd:dateTime xml format

When converting java.util.Date to xml xsd dateTime format, one of the approaches is to use XMLGregorianCalendar class to format it to xml xsd format specifications.

input
new java.util.Date()

output
2013-01-12T10:30:09.274-05:00

code snippet:
String convertedDate = "";
GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("EST"));
//use below line to pass in a java.util.Date as an argument
//gc.setTime(date);
try {
       convertedDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc).toXMLFormat();
} catch (DatatypeConfigurationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}