mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-16 07:10:48 +00:00
added synchronization for the case that the same competitor could be migrated twice triggered by two different tracked races from the same or even different regattas (in case of league events)
This commit is contained in:
1 parent
a919f2b172
commit
d4b1fe2a1b
3 files changed
+38
-30
No files matched your search
+4
-1
@@ -113,7 +113,10 @@ public class TransientCompetitorStoreImpl implements CompetitorStore, Serializab
|
||||
}
|
||||
|
||||
@Override
|
||||
public Competitor migrateToCompetitorWithoutBoat(CompetitorWithBoat competitorWithBoat) {
|
||||
public synchronized Competitor migrateToCompetitorWithoutBoat(CompetitorWithBoat competitorWithBoat) {
|
||||
// It should not be possible to call this for a competitor which has already been migrated.
|
||||
assert competitorWithBoat.hasBoat();
|
||||
|
||||
// We can't create a new competitor without boat here as the existing competitorWithBoat might be already referenced.
|
||||
// Therefore we only clear the 'boat' property and make sure that
|
||||
removeBoat(competitorWithBoat.getBoat());
|
||||
|
||||
+30
-28
@@ -741,39 +741,41 @@ public class DomainFactoryImpl implements DomainFactory {
|
||||
}
|
||||
Boat existingBoat = competitorAndBoatStore.getExistingBoatById(boatId);
|
||||
Competitor existingCompetitor = competitorAndBoatStore.getExistingCompetitorById(competitorId);
|
||||
boolean competitorMigrationRequired = existingCompetitor != null && existingCompetitor.hasBoat();
|
||||
// Now we check if we already have a separate competitor and boat for this competitor in the store
|
||||
if (existingCompetitor != null && existingBoat != null && !competitorMigrationRequired) {
|
||||
competitorsAndBoats.put(existingCompetitor, existingBoat);
|
||||
} else {
|
||||
Competitor competitorToUse = existingCompetitor;
|
||||
if (existingCompetitor == null) {
|
||||
competitorToUse = getOrCreateCompetitor(rc.getCompetitor());
|
||||
} else if (competitorMigrationRequired) {
|
||||
competitorToUse = competitorAndBoatStore.migrateToCompetitorWithoutBoat((CompetitorWithBoat) existingCompetitor);
|
||||
// we might also want to update the shortName field of the competitor during migration (instead of using sailID)
|
||||
if (competitorToUse.getShortName() != rc.getCompetitor().getShortName()) {
|
||||
boolean savedIsCompetitorToUpdateDuringGetOrCreate = competitorAndBoatStore.isCompetitorToUpdateDuringGetOrCreate(competitorToUse);
|
||||
competitorAndBoatStore.allowCompetitorResetToDefaults(competitorToUse);
|
||||
competitorAndBoatStore.updateCompetitor(competitorToUse.getId().toString(), competitorToUse.getName(),
|
||||
rc.getCompetitor().getShortName(), competitorToUse.getColor(),
|
||||
competitorToUse.getEmail(), competitorToUse.getNationality(), competitorToUse.getTeam().getImage(),
|
||||
competitorToUse.getFlagImage(), competitorToUse.getTimeOnTimeFactor(),
|
||||
competitorToUse.getTimeOnDistanceAllowancePerNauticalMile(), competitorToUse.getSearchTag());
|
||||
if (savedIsCompetitorToUpdateDuringGetOrCreate) {
|
||||
synchronized (existingCompetitor) {
|
||||
boolean competitorMigrationRequired = existingCompetitor != null && existingCompetitor.hasBoat();
|
||||
// Now we check if we already have a separate competitor and boat for this competitor in the store
|
||||
if (existingCompetitor != null && existingBoat != null && !competitorMigrationRequired) {
|
||||
competitorsAndBoats.put(existingCompetitor, existingBoat);
|
||||
} else {
|
||||
Competitor competitorToUse = existingCompetitor;
|
||||
if (existingCompetitor == null) {
|
||||
competitorToUse = getOrCreateCompetitor(rc.getCompetitor());
|
||||
} else if (competitorMigrationRequired) {
|
||||
competitorToUse = competitorAndBoatStore.migrateToCompetitorWithoutBoat((CompetitorWithBoat) existingCompetitor);
|
||||
// we might also want to update the shortName field of the competitor during migration (instead of using sailID)
|
||||
if (competitorToUse.getShortName() != rc.getCompetitor().getShortName()) {
|
||||
boolean savedIsCompetitorToUpdateDuringGetOrCreate = competitorAndBoatStore.isCompetitorToUpdateDuringGetOrCreate(competitorToUse);
|
||||
competitorAndBoatStore.allowCompetitorResetToDefaults(competitorToUse);
|
||||
competitorAndBoatStore.updateCompetitor(competitorToUse.getId().toString(), competitorToUse.getName(),
|
||||
rc.getCompetitor().getShortName(), competitorToUse.getColor(),
|
||||
competitorToUse.getEmail(), competitorToUse.getNationality(), competitorToUse.getTeam().getImage(),
|
||||
competitorToUse.getFlagImage(), competitorToUse.getTimeOnTimeFactor(),
|
||||
competitorToUse.getTimeOnDistanceAllowancePerNauticalMile(), competitorToUse.getSearchTag());
|
||||
if (savedIsCompetitorToUpdateDuringGetOrCreate) {
|
||||
competitorAndBoatStore.allowCompetitorResetToDefaults(competitorToUse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Boat boatToUse = existingBoat;
|
||||
if (existingBoat == null) {
|
||||
if (competitorBoatInfo != null) {
|
||||
boatToUse = getOrCreateBoat(boatId, competitorBoatInfo.getName(), defaultBoatClass, sailId, AbstractColor.getCssColor(competitorBoatInfo.getColor()));
|
||||
} else {
|
||||
boatToUse = getOrCreateBoat(boatId, /* boat name*/ null, defaultBoatClass, sailId, null);
|
||||
Boat boatToUse = existingBoat;
|
||||
if (existingBoat == null) {
|
||||
if (competitorBoatInfo != null) {
|
||||
boatToUse = getOrCreateBoat(boatId, competitorBoatInfo.getName(), defaultBoatClass, sailId, AbstractColor.getCssColor(competitorBoatInfo.getColor()));
|
||||
} else {
|
||||
boatToUse = getOrCreateBoat(boatId, /* boat name*/ null, defaultBoatClass, sailId, null);
|
||||
}
|
||||
}
|
||||
competitorsAndBoats.put(competitorToUse, boatToUse);
|
||||
}
|
||||
competitorsAndBoats.put(competitorToUse, boatToUse);
|
||||
}
|
||||
} else {
|
||||
// Case 2 we assume here that the boat is contained in competitor as it's always the same
|
||||
|
||||
+4
-1
@@ -121,7 +121,10 @@ public class PersistentCompetitorStore extends TransientCompetitorStoreImpl impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Competitor migrateToCompetitorWithoutBoat(CompetitorWithBoat competitorWithBoat) {
|
||||
public synchronized Competitor migrateToCompetitorWithoutBoat(CompetitorWithBoat competitorWithBoat) {
|
||||
// It should not be possible to call this for a competitor which has already been migrated.
|
||||
assert competitorWithBoat.hasBoat();
|
||||
|
||||
logger.log(Level.INFO, "Bug2822 DB-Migration: Migrate competitor " + competitorWithBoat.getName() + " with ID " + competitorWithBoat.getId().toString() + " to have a separate boat");
|
||||
Competitor migratedCompetitor = super.migrateToCompetitorWithoutBoat(competitorWithBoat);
|
||||
storeTo.storeCompetitor(migratedCompetitor);
|
||||
|
||||
Reference in new issue
Block a user