Skip to content

Commit 0ca9bcc

Browse files
committed
Optimized code
1 parent 783fd74 commit 0ca9bcc

File tree

11 files changed

+48
-12
lines changed

11 files changed

+48
-12
lines changed

spring-boot-data-aggregator-autoconfigure/src/main/java/io/github/lvyahui8/spring/enums/ExceptionProcessingMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ public enum ExceptionProcessingMethod {
1616
/**
1717
* Abort execution
1818
*/
19-
SUSPEND;
19+
SUSPEND
2020
}

spring-boot-data-aggregator-core/src/main/java/io/github/lvyahui8/spring/aggregate/consts/AggregatorConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
public interface AggregatorConstant
88
{
99
Object EMPTY_MODEL = new Object();
10+
int DEFAULT_INITIAL_CAPACITY = 8;
1011
}

spring-boot-data-aggregator-core/src/main/java/io/github/lvyahui8/spring/aggregate/facade/DataBeanAggregateQueryFacade.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,27 @@
44
import java.util.Map;
55

66
/**
7+
* The only API for this framework
8+
*
79
* @author lvyahui (lvyahui8@gmail.com,lvyahui8@126.com)
810
* @since 2019/6/1 0:22
911
*/
1012
public interface DataBeanAggregateQueryFacade {
11-
<T> T get(String id, Map<String,Object> invokeParams, Class<T> clazz) throws InterruptedException, IllegalAccessException, InvocationTargetException;
13+
/**
14+
* Used to query data. It has the following three functions
15+
* 1. Automatic analysis dependence
16+
* 2. Parallel access dependency
17+
* 3. Automatic injection
18+
*
19+
* @param id Data id
20+
* @param invokeParams Fixed parameters that need to be passed in the query process
21+
* @param clazz Return value type bytecode object
22+
* @param <T> Return value type
23+
* @return Return value
24+
* @throws InterruptedException If the thread is interrupted, this exception will be thrown
25+
* @throws IllegalAccessException Thrown if the data provider cannot be executed
26+
* @throws InvocationTargetException If the data provider throws an unhandled exception, this exception will be thrown
27+
*/
28+
<T> T get(String id, Map<String,Object> invokeParams, Class<T> clazz)
29+
throws InterruptedException, IllegalAccessException, InvocationTargetException;
1230
}

spring-boot-data-aggregator-core/src/main/java/io/github/lvyahui8/spring/aggregate/facade/impl/DataBeanAggregateQueryFacadeImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.lvyahui8.spring.aggregate.facade.impl;
22

3+
import io.github.lvyahui8.spring.aggregate.consts.AggregatorConstant;
34
import io.github.lvyahui8.spring.aggregate.service.DataBeanAggregateQueryService;
45
import io.github.lvyahui8.spring.aggregate.facade.DataBeanAggregateQueryFacade;
56
import org.springframework.util.Assert;
@@ -15,7 +16,7 @@
1516
*/
1617
public class DataBeanAggregateQueryFacadeImpl implements DataBeanAggregateQueryFacade {
1718

18-
private DataBeanAggregateQueryService dataBeanAggregateQueryService;
19+
private final DataBeanAggregateQueryService dataBeanAggregateQueryService;
1920

2021
public DataBeanAggregateQueryFacadeImpl(DataBeanAggregateQueryService dataBeanAggregateQueryService) {
2122
this.dataBeanAggregateQueryService = dataBeanAggregateQueryService;
@@ -28,6 +29,7 @@ public <T> T get(String id, Map<String,Object> invokeParams, Class<T> clazz) thr
2829
if(invokeParams == null) {
2930
invokeParams = Collections.emptyMap();
3031
}
31-
return dataBeanAggregateQueryService.get(id,invokeParams,clazz,new ConcurrentHashMap<>());
32+
return dataBeanAggregateQueryService.get(id,invokeParams,clazz,
33+
new ConcurrentHashMap<>(AggregatorConstant.DEFAULT_INITIAL_CAPACITY));
3234
}
3335
}

spring-boot-data-aggregator-core/src/main/java/io/github/lvyahui8/spring/aggregate/model/InvokeSignature.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ public InvokeSignature(Method method, Object[] args) {
2222

2323
@Override
2424
public boolean equals(Object o) {
25-
if (this == o) return true;
26-
if (o == null || getClass() != o.getClass()) return false;
25+
if (this == o) {
26+
return true;
27+
}
28+
if (o == null || getClass() != o.getClass()) {
29+
return false;
30+
}
2731
InvokeSignature that = (InvokeSignature) o;
2832
return Objects.deepEquals(method, that.method) &&
2933
Arrays.deepEquals(args, that.args);

spring-boot-data-aggregator-core/src/main/java/io/github/lvyahui8/spring/aggregate/repository/impl/DataProviderRepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
public class DataProviderRepositoryImpl implements DataProviderRepository {
1414

15-
private ConcurrentHashMap<String,DataProvideDefinition> providerMap = new ConcurrentHashMap<>();
15+
private final ConcurrentHashMap<String,DataProvideDefinition> providerMap = new ConcurrentHashMap<>();
1616

1717
@Override
1818
public void put(String id, DataProvideDefinition dataProvideDefinition) {

spring-boot-data-aggregator-core/src/main/java/io/github/lvyahui8/spring/aggregate/service/impl/DataBeanAggregateQueryServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
@Slf4j
2323
public class DataBeanAggregateQueryServiceImpl implements DataBeanAggregateQueryService {
2424

25-
private DataProviderRepository repository;
25+
private final DataProviderRepository repository;
2626

2727
@Setter
2828
private ApplicationContext applicationContext;

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/ExampleApplication.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
@SpringBootApplication
2121
@Slf4j
2222
public class ExampleApplication {
23+
24+
public static final int NUM = 100;
25+
2326
public static void main(String[] args) throws Exception {
2427
ConfigurableApplicationContext context = SpringApplication.run(ExampleApplication.class);
2528
try{
@@ -43,7 +46,7 @@ public static void main(String[] args) throws Exception {
4346
log.info("------------------------------------------------------------------");
4447

4548
{
46-
for (int i = 0; i < 100; i ++) {
49+
for (int i = 0; i < NUM; i ++) {
4750
String s = queryFacade.get("categoryTitle", Collections.singletonMap("categoryId", 1L), String.class);
4851
Assert.isTrue(org.apache.commons.lang3.StringUtils.isNotEmpty(s),"s not null");
4952
}

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/service/PostService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.lvyahui8.spring.example.service;
22

3-
import io.github.lvyahui8.spring.example.model.Post;
43
import io.github.lvyahui8.spring.example.model.Post;
54

65
import java.util.List;
@@ -10,5 +9,10 @@
109
* @since 2019/6/2 16:53
1110
*/
1211
public interface PostService {
12+
/**
13+
* s
14+
* @param userId
15+
* @return
16+
*/
1317
List<Post> getPosts(Long userId);
1418
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package io.github.lvyahui8.spring.example.service;
22

3-
import io.github.lvyahui8.spring.example.model.User;
43
import io.github.lvyahui8.spring.example.model.User;
54

65
/**
76
* @author lvyahui (lvyahui8@gmail.com,lvyahui8@126.com)
87
* @since 2019/6/2 16:36
98
*/
109
public interface UserService {
10+
/**
11+
* s
12+
* @param id
13+
* @return
14+
*/
1115
User get(Long id);
1216
}

0 commit comments

Comments
 (0)