Skip to content

Commit

Permalink
规范格式
Browse files Browse the repository at this point in the history
  • Loading branch information
scwlkq committed May 16, 2023
1 parent d28e1ea commit f12a8b2
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.plugin.datasource.mapper.Mapper;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,20 +36,20 @@
* @author hyx
**/
public class MapperProxy implements InvocationHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(MapperProxy.class);

private Mapper mapper;

private static final Map<String, MapperProxy> SINGLE_MAPPER_PROXY_MAP = new HashMap<>(16);

private static final ReadWriteLock LOCK = new ReentrantReadWriteLock(true);

public <R> R createProxy(Mapper mapper) {
this.mapper = mapper;
return (R) Proxy.newProxyInstance(MapperProxy.class.getClassLoader(), mapper.getClass().getInterfaces(), this);
}

/**
* create proxy-mapper single instead of using method createProxy.
*/
Expand All @@ -72,21 +73,21 @@ public static <R> R createSingleProxy(Mapper mapper) {
LOCK.readLock().unlock();
}
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object invoke = method.invoke(mapper, args);

String className = mapper.getClass().getSimpleName();
String methodName = method.getName();

String sql;
if(invoke instanceof MapperResult){
sql = ((MapperResult)invoke).getSql();
}else{
if (invoke instanceof MapperResult) {
sql = ((MapperResult) invoke).getSql();
} else {
sql = invoke.toString();
}

LOGGER.info("[{}] METHOD : {}, SQL : {}, ARGS : {}", className, methodName, sql, JacksonUtils.toJson(args));
return invoke;
}
Expand Down

0 comments on commit f12a8b2

Please sign in to comment.