use of org.springframework.orm.jpa.JpaOptimisticLockingFailureException in project open-smart-grid-platform by OSGP.
the class RtuResponseService method handleResponseMessageReceived.
@Transactional(value = "transactionManager")
public void handleResponseMessageReceived(final Logger logger, final String deviceIdentification, final boolean expectDeviceToBeKnown) throws FunctionalException {
try {
final RtuDevice device = this.rtuDeviceRepository.findByDeviceIdentification(deviceIdentification).orElse(null);
if (device == null && expectDeviceToBeKnown) {
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, COMPONENT_TYPE, new UnknownEntityException(RtuDevice.class, deviceIdentification));
} else if (device == null) {
logger.info("No RTU device {} found to update communication time information for." + " This may be appropriate as the device could be expected to be unknown to GXF.", deviceIdentification);
return;
}
if (this.shouldUpdateCommunicationTime(device, this.minimumDurationBetweenCommunicationTimeUpdates)) {
device.messageReceived();
this.rtuDeviceRepository.save(device);
} else {
logger.info("Last communication time within duration: {}. Skipping last communication date update.", this.minimumDurationBetweenCommunicationTimeUpdates);
}
} catch (final OptimisticLockException | JpaOptimisticLockingFailureException ex) {
logger.warn("Last communication time not updated due to optimistic lock exception", ex);
}
}
use of org.springframework.orm.jpa.JpaOptimisticLockingFailureException in project open-smart-grid-platform by OSGP.
the class ReportingService method storeLastReportEntry.
@Transactional(value = "transactionManager")
public void storeLastReportEntry(final Report report, final String deviceIdentification) {
if (Objects.isNull(report.getEntryId()) || Objects.isNull(report.getTimeOfEntry())) {
LOGGER.warn("Not all report entry data availabe for report id {} and device identification {}, skip storing last report entry", report.getRptId(), deviceIdentification);
return;
}
Iec61850ReportEntry reportEntry = this.iec61850ReportEntryRepository.findByDeviceIdentificationAndReportId(deviceIdentification, report.getRptId());
if (reportEntry == null) {
reportEntry = new Iec61850ReportEntry(deviceIdentification, report.getRptId(), report.getEntryId().getValue(), new Date(report.getTimeOfEntry().getTimestampValue()));
LOGGER.info("Store new last report entry: {}", reportEntry);
} else {
reportEntry.updateLastReportEntry(report.getEntryId().getValue(), new Date(report.getTimeOfEntry().getTimestampValue()));
LOGGER.info("Store updated last report entry: {}", reportEntry);
}
try {
this.iec61850ReportEntryRepository.saveAndFlush(reportEntry);
} catch (final JpaOptimisticLockingFailureException e) {
LOGGER.debug("JpaOptimisticLockingFailureException", e);
LOGGER.warn("JPA optimistic locking failure exception while saving last report entry: {} with id {} and version {}", reportEntry, reportEntry.getId(), reportEntry.getVersion());
}
}
Aggregations