mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-22 21:55:39 +00:00
Bug 4770: SwissTiming and TracTrac configurations now have a unique
index on the JSON URL instead of the name
This commit is contained in:
+14
-12
@@ -88,9 +88,9 @@ public class SwissTimingAdapterPersistenceImpl implements SwissTimingAdapterPers
|
||||
DBCollection stConfigCollection = database.getCollection(CollectionNames.SWISSTIMING_CONFIGURATIONS.name());
|
||||
stConfigCollection.createIndex(new BasicDBObject(CollectionNames.SWISSTIMING_CONFIGURATIONS.name(), 1));
|
||||
// remove old, non working index
|
||||
dropIndexSafe(stConfigCollection, "SWISSTIMING_CONFIGURATIONS_1");
|
||||
// adding unique index by config name
|
||||
stConfigCollection.createIndex(new BasicDBObject(FieldNames.ST_CONFIG_NAME.name(), 1), "st_config_name_unique",
|
||||
dropIndexSafe(stConfigCollection, "SWISSTIMING_CONFIGURATIONS_1", "st_config_name_unique");
|
||||
// adding unique index by JSON URL
|
||||
stConfigCollection.createIndex(new BasicDBObject(FieldNames.ST_CONFIG_JSON_URL.name(), 1), "st_config_json_url_unique",
|
||||
true);
|
||||
|
||||
BasicDBObject result = new BasicDBObject();
|
||||
@@ -102,8 +102,8 @@ public class SwissTimingAdapterPersistenceImpl implements SwissTimingAdapterPers
|
||||
result.put(FieldNames.ST_CONFIG_UPDATE_USERNAME.name(), swissTimingConfiguration.getUpdateUsername());
|
||||
result.put(FieldNames.ST_CONFIG_UPDATE_PASSWORD.name(), swissTimingConfiguration.getUpdatePassword());
|
||||
|
||||
final BasicDBObject updateQuery = new BasicDBObject(FieldNames.ST_CONFIG_NAME.name(),
|
||||
swissTimingConfiguration.getName());
|
||||
final BasicDBObject updateQuery = new BasicDBObject(FieldNames.ST_CONFIG_JSON_URL.name(),
|
||||
swissTimingConfiguration.getJsonURL());
|
||||
stConfigCollection.update(updateQuery, result, true, false);
|
||||
}
|
||||
|
||||
@@ -112,9 +112,9 @@ public class SwissTimingAdapterPersistenceImpl implements SwissTimingAdapterPers
|
||||
SwissTimingArchiveConfiguration createSwissTimingArchiveConfiguration) {
|
||||
DBCollection stArchiveConfigCollection = database.getCollection(CollectionNames.SWISSTIMING_ARCHIVE_CONFIGURATIONS.name());
|
||||
// remove old, non working index
|
||||
dropIndexSafe(stArchiveConfigCollection, "SWISSTIMING_ARCHIVE_CONFIGURATIONS_1");
|
||||
// adding unique index by json url
|
||||
stArchiveConfigCollection.createIndex(new BasicDBObject(FieldNames.ST_ARCHIVE_JSON_URL.name(), 1), "st_archive_config_name_unique",
|
||||
dropIndexSafe(stArchiveConfigCollection, "SWISSTIMING_ARCHIVE_CONFIGURATIONS_1", "st_archive_config_name_unique");
|
||||
// adding unique index by JSON URL
|
||||
stArchiveConfigCollection.createIndex(new BasicDBObject(FieldNames.ST_ARCHIVE_JSON_URL.name(), 1), "st_archive_json_url_unique",
|
||||
true);
|
||||
|
||||
BasicDBObject result = new BasicDBObject();
|
||||
@@ -122,11 +122,13 @@ public class SwissTimingAdapterPersistenceImpl implements SwissTimingAdapterPers
|
||||
|
||||
stArchiveConfigCollection.update(result, result, true, false);
|
||||
}
|
||||
|
||||
private void dropIndexSafe(DBCollection collection, String indexName) {
|
||||
|
||||
private void dropIndexSafe(DBCollection collection, String... indexNames) {
|
||||
collection.getIndexInfo().forEach(indexInfo -> {
|
||||
if (indexName.equals(indexInfo.get("name"))) {
|
||||
collection.dropIndex(indexName);
|
||||
for (String indexName : indexNames) {
|
||||
if (indexName.equals(indexInfo.get("name"))) {
|
||||
collection.dropIndex(indexName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+10
-8
@@ -18,9 +18,9 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
public void storeTracTracConfiguration(TracTracConfiguration tracTracConfiguration) {
|
||||
DBCollection ttConfigCollection = database.getCollection(CollectionNames.TRACTRAC_CONFIGURATIONS.name());
|
||||
// remove old, non working index
|
||||
dropIndexSafe(ttConfigCollection, "TRACTRAC_CONFIGURATIONS_1");
|
||||
// adding unique index by config name
|
||||
ttConfigCollection.createIndex(new BasicDBObject(FieldNames.TT_CONFIG_NAME.name(), 1), "tt_config_name_unique",
|
||||
dropIndexSafe(ttConfigCollection, "TRACTRAC_CONFIGURATIONS_1", "tt_config_name_unique");
|
||||
// adding unique index by JSON URL
|
||||
ttConfigCollection.createIndex(new BasicDBObject(FieldNames.TT_CONFIG_JSON_URL.name(), 1), "tt_config_json_url_unique",
|
||||
true);
|
||||
|
||||
final BasicDBObject result = new BasicDBObject();
|
||||
@@ -33,15 +33,17 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
result.put(FieldNames.TT_CONFIG_TRACTRAC_PASSWORD.name(), tracTracConfiguration.getTracTracPassword());
|
||||
|
||||
// Object with given name is updated or created if it does not exist yet
|
||||
final BasicDBObject updateQuery = new BasicDBObject(FieldNames.TT_CONFIG_NAME.name(),
|
||||
tracTracConfiguration.getName());
|
||||
final BasicDBObject updateQuery = new BasicDBObject(FieldNames.TT_CONFIG_JSON_URL.name(),
|
||||
tracTracConfiguration.getJSONURL());
|
||||
ttConfigCollection.update(updateQuery, result, true, false);
|
||||
}
|
||||
|
||||
private void dropIndexSafe(DBCollection collection, String indexName) {
|
||||
private void dropIndexSafe(DBCollection collection, String... indexNames) {
|
||||
collection.getIndexInfo().forEach(indexInfo -> {
|
||||
if (indexName.equals(indexInfo.get("name"))) {
|
||||
collection.dropIndex(indexName);
|
||||
for (String indexName : indexNames) {
|
||||
if (indexName.equals(indexInfo.get("name"))) {
|
||||
collection.dropIndex(indexName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user