网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

sharding-jdbc中WrapperAdapter的作用是什么

本篇文章为大家展示了sharding-jdbc中WrapperAdapter的作用是什么,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

成都创新互联专注于衡阳企业网站建设,自适应网站建设,商城系统网站开发。衡阳网站建设公司,为衡阳等地区提供建站服务。全流程按需定制网站,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务

Wrapper

jdk-12.jdk/Contents/Home/lib/src.zip!/java.sql/java/sql/Wrapper.java

public interface Wrapper {

     T unwrap(java.lang.Class iface) throws java.sql.SQLException;

    boolean isWrapperFor(java.lang.Class iface) throws java.sql.SQLException;

}
  • Wrapper接口定义了unwrap、isWrapperFor方法

WrapperAdapter

incubator-shardingsphere-4.0.0-RC1/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/adapter/WrapperAdapter.java

public abstract class WrapperAdapter implements Wrapper {
    
    private final Collection jdbcMethodInvocations = new ArrayList<>();
    
    @SuppressWarnings("unchecked")
    @Override
    public final  T unwrap(final Class iface) throws SQLException {
        if (isWrapperFor(iface)) {
            return (T) this;
        }
        throw new SQLException(String.format("[%s] cannot be unwrapped as [%s]", getClass().getName(), iface.getName()));
    }
    
    @Override
    public final boolean isWrapperFor(final Class iface) {
        return iface.isInstance(this);
    }
    
    /**
     * record method invocation.
     * 
     * @param targetClass target class
     * @param methodName method name
     * @param argumentTypes argument types
     * @param arguments arguments
     */
    @SneakyThrows
    public final void recordMethodInvocation(final Class targetClass, final String methodName, final Class[] argumentTypes, final Object[] arguments) {
        jdbcMethodInvocations.add(new JdbcMethodInvocation(targetClass.getMethod(methodName, argumentTypes), arguments));
    }
    
    /**
     * Replay methods invocation.
     * 
     * @param target target object
     */
    public final void replayMethodsInvocation(final Object target) {
        for (JdbcMethodInvocation each : jdbcMethodInvocations) {
            each.invoke(target);
        }
    }
}
  • WrapperAdapter声明实现java.sql.Wrapper接口,它定义了JdbcMethodInvocation集合;recordMethodInvocation方法会往jdbcMethodInvocations添加JdbcMethodInvocation;replayMethodsInvocation方法则会挨个执行JdbcMethodInvocation的invoke方法

JdbcMethodInvocation

incubator-shardingsphere-4.0.0-RC1/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/adapter/invocation/JdbcMethodInvocation.java

@RequiredArgsConstructor
public class JdbcMethodInvocation {
    
    @Getter
    private final Method method;
    
    @Getter
    private final Object[] arguments;
    
    /**
     * Invoke JDBC method.
     * 
     * @param target target object
     */
    @SneakyThrows
    public void invoke(final Object target) {
        method.invoke(target, arguments);
    }
}
  • JdbcMethodInvocation的invoke方法执行的是method.invoke

小结

WrapperAdapter声明实现java.sql.Wrapper接口,它定义了JdbcMethodInvocation集合;recordMethodInvocation方法会往jdbcMethodInvocations添加JdbcMethodInvocation;replayMethodsInvocation方法则会挨个执行JdbcMethodInvocation的invoke方法

上述内容就是sharding-jdbc中WrapperAdapter的作用是什么,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。


当前标题:sharding-jdbc中WrapperAdapter的作用是什么
文章网址:http://bjjierui.cn/article/pedoje.html

其他资讯