else
} else { int rows = psUpdateMessage.executeUpdate();  if (trace)
   public void addReferences(long channelID, List references, boolean loaded) throws Exception   {      Connection conn = null;      PreparedStatement psInsertReference = null;        PreparedStatement psInsertMessage = null;      PreparedStatement psUpdateMessage = null;      TransactionWrapper wrap = new TransactionWrapper();            try      {         conn = ds.getConnection();                  Iterator iter = references.iterator();                  boolean messageInsertsInBatch = false;         boolean messageUpdatesInBatch = false;                  if (usingBatchUpdates)         {            psInsertReference = conn.prepareStatement(insertMessageRef);            psInsertMessage = conn.prepareStatement(insertMessage);            psUpdateMessage = conn.prepareStatement(updateMessageChannelCount);         }                  while (iter.hasNext())         {            //We may need to persist the message itself             MessageReference ref = (MessageReference) iter.next();                        Message m = ref.getMessage();                                                //For non reliable refs we insert the ref (and maybe the message) itself                                       if (!usingBatchUpdates)            {               psInsertReference = conn.prepareStatement(insertMessageRef);            }                        //Now store the reference            addReference(channelID, ref, psInsertReference, loaded);                                    if (usingBatchUpdates)            {               psInsertReference.addBatch();            }            else            {               int rows = psInsertReference.executeUpdate();                              if (trace)               {                  log.trace("Inserted " + rows + " rows");               }                              psInsertReference.close();               psInsertReference = null;            }                        if (!usingBatchUpdates)            {               psInsertMessage = conn.prepareStatement(insertMessage);               psUpdateMessage = conn.prepareStatement(updateMessageChannelCount);            }                           synchronized (m)            {                                    m.incPersistentChannelCount();                                                            //Maybe we need to persist the message itself                 boolean added;               if (m.getPersistentChannelCount() == 1)               {                  //Hasn't been persisted before so need to persist the message                  storeMessage(m, psInsertMessage);                                    added = true;               }               else               {                  //Update the message with the new channel count                  updateMessageChannelCount(m, psUpdateMessage);                                    added = false;               }                              if (usingBatchUpdates)               {                  if (added)                  {                     psInsertMessage.addBatch();                     messageInsertsInBatch = true;                  }                  else                  {                     psUpdateMessage.addBatch();                     messageUpdatesInBatch = true;                  }               }               else               {                  if (added)                  {                     int rows = psInsertMessage.executeUpdate();                                                              if (trace)                     {                        log.trace("Inserted " + rows + " rows");                     }                  }                  else                  {                     int rows = psUpdateMessage.executeUpdate();                                         if (trace)                     {                        log.trace("Updated " + rows + " rows");                     }                  }                  psInsertMessage.close();                  psInsertMessage = null;                  psUpdateMessage.close();                  psUpdateMessage = null;               }                  }         }                  if (usingBatchUpdates)         {            int[] rowsReference = psInsertReference.executeBatch();                        if (trace)            {               logBatchUpdate(insertMessageRef, rowsReference, "inserted");            }                        if (messageInsertsInBatch)            {               int[] rowsMessage = psInsertMessage.executeBatch();                              if (trace)               {                  logBatchUpdate(insertMessage, rowsMessage, "inserted");               }            }            if (messageUpdatesInBatch)            {               int[] rowsMessage = psUpdateMessage.executeBatch();                              if (trace)               {                  logBatchUpdate(updateMessageChannelCount, rowsMessage, "updated");               }            }                        psInsertReference.close();            psInsertReference = null;            psInsertMessage.close();            psInsertMessage = null;            psUpdateMessage.close();            psUpdateMessage = null;         }      }      catch (Exception e)      {         wrap.exceptionOccurred();         throw e;      }      finally      {         if (psInsertReference != null)         {            try            {               psInsertReference.close();            }            catch (Throwable t)            {            }         }         if (psInsertMessage != null)         {            try            {               psInsertMessage.close();            }            catch (Throwable t)            {            }         }         if (psUpdateMessage != null)         {            try            {               psUpdateMessage.close();            }            catch (Throwable t)            {            }         }         if (conn != null)         {            try            {               conn.close();            }            catch (Throwable t)            {            }         }         wrap.end();      }         }