Skip to content

Commit 94c3b70

Browse files
committed
update readme
1 parent eab3606 commit 94c3b70

File tree

2 files changed

+51
-59
lines changed

2 files changed

+51
-59
lines changed

README.md

+26-32
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ public class PostServiceImpl implements PostService {
8989
@DataProvider("posts")
9090
@Override
9191
public List<Post> getPosts(@InvokeParameter("userId") Long userId) {
92-
try {
93-
Thread.sleep(1000L);
94-
} catch (InterruptedException e) {
95-
//
96-
}
97-
Post post = new Post();
98-
post.setTitle("spring data aggregate example");
99-
post.setContent("No active profile set, falling back to default profiles");
100-
return Collections.singletonList(post);
101-
}
102-
}
10392
```
10493

10594
**用户基础信息查询服务**
@@ -113,23 +102,33 @@ public class UserServiceImpl implements UserService {
113102
@DataProvider("user")
114103
@Override
115104
public User get(@InvokeParameter("userId") Long id) {
116-
/* */
117-
try {
118-
Thread.sleep(100L);
119-
} catch (InterruptedException e) {
120-
//
121-
}
122-
/* mock a user*/
123-
User user = new User();
124-
user.setId(id);
125-
user.setEmail("lvyahui8@gmail.com");
126-
user.setUsername("lvyahui8");
127-
return user;
128-
}
129-
}
130105
```
131106

132-
### 2. 定义并实现聚合层
107+
### 2. 调用聚合接口
108+
109+
```java
110+
@Autowired
111+
DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade;
112+
```
113+
114+
#### 方式一: 函数式调用
115+
116+
```java
117+
User user = dataBeanAggregateQueryFacade.get(
118+
Collections.singletonMap("userId", 1L),
119+
new Function2<User, List<Post>, User>() {
120+
@Override
121+
public User apply(@DataConsumer("user") User user,
122+
@DataConsumer("posts") List<Post> posts) {
123+
user.setPosts(posts);
124+
return user;
125+
}
126+
});
127+
Assert.notNull(user,"user not null");
128+
Assert.notNull(user.getPosts(),"user posts not null");
129+
```
130+
131+
#### 方式二: 定义聚合层查询
133132

134133
组合`@DataProvider` \ `@DataConsumer` \ `@InvokeParameter` 实现汇聚功能
135134

@@ -146,15 +145,10 @@ public class UserAggregate {
146145
}
147146
```
148147

149-
### 3. 调用聚合层接口
150-
151-
注解了`@DataProvider`方法的接口不需要直接调用, 而是通过门面类`DataBeanAggregateQueryFacade`访问.
152-
153148
指定要查询的data id, 查询参数, 返回值类型, 并调用`facade.get`方法即可
154149

155150
```java
156-
DataBeanAggregateQueryFacade queryFacade = context.getBean(DataBeanAggregateQueryFacade.class);
157-
User user = queryFacade.get(/*data id*/ "userWithPosts",
151+
User user = dataBeanAggregateQueryFacade.get(/*data id*/ "userWithPosts",
158152
/*Invoke Parameters*/
159153
Collections.singletonMap("userId",1L),
160154
User.class);

README_EN.md

+25-27
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ public class PostServiceImpl implements PostService {
9292
    @DataProvider("posts")
9393
    @Override
9494
    public List<Post> getPosts(@InvokeParameter("userId") Long userId) {
95-
try {
96-
            Thread.sleep(1000L);
97-
        } catch (InterruptedException e) {
98-
        }
99-
        Post post = new Post();
100-
        post.setTitle("spring data aggregate example");
101-
        post.setContent("No active profile set, falling back to default profiles");
102-
        return Collections.singletonList(post);
103-
    }
104-
}
10595
```
10696

10797
**User basic information query service**
@@ -115,21 +105,33 @@ public class UserServiceImpl implements UserService {
115105
    @DataProvider("user")
116106
    @Override
117107
    public User get(@InvokeParameter("userId") Long id) {
118-
try {
119-
            Thread.sleep(100L);
120-
        } catch (InterruptedException e) {
121-
        }
122-
        /* mock a user*/
123-
        User user = new User();
124-
        user.setId(id);
125-
        user.setEmail("lvyahui8@gmail.com");
126-
        user.setUsername("lvyahui8");
127-
        return user;
128-
    }
129-
}
130108
```
131109

132-
### 2. Define and implement an aggregation layer
110+
### 2. Call the aggregation interface
111+
112+
```java
113+
@Autowired
114+
DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade;
115+
```
116+
117+
#### Method 1: Functional call
118+
119+
```java
120+
User user = dataBeanAggregateQueryFacade.get(
121+
Collections.singletonMap("userId", 1L),
122+
new Function2<User, List<Post>, User>() {
123+
@Override
124+
public User apply(@DataConsumer("user") User user,
125+
@DataConsumer("posts") List<Post> posts) {
126+
user.setPosts(posts);
127+
return user;
128+
}
129+
});
130+
Assert.notNull(user,"user not null");
131+
Assert.notNull(user.getPosts(),"user posts not null");
132+
```
133+
134+
#### Method 2: Define and implement an aggregation layer
133135

134136
Combine `@DataProvider` ( `@DataConsumer` \ `@InvokeParameter` ) to achieve aggregation function
135137

@@ -146,10 +148,6 @@ public class UserAggregate {
146148
}
147149
```
148150

149-
### 3. Call the aggregation layer interface
150-
151-
Note that the interface of the `@DataProvider` method shouldn't to be called directly, but accessed through the facade class `DataBeanAggregateQueryFacade`.
152-
153151
Specify queried data id, invoke parameters, and return type to invoke `facade.get` method
154152

155153
```java

0 commit comments

Comments
 (0)