Skip to content

Commit

Permalink
Ensure that the ResultSet is returned as Proxy object when enabling t…
Browse files Browse the repository at this point in the history
…he StatementDecoratorInterceptor.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1755056 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Keiichi Fujino committed Aug 3, 2016
1 parent db52f44 commit b977afc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Expand Up @@ -40,7 +40,11 @@ public class StatementDecoratorInterceptor extends AbstractCreateStatementInterc

private static final Log logger = LogFactory.getLog(StatementDecoratorInterceptor.class);

private static final String[] EXECUTE_QUERY_TYPES = { "executeQuery" };
protected static final String EXECUTE_QUERY = "executeQuery";
protected static final String GETGENERATEDKEYS = "getGeneratedKeys";
protected static final String GET_RESULTSET = "getResultSet";

protected static final String[] RESULTSET_TYPES = {EXECUTE_QUERY, GETGENERATEDKEYS, GET_RESULTSET};

/**
* the constructors that are used to create statement proxies
Expand Down Expand Up @@ -157,13 +161,17 @@ protected Object createDecorator(Object proxy, Method method, Object[] args,
}

protected boolean isExecuteQuery(String methodName) {
return EXECUTE_QUERY_TYPES[0].equals(methodName);
return EXECUTE_QUERY.equals(methodName);
}

protected boolean isExecuteQuery(Method method) {
return isExecuteQuery(method.getName());
}

protected boolean isResultSet(Method method, boolean process) {
return process(RESULTSET_TYPES, method, process);
}

/**
* Class to measure query execute time.
*/
Expand Down Expand Up @@ -239,7 +247,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
if (compare(GETCONNECTION_VAL,method)){
return connection;
}
boolean process = isExecuteQuery(method);
boolean process = false;
process = isResultSet(method, process);
// check to see if we are about to execute a query
// if we are executing, get the current time
Object result = null;
Expand All @@ -259,7 +268,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
throw t;
}
}
if (process){
if (process && result != null) {
Constructor<?> cons = getResultSetConstructor();
result = cons.newInstance(new Object[]{new ResultSetProxy(actualProxy, result)});
}
Expand Down
4 changes: 4 additions & 0 deletions webapps/docs/changelog.xml
Expand Up @@ -157,6 +157,10 @@
that continues to return an invalid connection after database restart.
(kfujino)
</fix>
<fix>
Ensure that the <code>ResultSet</code> is returned as Proxy object when
enabling the <code>StatementDecoratorInterceptor</code>. (kfujino)
</fix>
</changelog>
</subsection>
<subsection name="Other">
Expand Down

0 comments on commit b977afc

Please sign in to comment.