if (rows != 1) { throw new IllegalStateException("Failed to update/delete message row for ref " + ref); }  if (trace) { log.trace("Delete/updated " + rows + " rows"); }
if (trace) { log.trace("Delete " + rows + " rows"); }
   public void removeReference(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.addReferenceToRemove(channelID, ref);      }      else      {                  //No tx so we remove the reference directly from the db                  TransactionWrapper wrap = new TransactionWrapper();                  PreparedStatement psReference = null;         PreparedStatement psMessage = null;                  Connection conn = ds.getConnection();                  Message m = ref.getMessage();                           boolean decremented = false;                  try         {            //get lock on message            LockMap.instance.obtainLock(m);                                          psReference = conn.prepareStatement(getSQLStatement("DELETE_MESSAGE_REF"));                        //Remove the message reference            removeReference(channelID, ref, psReference);                        int rows = psReference.executeUpdate();                        if (rows != 1)            {               throw new IllegalStateException("Failed to remove row for: " + ref);            }                        if (trace)            {               log.trace("Deleted " + rows + " rows");            }                        m.decPersistentChannelCount();            decremented = true;                                       if (m.getPersistentChannelCount() == 0)            {               //No other channels have a reference so we can delete the message               psMessage = conn.prepareStatement(getSQLStatement("DELETE_MESSAGE"));                                                removeMessage(m, psMessage);            }            else            {               //Other channel(s) still have hold references so update the channel count               psMessage = conn.prepareStatement(getSQLStatement("UPDATE_MESSAGE_CHANNELCOUNT"));                              updateMessageChannelCount(m, psMessage);            }                                          rows = psMessage.executeUpdate();                        if (rows != 1)            {               throw new IllegalStateException("Failed to update/delete message row for ref " + ref);            }                        if (trace)            {               log.trace("Delete/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() && decremented)               {                  //Reverse decrement                  m.incPersistentChannelCount();               }               //release the lock               LockMap.instance.releaseLock(m);            }         }            }   }