Java Persistence API
...
Transaction management refers to the tasks of processing multiple transactions issued by various clients of a database server in such a way that the ACID contract can be fulfilled, that is, the properties of atomicity, consistency preservation, isolation, and durability of each individual transaction can be guaranteed. Transaction management is generally understood as requiring serializability-based concurrency control as well as recovery from failures. Concurrency control is the task of scheduling transactions such that their serializability can be guaranteed, while recovery has to restore a consistent database state after a system or media failure. Assuming that the database server is in charge of the “C,” the former guarantees the “I” in ACID, the latter the “A” and “D” properties. Transaction management has to be highly efficient, as modern transaction servers need to accommodate thousands of transactions...
The Spring Framework provides a consistent abstraction for transaction management. The Spring Framework’s declarative transaction management is made possible with Spring aspect-oriented programming (AOP), although, as the transactional aspects code comes with the Spring Framework distribution and may be used in a boilerplate fashion, AOP concepts do not generally have to be understood to make effective use of this code.
Models
Models are implemented using Jakarta Persistence. Spring Data JPA needs same implementation.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Service public class ControlLoopInstantiationProvider { private final ControlLoopProvider controlLoopProvider; private final CommissioningProvider commissioningProvider; /** * Create a instantiation provider. * * @param databaseProviderParameters the parameters for database access */ public ControlLoopInstantiationProvider(ControlLoopProvider controlLoopProvider, CommissioningProvider commissioningProvider) { this.controlLoopProvider = controlLoopProvider; this.commissioningProvider = commissioningProvider; } @Transactional privatepublic voidInstantiationResponse createControlLoopsOpcreateControlLoops(ControlLoops controlLoops) throws PfModelException { for (ControlLoop controlLoop : controlLoops.getControlLoopList()) { ControlLoop checkControlLoop = controlLoopProvider.getControlLoop(controlLoop.getKey().asIdentifier()); if (checkControlLoop != null) { throw new PfModelException(Response.Status.BAD_REQUEST, controlLoop.getKey().asIdentifier() + " already defined"); } } BeanValidationResult validationResult = validateControlLoops(controlLoops); if (!validationResult.isValid()) { throw new PfModelException(Response.Status.BAD_REQUEST, validationResult.getResult()); } controlLoopProvider.createControlLoops(controlLoops.getControlLoopList()); } /** * Create control loops. * * @param controlLoops the control loop * @return the result of the instantiation operation * @throws PfModelException on creation errors */ public InstantiationResponse createControlLoops(ControlLoops controlLoops) throws PfModelException { createControlLoopsOp(controlLoops); InstantiationResponse response = new InstantiationResponse(); response.setAffectedControlLoops(controlLoops.getControlLoopList().stream() .map(cl -> cl.getKey().asIdentifier()).collect(Collectors.toList())); return response; } |
...