use of org.apache.qpid.server.model.ModelVersion 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.model.ModelVersion in project qpid-broker-j by apache.
the class BDBLinkStore method getStoredVersion.
private ModelVersion getStoredVersion() throws RuntimeException {
try (Cursor cursor = getLinksVersionDb().openCursor(null, null)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
ModelVersion storedVersion = null;
while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
String versionString = StringBinding.entryToString(key);
ModelVersion version = ModelVersion.fromString(versionString);
if (storedVersion == null || storedVersion.lessThan(version)) {
storedVersion = version;
}
}
if (storedVersion == null) {
throw new StoreException("No link version information.");
}
return storedVersion;
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Cannot visit link version", e);
}
}
use of org.apache.qpid.server.model.ModelVersion in project qpid-broker-j by apache.
the class DerbyPreferenceStoreTest method testVersionAfterUpgrade.
public void testVersionAfterUpgrade() throws Exception {
ModelVersion storeVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION - 1, BrokerModel.MODEL_MINOR_VERSION);
_testConnection = DriverManager.getConnection(_connectionUrl);
try (Statement stmt = _testConnection.createStatement()) {
stmt.execute("CREATE TABLE PREFERENCES_VERSION ( version VARCHAR(20) NOT NULL )");
}
try (PreparedStatement pstmt = _testConnection.prepareStatement("INSERT INTO PREFERENCES_VERSION ( version ) VALUES ( ? )")) {
pstmt.setString(1, storeVersion.toString());
pstmt.execute();
}
_preferenceStore.openAndLoad(_updater);
ModelVersion storedVersion = _preferenceStore.getPreferencesVersion();
assertEquals("Unexpected version", BrokerModel.MODEL_VERSION, storedVersion.toString());
}
use of org.apache.qpid.server.model.ModelVersion in project qpid-broker-j by apache.
the class JDBCLinkStore method doOpenAndLoad.
@Override
protected Collection<LinkDefinition<Source, Target>> doOpenAndLoad(final LinkStoreUpdater updater) throws StoreException {
Collection<LinkDefinition<Source, Target>> linkDefinitions;
try {
checkTransactionIsolationLevel();
createOrOpenStoreDatabase();
linkDefinitions = getLinks();
ModelVersion storedVersion = getStoredVersion();
ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
if (storedVersion.lessThan(currentVersion)) {
linkDefinitions = performUpdate(updater, linkDefinitions, storedVersion, currentVersion);
} else if (currentVersion.lessThan(storedVersion)) {
throw new StoreException(String.format("Cannot downgrade the store from %s to %s", storedVersion, currentVersion));
}
} catch (SQLException e) {
throw new StoreException("Cannot open link store", e);
}
return linkDefinitions;
}
Aggregations