mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-23 06:25:08 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -35,7 +35,7 @@ public interface UpdateService<T> {
|
||||
* Update entity.
|
||||
*
|
||||
* @param obj entity to update
|
||||
* @param id primary key
|
||||
* @param id primary key
|
||||
* @return modified entity
|
||||
*/
|
||||
T doUpdate(T obj, long id);
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.exception;
|
||||
|
||||
/**
|
||||
* Exception happens in application during business-logic execution.
|
||||
*/
|
||||
/** Exception happens in application during business-logic execution. */
|
||||
public class ApplicationException extends RuntimeException {
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,38 +24,27 @@
|
||||
*/
|
||||
package com.iluwatar.model;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Bank card entity.
|
||||
*/
|
||||
/** Bank card entity. */
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Card {
|
||||
|
||||
/**
|
||||
* Primary key.
|
||||
*/
|
||||
/** Primary key. */
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* Foreign key points to card's owner.
|
||||
*/
|
||||
/** Foreign key points to card's owner. */
|
||||
private long personId;
|
||||
|
||||
/**
|
||||
* Sum of money.
|
||||
*/
|
||||
/** Sum of money. */
|
||||
private float sum;
|
||||
|
||||
/**
|
||||
* Current version of object.
|
||||
*/
|
||||
/** Current version of object. */
|
||||
private int version;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@ import com.iluwatar.model.Card;
|
||||
import com.iluwatar.repository.JpaRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Service to update {@link Card} entity.
|
||||
*/
|
||||
/** Service to update {@link Card} entity. */
|
||||
@RequiredArgsConstructor
|
||||
public class CardUpdateService implements UpdateService<Card> {
|
||||
|
||||
@@ -45,11 +43,10 @@ public class CardUpdateService implements UpdateService<Card> {
|
||||
int initialVersion = cardToUpdate.getVersion();
|
||||
float resultSum = cardToUpdate.getSum() + additionalSum;
|
||||
cardToUpdate.setSum(resultSum);
|
||||
//Maybe more complex business-logic e.g. HTTP-requests and so on
|
||||
// Maybe more complex business-logic e.g. HTTP-requests and so on
|
||||
|
||||
if (initialVersion != cardJpaRepository.getEntityVersionById(id)) {
|
||||
String exMessage =
|
||||
String.format("Entity with id %s were updated in another transaction", id);
|
||||
String exMessage = String.format("Entity with id %s were updated in another transaction", id);
|
||||
throw new ApplicationException(exMessage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user