use of org.apache.qpid.server.protocol.v1_0.LinkKey in project qpid-broker-j by apache.
the class BDBLinkStore method save.
private void save(Database database, Transaction txn, final LinkDefinition<Source, Target> link) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
LinkKey linkKey = new LinkKey(link);
LinkKeyEntryBinding.getInstance().objectToEntry(linkKey, key);
LinkValueEntryBinding.getInstance().objectToEntry(new LinkValue(link), value);
// TODO: create transaction
OperationStatus status = database.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException(String.format("Cannot save link %s", linkKey));
}
}
use of org.apache.qpid.server.protocol.v1_0.LinkKey in project qpid-broker-j by apache.
the class LinkKeyEntryBinding method entryToObject.
@Override
public LinkKey entryToObject(final TupleInput input) {
String remoteContainerId = input.readString();
String linkName = input.readString();
Role role = null;
try {
role = Role.valueOf(input.readBoolean());
} catch (IllegalArgumentException e) {
throw new StoreException("Cannot load link from store", e);
}
final String remoteContainerId1 = remoteContainerId;
final String linkName1 = linkName;
final Role role1 = role;
return new LinkKey(remoteContainerId1, linkName1, role1);
}
use of org.apache.qpid.server.protocol.v1_0.LinkKey in project qpid-broker-j by apache.
the class JDBCLinkStore method doSaveLink.
@Override
protected void doSaveLink(final LinkDefinition<Source, Target> link) throws StoreException {
String linkKey = generateLinkKey(link);
Connection connection = getConnection();
try {
connection.setAutoCommit(false);
connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
try (PreparedStatement preparedStatement = connection.prepareStatement(String.format("SELECT remote_container_id, link_name, link_role, source, target FROM %s WHERE link_key = ?", getLinksTableName()))) {
preparedStatement.setString(1, linkKey);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
update(connection, linkKey, link);
} else {
insert(connection, linkKey, link);
}
}
}
connection.commit();
} catch (SQLException e) {
try {
connection.rollback();
} catch (SQLException re) {
LOGGER.debug("Rollback failed on rolling back saving link transaction", re);
}
throw new StoreException(String.format("Cannot save link %s", new LinkKey(link)), e);
} finally {
JdbcUtils.closeConnection(connection, LOGGER);
}
}
use of org.apache.qpid.server.protocol.v1_0.LinkKey in project qpid-broker-j by apache.
the class JDBCLinkStore method update.
private void update(final Connection connection, final String linkKey, final LinkDefinition<? extends BaseSource, ? extends BaseTarget> linkDefinition) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(String.format("UPDATE %s SET source = ?, target = ? WHERE link_key = ?", getLinksTableName()))) {
saveObjectAsBlob(statement, 1, linkDefinition.getSource());
saveObjectAsBlob(statement, 2, linkDefinition.getTarget());
statement.setString(3, linkKey);
if (statement.executeUpdate() != 1) {
throw new StoreException(String.format("Cannot save link %s", new LinkKey(linkDefinition)));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.LinkKey in project qpid-broker-j by apache.
the class JDBCLinkStore method doDeleteLink.
@Override
protected void doDeleteLink(final LinkDefinition<Source, Target> link) throws StoreException {
try (Connection connection = getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(String.format("DELETE FROM %s WHERE link_key = ?", getLinksTableName()))) {
preparedStatement.setString(1, generateLinkKey(link));
preparedStatement.execute();
} catch (SQLException e) {
throw new StoreException(String.format("Cannot delete link %s", new LinkKey(link)), e);
}
}
Aggregations