What is the function of WrapperAdapter in sharding-jdbc
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.