Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the function of WrapperAdapter in sharding-jdbc

Shulou Source: shulou.com Published: 2022-06-02 10:12:45 10月05日 Update

This article shows you what the role of WrapperAdapter in sharding-jdbc is, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Wrapper

Jdktel 12.jdkqqqql ContentsUniverse HomeUnixlibUnixsrc.zipAccording java.sqlUniverse java.sqlUniq.java

Public interface Wrapper {T unwrap (java.lang.Class iface) throws java.sql.SQLException; boolean isWrapperFor (java.lang.Class iface) throws java.sql.SQLException;}

The Wrapper interface defines unwrap and isWrapperFor methods.

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 (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);}

The WrapperAdapter declaration implements the java.sql.Wrapper interface, which defines the JdbcMethodInvocation collection; the recordMethodInvocation method adds the JdbcMethodInvocation;replayMethodsInvocation method to the jdbcMethodInvocations and executes the invoke method of JdbcMethodInvocation one by one

JdbcMethodInvocation

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

@ RequiredArgsConstructorpublic 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);}}

The invoke method of JdbcMethodInvocation executes method.invoke

Summary

The WrapperAdapter declaration implements the java.sql.Wrapper interface, which defines the JdbcMethodInvocation collection; the recordMethodInvocation method adds the JdbcMethodInvocation;replayMethodsInvocation method to the jdbcMethodInvocations and executes the invoke method of JdbcMethodInvocation one by one

The above content is what is the role of WrapperAdapter in sharding-jdbc. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Methods interfaces functions content skills knowledge conciseness conciseness summary that is articles more articles industries information channels channels bright reserve Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL macOS Docker Redmi Shulou Tech Info