use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method removeMessage.
private void removeMessage(long messageId) {
try (Connection conn = newConnection()) {
try {
try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + getMetaDataTableName() + " WHERE message_id = ?")) {
stmt.setLong(1, messageId);
int results = stmt.executeUpdate();
stmt.close();
if (results == 0) {
getLogger().debug("Message id {} not found (attempt to remove failed - probably application initiated rollback)", messageId);
}
getLogger().debug("Deleted metadata for message {}", messageId);
}
try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + getMessageContentTableName() + " WHERE message_id = ?")) {
stmt.setLong(1, messageId);
int results = stmt.executeUpdate();
}
conn.commit();
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException t) {
// ignore - we are re-throwing underlying exception
}
throw e;
}
} catch (SQLException e) {
throw new StoreException("Error removing message with id " + messageId + " from database: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method storeMetaData.
private void storeMetaData(Connection conn, long messageId, StorableMessageMetaData metaData) throws SQLException {
getLogger().debug("Adding metadata for message {}", messageId);
try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + getMetaDataTableName() + "( message_id , meta_data ) values (?, ?)")) {
stmt.setLong(1, messageId);
final int bodySize = 1 + metaData.getStorableSize();
byte[] underlying = new byte[bodySize];
underlying[0] = (byte) metaData.getType().ordinal();
try (QpidByteBuffer buf = QpidByteBuffer.wrap(underlying)) {
buf.position(1);
try (QpidByteBuffer bufSlice = buf.slice()) {
metaData.writeToBuffer(buf);
}
}
try (ByteArrayInputStream bis = new ByteArrayInputStream(underlying)) {
stmt.setBinaryStream(2, bis, underlying.length);
int result = stmt.executeUpdate();
if (result == 0) {
throw new StoreException("Unable to add meta data for message " + messageId);
}
} catch (IOException e) {
throw new SQLException("Failed to close ByteArrayInputStream", e);
}
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method createOrOpenMessageStoreDatabase.
protected void createOrOpenMessageStoreDatabase() throws StoreException {
try (Connection conn = newAutoCommitConnection()) {
createVersionTable(conn);
createQueueEntryTable(conn);
createMetaDataTable(conn);
createMessageContentTable(conn);
createXidTable(conn);
createXidActionTable(conn);
} catch (SQLException e) {
throw new StoreException("Failed to create message store tables", e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method dequeueMessage.
private void dequeueMessage(ConnectionWrapper connWrapper, final UUID queueId, Long messageId) throws StoreException {
Connection conn = connWrapper.getConnection();
try {
try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + getQueueEntryTableName() + " WHERE queue_id = ? AND message_id =?")) {
stmt.setString(1, queueId.toString());
stmt.setLong(2, messageId);
int results = stmt.executeUpdate();
if (results != 1) {
throw new StoreException("Unable to find message with id " + messageId + " on queue with id " + queueId);
}
getLogger().debug("Dequeuing message {} on queue with id {}", messageId, queueId);
}
} catch (SQLException e) {
getLogger().error("Failed to dequeue message {}", messageId, e);
throw new StoreException("Error deleting enqueued message with id " + messageId + " for queue with id " + queueId + " from database", e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method enqueueMessage.
private void enqueueMessage(ConnectionWrapper connWrapper, final TransactionLogResource queue, Long messageId) throws StoreException {
Connection conn = connWrapper.getConnection();
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Enqueuing message {} on queue {} with id {} [Connection {}]", messageId, queue.getName(), queue.getId(), conn);
}
try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + getQueueEntryTableName() + " (queue_id, message_id) values (?,?)")) {
stmt.setString(1, queue.getId().toString());
stmt.setLong(2, messageId);
stmt.executeUpdate();
}
} catch (SQLException e) {
getLogger().error("Failed to enqueue message {}", messageId, e);
throw new StoreException("Error writing enqueued message with id " + messageId + " for queue " + queue.getName() + " with id " + queue.getId() + " to database", e);
}
}
Aggregations