jdbc-observations/datasource-proxy

equals method of ProxyLogicSupport class not working as expected.

deepeshkataria3092 opened this issue · 1 comments

Hi i am going through the code changes in 1.10-SNAPSHOT ... the equals method is comparing original connection to proxy of connection which turns out to be false everytime. Please review the equals logic. Below code belogs to ProxyLogicSupport class.

    protected Object handleCommonMethod(String methodName, Object original, ProxyConfig proxyConfig, Object[] args) throws SQLException {
        if ("toString".equals(methodName)) {
            // special treat for toString method
            final StringBuilder sb = new StringBuilder();
            sb.append(original.getClass().getSimpleName());
            sb.append(" [");
            sb.append(original);
            sb.append("]");
            return sb.toString(); // differentiate toString message.
        **} else if ("equals".equals(methodName)) {
            return original.equals(args[0]);**
        } else if ("hashCode".equals(methodName)) {
            return original.hashCode();
        } else if ("getDataSourceName".equals(methodName)) {
            return proxyConfig.getDataSourceName();
        } else if ("getTarget".equals(methodName)) {
            return original;  // ProxyJdbcObject interface has a method to return original object.
        } else if ("getProxyConfig".equals(methodName)) {
            return proxyConfig;
        } else if ("unwrap".equals(methodName)) {
            final Class<?> clazz = (Class<?>) args[0];
            return ((Wrapper) original).unwrap(clazz);
        } else if ("isWrapperFor".equals(methodName)) {
            final Class<?> clazz = (Class<?>) args[0];
            return ((Wrapper) original).isWrapperFor(clazz);
        }
        throw new IllegalStateException(methodName + " does not match with " + COMMON_METHOD_NAMES);
    }
ttddyy commented

Thanks for the report.
It is a duplicate of #105