if (log.isTraceEnabled()) { log.trace(JDBCUtil.statementToString(updateReferenceCount, new Integer(referenceCount), id) + " executed successfully"); }
if (trace) { log.trace(JDBCUtil.statementToString(updateReferenceCount, new Integer(referenceCount), id) + " executed successfully"); }
   public void storeMessage(Message m) throws Exception   {      Connection conn = null;      PreparedStatement ps = null;      TransactionWrapper wrap = new TransactionWrapper();      String id = (String)m.getMessageID();      try      {         conn = ds.getConnection();         // get the reference count from the database         // TODO Probably this can be done smarter than that incrementing directly in the database         ps = conn.prepareStatement(selectReferenceCount);         ps.setString(1, id);         int referenceCount = 0;         ResultSet rs = ps.executeQuery();         if (rs.next())         {            referenceCount = rs.getInt(1);         }         if (log.isTraceEnabled()) { log.trace(JDBCUtil.statementToString(selectReferenceCount, id) + " returned " + (referenceCount == 0 ? "no rows" : Integer.toString(referenceCount))); }         if (referenceCount == 0)         {            // physically insert the row in the database            //First set the fields from org.jboss.messaging.core.Routable            ps = conn.prepareStatement(insertMessage);            ps.setString(1, id);            ps.setString(2, m.isReliable() ? "Y" : "N");            ps.setLong(3, m.getExpiration());            ps.setLong(4, m.getTimestamp());            ps.setInt(5, m.getPriority());            ps.setInt(6, m.getDeliveryCount());            ps.setObject(7, ((MessageSupport)m).getHeaders());            //Now set the fields from org.jboss.messaging.core.Message            ps.setObject(8, m.getPayload());            //Now set the fields from org.joss.jms.message.JBossMessage if appropriate            int type = -1;            String jmsType = null;            Object correlationID = null;            boolean destIsQueue = false;            String dest = null;            boolean replyToIsQueue = false;            String replyTo = null;            Map jmsProperties = null;            String connectionID = null;            if (m instanceof JBossMessage)            {               JBossMessage jbm = (JBossMessage)m;               type = jbm.getType();               jmsType = jbm.getJMSType();               connectionID = jbm.getConnectionID();               if (jbm.isCorrelationIDBytes())               {                  correlationID = jbm.getJMSCorrelationIDAsBytes();               }               else               {                  correlationID = jbm.getJMSCorrelationID();               }               Destination d = jbm.getJMSDestination();               if (d != null)               {                  destIsQueue = d instanceof Queue;                  if (destIsQueue)                  {                     dest = ((Queue)d).getQueueName();                  }                  else                  {                     dest = ((Topic)d).getTopicName();                  }               }               Destination r = jbm.getJMSReplyTo();               if (r != null)               {                  replyToIsQueue = r instanceof Queue;                  if (replyToIsQueue)                  {                     replyTo = ((Queue)r).getQueueName();                  }                  else                  {                     replyTo = ((Topic)r).getTopicName();                  }               }               jmsProperties = jbm.getJMSProperties();            }            ps.setInt(9, type);            ps.setString(10, jmsType);            ps.setObject(11, correlationID);            ps.setString(12, destIsQueue ? "Y" : "N");            ps.setString(13, dest);            ps.setString(14, replyToIsQueue ? "Y" : "N");            ps.setString(15, replyTo);            ps.setString(16, connectionID);            ps.setObject(17, jmsProperties);            ps.setInt(18, 1);            int result = ps.executeUpdate();            if (log.isTraceEnabled()) { log.trace(JDBCUtil.statementToString(insertMessage, id) + " inserted " + result + " row(s)"); }         }         else         {            // increment the reference count            ps = conn.prepareStatement(updateReferenceCount);            ps.setInt(1, ++referenceCount);            ps.setString(2, id);            ps.executeUpdate();            if (log.isTraceEnabled()) { log.trace(JDBCUtil.statementToString(updateReferenceCount, new Integer(referenceCount), id) + " executed successfully"); }         }      }      catch (Exception e)      {         if (log.isTraceEnabled()) { log.trace(JDBCUtil.statementToString(insertMessage, id) + " failed"); }         wrap.exceptionOccurred();         throw e;      }      finally      {         if (ps != null)         {            try            {               ps.close();            }            catch (Throwable e)            {}         }         if (conn != null)         {            try            {               conn.close();            }            catch (Throwable e)            {}         }        wrap.end();      }   }