storeMessage(m, psMessage);
storeMessage(m, psMessage);  m.setPersisted(true);
   public void addReference(long channelID, MessageReference ref, Transaction tx) throws Exception   {            if (tx != null)      {         //In a tx so we just add the ref in the tx in memory for now         TransactionCallback callback = getCallback(tx);         callback.addReferenceToAdd(channelID, ref);      }      else      {                  //No tx so add the ref directly in the db                  TransactionWrapper wrap = new TransactionWrapper();                  PreparedStatement psReference = null;         PreparedStatement psMessage = null;                  Connection conn = ds.getConnection();                  Message m = ref.getMessage();                       boolean incremented = false;                  try         {                        // Get lock on message            LockMap.instance.obtainLock(m);                                                psReference = conn.prepareStatement(getSQLStatement("INSERT_MESSAGE_REF"));                        // Add the reference            addReference(channelID, ref, psReference, false);                        int rows = psReference.executeUpdate();                                    if (trace)            {               log.trace("Inserted " + rows + " rows");            }                        m.incPersistentChannelCount();            incremented = true;                                       if (m.getPersistentChannelCount() == 1)            {               // First time so persist the message               psMessage = conn.prepareStatement(getSQLStatement("INSERT_MESSAGE"));                              storeMessage(m, psMessage);                    }            else            {               //Update the message's channel count               psMessage = conn.prepareStatement(getSQLStatement("UPDATE_MESSAGE_CHANNELCOUNT"));                              updateMessageChannelCount(m, psMessage);            }                                       rows = psMessage.executeUpdate();            if (trace)            {               log.trace("Inserted/updated " + rows + " rows");            }                                              }         catch (Exception e)         {            wrap.exceptionOccurred();            throw e;         }         finally         {            if (psReference != null)            {               try               {                  psReference.close();               }               catch (Throwable t)               {               }            }            if (psMessage != null)            {               try               {                  psMessage.close();               }               catch (Throwable t)               {               }            }            if (conn != null)            {               try               {                  conn.close();               }               catch (Throwable t)               {               }            }            try            {               wrap.end();            }            finally            {                  if (wrap.isFailed() && incremented)               {                  //reverse the inc                                    m.decPersistentChannelCount();                                 }                              //Release Lock               LockMap.instance.releaseLock(m);            }         }            }   }