Esempio n. 1
0
  void migrateEventToCurrentVersion(Event event) {
    Optional<EventMigration> optional =
        optionally(() -> eventMigrationRepository.loadEventMigration(event.getId()));
    boolean alreadyDefined = optional.isPresent();
    if (!alreadyDefined || optional.filter(this::needsFixing).isPresent()) {
      transactionTemplate.execute(
          s -> {
            optional.ifPresent(
                eventMigration ->
                    eventMigrationRepository.lockEventMigrationForUpdate(eventMigration.getId()));
            createMissingTickets(event);
            fillDescriptions(event);
            if (alreadyDefined) {
              EventMigration eventMigration = optional.get();
              int result =
                  eventMigrationRepository.updateMigrationData(
                      eventMigration.getId(),
                      currentVersionAsString,
                      buildTimestamp,
                      EventMigration.Status.COMPLETE.name());
              Validate.isTrue(result == 1, "error during update " + result);
            } else {
              eventMigrationRepository.insertMigrationData(
                  event.getId(),
                  currentVersionAsString,
                  buildTimestamp,
                  EventMigration.Status.COMPLETE.name());
            }

            return null;
          });
    }
  }
Esempio n. 2
0
 boolean needsFixing(EventMigration eventMigration) {
   return eventMigration.getBuildTimestamp().isBefore(buildTimestamp)
       || parseVersion(eventMigration.getCurrentVersion()).compareTo(currentVersion) < 0;
 }