1 Reply Latest reply on Feb 25, 2009 6:45 PM by Pulkit Singhal

    Connection striping (or labeling) with JBoss and Hibernate

    Pulkit Singhal Newbie

      Connection striping (or labeling) involves applying user-defined attributes to a connection and making the state of the attributes persist when the connection is returned back to the cache. This striping speeds up future connection retrieval, because cached connections don't have to reinitialize their state every time they are retrieved.

      For example:
      - You may run "alter session ..." statements in your ConnectionProvider implementation before returning from the getConnection() method.
      - It would be great if you didn't have to do this, every single time you called getConnection().
      - Usually when the connection is closed, it will be returned to the DataSource configured in JBoss. It would be beneficial if the connection was tagged in order to mark the changes that have already been made to it, then we would be able to avoid running need-less alter session statements on the connection when our ConnectionProvider gets it again from the DataSource.

      java.util.Properties connAttr = null;
      connAttr.setProperty("NLS_LANG", "ISO-LATIN-1");
      conn = ds.getConnection(connAttr);

      1) What is a good way to implement such a scheme in Hibernate to work with JBoss?
      2) I'm having problems identifying the connections returned from the DataSource because they are always wrapped in a new wrapper. Can anyone suggest an intelligent way of identifying the connections that are are simply being RE-returned from the DataSource's pool?
      I'm hoping to use the ConnectionProvider, itself, to maintain a map of the connections that it has already initialized but I can't do that if I can't identify connections when they come back wrapped in a new object from the DataSource :(

      Is there an interface or class that can be used to gain some control over the JBoss DataSource or plug into it?

      I was thinking about working with the Hibernate's Cache and CacheProvider interfaces to come up with a solution but right now ... I can't imagine how I would be able to implement tagging on (specify Properties for) each of the connections.

      Any one out there with some comments?

        • 1. Re: Connection striping (or labeling) with JBoss and Hiberna
          Pulkit Singhal Newbie

          It usually make sense to leverage Hibernate’s DriverManagerConnectionProvider when working with a DataSource configured via config files and accessible via JNDI.

          But the problem is that the JBoss implementation of the DataSource mechanism ... wraps the Connection objects in a Wrapper (WrappedConnection.java) every time.

          It is possible to get at the underlying connection by casting the Connection object to WrappedConnection and then invoking the getUnderlyingConnection() method. This is great as it allows Connection objects to be identified as they come & go to the pool over and over. BUT isn't there a cleaner way to do this?

          In Java 1.6, the Connection interface extends the Wrapper interface which requires the implementation of a unwrap() method, that seems a lot more generic but I'm not sure which version of JBoss is up to date with Java 6 in order to allow its user to do that... any comments?