aws-xray-recorder-sdk-sql-mysql/src/main/java/com/amazonaws/xray/sql/mysql/TracingInterceptor.java [137:249]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            logger.warn("Unable to create statement proxy for tracing.", e);
        }
        return statementObject;
    }

    protected class TracingStatementProxy implements InvocationHandler {
        protected boolean closed = false;
        protected Object delegate;
        protected final String query;
        protected final String hostname;
        protected Map<String, Object> additionalParams;

        public TracingStatementProxy(Object parent, String query, String hostname, Map<String, Object> additionalParams) {
            this.delegate = parent;
            this.query = query;
            this.hostname = hostname;
            this.additionalParams = additionalParams;
        }

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            //get the name of the method for comparison
            final String name = method.getName();
            //was close invoked?
            boolean close = compare(JdbcInterceptor.CLOSE_VAL, name);
            //allow close to be called multiple times
            if (close && closed) {
                return null;
            }
            //are we calling isClosed?
            if (compare(JdbcInterceptor.ISCLOSED_VAL, name)) {
                return Boolean.valueOf(closed);
            }
            //if we are calling anything else, bail out
            if (closed) {
                throw new SQLException("Statement closed.");
            }
            //check to see if we are about to execute a query
            final boolean process = isExecute(method);
            Object result = null;
            Subsegment subsegment = null;
            if (process) {
                subsegment = AWSXRay.beginSubsegment(hostname);
            }
            try {
                if (process && null != subsegment) {
                    subsegment.putAllSql(additionalParams);
                    subsegment.setNamespace(Namespace.REMOTE.toString());
                }
                result = method.invoke(delegate, args); //execute the query
            } catch (Throwable t) {
                if (null != subsegment) {
                    subsegment.addException(t);
                }
                if (t instanceof InvocationTargetException && t.getCause() != null) {
                    throw t.getCause();
                } else {
                    throw t;
                }
            } finally {
                if (process && null != subsegment) {
                    AWSXRay.endSubsegment();
                }
            }

            //perform close cleanup
            if (close) {
                closed = true;
                delegate = null;
            }

            return result;
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (compare(CLOSE_VAL, method)) {
            return super.invoke(proxy, method, args);
        } else {
            boolean process = isStatement(method);
            if (process) {
                Object statement = super.invoke(proxy, method, args);
                return createStatement(proxy, method, args, statement);
            } else {
                return super.invoke(proxy, method, args);
            }
        }
    }


    private boolean isStatement(Method method) {
        return isMemberOf(STATEMENT_TYPES, method);
    }

    private boolean isExecute(Method method) {
        return isMemberOf(EXECUTE_TYPES, method);
    }

    protected boolean isMemberOf(String[] names, Method method) {
        boolean member = false;
        final String name = method.getName();
        for (int i = 0; !member && i < names.length; i++) {
            member = compare(names[i], name);
        }
        return member;
    }

    @Override
    public void reset(ConnectionPool parent, PooledConnection con) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



aws-xray-recorder-sdk-sql-postgres/src/main/java/com/amazonaws/xray/sql/postgres/TracingInterceptor.java [137:249]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            logger.warn("Unable to create statement proxy for tracing.", e);
        }
        return statementObject;
    }

    protected class TracingStatementProxy implements InvocationHandler {
        protected boolean closed = false;
        protected Object delegate;
        protected final String query;
        protected final String hostname;
        protected Map<String, Object> additionalParams;

        public TracingStatementProxy(Object parent, String query, String hostname, Map<String, Object> additionalParams) {
            this.delegate = parent;
            this.query = query;
            this.hostname = hostname;
            this.additionalParams = additionalParams;
        }

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            //get the name of the method for comparison
            final String name = method.getName();
            //was close invoked?
            boolean close = compare(JdbcInterceptor.CLOSE_VAL, name);
            //allow close to be called multiple times
            if (close && closed) {
                return null;
            }
            //are we calling isClosed?
            if (compare(JdbcInterceptor.ISCLOSED_VAL, name)) {
                return Boolean.valueOf(closed);
            }
            //if we are calling anything else, bail out
            if (closed) {
                throw new SQLException("Statement closed.");
            }
            //check to see if we are about to execute a query
            final boolean process = isExecute(method);
            Object result = null;
            Subsegment subsegment = null;
            if (process) {
                subsegment = AWSXRay.beginSubsegment(hostname);
            }
            try {
                if (process && null != subsegment) {
                    subsegment.putAllSql(additionalParams);
                    subsegment.setNamespace(Namespace.REMOTE.toString());
                }
                result = method.invoke(delegate, args); //execute the query
            } catch (Throwable t) {
                if (null != subsegment) {
                    subsegment.addException(t);
                }
                if (t instanceof InvocationTargetException && t.getCause() != null) {
                    throw t.getCause();
                } else {
                    throw t;
                }
            } finally {
                if (process && null != subsegment) {
                    AWSXRay.endSubsegment();
                }
            }

            //perform close cleanup
            if (close) {
                closed = true;
                delegate = null;
            }

            return result;
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (compare(CLOSE_VAL, method)) {
            return super.invoke(proxy, method, args);
        } else {
            boolean process = isStatement(method);
            if (process) {
                Object statement = super.invoke(proxy, method, args);
                return createStatement(proxy, method, args, statement);
            } else {
                return super.invoke(proxy, method, args);
            }
        }
    }


    private boolean isStatement(Method method) {
        return isMemberOf(STATEMENT_TYPES, method);
    }

    private boolean isExecute(Method method) {
        return isMemberOf(EXECUTE_TYPES, method);
    }

    protected boolean isMemberOf(String[] names, Method method) {
        boolean member = false;
        final String name = method.getName();
        for (int i = 0; !member && i < names.length; i++) {
            member = compare(names[i], name);
        }
        return member;
    }

    @Override
    public void reset(ConnectionPool parent, PooledConnection con) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



