Unique constraint violation
celinemurphy Oct 6, 2005 4:30 AMShouldn't there be an order by messageid in this select statement?
Thanks
Celine
SELECT_MESSAGE = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?
public SpyMessage loadFromStorage(MessageReference messageRef) throws JMSException
{
if (log.isTraceEnabled())
log.trace("Loading message from storage " + messageRef);
TransactionManagerStrategy tms = new TransactionManagerStrategy();
tms.startTX();
Connection c = null;
PreparedStatement stmt = null;
ResultSet rs = null;
boolean threadWasInterrupted = Thread.interrupted();
try
{
c = this.getConnection();
stmt = c.prepareStatement(SELECT_MESSAGE);
stmt.setLong(1, messageRef.messageId);
stmt.setString(2, messageRef.getPersistentKey());
rs = stmt.executeQuery();
if (rs.next())
return extractMessage(rs, 2);
return null;
}
catch (IOException e)
{
tms.setRollbackOnly();
throw new SpyJMSException("Could not load message : " + messageRef, e);
}
catch (SQLException e)
{
tms.setRollbackOnly();
throw new SpyJMSException("Could not load message : " + messageRef, e);
}
finally
{
try
{
rs.close();
}
catch (Throwable ignore)
{
}
try
{
stmt.close();
}
catch (Throwable ignore)
{
}
try
{
c.close();
}
catch (Throwable ignore)
{
}
tms.endTX();
// Restore the interrupted state of the thread
if( threadWasInterrupted )
Thread.currentThread().interrupt();
}
}
protected SpyMessage extractMessage(ResultSet rs, int column) throws SQLException, IOException
{
long messageid = rs.getLong(1);
SpyMessage message = null;
if (blobType == OBJECT_BLOB)
{
message = (SpyMessage) rs.getObject(column);
}
else if (blobType == BYTES_BLOB)
{
byte[] st = rs.getBytes(column);
ByteArrayInputStream baip = new ByteArrayInputStream(st);
ObjectInputStream ois = new ObjectInputStream(baip);
message = SpyMessage.readMessage(ois);
}
else if (blobType == BINARYSTREAM_BLOB)
{
ObjectInputStream ois = new ObjectInputStream(rs.getBinaryStream(column));
message = SpyMessage.readMessage(ois);
}
else if (blobType == BLOB_BLOB)
{
ObjectInputStream ois = new ObjectInputStream(rs.getBlob(column).getBinaryStream());
message = SpyMessage.readMessage(ois);
}
message.header.messageId = messageid; return message;
}