}
while (iter.hasNext())
{
//We may need to persist the message itself
MessageReference ref = (MessageReference) iter.next();
//For non reliable refs we insert the ref (and maybe the message) itself
if (!usingBatchUpdates)
{
psInsertReference = conn.prepareStatement(getSQLStatement("INSERT_MESSAGE_REF"));
}
//Now store the reference
addReference(channelID, ref, psInsertReference, paged);
if (usingBatchUpdates)
{
psInsertReference.addBatch();
}
else
{
int rows = updateWithRetry(psInsertReference);
if (trace)
{
log.trace("Inserted " + rows + " rows");
}
psInsertReference.close();
psInsertReference = null;
}
if (!usingBatchUpdates)
{
psInsertMessage = conn.prepareStatement(getSQLStatement("INSERT_MESSAGE"));
psUpdateMessage = conn.prepareStatement(getSQLStatement("INC_CHANNEL_COUNT"));
}
//Maybe we need to persist the message itself
Message m = ref.getMessage();
//In a paging situation, we cannot use the persisted flag on the message to determine whether
//to insert the message or not.
//This is because a channel (possibly on another node) may be paging too and referencing
//the same message, and might have removed the message independently, the other