Skip to content

Commit 4faea45

Browse files
committed
Refactor to use BiConsumer instead of BiFunction in DAOs
Replaced `BiFunction` with `BiConsumer` for association linkers across all DAOs to simplify code and improve readability. This change removes the need to return the first object, aligning the implementation with a more natural functional style.
1 parent 31ffdc1 commit 4faea45

File tree

3 files changed

+41
-43
lines changed

3 files changed

+41
-43
lines changed

example-sql-file/src/main/java/example/sql/file/dao/EmployeeDao.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import example.common.domain.Salary;
55
import example.common.entity.Department;
66
import example.common.entity.Employee;
7+
78
import java.time.LocalDateTime;
89
import java.util.List;
10+
import java.util.function.BiConsumer;
911
import java.util.function.BiFunction;
1012
import java.util.function.Function;
1113
import java.util.stream.Stream;
14+
1215
import org.seasar.doma.AggregateStrategy;
1316
import org.seasar.doma.AssociationLinker;
1417
import org.seasar.doma.Dao;
@@ -86,9 +89,5 @@ public interface EmployeeDao {
8689
@AggregateStrategy(root = Employee.class, tableAlias = "e")
8790
interface EmployeeAggregateStrategy {
8891
@AssociationLinker(propertyPath = "department", tableAlias = "d")
89-
BiFunction<Employee, Department, Employee> department =
90-
(e, d) -> {
91-
e.setDepartment(d);
92-
return e;
93-
};
92+
BiConsumer<Employee, Department> department = Employee::setDepartment;
9493
}

example-sql-file/src/main/java/example/sql/file/dao/OrderDao.java

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import example.common.entity.Payment;
77
import example.common.entity.Product;
88
import example.common.entity.User;
9+
10+
import java.util.function.BiConsumer;
911
import java.util.function.BiFunction;
12+
1013
import org.seasar.doma.AggregateStrategy;
1114
import org.seasar.doma.AssociationLinker;
1215
import org.seasar.doma.Dao;
@@ -22,40 +25,35 @@ public interface OrderDao {
2225
@AggregateStrategy(root = Order.class, tableAlias = "o")
2326
interface OrderAggregateStrategy {
2427
@AssociationLinker(propertyPath = "payment", tableAlias = "pa")
25-
BiFunction<Order, Payment, Order> payment =
26-
(order, payment) -> {
27-
order.payment = payment;
28-
payment.order = order;
29-
return order;
30-
};
28+
BiConsumer<Order, Payment> payment =
29+
(order, payment) -> {
30+
order.payment = payment;
31+
payment.order = order;
32+
};
3133

3234
@AssociationLinker(propertyPath = "user", tableAlias = "u")
33-
BiFunction<Order, User, Order> user =
34-
(order, user) -> {
35-
order.user = user;
36-
return order;
37-
};
35+
BiConsumer<Order, User> user =
36+
(order, user) -> {
37+
order.user = user;
38+
};
3839

3940
@AssociationLinker(propertyPath = "orderItemList", tableAlias = "oi")
40-
BiFunction<Order, OrderItem, Order> orderItemList =
41-
(order, orderItem) -> {
42-
order.orderItemList.add(orderItem);
43-
orderItem.order = order;
44-
return order;
45-
};
41+
BiConsumer<Order, OrderItem> orderItemList =
42+
(order, orderItem) -> {
43+
order.orderItemList.add(orderItem);
44+
orderItem.order = order;
45+
};
4646

4747
@AssociationLinker(propertyPath = "orderItemList.product", tableAlias = "pr")
48-
BiFunction<OrderItem, Product, OrderItem> orderItemList$product =
49-
(orderItem, product) -> {
50-
orderItem.product = product;
51-
return orderItem;
52-
};
48+
BiConsumer<OrderItem, Product> orderItemList$product =
49+
(orderItem, product) -> {
50+
orderItem.product = product;
51+
};
5352

5453
@AssociationLinker(propertyPath = "orderItemList.product.categoryList", tableAlias = "c")
55-
BiFunction<Product, Category, Product> orderItemList$product$category =
56-
(product, category) -> {
57-
product.categoryList.add(category);
58-
category.productList.add(product);
59-
return product;
60-
};
54+
BiConsumer<Product, Category> orderItemList$product$category =
55+
(product, category) -> {
56+
product.categoryList.add(category);
57+
category.productList.add(product);
58+
};
6159
}

example-sql-file/src/main/java/example/sql/file/dao/ReviewDao.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import example.common.entity.Product;
44
import example.common.entity.Review;
55
import example.common.entity.User;
6+
67
import java.util.List;
8+
import java.util.function.BiConsumer;
79
import java.util.function.BiFunction;
10+
811
import org.seasar.doma.AggregateStrategy;
912
import org.seasar.doma.AssociationLinker;
1013
import org.seasar.doma.Dao;
@@ -20,16 +23,14 @@ public interface ReviewDao {
2023
interface ReviewAggregateStrategy {
2124

2225
@AssociationLinker(propertyPath = "product", tableAlias = "pr")
23-
BiFunction<Review, Product, Review> product =
24-
(review, product) -> {
25-
review.product = product;
26-
return review;
27-
};
26+
BiConsumer<Review, Product> product =
27+
(review, product) -> {
28+
review.product = product;
29+
};
2830

2931
@AssociationLinker(propertyPath = "user", tableAlias = "u")
30-
BiFunction<Review, User, Review> user =
31-
(review, user) -> {
32-
review.user = user;
33-
return review;
34-
};
32+
BiConsumer<Review, User> user =
33+
(review, user) -> {
34+
review.user = user;
35+
};
3536
}

0 commit comments

Comments
 (0)