Tuesday, August 30, 2005

Monday, August 29, 2005

Getting the underlying JDBC Connection from JBoss wrapped Connect ion.

While using connection pools with xa-datasource and xa-connections, sometimes it becomes necessary to extract the underlying JDBC connection object from the wrapped connection object returned by a JBoss datasource look-up. This is especially the case when you want to invoke some of the non-standard methods which are provided by the DataSource and Connection implementations that you are using. We will use reflection to invoke the getUnderlyingConnection() method on the wrapped connection returned by ds.getConnection( ) at runtime.
 
private static Connection con;
private Connection jbosscon;
private Class wrappedConnectionClass;
private Method getUnderlyingConnectionMethod;
 
 
try {
            this.wrappedConnectionClass = getClass().getClassLoader().loadClass("org.jboss.resource.adapter.jdbc.WrappedConnection");
            this.getUnderlyingConnectionMethod = this.wrappedConnectionClass.getMethod("getUnderlyingConnection", (Class[]) null);
            Context jndiCntx = new InitialContext();
            
            DataSource ds = (javax.sql.DataSource)jndiCntx.lookup("java:/jdbc/sibr" );
            jbosscon = ds.getConnection(db_user,getUserPasswd(db_user));
            con = (Connection) this.getUnderlyingConnectionMethod.invoke(jbosscon, (Object[]) null);
            con.setAutoCommit(false);
}
catch (Exception e) {
           e.printStackTrace();
}

Some kind of monster (2004)

This was a DVD that I've been waiting to watch -  partly because I've been a Metallica fan in my younger years, and partly because of the voyeuristic pleasure associated with reality shows that seems to have taken over show-biz these days. Directors Bruce Sinofsky and Joe Berlinger have had previous experience with the band while making their critically acclaimed documentary Paradise Lost. They have made SKOM to be one hell of a back-stage "All access" pass which is both intense and hilarious at the same time..

Tuesday, August 23, 2005

St. Mary's Basilica





America's first Basilica, also co-cathedral for the twin cities of St. Paul and Minneapolis.

Monday, August 22, 2005

Autographs, Deep Purple



All the band members obliged to sign, and Steve Morse threw in a pick too! But this T ain't mine! ;-)

Kids wanna rock...



"War of bands" at Lakers' Park, Plymouth

Tuesday, August 16, 2005

Java 5

When you take an element out of a Collection, you must cast it to the type of element that is stored in the collection. Besides being inconvenient, this is unsafe. The compiler does not check that your cast is the same as the collection's type, so the cast can fail at run time.
 
Generics provides a way for you to communicate the type of a collection to the compiler, so that it can be checked. Once the compiler knows the element type of the collection, the compiler can check that you have used the collection consistently and can insert the correct casts on values being taken out of the collection.
 
Here is a simple example taken from the existing Collections tutorial:
 
// Removes 4-letter words from c. Elements must be strings
static void expurgate(Collection c) {
    for (Iterator i = c.iterator(); i.hasNext(); )
      if (((String) i.next()).length() == 4)
        i.remove();
}
 
Here is the same example modified to use generics:
 
// Removes the 4-letter words from c
static void expurgate(Collection<String> c) {
    for (Iterator<String> i = c.iterator(); i.hasNext(); )
      if (i.next().length() == 4)
        i.remove();
}
 
When you see the code <Type>, read it as “of Type”; the declaration above reads as “Collection of String c.” The code using generics is clearer and safer. We have eliminated an unsafe cast and a number of extra parentheses. More importantly, we have moved part of the specification of the method from a comment to its signature, so the compiler can verify at compile time that the type constraints are not violated at run time. Because the program compiles without warnings, we can state with certainty that it will not throw a ClassCastException at run time. The net effect of using generics, especially in large programs, is improved readability and robustness.
 

Thursday, August 11, 2005

Minneapolis:

Hiawatha Light Rail, Skyline

Mall of America

Once the biggest mall in the world, still the most visited..