psMessage = conn.prepareStatement(insertMessage);   boolean added = checkStoreMessage(ref, psMessage);  if (added) {
synchronized (m) { m.incPersistentChannelCount();  if (m.getPersistentChannelCount() == 1) {  psMessage = conn.prepareStatement(insertMessage);  storeMessage(m, psMessage); } else {  psMessage = conn.prepareStatement(updateMessageChannelCount);  updateMessageChannelCount(m, psMessage); }
   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 in it's own jdbc tx         TransactionWrapper wrap = new TransactionWrapper();         PreparedStatement psReference = null;         PreparedStatement psMessage = null;         Connection conn = ds.getConnection();         try         {            psReference = conn.prepareStatement(insertMessageRef);            //Add the reference            addReference(channelID, ref, psReference);            int rows = psReference.executeUpdate();            if (trace)            {               log.trace("Inserted " + rows + " rows");            }            psMessage = conn.prepareStatement(insertMessage);            //Maybe we need to persist the message itself            boolean added = checkStoreMessage(ref, psMessage);            if (added)            {               rows = psMessage.executeUpdate();               if (trace)               {                  log.trace("Inserted " + 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)               {               }            }            wrap.end();         }      }   }