use of org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl in project qpid-broker-j by apache.
the class BDBLinkStore method getLinkDefinitions.
private Collection<LinkDefinition<Source, Target>> getLinkDefinitions(final LinkStoreUpdater updater) {
Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
Collection<LinkDefinition<Source, Target>> links = new HashSet<>();
ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
ModelVersion storedVersion = getStoredVersion();
if (currentVersion.lessThan(storedVersion)) {
throw new StoreException(String.format("Cannot downgrade preference store from '%s' to '%s'", storedVersion, currentVersion));
}
try (Cursor cursor = linksDatabase.openCursor(null, null)) {
final DatabaseEntry key = new DatabaseEntry();
final DatabaseEntry value = new DatabaseEntry();
LinkKeyEntryBinding keyEntryBinding = LinkKeyEntryBinding.getInstance();
LinkValueEntryBinding linkValueEntryBinding = LinkValueEntryBinding.getInstance();
while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
LinkKey linkKey = keyEntryBinding.entryToObject(key);
LinkValue linkValue = linkValueEntryBinding.entryToObject(value);
LinkDefinition<Source, Target> link = new LinkDefinitionImpl<>(linkKey.getRemoteContainerId(), linkKey.getLinkName(), linkKey.getRole(), linkValue.getSource(), linkValue.getTarget());
links.add(link);
}
}
if (storedVersion.lessThan(currentVersion)) {
links = updater.update(storedVersion.toString(), links);
final Transaction txn = getEnvironmentFacade().beginTransaction(null);
try {
linksDatabase = getEnvironmentFacade().clearDatabase(txn, LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
for (LinkDefinition<Source, Target> link : links) {
save(linksDatabase, txn, link);
}
updateVersion(txn, currentVersion.toString());
txn.commit();
linksDatabase.close();
} catch (Exception e) {
txn.abort();
throw e;
}
}
return links;
}
use of org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl in project qpid-broker-j by apache.
the class JDBCLinkStore method getLinks.
private Collection<LinkDefinition<Source, Target>> getLinks() throws SQLException {
Collection<LinkDefinition<Source, Target>> links = new ArrayList<>();
try (Connection connection = getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(String.format("SELECT remote_container_id, link_name, link_role, source, target FROM %s", getLinksTableName()))) {
while (resultSet.next()) {
String remoteContainerId = getBlobValueAsString(resultSet, 1);
String linkName = getBlobValueAsString(resultSet, 2);
Role role = Role.valueOf(resultSet.getBoolean(3));
Source source = (Source) getBlobAsAmqpObject(resultSet, 4);
Target target = (Target) getBlobAsAmqpObject(resultSet, 5);
links.add(new LinkDefinitionImpl<>(remoteContainerId, linkName, role, source, target));
}
} catch (IllegalArgumentException e) {
throw new StoreException("Cannot load links from store", e);
}
return links;
}
Aggregations