if (trace)
{
log.trace("Inserted " + rows + " rows");
}
Message m = ref.getMessage();
synchronized (m)
{
if (!m.isPersisted())
{
if (psInsertMessage == null)
{
psInsertMessage = conn
.prepareStatement(getSQLStatement("INSERT_MESSAGE"));
}
// First time so add message
// And in case of clustered queues/topics, the message
// could possibly be already persisted on the different
// node
// so we persist also using the Conditional Update
if (trace)
{
log
.trace("Message does not already exist so inserting it");
}
storeMessage(m, psInsertMessage, true);
rows = psInsertMessage.executeUpdate();
if (trace)
{
log.trace("Inserted " + rows + " rows");
}
m.setPersisted(true);
messagesStored.add(m);
}
}
}
// Now the removes
for (Iterator i = refsToRemove.iterator(); i.hasNext();)
{
ChannelRefPair pair = (ChannelRefPair) i.next();
if (psDeleteReference == null)
{
psDeleteReference = conn
.prepareStatement(getSQLStatement("DELETE_MESSAGE_REF"));
}
removeReference(pair.channelID, pair.ref, psDeleteReference);
int rows = psDeleteReference.executeUpdate();
if (trace)
{
log.trace("Deleted " + rows + " references");
}
}
return null;
}
catch (Exception e)
{
for (Iterator i = messagesStored.iterator(); i.hasNext();)
{
Message msg = (Message) i.next();
msg.setPersisted(false);
}
throw e;
}
finally
{