use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCConfigurationStore method openConfigurationStore.
@Override
public boolean openConfigurationStore(ConfiguredObjectRecordHandler handler, final ConfiguredObjectRecord... initialRecords) {
changeState(CONFIGURED, OPEN);
_deleteActions.clear();
try {
Collection<? extends ConfiguredObjectRecord> records = doVisitAllConfiguredObjectRecords(handler);
boolean isNew = records.isEmpty();
if (isNew) {
records = Arrays.asList(initialRecords);
try {
try (Connection conn = newConnection()) {
for (ConfiguredObjectRecord record : records) {
updateConfiguredObject(record, true, conn);
}
conn.commit();
}
} catch (SQLException e) {
throw new StoreException("Error updating configured objects in database: " + e.getMessage(), e);
}
}
for (ConfiguredObjectRecord record : records) {
handler.handle(record);
}
return isNew;
} catch (SQLException e) {
throw new StoreException("Cannot visit configured object records", e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method removeXid.
private void removeXid(ConnectionWrapper connWrapper, long format, byte[] globalId, byte[] branchId) throws StoreException {
Connection conn = connWrapper.getConnection();
try {
try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + getXidTableName() + " WHERE format = ? and global_id = ? and branch_id = ?")) {
stmt.setLong(1, format);
stmt.setBytes(2, globalId);
stmt.setBytes(3, branchId);
int results = stmt.executeUpdate();
if (results != 1) {
throw new StoreException("Unable to find message with xid");
}
}
try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + getXidActionsTableName() + " WHERE format = ? and global_id = ? and branch_id = ?")) {
stmt.setLong(1, format);
stmt.setBytes(2, globalId);
stmt.setBytes(3, branchId);
int results = stmt.executeUpdate();
}
} catch (SQLException e) {
getLogger().error("Failed to remove xid", e);
throw new StoreException("Error deleting enqueued message with xid", e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method commitTran.
private void commitTran(ConnectionWrapper connWrapper) throws StoreException {
try {
Connection conn = connWrapper.getConnection();
conn.commit();
getLogger().debug("commit tran completed");
conn.close();
} catch (SQLException e) {
throw new StoreException("Error commit tx", e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method addContent.
private void addContent(final Connection conn, long messageId, QpidByteBuffer contentBody) {
getLogger().debug("Adding content for message {}", messageId);
try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + getMessageContentTableName() + "( message_id, content ) values (?, ?)");
QpidByteBuffer bodyDuplicate = contentBody.duplicate();
InputStream inputStream = bodyDuplicate.asInputStream()) {
stmt.setLong(1, messageId);
stmt.setBinaryStream(2, inputStream, contentBody.remaining());
stmt.executeUpdate();
} catch (SQLException | IOException e) {
JdbcUtils.closeConnection(conn, getLogger());
throw new StoreException("Error adding content for message " + messageId + ": " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method setMaximumMessageId.
protected void setMaximumMessageId() {
try (Connection conn = newAutoCommitConnection()) {
setMaxMessageId(conn, "SELECT max(message_id) FROM " + getMessageContentTableName(), 1);
setMaxMessageId(conn, "SELECT max(message_id) FROM " + getMetaDataTableName(), 1);
setMaxMessageId(conn, "SELECT queue_id, max(message_id) FROM " + getQueueEntryTableName() + " GROUP BY queue_id ", 2);
} catch (SQLException e) {
throw new StoreException("Failed to determine maximum ids", e);
}
}
Aggregations