}
public boolean enqueue(QueueMessage messageInput) throws QueueException {
if (messageInput == null) {
throw new QueueException();
}
byte[] b = null;
if (messageInput.getObject() != null) {
b = SerializationUtility.serialize(messageInput.getObject());
// Check if the byte array can fit in the 'object' column.
// the 'object' column is a BIGINT and has the same max size as Integer.MAX_VALUE
if (b.length > Integer.MAX_VALUE) {
throw new IllegalArgumentException("The Object is to large, it can only be " + Integer.MAX_VALUE + " bytes.");
}
}
try {
PreparedStatement ps;
if (b != null) {
ps = conn.prepareStatement("INSERT INTO message (messageid, body, time, iserrormessage,object) VALUES(?, ?, ?, ?, ?)");
ps.setBinaryStream(5, new ByteArrayInputStream(b), b.length);
} else {
ps = conn.prepareStatement("INSERT INTO message (messageid, body, time, iserrormessage) VALUES(?, ?, ?, ?)");
}
ps.setString(1, messageInput.getMessageID());
ps.setString(2, messageInput.getBody());
ps.setLong(3, System.nanoTime());
ps.setBoolean(4, messageInput.isErrorMessage());
ps.executeUpdate();
ps.close();
return true;
} catch (SQLException e) {
logger.error(e);
throw new QueueException();
}
}