Skip to content

Commit 078ddeb

Browse files
committed
add FastMapping verify #16
1 parent 48df7dc commit 078ddeb

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

springboot-example/src/main/java/com/codingapi/springboot/example/infrastructure/query/FastDemoApi.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
@FastController
1111
public interface FastDemoApi {
1212

13-
@FastMapping(method = RequestMethod.GET,
13+
@FastMapping(
14+
method = RequestMethod.GET,
1415
mapping = "/open/demo/findByName",
15-
hql = "select d from DemoEntity d where name = :name",
16-
countHql = "select count(d) from DemoEntity d where name = :name")
16+
value = "select d from DemoEntity d where name = :name",
17+
countQuery = "select count(d) from DemoEntity d where name = :name")
1718
MultiResponse<DemoEntity> findByName(DemoDTO.DemoQuery query);
1819

1920
}

springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/annotation/FastMapping.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,27 @@
1414
@ResponseBody
1515
public @interface FastMapping {
1616

17-
String hql() default "";
17+
/**
18+
* execute jpa hql
19+
*/
20+
String value() default "";
1821

1922

20-
String countHql() default "";
23+
/**
24+
* execute jpa count hql
25+
*/
26+
String countQuery() default "";
2127

28+
/**
29+
* mvc request method
30+
*
31+
*/
2232
RequestMethod method() default RequestMethod.GET;
2333

24-
34+
/**
35+
* mvc request url
36+
*
37+
*/
2538
String mapping() default "";
2639

2740
}

springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/executor/MvcMethodProxy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public Object invoke(Object proxy, Method method, Object[] args)
2222
}
2323
FastMapping fastMapping = method.getAnnotation(FastMapping.class);
2424
Class<?> returnType = method.getReturnType();
25-
return jpaExecutor.execute(fastMapping.hql(),fastMapping.countHql(),args,returnType);
25+
return jpaExecutor.execute(fastMapping.value(),fastMapping.countQuery(),args,returnType);
2626
}
2727
}

springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/registrar/MvcMappingRegistrar.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void registerMvcMapping() {
2929
Method[] methods = clazz.getDeclaredMethods();
3030
for(Method method:methods){
3131
FastMapping fastMapping = method.getAnnotation(FastMapping.class);
32-
if(fastMapping!=null&&isVerify(fastMapping,method)) {
32+
if(verify(fastMapping,method)) {
3333
MvcMethodProxy handler = new MvcMethodProxy(jpaExecutor);
3434
Object methodProxy = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, handler);
3535
mvcEndpointMapping.addMapping(fastMapping.mapping(), fastMapping.method(), methodProxy, method);
@@ -38,15 +38,28 @@ public void registerMvcMapping() {
3838
}
3939
}
4040

41-
private boolean isVerify(FastMapping fastMapping,Method method) throws FastMappingErrorException {
41+
private boolean verify(FastMapping fastMapping, Method method) throws FastMappingErrorException {
42+
if(fastMapping==null){
43+
return false;
44+
}
45+
46+
if(!StringUtils.hasText(fastMapping.mapping())){
47+
throw new FastMappingErrorException(String.format("fast method %s missing mapping .",method.getName()));
48+
}
49+
50+
if(!StringUtils.hasText(fastMapping.value())){
51+
throw new FastMappingErrorException(String.format("fast mapping %s missing value .",fastMapping.mapping()));
52+
}
53+
4254
Class<?>[] parameterTypes = method.getParameterTypes();
4355
for(Class<?> parameter:parameterTypes){
4456
if(Pageable.class.isAssignableFrom(parameter)){
45-
if(!StringUtils.hasText(fastMapping.countHql())){
46-
throw new FastMappingErrorException(String.format("fast mapping %s missing countHql .",fastMapping.mapping()));
57+
if(!StringUtils.hasText(fastMapping.countQuery())){
58+
throw new FastMappingErrorException(String.format("fast mapping %s missing countQuery .",fastMapping.mapping()));
4759
}
4860
}
4961
}
62+
5063
return true;
5164
}
5265

0 commit comments

Comments
 (0)