...
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 public InstantiationResponse createControlLoops(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()); InstantiationResponse response = new InstantiationResponse(); response.setAffectedControlLoops(controlLoops.getControlLoopList().stream() .map(cl -> cl.getKey().asIdentifier()).collect(Collectors.toList())); return response; } |
Transaction
Transaction Propagation in SpringBoot:
- REQUIRED is the default propagation. Spring checks if there is an active transaction, then it creates a new one if nothing existed;
- For SUPPORTS, Spring first checks if an active transaction exists. If a transaction exists, then the existing transaction will be used. If there isn't a transaction, it is executed non-transactional;
- When the propagation is MANDATORY, if there is an active transaction, then it will be used. If there isn't an active transaction, then Spring throws an exception;
- For transactional logic with NEVER propagation, Spring throws an exception if there's an active transaction;
- NOT_SUPPORTED, Spring at first suspends the current transaction if it exists, then the business logic is executed without a transaction;
- When the propagation is REQUIRES_NEW, Spring suspends the current transaction if it exists and then creates a new one.
Read only Transaction
If the transaction is effectively read-only, it allows for corresponding optimizations at runtime. (https://stackoverflow.com/questions/1614139/spring-transactional-read-only-propagation)
Note: In Spring, @Transactional
works by creating a proxy of the class and intercepting the annotated method (AOP Proxies). This means that @Transactional
doesn't work if you are calling the annotated method from another method of the same class.
Other links
- https://gerrit.nordix.org/c/local/onap/clamp-pilot/+/8929
- https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/
- https://docs.spring.io/spring-framework/docs/current/reference/html/
- https://www.adam-bien.com/roller/abien/entry/jpa_ejb3_killed_the_dao
- https://www.adam-bien.com/roller/abien/entry/daos_aren_t_dead_but
...