Skip to content

Commit f9d8b70

Browse files
committed
add fast show #16
1 parent 8cd88a1 commit f9d8b70

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

springboot-starter-fastshow/src/main/java/com/codingapi/springboot/fastshow/executor/JpaExecutor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.codingapi.springboot.fastshow.executor;
22

33
import lombok.AllArgsConstructor;
4-
import org.springframework.web.bind.annotation.ResponseBody;
54

65
import javax.persistence.EntityManager;
76
import javax.persistence.Query;
@@ -11,7 +10,6 @@ public class JpaExecutor {
1110

1211
private final EntityManager entityManager;
1312

14-
@ResponseBody
1513
public Object execute(String jpaSql,Object[] args){
1614
Query query = entityManager.createQuery(jpaSql);
1715
if(args!=null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.codingapi.springboot.fastshow.executor;
2+
3+
import com.codingapi.springboot.fastshow.annotation.FastMapping;
4+
import lombok.AllArgsConstructor;
5+
6+
import java.lang.reflect.InvocationHandler;
7+
import java.lang.reflect.Method;
8+
9+
@AllArgsConstructor
10+
public class MvcMethodProxy implements InvocationHandler {
11+
12+
private final JpaExecutor jpaExecutor;
13+
14+
@Override
15+
public Object invoke(Object proxy, Method method, Object[] args)
16+
throws Throwable {
17+
if(method.equals(Object.class.getMethod("equals", Object.class))){
18+
return false;
19+
}
20+
if(method.equals(Object.class.getMethod("hashCode"))){
21+
return hashCode();
22+
}
23+
FastMapping fastMapping = method.getAnnotation(FastMapping.class);
24+
return jpaExecutor.execute(fastMapping.hql(),args);
25+
}
26+
}

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

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import com.codingapi.springboot.fastshow.annotation.FastMapping;
44
import com.codingapi.springboot.fastshow.executor.JpaExecutor;
5+
import com.codingapi.springboot.fastshow.executor.MvcMethodProxy;
56
import com.codingapi.springboot.fastshow.mapping.MvcEndpointMapping;
67
import lombok.AllArgsConstructor;
78
import lombok.SneakyThrows;
89
import lombok.extern.slf4j.Slf4j;
910

10-
import java.lang.reflect.InvocationHandler;
1111
import java.lang.reflect.Method;
1212
import java.lang.reflect.Proxy;
1313
import java.util.HashSet;
@@ -18,7 +18,6 @@
1818
public class MvcMappingRegistrar {
1919
protected final static Set<Class<?>> classSet = new HashSet<>();
2020
private final MvcEndpointMapping mvcEndpointMapping;
21-
2221
private final JpaExecutor jpaExecutor;
2322

2423
@SneakyThrows
@@ -28,36 +27,12 @@ public void registerMvcMapping() {
2827
for(Method method:methods){
2928
FastMapping fastMapping = method.getAnnotation(FastMapping.class);
3029
if(fastMapping!=null) {
31-
MethodProxy handler = new MethodProxy(jpaExecutor);
30+
MvcMethodProxy handler = new MvcMethodProxy(jpaExecutor);
3231
Object methodProxy = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, handler);
3332
mvcEndpointMapping.addMapping(fastMapping.mapping(), fastMapping.method(), methodProxy, method);
3433
}
3534
}
3635
}
3736
}
3837

39-
@Slf4j
40-
@AllArgsConstructor
41-
public static class MethodProxy implements InvocationHandler {
42-
43-
private final JpaExecutor jpaExecutor;
44-
45-
@Override
46-
public Object invoke(Object proxy, Method method, Object[] args)
47-
throws Throwable {
48-
if(method.equals(Object.class.getMethod("equals", Object.class))){
49-
return false;
50-
}
51-
if(method.equals(Object.class.getMethod("hashCode"))){
52-
return hashCode();
53-
}
54-
log.info("method.name:{}",method.getName());
55-
log.info("xxx->{}",args);
56-
57-
FastMapping fastMapping = method.getAnnotation(FastMapping.class);
58-
return jpaExecutor.execute(fastMapping.hql(),args);
59-
}
60-
}
61-
62-
6338
}

0 commit comments

Comments
 (0)