Skip to content

Commit 0b92255

Browse files
committed
228: Added formatting
1 parent 7b8da8a commit 0b92255

File tree

4 files changed

+83
-90
lines changed

4 files changed

+83
-90
lines changed
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
package com.google.cloud.sqlcommenter.filter;
22

3+
import com.google.cloud.sqlcommenter.threadlocalstorage.State;
34
import org.springframework.web.method.HandlerMethod;
45
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
56
import org.springframework.web.server.ServerWebExchange;
67
import org.springframework.web.server.WebFilter;
78
import org.springframework.web.server.WebFilterChain;
8-
9-
import com.google.cloud.sqlcommenter.threadlocalstorage.State;
10-
119
import reactor.core.publisher.Mono;
1210

1311
public class SpringSQLCommenterWebFilter implements WebFilter {
1412

15-
private final RequestMappingHandlerMapping handlerMapping;
16-
17-
public SpringSQLCommenterWebFilter(RequestMappingHandlerMapping handlerMapping) {
18-
this.handlerMapping = handlerMapping;
19-
}
13+
private final RequestMappingHandlerMapping handlerMapping;
2014

21-
@Override
22-
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
23-
HandlerMethod handlerMethod = (HandlerMethod) this.handlerMapping.getHandler(exchange).toFuture().getNow(null);
15+
public SpringSQLCommenterWebFilter(RequestMappingHandlerMapping handlerMapping) {
16+
this.handlerMapping = handlerMapping;
17+
}
2418

25-
State state = State.newBuilder()
26-
.withActionName(handlerMethod.getMethod().getName())
27-
.withFramework("spring")
28-
.withControllerName(handlerMethod.getBeanType().getSimpleName().replace("Controller",""))
29-
.build();
19+
@Override
20+
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
21+
HandlerMethod handlerMethod =
22+
(HandlerMethod) this.handlerMapping.getHandler(exchange).toFuture().getNow(null);
3023

31-
return chain
32-
.filter(exchange)
33-
.contextWrite(ctx -> ctx.put("state", state));
34-
}
24+
State state =
25+
State.newBuilder()
26+
.withActionName(handlerMethod.getMethod().getName())
27+
.withFramework("spring")
28+
.withControllerName(
29+
handlerMethod.getBeanType().getSimpleName().replace("Controller", ""))
30+
.build();
3531

32+
return chain.filter(exchange).contextWrite(ctx -> ctx.put("state", state));
33+
}
3634
}
Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
package com.google.cloud.sqlcommenter.r2dbc;
22

3+
import io.r2dbc.spi.Connection;
34
import java.lang.reflect.Proxy;
4-
55
import org.reactivestreams.Subscription;
6-
7-
import io.r2dbc.spi.Connection;
86
import reactor.core.CoreSubscriber;
97

108
public class ConnectionDecorator implements CoreSubscriber<Object> {
119

12-
private final CoreSubscriber<Object> delegate;
13-
14-
public ConnectionDecorator(CoreSubscriber<Object> delegate) {
15-
this.delegate = delegate;
16-
}
17-
18-
@Override
19-
public void onSubscribe(Subscription s) {
20-
this.delegate.onSubscribe(s);
21-
}
22-
23-
@Override
24-
public void onNext(Object o) {
25-
assert o instanceof Connection;
26-
Connection connection = (Connection) o;
27-
28-
Object proxied = Proxy.newProxyInstance(Connection.class.getClassLoader(),
29-
new Class[] {Connection.class},
30-
new ConnectionInvocationHandler(connection,delegate.currentContext()));
31-
this.delegate.onNext(proxied);
32-
}
33-
34-
@Override
35-
public void onError(Throwable t) {
36-
this.delegate.onError(t);
37-
}
38-
39-
@Override
40-
public void onComplete() {
41-
this.delegate.onComplete();
42-
}
43-
10+
private final CoreSubscriber<Object> delegate;
11+
12+
public ConnectionDecorator(CoreSubscriber<Object> delegate) {
13+
this.delegate = delegate;
14+
}
15+
16+
@Override
17+
public void onSubscribe(Subscription s) {
18+
this.delegate.onSubscribe(s);
19+
}
20+
21+
@Override
22+
public void onNext(Object o) {
23+
assert o instanceof Connection;
24+
Connection connection = (Connection) o;
25+
26+
Object proxied =
27+
Proxy.newProxyInstance(
28+
Connection.class.getClassLoader(),
29+
new Class[] {Connection.class},
30+
new ConnectionInvocationHandler(connection, delegate.currentContext()));
31+
this.delegate.onNext(proxied);
32+
}
33+
34+
@Override
35+
public void onError(Throwable t) {
36+
this.delegate.onError(t);
37+
}
38+
39+
@Override
40+
public void onComplete() {
41+
this.delegate.onComplete();
42+
}
4443
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package com.google.cloud.sqlcommenter.r2dbc;
22

3-
4-
53
import org.aspectj.lang.ProceedingJoinPoint;
64
import org.aspectj.lang.annotation.Around;
75
import org.aspectj.lang.annotation.Aspect;
86
import org.reactivestreams.Publisher;
9-
107
import reactor.core.publisher.Mono;
118
import reactor.core.publisher.Operators;
129

1310
@Aspect
1411
public class ConnectionFactoryAspect {
1512

16-
@Around("execution(* io.r2dbc.spi.ConnectionFactory.create(..)) ")
17-
public Object beforeSampleCreation(ProceedingJoinPoint joinPoint) throws Throwable {
18-
Object object = joinPoint.proceed();
19-
20-
@SuppressWarnings("unchecked") Publisher<Object> publisher = (Publisher<Object>) object;
13+
@Around("execution(* io.r2dbc.spi.ConnectionFactory.create(..)) ")
14+
public Object beforeSampleCreation(ProceedingJoinPoint joinPoint) throws Throwable {
15+
Object object = joinPoint.proceed();
2116

22-
return Mono.from(publisher)
23-
.transform(Operators.liftPublisher((publisher1, coreSubscriber) -> new ConnectionDecorator(coreSubscriber)));
24-
}
17+
@SuppressWarnings("unchecked")
18+
Publisher<Object> publisher = (Publisher<Object>) object;
2519

20+
return Mono.from(publisher)
21+
.transform(
22+
Operators.liftPublisher(
23+
(publisher1, coreSubscriber) -> new ConnectionDecorator(coreSubscriber)));
24+
}
2625
}
Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
package com.google.cloud.sqlcommenter.r2dbc;
22

3-
import java.lang.reflect.InvocationHandler;
4-
import java.lang.reflect.Method;
5-
63
import com.google.cloud.sqlcommenter.threadlocalstorage.State;
7-
84
import io.r2dbc.spi.Connection;
5+
import java.lang.reflect.InvocationHandler;
6+
import java.lang.reflect.Method;
97
import reactor.util.context.ContextView;
108

119
public class ConnectionInvocationHandler implements InvocationHandler {
1210

13-
private final Connection connection;
14-
private final ContextView contextView;
11+
private final Connection connection;
12+
private final ContextView contextView;
1513

16-
public ConnectionInvocationHandler(Connection connection, ContextView contextView) {
17-
this.connection = connection;
18-
this.contextView = contextView;
19-
}
14+
public ConnectionInvocationHandler(Connection connection, ContextView contextView) {
15+
this.connection = connection;
16+
this.contextView = contextView;
17+
}
2018

21-
@Override
22-
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
23-
String methodName = method.getName();
19+
@Override
20+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
21+
String methodName = method.getName();
2422

25-
if ("createStatement".equals(methodName)) {
26-
String query = (String) args[0];
27-
if(contextView!=null) {
28-
State state = contextView.get("state");
29-
query = state.formatAndAppendToSQL(query);
30-
}
23+
if ("createStatement".equals(methodName)) {
24+
String query = (String) args[0];
25+
if (contextView != null) {
26+
State state = contextView.get("state");
27+
query = state.formatAndAppendToSQL(query);
28+
}
3129

32-
return method.invoke(connection, query);
33-
} else {
34-
return method.invoke(connection, args);
35-
}
30+
return method.invoke(connection, query);
31+
} else {
32+
return method.invoke(connection, args);
3633
}
37-
34+
}
3835
}

0 commit comments

Comments
 (0)