-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable 1-n mapping with caching
- Loading branch information
1 parent
75f3054
commit 3213f2c
Showing
26 changed files
with
625 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 17 additions & 2 deletions
19
...ibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/entities/Order.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/mapper/Mapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.example.hibernatecache.mapper; | ||
|
||
import com.example.hibernatecache.entities.Customer; | ||
import com.example.hibernatecache.entities.Order; | ||
import com.example.hibernatecache.entities.OrderItem; | ||
import com.example.hibernatecache.model.request.OrderRequest; | ||
import com.example.hibernatecache.model.response.CustomerResponse; | ||
import com.example.hibernatecache.model.response.OrderItemResponse; | ||
import com.example.hibernatecache.model.response.OrderResponse; | ||
import java.util.List; | ||
import org.mapstruct.IterableMapping; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.MappingTarget; | ||
import org.mapstruct.NullValueCheckStrategy; | ||
|
||
@org.mapstruct.Mapper( | ||
componentModel = "spring", | ||
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) | ||
public interface Mapper { | ||
|
||
@Mapping(source = "id", target = "customerId") | ||
CustomerResponse mapToCustomerResponse(Customer customer); | ||
|
||
@IterableMapping(elementTargetType = CustomerResponse.class) | ||
List<CustomerResponse> mapToCustomerResponseList(List<Customer> customerList); | ||
|
||
void updateCustomerWithRequest(Customer customerRequest, @MappingTarget Customer savedCustomer); | ||
|
||
@Mapping(target = "customerId", source = "customer.id") | ||
@Mapping(source = "id", target = "orderId") | ||
OrderResponse orderToOrderResponse(Order order); | ||
|
||
@IterableMapping(elementTargetType = OrderResponse.class) | ||
List<OrderResponse> mapToOrderResponseList(List<Order> orderList); | ||
|
||
@Mapping(target = "orderItems", ignore = true) | ||
@Mapping(target = "id", ignore = true) | ||
@Mapping(target = "customer", ignore = true) | ||
void updateOrderWithRequest(OrderRequest orderRequest, @MappingTarget Order savedOrder); | ||
|
||
@Mapping(source = "id", target = "orderItemId") | ||
OrderItemResponse orderItemToOrderItemResponse(OrderItem orderItem); | ||
|
||
@IterableMapping(elementTargetType = OrderItemResponse.class) | ||
List<OrderItemResponse> orderItemListToOrderItemResponseList(List<OrderItem> list); | ||
|
||
@Mapping(target = "orderItems", ignore = true) | ||
@Mapping(target = "id", ignore = true) | ||
@Mapping(target = "customer.id", source = "customerId") | ||
Order mapToOrder(OrderRequest orderRequest); | ||
} |
6 changes: 6 additions & 0 deletions
6
...evelcache-sample/src/main/java/com/example/hibernatecache/model/request/OrderRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.hibernatecache.model.request; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
public record OrderRequest( | ||
Long customerId, @NotEmpty(message = "Text cannot be empty") String text) {} |
11 changes: 11 additions & 0 deletions
11
...ache-sample/src/main/java/com/example/hibernatecache/model/response/CustomerResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.hibernatecache.model.response; | ||
|
||
import java.util.List; | ||
|
||
public record CustomerResponse( | ||
Long customerId, | ||
String firstName, | ||
String lastName, | ||
String email, | ||
String phone, | ||
List<OrderResponse> orders) {} |
3 changes: 3 additions & 0 deletions
3
...che-sample/src/main/java/com/example/hibernatecache/model/response/OrderItemResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.example.hibernatecache.model.response; | ||
|
||
public record OrderItemResponse(Long orderItemId, String text) {} |
6 changes: 6 additions & 0 deletions
6
...elcache-sample/src/main/java/com/example/hibernatecache/model/response/OrderResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.hibernatecache.model.response; | ||
|
||
import java.util.List; | ||
|
||
public record OrderResponse( | ||
Long customerId, Long orderId, String text, List<OrderItemResponse> orderItems) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.