-
-
Save rmannibucau/957a77139e7b83ce0fdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: core/src/main/java/org/apache/commons/monitoring/util/ClassLoaders.java | |
=================================================================== | |
--- core/src/main/java/org/apache/commons/monitoring/util/ClassLoaders.java (revision 0) | |
+++ core/src/main/java/org/apache/commons/monitoring/util/ClassLoaders.java (working copy) | |
@@ -0,0 +1,34 @@ | |
+/* | |
+ * Licensed to the Apache Software Foundation (ASF) under one or more | |
+ * contributor license agreements. See the NOTICE file distributed with | |
+ * this work for additional information regarding copyright ownership. | |
+ * The ASF licenses this file to You under the Apache License, Version 2.0 | |
+ * (the "License"); you may not use this file except in compliance with | |
+ * the License. You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
+ */ | |
+package org.apache.commons.monitoring.util; | |
+ | |
+public final class ClassLoaders | |
+{ | |
+ public static ClassLoader current() | |
+ { | |
+ final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); | |
+ if (tccl != null) { | |
+ return tccl; | |
+ } | |
+ return ClassLoaders.class.getClassLoader(); | |
+ } | |
+ | |
+ private ClassLoaders() | |
+ { | |
+ // no-op | |
+ } | |
+} | |
Index: core/src/main/java/org/apache/commons/monitoring/repositories/RepositoryFinder.java | |
=================================================================== | |
--- core/src/main/java/org/apache/commons/monitoring/repositories/RepositoryFinder.java (revision 0) | |
+++ core/src/main/java/org/apache/commons/monitoring/repositories/RepositoryFinder.java (working copy) | |
@@ -0,0 +1,41 @@ | |
+/* | |
+ * Licensed to the Apache Software Foundation (ASF) under one or more | |
+ * contributor license agreements. See the NOTICE file distributed with | |
+ * this work for additional information regarding copyright ownership. | |
+ * The ASF licenses this file to You under the Apache License, Version 2.0 | |
+ * (the "License"); you may not use this file except in compliance with | |
+ * the License. You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
+ */ | |
+package org.apache.commons.monitoring.repositories; | |
+ | |
+import org.apache.commons.monitoring.Repository; | |
+ | |
+import java.util.Iterator; | |
+import java.util.ServiceLoader; | |
+ | |
+public final class RepositoryFinder | |
+{ | |
+ public static final Repository REPOSITORY = findRepository(); | |
+ | |
+ private static Repository findRepository() { | |
+ final ServiceLoader<Repository> loader = ServiceLoader.load(Repository.class, RepositoryFinder.class.getClassLoader()); | |
+ final Iterator<Repository> iterator = loader.iterator(); | |
+ if (iterator.hasNext()) | |
+ { | |
+ return iterator.next(); | |
+ } | |
+ return new DefaultRepository(); | |
+ } | |
+ | |
+ private RepositoryFinder() { | |
+ // no-op | |
+ } | |
+} | |
Index: core/pom.xml | |
=================================================================== | |
--- core/pom.xml (revision 1506597) | |
+++ core/pom.xml (working copy) | |
@@ -26,13 +26,11 @@ | |
</parent> | |
<artifactId>commons-monitoring-core</artifactId> | |
<packaging>jar</packaging> | |
- <name>Commons Monitoring (Sandbox) core package</name> | |
+ <name>Commons Monitoring (Sandbox) :: Core</name> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
- <version>4.5</version> | |
- <scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.commons</groupId> | |
Index: pom.xml | |
=================================================================== | |
--- pom.xml (revision 1506597) | |
+++ pom.xml (working copy) | |
@@ -41,6 +41,7 @@ | |
<module>spring</module> | |
<module>reporting</module> | |
<module>jdbc</module> | |
+ <module>cdi</module> | |
</modules> | |
<developers> | |
@@ -99,6 +100,18 @@ | |
<commons.componentid>monitoring</commons.componentid> | |
<commons.jira.componentid>12312100</commons.jira.componentid> | |
</properties> | |
+ | |
+ <dependencyManagement> | |
+ <dependencies> | |
+ <dependency> | |
+ <groupId>junit</groupId> | |
+ <artifactId>junit</artifactId> | |
+ <version>4.11</version> | |
+ <scope>test</scope> | |
+ </dependency> | |
+ </dependencies> | |
+ </dependencyManagement> | |
+ | |
<reporting> | |
<plugins> | |
<plugin> | |
Index: cdi/src/test/java/org/apache/commons/monitoring/cdi/CommonsMonitoringInterceptorTest.java | |
=================================================================== | |
--- cdi/src/test/java/org/apache/commons/monitoring/cdi/CommonsMonitoringInterceptorTest.java (revision 0) | |
+++ cdi/src/test/java/org/apache/commons/monitoring/cdi/CommonsMonitoringInterceptorTest.java (working copy) | |
@@ -0,0 +1,64 @@ | |
+/* | |
+ * Licensed to the Apache Software Foundation (ASF) under one or more | |
+ * contributor license agreements. See the NOTICE file distributed with | |
+ * this work for additional information regarding copyright ownership. | |
+ * The ASF licenses this file to You under the Apache License, Version 2.0 | |
+ * (the "License"); you may not use this file except in compliance with | |
+ * the License. You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
+ */ | |
+package org.apache.commons.monitoring.cdi; | |
+ | |
+import org.apache.commons.monitoring.Counter; | |
+import org.apache.commons.monitoring.repositories.RepositoryFinder; | |
+import org.apache.webbeans.cditest.CdiTestContainer; | |
+import org.apache.webbeans.cditest.CdiTestContainerLoader; | |
+import org.junit.Test; | |
+ | |
+import javax.enterprise.context.ApplicationScoped; | |
+import javax.enterprise.inject.spi.BeanManager; | |
+ | |
+import static org.junit.Assert.assertEquals; | |
+import static org.junit.Assert.assertNotNull; | |
+ | |
+public class CommonsMonitoringInterceptorTest | |
+{ | |
+ @Test | |
+ public void checkMeasures() throws Exception | |
+ { | |
+ final CdiTestContainer container = CdiTestContainerLoader.getCdiContainer(); | |
+ container.bootContainer(); | |
+ container.startApplicationScope(); | |
+ | |
+ final BeanManager beanManager = container.getBeanManager(); | |
+ final MonitoredBean bean = MonitoredBean.class.cast(beanManager.getReference(beanManager.resolve(beanManager.getBeans(MonitoredBean.class)), MonitoredBean.class, null)); | |
+ | |
+ bean.twoSeconds(); | |
+ | |
+ container.stopApplicationScope(); | |
+ container.shutdownContainer(); | |
+ | |
+ final Counter perf = RepositoryFinder.REPOSITORY.getMonitor(MonitoredBean.class.getName() + ".twoSeconds").getCounter("performances"); | |
+ assertNotNull(perf); | |
+ | |
+ assertEquals(2000, perf.getMax(), 200); | |
+ } | |
+ | |
+ @Monitored @ApplicationScoped | |
+ public static class MonitoredBean { | |
+ public void twoSeconds() { | |
+ try { | |
+ Thread.sleep(2000); | |
+ } catch (final InterruptedException e) { | |
+ // no-op | |
+ } | |
+ } | |
+ } | |
+} | |
Index: cdi/src/test/resources/META-INF/beans.xml | |
=================================================================== | |
--- cdi/src/test/resources/META-INF/beans.xml (revision 0) | |
+++ cdi/src/test/resources/META-INF/beans.xml (working copy) | |
@@ -0,0 +1,24 @@ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<!-- | |
+ Licensed to the Apache Software Foundation (ASF) under one | |
+ or more contributor license agreements. See the NOTICE file | |
+ distributed with this work for additional information | |
+ regarding copyright ownership. The ASF licenses this file | |
+ to you under the Apache License, Version 2.0 (the | |
+ "License"); you may not use this file except in compliance | |
+ with the License. You may obtain a copy of the License at | |
+ | |
+ http://www.apache.org/licenses/LICENSE-2.0 | |
+ | |
+ Unless required by applicable law or agreed to in writing, | |
+ software distributed under the License is distributed on an | |
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
+ KIND, either express or implied. See the License for the | |
+ specific language governing permissions and limitations | |
+ under the License. | |
+--> | |
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | |
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
+ | |
+</beans> | |
Index: cdi/src/main/resources/META-INF/beans.xml | |
=================================================================== | |
--- cdi/src/main/resources/META-INF/beans.xml (revision 0) | |
+++ cdi/src/main/resources/META-INF/beans.xml (working copy) | |
@@ -0,0 +1,26 @@ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<!-- | |
+ Licensed to the Apache Software Foundation (ASF) under one | |
+ or more contributor license agreements. See the NOTICE file | |
+ distributed with this work for additional information | |
+ regarding copyright ownership. The ASF licenses this file | |
+ to you under the Apache License, Version 2.0 (the | |
+ "License"); you may not use this file except in compliance | |
+ with the License. You may obtain a copy of the License at | |
+ | |
+ http://www.apache.org/licenses/LICENSE-2.0 | |
+ | |
+ Unless required by applicable law or agreed to in writing, | |
+ software distributed under the License is distributed on an | |
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
+ KIND, either express or implied. See the License for the | |
+ specific language governing permissions and limitations | |
+ under the License. | |
+--> | |
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | |
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
+ <interceptors> | |
+ <class>org.apache.commons.monitoring.cdi.CommonsMonitoringInterceptor</class> | |
+ </interceptors> | |
+</beans> | |
Index: cdi/src/main/java/org/apache/commons/monitoring/cdi/CommonsMonitoringInterceptor.java | |
=================================================================== | |
--- cdi/src/main/java/org/apache/commons/monitoring/cdi/CommonsMonitoringInterceptor.java (revision 0) | |
+++ cdi/src/main/java/org/apache/commons/monitoring/cdi/CommonsMonitoringInterceptor.java (working copy) | |
@@ -0,0 +1,49 @@ | |
+/* | |
+ * Licensed to the Apache Software Foundation (ASF) under one or more | |
+ * contributor license agreements. See the NOTICE file distributed with | |
+ * this work for additional information regarding copyright ownership. | |
+ * The ASF licenses this file to You under the Apache License, Version 2.0 | |
+ * (the "License"); you may not use this file except in compliance with | |
+ * the License. You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
+ */ | |
+package org.apache.commons.monitoring.cdi; | |
+ | |
+import org.apache.commons.monitoring.instrumentation.aop.AbstractPerformanceInterceptor; | |
+import org.apache.commons.monitoring.repositories.RepositoryFinder; | |
+ | |
+import javax.interceptor.AroundInvoke; | |
+import javax.interceptor.Interceptor; | |
+import javax.interceptor.InvocationContext; | |
+ | |
+@Interceptor @Monitored | |
+public class CommonsMonitoringInterceptor extends AbstractPerformanceInterceptor<InvocationContext> { | |
+ public CommonsMonitoringInterceptor() { | |
+ setRepository(RepositoryFinder.REPOSITORY); | |
+ } | |
+ | |
+ @AroundInvoke | |
+ public Object monitor(final InvocationContext invocationContext) throws Throwable | |
+ { | |
+ return doInvoke(invocationContext); | |
+ } | |
+ | |
+ @Override | |
+ protected Object proceed(final InvocationContext invocation) throws Throwable | |
+ { | |
+ return invocation.proceed(); | |
+ } | |
+ | |
+ @Override | |
+ protected String getMonitorName(InvocationContext invocation) | |
+ { | |
+ return getMonitorName(invocation.getMethod()); | |
+ } | |
+} | |
Index: cdi/src/main/java/org/apache/commons/monitoring/cdi/Monitored.java | |
=================================================================== | |
--- cdi/src/main/java/org/apache/commons/monitoring/cdi/Monitored.java (revision 0) | |
+++ cdi/src/main/java/org/apache/commons/monitoring/cdi/Monitored.java (working copy) | |
@@ -0,0 +1,29 @@ | |
+/* | |
+ * Licensed to the Apache Software Foundation (ASF) under one or more | |
+ * contributor license agreements. See the NOTICE file distributed with | |
+ * this work for additional information regarding copyright ownership. | |
+ * The ASF licenses this file to You under the Apache License, Version 2.0 | |
+ * (the "License"); you may not use this file except in compliance with | |
+ * the License. You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
+ */ | |
+package org.apache.commons.monitoring.cdi; | |
+ | |
+import javax.interceptor.InterceptorBinding; | |
+import java.lang.annotation.ElementType; | |
+import java.lang.annotation.Retention; | |
+import java.lang.annotation.RetentionPolicy; | |
+import java.lang.annotation.Target; | |
+ | |
+@InterceptorBinding | |
+@Target({ElementType.TYPE, ElementType.METHOD }) | |
+@Retention(RetentionPolicy.RUNTIME) | |
+public @interface Monitored { | |
+} | |
Index: cdi/pom.xml | |
=================================================================== | |
--- cdi/pom.xml (revision 0) | |
+++ cdi/pom.xml (working copy) | |
@@ -0,0 +1,70 @@ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<!-- | |
+ Licensed to the Apache Software Foundation (ASF) under one or more | |
+ contributor license agreements. See the NOTICE file distributed with | |
+ this work for additional information regarding copyright ownership. | |
+ The ASF licenses this file to You under the Apache License, Version 2.0 | |
+ (the "License"); you may not use this file except in compliance with | |
+ the License. You may obtain a copy of the License at | |
+ | |
+ http://www.apache.org/licenses/LICENSE-2.0 | |
+ | |
+ Unless required by applicable law or agreed to in writing, software | |
+ distributed under the License is distributed on an "AS IS" BASIS, | |
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ See the License for the specific language governing permissions and | |
+ limitations under the License. | |
+--> | |
+<project xmlns="http://maven.apache.org/POM/4.0.0" | |
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
+ <parent> | |
+ <artifactId>commons-monitoring-parent</artifactId> | |
+ <groupId>org.apache.commons.monitoring</groupId> | |
+ <version>1.0-SNAPSHOT</version> | |
+ </parent> | |
+ | |
+ <modelVersion>4.0.0</modelVersion> | |
+ | |
+ <artifactId>commons-monitoring-cdi</artifactId> | |
+ <name>Commons Monitoring (Sandbox) :: CDI Integration</name> | |
+ | |
+ <dependencies> | |
+ <dependency> | |
+ <groupId>org.apache.geronimo.specs</groupId> | |
+ <artifactId>geronimo-jcdi_1.0_spec</artifactId> | |
+ <version>1.0</version> | |
+ <scope>provided</scope> | |
+ </dependency> | |
+ <dependency> | |
+ <groupId>org.apache.geronimo.specs</groupId> | |
+ <artifactId>geronimo-interceptor_1.1_spec</artifactId> | |
+ <version>1.0</version> | |
+ <scope>provided</scope> | |
+ </dependency> | |
+ | |
+ <dependency> | |
+ <groupId>org.apache.commons.monitoring</groupId> | |
+ <artifactId>commons-monitoring-instrumentation</artifactId> | |
+ <version>${project.version}</version> | |
+ </dependency> | |
+ | |
+ <dependency> | |
+ <groupId>junit</groupId> | |
+ <artifactId>junit</artifactId> | |
+ </dependency> | |
+ <dependency> | |
+ <groupId>org.apache.geronimo.specs</groupId> | |
+ <artifactId>geronimo-servlet_2.5_spec</artifactId> | |
+ <version>1.2</version> | |
+ </dependency> | |
+ | |
+ <dependency> | |
+ <groupId>org.apache.openwebbeans.test</groupId> | |
+ <artifactId>cditest-owb</artifactId> | |
+ <version>1.2.0</version> | |
+ <scope>test</scope> | |
+ </dependency> | |
+ </dependencies> | |
+ | |
+</project> | |
Index: spring/pom.xml | |
=================================================================== | |
--- spring/pom.xml (revision 1506597) | |
+++ spring/pom.xml (working copy) | |
@@ -24,7 +24,7 @@ | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.apache.commons.monitoring</groupId> | |
<artifactId>commons-monitoring-spring</artifactId> | |
- <name>Commons Monitoring (Sandbox) spring integration</name> | |
+ <name>Commons Monitoring (Sandbox) :: Spring Integration</name> | |
<dependencies> | |
<dependency> | |
Index: jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnection.java | |
=================================================================== | |
--- jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnection.java (revision 1506597) | |
+++ jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnection.java (working copy) | |
@@ -17,32 +17,23 @@ | |
package org.apache.commons.monitoring.jdbc; | |
-import java.sql.Array; | |
-import java.sql.Blob; | |
+import org.apache.commons.monitoring.Repository; | |
+import org.apache.commons.monitoring.util.ClassLoaders; | |
+ | |
+import java.lang.reflect.InvocationHandler; | |
+import java.lang.reflect.InvocationTargetException; | |
+import java.lang.reflect.Method; | |
+import java.lang.reflect.Proxy; | |
import java.sql.CallableStatement; | |
-import java.sql.Clob; | |
import java.sql.Connection; | |
-import java.sql.DatabaseMetaData; | |
-import java.sql.NClob; | |
import java.sql.PreparedStatement; | |
-import java.sql.SQLClientInfoException; | |
-import java.sql.SQLException; | |
-import java.sql.SQLWarning; | |
-import java.sql.SQLXML; | |
-import java.sql.Savepoint; | |
import java.sql.Statement; | |
-import java.sql.Struct; | |
-import java.util.Map; | |
-import java.util.Properties; | |
-import org.apache.commons.monitoring.Repository; | |
-import org.apache.commons.monitoring.jdbc.MonitoredCallableStatement; | |
- | |
/** | |
* @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a> | |
*/ | |
public class MonitoredConnection | |
- implements Connection | |
+ implements InvocationHandler | |
{ | |
/** target connection */ | |
@@ -54,7 +45,7 @@ | |
/** | |
* @param connection target connection | |
- * @param monitor monitor for opened connections | |
+ * @param repository repository to get monitors for opened connections | |
*/ | |
public MonitoredConnection( Connection connection, Repository repository, ConnectionClosedCallBack callBack ) | |
{ | |
@@ -64,95 +55,49 @@ | |
this.callBack = callBack; | |
} | |
- public void close() | |
- throws SQLException | |
+ @Override | |
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable | |
{ | |
- connection.close(); | |
- callBack.onConnectionClosed(); | |
- } | |
+ final String name = method.getName(); | |
+ if ("close".equals(name)) | |
+ { | |
+ connection.close(); | |
+ callBack.onConnectionClosed(); | |
+ return null; | |
+ } | |
- public Statement createStatement() | |
- throws SQLException | |
- { | |
- return monitor( connection.createStatement() ); | |
- } | |
+ if (name.startsWith("prepare") || name.startsWith("create")) | |
+ { | |
+ final Class<?> returnType = method.getReturnType(); | |
+ if (CallableStatement.class.equals(returnType)) | |
+ { | |
+ monitor(CallableStatement.class.cast(doInvoke(method, args))); | |
+ } | |
+ else if (PreparedStatement.class.equals(returnType)) | |
+ { | |
+ monitor(PreparedStatement.class.cast(doInvoke(method, args))); | |
+ } | |
+ else if (Statement.class.equals(returnType)) | |
+ { | |
+ monitor(Statement.class.cast(doInvoke(method, args))); | |
+ } | |
+ } | |
- public Statement createStatement( int resultSetType, int resultSetConcurrency, int resultSetHoldability ) | |
- throws SQLException | |
- { | |
- return monitor( connection.createStatement( resultSetType, resultSetConcurrency, resultSetHoldability ) ); | |
+ return doInvoke(method, args); | |
} | |
- public Statement createStatement( int resultSetType, int resultSetConcurrency ) | |
- throws SQLException | |
+ private Object doInvoke(final Method method, final Object[] args) throws IllegalAccessException, InvocationTargetException | |
{ | |
- return monitor( connection.createStatement( resultSetType, resultSetConcurrency ) ); | |
+ return method.invoke(connection, args); | |
} | |
- public CallableStatement prepareCall( String sql, int resultSetType, int resultSetConcurrency, | |
- int resultSetHoldability ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareCall( sql, resultSetType, resultSetConcurrency, resultSetHoldability ), sql ); | |
- } | |
- | |
- public CallableStatement prepareCall( String sql, int resultSetType, int resultSetConcurrency ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareCall( sql, resultSetType, resultSetConcurrency ), sql ); | |
- } | |
- | |
- public CallableStatement prepareCall( String sql ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareCall( sql ), sql ); | |
- } | |
- | |
- public PreparedStatement prepareStatement( String sql, int resultSetType, int resultSetConcurrency, | |
- int resultSetHoldability ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareStatement( sql, resultSetType, resultSetConcurrency, resultSetHoldability ), | |
- sql ); | |
- } | |
- | |
- public PreparedStatement prepareStatement( String sql, int resultSetType, int resultSetConcurrency ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareStatement( sql, resultSetType, resultSetConcurrency ), sql ); | |
- } | |
- | |
- public PreparedStatement prepareStatement( String sql, int autoGeneratedKeys ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareStatement( sql, autoGeneratedKeys ), sql ); | |
- } | |
- | |
- public PreparedStatement prepareStatement( String sql, int[] columnIndexes ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareStatement( sql, columnIndexes ), sql ); | |
- } | |
- | |
- public PreparedStatement prepareStatement( String sql, String[] columnNames ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareStatement( sql, columnNames ), sql ); | |
- } | |
- | |
- public PreparedStatement prepareStatement( String sql ) | |
- throws SQLException | |
- { | |
- return monitor( connection.prepareStatement( sql ), sql ); | |
- } | |
- | |
/** | |
* @param statement traget Statement | |
* @return monitored Statement | |
*/ | |
private Statement monitor( Statement statement ) | |
{ | |
- return new MonitoredStatement( statement, repository ); | |
+ return Statement.class.cast(Proxy.newProxyInstance(ClassLoaders.current(), new Class<?>[] { Statement.class }, new MonitoredStatement( statement, repository ))); | |
} | |
/** | |
@@ -162,7 +107,7 @@ | |
*/ | |
private PreparedStatement monitor( PreparedStatement statement, String sql ) | |
{ | |
- return new MonitoredPreparedStatement( statement, sql, repository ); | |
+ return PreparedStatement.class.cast(Proxy.newProxyInstance(ClassLoaders.current(), new Class<?>[] { PreparedStatement.class }, new MonitoredPreparedStatement( statement, sql, repository ))); | |
} | |
/** | |
@@ -172,226 +117,6 @@ | |
*/ | |
private CallableStatement monitor( CallableStatement statement, String sql ) | |
{ | |
- return new MonitoredCallableStatement( statement, sql, repository ); | |
+ return CallableStatement.class.cast(Proxy.newProxyInstance(ClassLoaders.current(), new Class<?>[] { CallableStatement.class }, new MonitoredPreparedStatement( statement, sql, repository ))); | |
} | |
- | |
- // --- delegates methods --- | |
- | |
- public void clearWarnings() | |
- throws SQLException | |
- { | |
- connection.clearWarnings(); | |
- } | |
- | |
- public void commit() | |
- throws SQLException | |
- { | |
- connection.commit(); | |
- } | |
- | |
- public boolean getAutoCommit() | |
- throws SQLException | |
- { | |
- return connection.getAutoCommit(); | |
- } | |
- | |
- public String getCatalog() | |
- throws SQLException | |
- { | |
- return connection.getCatalog(); | |
- } | |
- | |
- public int getHoldability() | |
- throws SQLException | |
- { | |
- return connection.getHoldability(); | |
- } | |
- | |
- public DatabaseMetaData getMetaData() | |
- throws SQLException | |
- { | |
- return connection.getMetaData(); | |
- } | |
- | |
- public int getTransactionIsolation() | |
- throws SQLException | |
- { | |
- return connection.getTransactionIsolation(); | |
- } | |
- | |
- public Map<String, Class<?>> getTypeMap() | |
- throws SQLException | |
- { | |
- return connection.getTypeMap(); | |
- } | |
- | |
- public SQLWarning getWarnings() | |
- throws SQLException | |
- { | |
- return connection.getWarnings(); | |
- } | |
- | |
- public boolean isClosed() | |
- throws SQLException | |
- { | |
- return connection.isClosed(); | |
- } | |
- | |
- public boolean isReadOnly() | |
- throws SQLException | |
- { | |
- return connection.isReadOnly(); | |
- } | |
- | |
- public String nativeSQL( String sql ) | |
- throws SQLException | |
- { | |
- return connection.nativeSQL( sql ); | |
- } | |
- | |
- public void releaseSavepoint( Savepoint savepoint ) | |
- throws SQLException | |
- { | |
- connection.releaseSavepoint( savepoint ); | |
- } | |
- | |
- public void rollback() | |
- throws SQLException | |
- { | |
- connection.rollback(); | |
- } | |
- | |
- public void rollback( Savepoint savepoint ) | |
- throws SQLException | |
- { | |
- connection.rollback( savepoint ); | |
- } | |
- | |
- public void setAutoCommit( boolean autoCommit ) | |
- throws SQLException | |
- { | |
- connection.setAutoCommit( autoCommit ); | |
- } | |
- | |
- public void setCatalog( String catalog ) | |
- throws SQLException | |
- { | |
- connection.setCatalog( catalog ); | |
- } | |
- | |
- public void setHoldability( int holdability ) | |
- throws SQLException | |
- { | |
- connection.setHoldability( holdability ); | |
- } | |
- | |
- public void setReadOnly( boolean readOnly ) | |
- throws SQLException | |
- { | |
- connection.setReadOnly( readOnly ); | |
- } | |
- | |
- public Savepoint setSavepoint() | |
- throws SQLException | |
- { | |
- return connection.setSavepoint(); | |
- } | |
- | |
- public Savepoint setSavepoint( String name ) | |
- throws SQLException | |
- { | |
- return connection.setSavepoint( name ); | |
- } | |
- | |
- public void setTransactionIsolation( int level ) | |
- throws SQLException | |
- { | |
- connection.setTransactionIsolation( level ); | |
- } | |
- | |
- public void setTypeMap( Map<String, Class<?>> map ) | |
- throws SQLException | |
- { | |
- connection.setTypeMap( map ); | |
- } | |
- | |
- // --- jdbc4 ---- | |
- | |
- public Array createArrayOf( String typeName, Object[] elements ) | |
- throws SQLException | |
- { | |
- return connection.createArrayOf( typeName, elements ); | |
- } | |
- | |
- public Blob createBlob() | |
- throws SQLException | |
- { | |
- return connection.createBlob(); | |
- } | |
- | |
- public Clob createClob() | |
- throws SQLException | |
- { | |
- return connection.createClob(); | |
- } | |
- | |
- public NClob createNClob() | |
- throws SQLException | |
- { | |
- return connection.createNClob(); | |
- } | |
- | |
- public SQLXML createSQLXML() | |
- throws SQLException | |
- { | |
- return connection.createSQLXML(); | |
- } | |
- | |
- public Struct createStruct( String typeName, Object[] attributes ) | |
- throws SQLException | |
- { | |
- return connection.createStruct( typeName, attributes ); | |
- } | |
- | |
- public Properties getClientInfo() | |
- throws SQLException | |
- { | |
- return connection.getClientInfo(); | |
- } | |
- | |
- public String getClientInfo( String name ) | |
- throws SQLException | |
- { | |
- return connection.getClientInfo( name ); | |
- } | |
- | |
- public boolean isValid( int timeout ) | |
- throws SQLException | |
- { | |
- return connection.isValid( timeout ); | |
- } | |
- | |
- public boolean isWrapperFor( Class<?> iface ) | |
- throws SQLException | |
- { | |
- return connection.isWrapperFor( iface ); | |
- } | |
- | |
- public void setClientInfo( Properties properties ) | |
- throws SQLClientInfoException | |
- { | |
- connection.setClientInfo( properties ); | |
- } | |
- | |
- public void setClientInfo( String name, String value ) | |
- throws SQLClientInfoException | |
- { | |
- connection.setClientInfo( name, value ); | |
- } | |
- | |
- public <T> T unwrap( Class<T> iface ) | |
- throws SQLException | |
- { | |
- return connection.unwrap( iface ); | |
- } | |
} | |
Index: jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredStatementHandler.java | |
=================================================================== | |
--- jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredStatementHandler.java (revision 1506597) | |
+++ jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredStatementHandler.java (working copy) | |
@@ -1,73 +0,0 @@ | |
-package org.apache.commons.monitoring.jdbc; | |
- | |
-import java.lang.reflect.InvocationHandler; | |
-import java.lang.reflect.InvocationTargetException; | |
-import java.lang.reflect.Method; | |
-import java.sql.SQLException; | |
-import java.sql.Statement; | |
- | |
-import org.apache.commons.monitoring.Monitor; | |
-import org.apache.commons.monitoring.Repository; | |
-import org.apache.commons.monitoring.StopWatch; | |
- | |
-/** | |
- * @author ndeloof | |
- * | |
- */ | |
-public class MonitoredStatementHandler | |
- implements InvocationHandler | |
-{ | |
- | |
- private Repository repository; | |
- | |
- private Statement statement; | |
- | |
- /** | |
- * @param repository | |
- * @param statement | |
- */ | |
- public MonitoredStatementHandler( Repository repository, Statement statement ) | |
- { | |
- super(); | |
- this.repository = repository; | |
- this.statement = statement; | |
- } | |
- | |
- /** | |
- * {@inheritDoc} | |
- * | |
- * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) | |
- */ | |
- public Object invoke( Object proxy, Method method, Object[] args ) | |
- throws Throwable | |
- { | |
- if ( method.getName().startsWith( "execute" ) ) | |
- { | |
- // skip executeUpdate | |
- String sql = ( args.length > 0 ? (String) args[0] : "batch" ); | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return method.invoke( statement, args ); | |
- } | |
- catch ( InvocationTargetException ite ) | |
- { | |
- if ( ite.getCause() instanceof SQLException ) | |
- { | |
- SQLException sqle = (SQLException) ite.getCause(); | |
- String name = "SQLException:" + sqle.getSQLState() + ":" + sqle.getErrorCode(); | |
- Monitor monitor = repository.getMonitor( name, "jdbc" ); | |
- monitor.getCounter( Monitor.FAILURES ).add( 1 ); | |
- throw sqle; | |
- } | |
- throw ite; | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- return method.invoke( proxy, args ); | |
- } | |
- | |
-} | |
Index: jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredStatement.java | |
=================================================================== | |
--- jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredStatement.java (revision 1506597) | |
+++ jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredStatement.java (working copy) | |
@@ -17,35 +17,35 @@ | |
package org.apache.commons.monitoring.jdbc; | |
-import java.sql.Connection; | |
-import java.sql.ResultSet; | |
-import java.sql.SQLException; | |
-import java.sql.SQLWarning; | |
-import java.sql.Statement; | |
- | |
import org.apache.commons.monitoring.Monitor; | |
import org.apache.commons.monitoring.Repository; | |
import org.apache.commons.monitoring.StopWatch; | |
+import java.lang.reflect.InvocationHandler; | |
+import java.lang.reflect.InvocationTargetException; | |
+import java.lang.reflect.Method; | |
+import java.sql.SQLException; | |
+import java.sql.Statement; | |
+ | |
/** | |
* @author <a href="mailto:ndeloof@sourceforge.net">Nicolas De Loof</a> | |
*/ | |
public class MonitoredStatement | |
- implements Statement | |
+ implements InvocationHandler | |
{ | |
/** delegate statement */ | |
private Statement statement; | |
protected Repository repository; | |
- public MonitoredStatement( Statement statement, Repository repository ) | |
+ public MonitoredStatement( final Statement statement, final Repository repository ) | |
{ | |
super(); | |
this.statement = statement; | |
this.repository = repository; | |
} | |
- protected SQLException monitor( SQLException sqle ) | |
+ protected SQLException monitor( final SQLException sqle ) | |
{ | |
String name = "SQLException:" + sqle.getSQLState() + ":" + sqle.getErrorCode(); | |
Monitor monitor = repository.getMonitor( name, "jdbc" ); | |
@@ -53,379 +53,50 @@ | |
return sqle; | |
} | |
- // --- delegate methods --- | |
- | |
- public final void addBatch( String sql ) | |
- throws SQLException | |
+ @Override | |
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable | |
{ | |
- statement.addBatch( sql ); | |
- } | |
- | |
- public final void cancel() | |
- throws SQLException | |
- { | |
- statement.cancel(); | |
- } | |
- | |
- public final void clearBatch() | |
- throws SQLException | |
- { | |
- statement.clearBatch(); | |
- } | |
- | |
- public final void clearWarnings() | |
- throws SQLException | |
- { | |
- statement.clearWarnings(); | |
- } | |
- | |
- public final void close() | |
- throws SQLException | |
- { | |
- statement.close(); | |
- } | |
- | |
- public final boolean execute( String sql, int autoGeneratedKeys ) | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
+ final String name = method.getName(); | |
+ if (name.startsWith("execute")) | |
{ | |
- return statement.execute( sql, autoGeneratedKeys ); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
+ final StopWatch stopWatch; | |
+ if (name.endsWith("Batch") && (args == null || args.length == 0)) | |
+ { | |
+ stopWatch = repository.start( repository.getMonitor( "batch", "jdbc" ) ); | |
+ } | |
+ else | |
+ { | |
+ stopWatch = repository.start( repository.getMonitor( (String) args[0], "jdbc" ) ); | |
+ } | |
- public final boolean execute( String sql, int[] columnIndexes ) | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.execute( sql, columnIndexes ); | |
+ try | |
+ { | |
+ return doInvoke(method, args); | |
+ } | |
+ catch ( final InvocationTargetException e ) | |
+ { | |
+ throw extractSQLException(e); | |
+ } | |
+ finally | |
+ { | |
+ stopWatch.stop(); | |
+ } | |
} | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
+ return doInvoke(method, args); | |
} | |
- public final boolean execute( String sql, String[] columnNames ) | |
- throws SQLException | |
+ private Object doInvoke(final Method method, final Object[] args) throws IllegalAccessException, InvocationTargetException | |
{ | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.execute( sql, columnNames ); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
+ return method.invoke(statement, args); | |
} | |
- public final boolean execute( String sql ) | |
- throws SQLException | |
+ protected Throwable extractSQLException(final InvocationTargetException e) throws Throwable | |
{ | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
+ final Throwable th = e.getCause(); | |
+ if (SQLException.class.isInstance(th)) | |
{ | |
- return statement.execute( sql ); | |
+ return monitor( SQLException.class.cast(th) ); | |
} | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
+ return th; | |
} | |
- | |
- public final int[] executeBatch() | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( "batch", "jdbc" ) ); | |
- try | |
- { | |
- return statement.executeBatch(); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- | |
- public final ResultSet executeQuery( String sql ) | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.executeQuery( sql ); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- | |
- public final int executeUpdate( String sql, int autoGeneratedKeys ) | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.executeUpdate( sql, autoGeneratedKeys ); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- | |
- public final int executeUpdate( String sql, int[] columnIndexes ) | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.executeUpdate( sql, columnIndexes ); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- | |
- public final int executeUpdate( String sql, String[] columnNames ) | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.executeUpdate( sql, columnNames ); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- | |
- public final int executeUpdate( String sql ) | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.executeUpdate( sql ); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- | |
- public final Connection getConnection() | |
- throws SQLException | |
- { | |
- return statement.getConnection(); | |
- } | |
- | |
- public final int getFetchDirection() | |
- throws SQLException | |
- { | |
- return statement.getFetchDirection(); | |
- } | |
- | |
- public final int getFetchSize() | |
- throws SQLException | |
- { | |
- return statement.getFetchSize(); | |
- } | |
- | |
- public final ResultSet getGeneratedKeys() | |
- throws SQLException | |
- { | |
- return statement.getGeneratedKeys(); | |
- } | |
- | |
- public final int getMaxFieldSize() | |
- throws SQLException | |
- { | |
- return statement.getMaxFieldSize(); | |
- } | |
- | |
- public final int getMaxRows() | |
- throws SQLException | |
- { | |
- return statement.getMaxRows(); | |
- } | |
- | |
- public final boolean getMoreResults() | |
- throws SQLException | |
- { | |
- return statement.getMoreResults(); | |
- } | |
- | |
- public final boolean getMoreResults( int current ) | |
- throws SQLException | |
- { | |
- return statement.getMoreResults( current ); | |
- } | |
- | |
- public final int getQueryTimeout() | |
- throws SQLException | |
- { | |
- return statement.getQueryTimeout(); | |
- } | |
- | |
- public final ResultSet getResultSet() | |
- throws SQLException | |
- { | |
- return statement.getResultSet(); | |
- } | |
- | |
- public final int getResultSetConcurrency() | |
- throws SQLException | |
- { | |
- return statement.getResultSetConcurrency(); | |
- } | |
- | |
- public final int getResultSetHoldability() | |
- throws SQLException | |
- { | |
- return statement.getResultSetHoldability(); | |
- } | |
- | |
- public final int getResultSetType() | |
- throws SQLException | |
- { | |
- return statement.getResultSetType(); | |
- } | |
- | |
- public final int getUpdateCount() | |
- throws SQLException | |
- { | |
- return statement.getUpdateCount(); | |
- } | |
- | |
- public final SQLWarning getWarnings() | |
- throws SQLException | |
- { | |
- return statement.getWarnings(); | |
- } | |
- | |
- public final void setCursorName( String name ) | |
- throws SQLException | |
- { | |
- statement.setCursorName( name ); | |
- } | |
- | |
- public final void setEscapeProcessing( boolean enable ) | |
- throws SQLException | |
- { | |
- statement.setEscapeProcessing( enable ); | |
- } | |
- | |
- public final void setFetchDirection( int direction ) | |
- throws SQLException | |
- { | |
- statement.setFetchDirection( direction ); | |
- } | |
- | |
- public final void setFetchSize( int rows ) | |
- throws SQLException | |
- { | |
- statement.setFetchSize( rows ); | |
- } | |
- | |
- public final void setMaxFieldSize( int max ) | |
- throws SQLException | |
- { | |
- statement.setMaxFieldSize( max ); | |
- } | |
- | |
- public final void setMaxRows( int max ) | |
- throws SQLException | |
- { | |
- statement.setMaxRows( max ); | |
- } | |
- | |
- public final void setQueryTimeout( int seconds ) | |
- throws SQLException | |
- { | |
- statement.setQueryTimeout( seconds ); | |
- } | |
- | |
- // --- jdbc4 ---- | |
- | |
- public final boolean isClosed() | |
- throws SQLException | |
- { | |
- return statement.isClosed(); | |
- } | |
- | |
- public final boolean isPoolable() | |
- throws SQLException | |
- { | |
- return statement.isPoolable(); | |
- } | |
- | |
- public final boolean isWrapperFor( Class<?> iface ) | |
- throws SQLException | |
- { | |
- return statement.isWrapperFor( iface ); | |
- } | |
- | |
- public final void setPoolable( boolean poolable ) | |
- throws SQLException | |
- { | |
- statement.setPoolable( poolable ); | |
- } | |
- | |
- public final <T> T unwrap( Class<T> iface ) | |
- throws SQLException | |
- { | |
- return statement.unwrap( iface ); | |
- } | |
} | |
Index: jdbc/src/main/java/org/apache/commons/monitoring/jdbc/AbstractMonitoredDataSource.java | |
=================================================================== | |
--- jdbc/src/main/java/org/apache/commons/monitoring/jdbc/AbstractMonitoredDataSource.java (revision 1506597) | |
+++ jdbc/src/main/java/org/apache/commons/monitoring/jdbc/AbstractMonitoredDataSource.java (working copy) | |
@@ -1,6 +1,8 @@ | |
package org.apache.commons.monitoring.jdbc; | |
+import java.lang.reflect.Proxy; | |
import java.sql.Connection; | |
+import java.sql.Statement; | |
import javax.sql.DataSource; | |
@@ -11,6 +13,7 @@ | |
import org.apache.commons.monitoring.Unit; | |
import org.apache.commons.monitoring.Metric.Type; | |
import org.apache.commons.monitoring.stopwatches.DefaultStopWatch; | |
+import org.apache.commons.monitoring.util.ClassLoaders; | |
/** | |
* @author ndeloof | |
@@ -46,7 +49,7 @@ | |
/** | |
* Constructor | |
- * | |
+ * | |
* @param dataSource the datasource to monitor | |
* @param repository the Monitoring repository | |
*/ | |
@@ -102,13 +105,14 @@ | |
{ | |
// Computes the number of open connections and the connection duration | |
final StopWatch stopWatch = new DefaultStopWatch( monitor, OPEN_CONECTIONS, CONECTION_DURATION ); | |
- return new MonitoredConnection( connection, repository, new ConnectionClosedCallBack() | |
+ return Connection.class.cast(Proxy.newProxyInstance(ClassLoaders.current(), new Class<?>[]{Connection.class}, new MonitoredConnection( connection, repository, new ConnectionClosedCallBack() | |
{ | |
+ @Override | |
public void onConnectionClosed() | |
{ | |
stopWatch.stop(); | |
} | |
- } ); | |
+ } ))); | |
} | |
/** | |
Index: jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredCallableStatement.java | |
=================================================================== | |
--- jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredCallableStatement.java (revision 1506597) | |
+++ jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredCallableStatement.java (working copy) | |
@@ -1,717 +0,0 @@ | |
-package org.apache.commons.monitoring.jdbc; | |
- | |
-import java.io.InputStream; | |
-import java.io.Reader; | |
-import java.math.BigDecimal; | |
-import java.net.URL; | |
-import java.sql.Array; | |
-import java.sql.Blob; | |
-import java.sql.CallableStatement; | |
-import java.sql.Clob; | |
-import java.sql.Date; | |
-import java.sql.NClob; | |
-import java.sql.Ref; | |
-import java.sql.RowId; | |
-import java.sql.SQLException; | |
-import java.sql.SQLXML; | |
-import java.sql.Time; | |
-import java.sql.Timestamp; | |
-import java.util.Calendar; | |
-import java.util.Map; | |
- | |
-import org.apache.commons.monitoring.Repository; | |
-import org.apache.commons.monitoring.jdbc.MonitoredPreparedStatement; | |
- | |
-/** | |
- * @author ndeloof | |
- * | |
- */ | |
-public class MonitoredCallableStatement | |
- extends MonitoredPreparedStatement | |
- implements CallableStatement | |
-{ | |
- private CallableStatement statement; | |
- | |
- /** | |
- * @param statement | |
- * @param sql | |
- * @param repository | |
- */ | |
- public MonitoredCallableStatement( CallableStatement statement, String sql, Repository repository ) | |
- { | |
- super( statement, sql, repository ); | |
- this.statement = statement; | |
- } | |
- | |
- // --- delegate methods --- | |
- | |
- public Array getArray( int i ) | |
- throws SQLException | |
- { | |
- return statement.getArray( i ); | |
- } | |
- | |
- public Array getArray( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getArray( parameterName ); | |
- } | |
- | |
- @Deprecated | |
- public BigDecimal getBigDecimal( int parameterIndex, int scale ) | |
- throws SQLException | |
- { | |
- return statement.getBigDecimal( parameterIndex, scale ); | |
- } | |
- | |
- public BigDecimal getBigDecimal( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getBigDecimal( parameterIndex ); | |
- } | |
- | |
- public BigDecimal getBigDecimal( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getBigDecimal( parameterName ); | |
- } | |
- | |
- public Blob getBlob( int i ) | |
- throws SQLException | |
- { | |
- return statement.getBlob( i ); | |
- } | |
- | |
- public Blob getBlob( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getBlob( parameterName ); | |
- } | |
- | |
- public boolean getBoolean( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getBoolean( parameterIndex ); | |
- } | |
- | |
- public boolean getBoolean( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getBoolean( parameterName ); | |
- } | |
- | |
- public byte getByte( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getByte( parameterIndex ); | |
- } | |
- | |
- public byte getByte( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getByte( parameterName ); | |
- } | |
- | |
- public byte[] getBytes( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getBytes( parameterIndex ); | |
- } | |
- | |
- public byte[] getBytes( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getBytes( parameterName ); | |
- } | |
- | |
- public Clob getClob( int i ) | |
- throws SQLException | |
- { | |
- return statement.getClob( i ); | |
- } | |
- | |
- public Clob getClob( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getClob( parameterName ); | |
- } | |
- | |
- public Date getDate( int parameterIndex, Calendar cal ) | |
- throws SQLException | |
- { | |
- return statement.getDate( parameterIndex, cal ); | |
- } | |
- | |
- public Date getDate( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getDate( parameterIndex ); | |
- } | |
- | |
- public Date getDate( String parameterName, Calendar cal ) | |
- throws SQLException | |
- { | |
- return statement.getDate( parameterName, cal ); | |
- } | |
- | |
- public Date getDate( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getDate( parameterName ); | |
- } | |
- | |
- public double getDouble( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getDouble( parameterIndex ); | |
- } | |
- | |
- public double getDouble( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getDouble( parameterName ); | |
- } | |
- | |
- public float getFloat( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getFloat( parameterIndex ); | |
- } | |
- | |
- public float getFloat( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getFloat( parameterName ); | |
- } | |
- | |
- public int getInt( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getInt( parameterIndex ); | |
- } | |
- | |
- public int getInt( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getInt( parameterName ); | |
- } | |
- | |
- public long getLong( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getLong( parameterIndex ); | |
- } | |
- | |
- public long getLong( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getLong( parameterName ); | |
- } | |
- | |
- public Object getObject( int i, Map<String, Class<?>> map ) | |
- throws SQLException | |
- { | |
- return statement.getObject( i, map ); | |
- } | |
- | |
- public Object getObject( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getObject( parameterIndex ); | |
- } | |
- | |
- public Object getObject( String parameterName, Map<String, Class<?>> map ) | |
- throws SQLException | |
- { | |
- return statement.getObject( parameterName, map ); | |
- } | |
- | |
- public Object getObject( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getObject( parameterName ); | |
- } | |
- | |
- public Ref getRef( int i ) | |
- throws SQLException | |
- { | |
- return statement.getRef( i ); | |
- } | |
- | |
- public Ref getRef( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getRef( parameterName ); | |
- } | |
- | |
- public short getShort( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getShort( parameterIndex ); | |
- } | |
- | |
- public short getShort( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getShort( parameterName ); | |
- } | |
- | |
- public String getString( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getString( parameterIndex ); | |
- } | |
- | |
- public String getString( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getString( parameterName ); | |
- } | |
- | |
- public Time getTime( int parameterIndex, Calendar cal ) | |
- throws SQLException | |
- { | |
- return statement.getTime( parameterIndex, cal ); | |
- } | |
- | |
- public Time getTime( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getTime( parameterIndex ); | |
- } | |
- | |
- public Time getTime( String parameterName, Calendar cal ) | |
- throws SQLException | |
- { | |
- return statement.getTime( parameterName, cal ); | |
- } | |
- | |
- public Time getTime( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getTime( parameterName ); | |
- } | |
- | |
- public Timestamp getTimestamp( int parameterIndex, Calendar cal ) | |
- throws SQLException | |
- { | |
- return statement.getTimestamp( parameterIndex, cal ); | |
- } | |
- | |
- public Timestamp getTimestamp( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getTimestamp( parameterIndex ); | |
- } | |
- | |
- public Timestamp getTimestamp( String parameterName, Calendar cal ) | |
- throws SQLException | |
- { | |
- return statement.getTimestamp( parameterName, cal ); | |
- } | |
- | |
- public Timestamp getTimestamp( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getTimestamp( parameterName ); | |
- } | |
- | |
- public URL getURL( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getURL( parameterIndex ); | |
- } | |
- | |
- public URL getURL( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getURL( parameterName ); | |
- } | |
- | |
- public void registerOutParameter( int parameterIndex, int sqlType, int scale ) | |
- throws SQLException | |
- { | |
- statement.registerOutParameter( parameterIndex, sqlType, scale ); | |
- } | |
- | |
- public void registerOutParameter( int paramIndex, int sqlType, String typeName ) | |
- throws SQLException | |
- { | |
- statement.registerOutParameter( paramIndex, sqlType, typeName ); | |
- } | |
- | |
- public void registerOutParameter( int parameterIndex, int sqlType ) | |
- throws SQLException | |
- { | |
- statement.registerOutParameter( parameterIndex, sqlType ); | |
- } | |
- | |
- public void registerOutParameter( String parameterName, int sqlType, int scale ) | |
- throws SQLException | |
- { | |
- statement.registerOutParameter( parameterName, sqlType, scale ); | |
- } | |
- | |
- public void registerOutParameter( String parameterName, int sqlType, String typeName ) | |
- throws SQLException | |
- { | |
- statement.registerOutParameter( parameterName, sqlType, typeName ); | |
- } | |
- | |
- public void registerOutParameter( String parameterName, int sqlType ) | |
- throws SQLException | |
- { | |
- statement.registerOutParameter( parameterName, sqlType ); | |
- } | |
- | |
- public void setAsciiStream( String parameterName, InputStream x, int length ) | |
- throws SQLException | |
- { | |
- statement.setAsciiStream( parameterName, x, length ); | |
- } | |
- | |
- public void setBigDecimal( String parameterName, BigDecimal x ) | |
- throws SQLException | |
- { | |
- statement.setBigDecimal( parameterName, x ); | |
- } | |
- | |
- public void setBinaryStream( String parameterName, InputStream x, int length ) | |
- throws SQLException | |
- { | |
- statement.setBinaryStream( parameterName, x, length ); | |
- } | |
- | |
- public void setBoolean( String parameterName, boolean x ) | |
- throws SQLException | |
- { | |
- statement.setBoolean( parameterName, x ); | |
- } | |
- | |
- public void setByte( String parameterName, byte x ) | |
- throws SQLException | |
- { | |
- statement.setByte( parameterName, x ); | |
- } | |
- | |
- public void setBytes( String parameterName, byte[] x ) | |
- throws SQLException | |
- { | |
- statement.setBytes( parameterName, x ); | |
- } | |
- | |
- public void setCharacterStream( String parameterName, Reader reader, int length ) | |
- throws SQLException | |
- { | |
- statement.setCharacterStream( parameterName, reader, length ); | |
- } | |
- | |
- public void setDate( String parameterName, Date x, Calendar cal ) | |
- throws SQLException | |
- { | |
- statement.setDate( parameterName, x, cal ); | |
- } | |
- | |
- public void setDate( String parameterName, Date x ) | |
- throws SQLException | |
- { | |
- statement.setDate( parameterName, x ); | |
- } | |
- | |
- public void setDouble( String parameterName, double x ) | |
- throws SQLException | |
- { | |
- statement.setDouble( parameterName, x ); | |
- } | |
- | |
- public void setFloat( String parameterName, float x ) | |
- throws SQLException | |
- { | |
- statement.setFloat( parameterName, x ); | |
- } | |
- | |
- public void setInt( String parameterName, int x ) | |
- throws SQLException | |
- { | |
- statement.setInt( parameterName, x ); | |
- } | |
- | |
- public void setLong( String parameterName, long x ) | |
- throws SQLException | |
- { | |
- statement.setLong( parameterName, x ); | |
- } | |
- | |
- public void setNull( String parameterName, int sqlType, String typeName ) | |
- throws SQLException | |
- { | |
- statement.setNull( parameterName, sqlType, typeName ); | |
- } | |
- | |
- public void setNull( String parameterName, int sqlType ) | |
- throws SQLException | |
- { | |
- statement.setNull( parameterName, sqlType ); | |
- } | |
- | |
- public void setObject( String parameterName, Object x, int targetSqlType, int scale ) | |
- throws SQLException | |
- { | |
- statement.setObject( parameterName, x, targetSqlType, scale ); | |
- } | |
- | |
- public void setObject( String parameterName, Object x, int targetSqlType ) | |
- throws SQLException | |
- { | |
- statement.setObject( parameterName, x, targetSqlType ); | |
- } | |
- | |
- public void setObject( String parameterName, Object x ) | |
- throws SQLException | |
- { | |
- statement.setObject( parameterName, x ); | |
- } | |
- | |
- public void setShort( String parameterName, short x ) | |
- throws SQLException | |
- { | |
- statement.setShort( parameterName, x ); | |
- } | |
- | |
- public void setString( String parameterName, String x ) | |
- throws SQLException | |
- { | |
- statement.setString( parameterName, x ); | |
- } | |
- | |
- public void setTime( String parameterName, Time x, Calendar cal ) | |
- throws SQLException | |
- { | |
- statement.setTime( parameterName, x, cal ); | |
- } | |
- | |
- public void setTime( String parameterName, Time x ) | |
- throws SQLException | |
- { | |
- statement.setTime( parameterName, x ); | |
- } | |
- | |
- public void setTimestamp( String parameterName, Timestamp x, Calendar cal ) | |
- throws SQLException | |
- { | |
- statement.setTimestamp( parameterName, x, cal ); | |
- } | |
- | |
- public void setTimestamp( String parameterName, Timestamp x ) | |
- throws SQLException | |
- { | |
- statement.setTimestamp( parameterName, x ); | |
- } | |
- | |
- public void setURL( String parameterName, URL val ) | |
- throws SQLException | |
- { | |
- statement.setURL( parameterName, val ); | |
- } | |
- | |
- public boolean wasNull() | |
- throws SQLException | |
- { | |
- return statement.wasNull(); | |
- } | |
- | |
- // --- jdbc 4 --- | |
- | |
- public final Reader getCharacterStream( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getCharacterStream( parameterIndex ); | |
- } | |
- | |
- public final Reader getCharacterStream( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getCharacterStream( parameterName ); | |
- } | |
- | |
- public final Reader getNCharacterStream( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getNCharacterStream( parameterIndex ); | |
- } | |
- | |
- public final Reader getNCharacterStream( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getNCharacterStream( parameterName ); | |
- } | |
- | |
- public final NClob getNClob( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getNClob( parameterIndex ); | |
- } | |
- | |
- public final NClob getNClob( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getNClob( parameterName ); | |
- } | |
- | |
- public final String getNString( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getNString( parameterIndex ); | |
- } | |
- | |
- public final String getNString( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getNString( parameterName ); | |
- } | |
- | |
- public final RowId getRowId( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getRowId( parameterIndex ); | |
- } | |
- | |
- public final RowId getRowId( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getRowId( parameterName ); | |
- } | |
- | |
- public final SQLXML getSQLXML( int parameterIndex ) | |
- throws SQLException | |
- { | |
- return statement.getSQLXML( parameterIndex ); | |
- } | |
- | |
- public final SQLXML getSQLXML( String parameterName ) | |
- throws SQLException | |
- { | |
- return statement.getSQLXML( parameterName ); | |
- } | |
- | |
- public final void setAsciiStream( String parameterName, InputStream x, long length ) | |
- throws SQLException | |
- { | |
- statement.setAsciiStream( parameterName, x, length ); | |
- } | |
- | |
- public final void setAsciiStream( String parameterName, InputStream x ) | |
- throws SQLException | |
- { | |
- statement.setAsciiStream( parameterName, x ); | |
- } | |
- | |
- public final void setBinaryStream( String parameterName, InputStream x, long length ) | |
- throws SQLException | |
- { | |
- statement.setBinaryStream( parameterName, x, length ); | |
- } | |
- | |
- public final void setBinaryStream( String parameterName, InputStream x ) | |
- throws SQLException | |
- { | |
- statement.setBinaryStream( parameterName, x ); | |
- } | |
- | |
- public final void setBlob( String parameterName, Blob x ) | |
- throws SQLException | |
- { | |
- statement.setBlob( parameterName, x ); | |
- } | |
- | |
- public final void setBlob( String parameterName, InputStream inputStream, long length ) | |
- throws SQLException | |
- { | |
- statement.setBlob( parameterName, inputStream, length ); | |
- } | |
- | |
- public final void setBlob( String parameterName, InputStream inputStream ) | |
- throws SQLException | |
- { | |
- statement.setBlob( parameterName, inputStream ); | |
- } | |
- | |
- public final void setCharacterStream( String parameterName, Reader reader, long length ) | |
- throws SQLException | |
- { | |
- statement.setCharacterStream( parameterName, reader, length ); | |
- } | |
- | |
- public final void setCharacterStream( String parameterName, Reader reader ) | |
- throws SQLException | |
- { | |
- statement.setCharacterStream( parameterName, reader ); | |
- } | |
- | |
- public final void setClob( String parameterName, Clob x ) | |
- throws SQLException | |
- { | |
- statement.setClob( parameterName, x ); | |
- } | |
- | |
- public final void setClob( String parameterName, Reader reader, long length ) | |
- throws SQLException | |
- { | |
- statement.setClob( parameterName, reader, length ); | |
- } | |
- | |
- public final void setClob( String parameterName, Reader reader ) | |
- throws SQLException | |
- { | |
- statement.setClob( parameterName, reader ); | |
- } | |
- | |
- public final void setNCharacterStream( String parameterName, Reader value, long length ) | |
- throws SQLException | |
- { | |
- statement.setNCharacterStream( parameterName, value, length ); | |
- } | |
- | |
- public final void setNCharacterStream( String parameterName, Reader value ) | |
- throws SQLException | |
- { | |
- statement.setNCharacterStream( parameterName, value ); | |
- } | |
- | |
- public final void setNClob( String parameterName, NClob value ) | |
- throws SQLException | |
- { | |
- statement.setNClob( parameterName, value ); | |
- } | |
- | |
- public final void setNClob( String parameterName, Reader reader, long length ) | |
- throws SQLException | |
- { | |
- statement.setNClob( parameterName, reader, length ); | |
- } | |
- | |
- public final void setNClob( String parameterName, Reader reader ) | |
- throws SQLException | |
- { | |
- statement.setNClob( parameterName, reader ); | |
- } | |
- | |
- public final void setNString( String parameterName, String value ) | |
- throws SQLException | |
- { | |
- statement.setNString( parameterName, value ); | |
- } | |
- | |
- public final void setRowId( String parameterName, RowId x ) | |
- throws SQLException | |
- { | |
- statement.setRowId( parameterName, x ); | |
- } | |
- | |
- public final void setSQLXML( String parameterName, SQLXML xmlObject ) | |
- throws SQLException | |
- { | |
- statement.setSQLXML( parameterName, xmlObject ); | |
- } | |
- | |
-} | |
Index: jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredPreparedStatement.java | |
=================================================================== | |
--- jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredPreparedStatement.java (revision 1506597) | |
+++ jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredPreparedStatement.java (working copy) | |
@@ -1,36 +1,18 @@ | |
package org.apache.commons.monitoring.jdbc; | |
-import java.io.InputStream; | |
-import java.io.Reader; | |
-import java.math.BigDecimal; | |
-import java.net.URL; | |
-import java.sql.Array; | |
-import java.sql.Blob; | |
-import java.sql.Clob; | |
-import java.sql.Date; | |
-import java.sql.NClob; | |
-import java.sql.ParameterMetaData; | |
-import java.sql.PreparedStatement; | |
-import java.sql.Ref; | |
-import java.sql.ResultSet; | |
-import java.sql.ResultSetMetaData; | |
-import java.sql.RowId; | |
-import java.sql.SQLException; | |
-import java.sql.SQLXML; | |
-import java.sql.Time; | |
-import java.sql.Timestamp; | |
-import java.util.Calendar; | |
- | |
import org.apache.commons.monitoring.Repository; | |
import org.apache.commons.monitoring.StopWatch; | |
+import java.lang.reflect.InvocationTargetException; | |
+import java.lang.reflect.Method; | |
+import java.sql.PreparedStatement; | |
+ | |
/** | |
* @author ndeloof | |
* | |
*/ | |
public class MonitoredPreparedStatement | |
extends MonitoredStatement | |
- implements PreparedStatement | |
{ | |
private PreparedStatement statement; | |
@@ -47,374 +29,27 @@ | |
this.sql = sql; | |
} | |
- // --- delegate methods --- | |
- | |
- public final void addBatch() | |
- throws SQLException | |
+ @Override | |
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable | |
{ | |
- statement.addBatch(); | |
- } | |
- | |
- public final void clearParameters() | |
- throws SQLException | |
- { | |
- statement.clearParameters(); | |
- } | |
- | |
- public final boolean execute() | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
+ final String name = method.getName(); | |
+ if ((args == null || args.length == 0) && name.startsWith("execute")) | |
{ | |
- return statement.execute(); | |
+ final StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
+ try | |
+ { | |
+ return method.invoke(statement, args); | |
+ } | |
+ catch ( final InvocationTargetException e ) | |
+ { | |
+ throw extractSQLException(e); | |
+ } | |
+ finally | |
+ { | |
+ stopWatch.stop(); | |
+ } | |
} | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
+ return super.invoke(proxy, method, args); | |
} | |
- public final ResultSet executeQuery() | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.executeQuery(); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- | |
- public final int executeUpdate() | |
- throws SQLException | |
- { | |
- StopWatch stopWatch = repository.start( repository.getMonitor( sql, "jdbc" ) ); | |
- try | |
- { | |
- return statement.executeUpdate(); | |
- } | |
- catch ( SQLException sqle ) | |
- { | |
- throw monitor( sqle ); | |
- } | |
- finally | |
- { | |
- stopWatch.stop(); | |
- } | |
- } | |
- | |
- public final ResultSetMetaData getMetaData() | |
- throws SQLException | |
- { | |
- return statement.getMetaData(); | |
- } | |
- | |
- public final ParameterMetaData getParameterMetaData() | |
- throws SQLException | |
- { | |
- return statement.getParameterMetaData(); | |
- } | |
- | |
- public final void setArray( int i, Array x ) | |
- throws SQLException | |
- { | |
- statement.setArray( i, x ); | |
- } | |
- | |
- public final void setAsciiStream( int parameterIndex, InputStream x, int length ) | |
- throws SQLException | |
- { | |
- statement.setAsciiStream( parameterIndex, x, length ); | |
- } | |
- | |
- public final void setBigDecimal( int parameterIndex, BigDecimal x ) | |
- throws SQLException | |
- { | |
- statement.setBigDecimal( parameterIndex, x ); | |
- } | |
- | |
- public final void setBinaryStream( int parameterIndex, InputStream x, int length ) | |
- throws SQLException | |
- { | |
- statement.setBinaryStream( parameterIndex, x, length ); | |
- } | |
- | |
- public final void setBlob( int i, Blob x ) | |
- throws SQLException | |
- { | |
- statement.setBlob( i, x ); | |
- } | |
- | |
- public final void setBoolean( int parameterIndex, boolean x ) | |
- throws SQLException | |
- { | |
- statement.setBoolean( parameterIndex, x ); | |
- } | |
- | |
- public final void setByte( int parameterIndex, byte x ) | |
- throws SQLException | |
- { | |
- statement.setByte( parameterIndex, x ); | |
- } | |
- | |
- public final void setBytes( int parameterIndex, byte[] x ) | |
- throws SQLException | |
- { | |
- statement.setBytes( parameterIndex, x ); | |
- } | |
- | |
- public final void setCharacterStream( int parameterIndex, Reader reader, int length ) | |
- throws SQLException | |
- { | |
- statement.setCharacterStream( parameterIndex, reader, length ); | |
- } | |
- | |
- public final void setClob( int i, Clob x ) | |
- throws SQLException | |
- { | |
- statement.setClob( i, x ); | |
- } | |
- | |
- public final void setDate( int parameterIndex, Date x, Calendar cal ) | |
- throws SQLException | |
- { | |
- statement.setDate( parameterIndex, x, cal ); | |
- } | |
- | |
- public final void setDate( int parameterIndex, Date x ) | |
- throws SQLException | |
- { | |
- statement.setDate( parameterIndex, x ); | |
- } | |
- | |
- public final void setDouble( int parameterIndex, double x ) | |
- throws SQLException | |
- { | |
- statement.setDouble( parameterIndex, x ); | |
- } | |
- | |
- public final void setFloat( int parameterIndex, float x ) | |
- throws SQLException | |
- { | |
- statement.setFloat( parameterIndex, x ); | |
- } | |
- | |
- public final void setInt( int parameterIndex, int x ) | |
- throws SQLException | |
- { | |
- statement.setInt( parameterIndex, x ); | |
- } | |
- | |
- public final void setLong( int parameterIndex, long x ) | |
- throws SQLException | |
- { | |
- statement.setLong( parameterIndex, x ); | |
- } | |
- | |
- public final void setNull( int paramIndex, int sqlType, String typeName ) | |
- throws SQLException | |
- { | |
- statement.setNull( paramIndex, sqlType, typeName ); | |
- } | |
- | |
- public final void setNull( int parameterIndex, int sqlType ) | |
- throws SQLException | |
- { | |
- statement.setNull( parameterIndex, sqlType ); | |
- } | |
- | |
- public final void setObject( int parameterIndex, Object x, int targetSqlType, int scale ) | |
- throws SQLException | |
- { | |
- statement.setObject( parameterIndex, x, targetSqlType, scale ); | |
- } | |
- | |
- public final void setObject( int parameterIndex, Object x, int targetSqlType ) | |
- throws SQLException | |
- { | |
- statement.setObject( parameterIndex, x, targetSqlType ); | |
- } | |
- | |
- public final void setObject( int parameterIndex, Object x ) | |
- throws SQLException | |
- { | |
- statement.setObject( parameterIndex, x ); | |
- } | |
- | |
- public final void setRef( int i, Ref x ) | |
- throws SQLException | |
- { | |
- statement.setRef( i, x ); | |
- } | |
- | |
- public final void setShort( int parameterIndex, short x ) | |
- throws SQLException | |
- { | |
- statement.setShort( parameterIndex, x ); | |
- } | |
- | |
- public final void setString( int parameterIndex, String x ) | |
- throws SQLException | |
- { | |
- statement.setString( parameterIndex, x ); | |
- } | |
- | |
- public final void setTime( int parameterIndex, Time x, Calendar cal ) | |
- throws SQLException | |
- { | |
- statement.setTime( parameterIndex, x, cal ); | |
- } | |
- | |
- public final void setTime( int parameterIndex, Time x ) | |
- throws SQLException | |
- { | |
- statement.setTime( parameterIndex, x ); | |
- } | |
- | |
- public final void setTimestamp( int parameterIndex, Timestamp x, Calendar cal ) | |
- throws SQLException | |
- { | |
- statement.setTimestamp( parameterIndex, x, cal ); | |
- } | |
- | |
- public final void setTimestamp( int parameterIndex, Timestamp x ) | |
- throws SQLException | |
- { | |
- statement.setTimestamp( parameterIndex, x ); | |
- } | |
- | |
- public final void setUnicodeStream( int parameterIndex, InputStream x, int length ) | |
- throws SQLException | |
- { | |
- statement.setUnicodeStream( parameterIndex, x, length ); | |
- } | |
- | |
- public final void setURL( int parameterIndex, URL x ) | |
- throws SQLException | |
- { | |
- statement.setURL( parameterIndex, x ); | |
- } | |
- | |
- // --- jdbc 4 --- | |
- | |
- public final void setAsciiStream( int parameterIndex, InputStream x, long length ) | |
- throws SQLException | |
- { | |
- statement.setAsciiStream( parameterIndex, x, length ); | |
- } | |
- | |
- public final void setAsciiStream( int parameterIndex, InputStream x ) | |
- throws SQLException | |
- { | |
- statement.setAsciiStream( parameterIndex, x ); | |
- } | |
- | |
- public final void setBinaryStream( int parameterIndex, InputStream x, long length ) | |
- throws SQLException | |
- { | |
- statement.setBinaryStream( parameterIndex, x, length ); | |
- } | |
- | |
- public final void setBinaryStream( int parameterIndex, InputStream x ) | |
- throws SQLException | |
- { | |
- statement.setBinaryStream( parameterIndex, x ); | |
- } | |
- | |
- public final void setBlob( int parameterIndex, InputStream inputStream, long length ) | |
- throws SQLException | |
- { | |
- statement.setBlob( parameterIndex, inputStream, length ); | |
- } | |
- | |
- public final void setBlob( int parameterIndex, InputStream inputStream ) | |
- throws SQLException | |
- { | |
- statement.setBlob( parameterIndex, inputStream ); | |
- } | |
- | |
- public final void setCharacterStream( int parameterIndex, Reader reader, long length ) | |
- throws SQLException | |
- { | |
- statement.setCharacterStream( parameterIndex, reader, length ); | |
- } | |
- | |
- public final void setCharacterStream( int parameterIndex, Reader reader ) | |
- throws SQLException | |
- { | |
- statement.setCharacterStream( parameterIndex, reader ); | |
- } | |
- | |
- public final void setClob( int parameterIndex, Reader reader, long length ) | |
- throws SQLException | |
- { | |
- statement.setClob( parameterIndex, reader, length ); | |
- } | |
- | |
- public final void setClob( int parameterIndex, Reader reader ) | |
- throws SQLException | |
- { | |
- statement.setClob( parameterIndex, reader ); | |
- } | |
- | |
- public final void setNCharacterStream( int parameterIndex, Reader value, long length ) | |
- throws SQLException | |
- { | |
- statement.setNCharacterStream( parameterIndex, value, length ); | |
- } | |
- | |
- public final void setNCharacterStream( int parameterIndex, Reader value ) | |
- throws SQLException | |
- { | |
- statement.setNCharacterStream( parameterIndex, value ); | |
- } | |
- | |
- public final void setNClob( int parameterIndex, NClob value ) | |
- throws SQLException | |
- { | |
- statement.setNClob( parameterIndex, value ); | |
- } | |
- | |
- public final void setNClob( int parameterIndex, Reader reader, long length ) | |
- throws SQLException | |
- { | |
- statement.setNClob( parameterIndex, reader, length ); | |
- } | |
- | |
- public final void setNClob( int parameterIndex, Reader reader ) | |
- throws SQLException | |
- { | |
- statement.setNClob( parameterIndex, reader ); | |
- } | |
- | |
- public final void setNString( int parameterIndex, String value ) | |
- throws SQLException | |
- { | |
- statement.setNString( parameterIndex, value ); | |
- } | |
- | |
- public final void setRowId( int parameterIndex, RowId x ) | |
- throws SQLException | |
- { | |
- statement.setRowId( parameterIndex, x ); | |
- } | |
- | |
- public final void setSQLXML( int parameterIndex, SQLXML xmlObject ) | |
- throws SQLException | |
- { | |
- statement.setSQLXML( parameterIndex, xmlObject ); | |
- } | |
- | |
} | |
Index: jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnectionHandler.java | |
=================================================================== | |
--- jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnectionHandler.java (revision 1506597) | |
+++ jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnectionHandler.java (working copy) | |
@@ -1,98 +0,0 @@ | |
-/* | |
- * Licensed to the Apache Software Foundation (ASF) under one or more | |
- * contributor license agreements. See the NOTICE file distributed with | |
- * this work for additional information regarding copyright ownership. | |
- * The ASF licenses this file to You under the Apache License, Version 2.0 | |
- * (the "License"); you may not use this file except in compliance with | |
- * the License. You may obtain a copy of the License at | |
- * | |
- * http://www.apache.org/licenses/LICENSE-2.0 | |
- * | |
- * Unless required by applicable law or agreed to in writing, software | |
- * distributed under the License is distributed on an "AS IS" BASIS, | |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
- * See the License for the specific language governing permissions and | |
- * limitations under the License. | |
- */ | |
- | |
-package org.apache.commons.monitoring.jdbc; | |
- | |
-import java.lang.reflect.InvocationHandler; | |
-import java.lang.reflect.Method; | |
-import java.lang.reflect.Proxy; | |
-import java.sql.CallableStatement; | |
-import java.sql.Connection; | |
-import java.sql.PreparedStatement; | |
-import java.sql.Statement; | |
- | |
-import org.apache.commons.monitoring.Repository; | |
- | |
-/** | |
- * @author ndeloof | |
- * | |
- */ | |
-public class MonitoredConnectionHandler | |
- implements InvocationHandler | |
-{ | |
- /** target connection */ | |
- private Connection connection; | |
- | |
- private Repository repository; | |
- | |
- private ConnectionClosedCallBack callBack; | |
- | |
- public MonitoredConnectionHandler( Connection connection, Repository repository, ConnectionClosedCallBack callBack ) | |
- { | |
- super(); | |
- this.connection = connection; | |
- this.repository = repository; | |
- this.callBack = callBack; | |
- } | |
- | |
- /** | |
- * {@inheritDoc} | |
- * | |
- * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) | |
- */ | |
- public Object invoke( Object proxy, Method method, Object[] args ) | |
- throws Throwable | |
- { | |
- String name = method.getName(); | |
- if ( name.equals( "createStatement" ) ) | |
- { | |
- Statement statement = (Statement) method.invoke( connection, args ); | |
- return Proxy.newProxyInstance( getClassLoader(), new Class[] { Statement.class }, | |
- new MonitoredStatementHandler( repository, statement ) ); | |
- } | |
- else if ( name.equals( "prepareStatement" ) ) | |
- { | |
- PreparedStatement statement = (PreparedStatement) method.invoke( connection, args ); | |
- return Proxy.newProxyInstance( getClassLoader(), new Class[] { PreparedStatement.class }, | |
- new MonitoredStatementHandler( repository, statement ) ); | |
- } | |
- else if ( name.equals( "prepareCall" ) ) | |
- { | |
- CallableStatement statement = (CallableStatement) method.invoke( connection, args ); | |
- return Proxy.newProxyInstance( getClassLoader(), new Class[] { CallableStatement.class }, | |
- new MonitoredStatementHandler( repository, statement ) ); | |
- } | |
- else if ( name.equals( "close" ) ) | |
- { | |
- callBack.onConnectionClosed(); | |
- } | |
- return method.invoke( connection, args ); | |
- } | |
- | |
- /** | |
- * @return | |
- */ | |
- private ClassLoader getClassLoader() | |
- { | |
- ClassLoader cl = Thread.currentThread().getContextClassLoader(); | |
- if ( cl == null ) | |
- { | |
- cl = getClass().getClassLoader(); | |
- } | |
- return cl; | |
- } | |
-} | |
Index: jdbc/pom.xml | |
=================================================================== | |
--- jdbc/pom.xml (revision 1506597) | |
+++ jdbc/pom.xml (working copy) | |
@@ -23,9 +23,9 @@ | |
<version>1.0-SNAPSHOT</version> | |
</parent> | |
<modelVersion>4.0.0</modelVersion> | |
- <groupId>org.apache.commons.monitoring</groupId> | |
<artifactId>commons-monitoring-jdbc</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
+ <name>Commons Monitoring (Sandbox) :: JDBC</name> | |
<properties> | |
<!-- Java6 required for JDBC 4 --> | |
Index: instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/aop/DefaultMonitorNameExtractor.java | |
=================================================================== | |
--- instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/aop/DefaultMonitorNameExtractor.java (revision 1506597) | |
+++ instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/aop/DefaultMonitorNameExtractor.java (working copy) | |
@@ -33,7 +33,7 @@ | |
*/ | |
public String getMonitorName( Method method ) | |
{ | |
- return method.getDeclaringClass().getSimpleName() + "." + method.getName(); | |
+ return method.getDeclaringClass().getName() + "." + method.getName(); | |
} | |
} | |
Index: instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/ServletContextUtil.java | |
=================================================================== | |
--- instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/ServletContextUtil.java (revision 1506597) | |
+++ instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/ServletContextUtil.java (working copy) | |
@@ -17,12 +17,12 @@ | |
package org.apache.commons.monitoring.instrumentation.servlet; | |
+import org.apache.commons.monitoring.Repository; | |
+import org.apache.commons.monitoring.repositories.RepositoryFinder; | |
+ | |
import javax.servlet.ServletContext; | |
import javax.servlet.ServletException; | |
-import org.apache.commons.monitoring.Repository; | |
-import org.apache.commons.monitoring.repositories.DefaultRepository; | |
- | |
/** | |
* | |
* @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a> | |
@@ -49,9 +49,8 @@ | |
} | |
else | |
{ | |
- Repository repository = new DefaultRepository(); | |
- context.setAttribute( REPOSITORY_KEY, repository ); | |
- return repository; | |
+ context.setAttribute( REPOSITORY_KEY, RepositoryFinder.REPOSITORY ); | |
+ return RepositoryFinder.REPOSITORY; | |
} | |
} | |
} | |
Index: instrumentation/pom.xml | |
=================================================================== | |
--- instrumentation/pom.xml (revision 1506597) | |
+++ instrumentation/pom.xml (working copy) | |
@@ -23,9 +23,9 @@ | |
<version>1.0-SNAPSHOT</version> | |
</parent> | |
<modelVersion>4.0.0</modelVersion> | |
- <groupId>org.apache.commons.monitoring</groupId> | |
<artifactId>commons-monitoring-instrumentation</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
+ <name>Commons Monitoring (Sandbox) :: Instrumentation</name> | |
<dependencies> | |
<dependency> | |
<groupId>org.apache.commons.monitoring</groupId> | |
Index: reporting/src/main/java/org/apache/commons/monitoring/reporting/web/HttpUtils.java | |
=================================================================== | |
--- reporting/src/main/java/org/apache/commons/monitoring/reporting/web/HttpUtils.java (revision 1506597) | |
+++ reporting/src/main/java/org/apache/commons/monitoring/reporting/web/HttpUtils.java (working copy) | |
@@ -34,7 +34,7 @@ | |
return null; | |
} | |
String[] languages = header.split( "," ); | |
- String prefered; | |
+ String prefered = null; | |
double preference = 0.0D; | |
for ( String language : languages ) | |
{ | |
@@ -54,7 +54,7 @@ | |
return language; | |
} | |
} | |
- return null; | |
+ return prefered; | |
} | |
private static double getQuality( String paramString ) | |
Index: reporting/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java | |
=================================================================== | |
--- reporting/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java (revision 1506597) | |
+++ reporting/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java (working copy) | |
@@ -31,6 +31,7 @@ | |
import org.apache.commons.monitoring.Visitor; | |
import org.apache.commons.monitoring.reporting.Format; | |
import org.apache.commons.monitoring.reporting.FormattingVisitor; | |
+import org.apache.commons.monitoring.repositories.RepositoryFinder; | |
public class MonitoringServlet | |
extends HttpServlet | |
@@ -42,6 +43,9 @@ | |
throws ServletException | |
{ | |
repository = (Repository) config.getServletContext().getAttribute( Repository.class.getName() ); | |
+ if (repository == null) { | |
+ repository = RepositoryFinder.REPOSITORY; | |
+ } | |
} | |
private static Map<String, Format> formats = new HashMap<String, Format>(); | |
Index: reporting/src/main/java/org/apache/commons/monitoring/reporting/jaxrs/RepositoryResource.java | |
=================================================================== | |
--- reporting/src/main/java/org/apache/commons/monitoring/reporting/jaxrs/RepositoryResource.java (revision 1506597) | |
+++ reporting/src/main/java/org/apache/commons/monitoring/reporting/jaxrs/RepositoryResource.java (working copy) | |
@@ -39,6 +39,7 @@ | |
import org.apache.commons.monitoring.reporting.Format; | |
import org.apache.commons.monitoring.reporting.FormattingVisitor; | |
import org.apache.commons.monitoring.reporting.web.HttpUtils; | |
+import org.apache.commons.monitoring.repositories.RepositoryFinder; | |
@Path( "/repository" ) | |
public class RepositoryResource | |
@@ -49,7 +50,7 @@ | |
@Produces( TEXT_XML ) | |
public String asXML( @Context ServletContext context ) | |
{ | |
- this.repository = (Repository) context.getAttribute( Repository.class.getName() ); | |
+ initRepository(context); | |
return asFormat( Format.XML ); | |
} | |
@@ -59,7 +60,7 @@ | |
public String asJSONP( @Context ServletContext context, | |
@QueryParam( "callback" ) String callback ) | |
{ | |
- this.repository = (Repository) context.getAttribute( Repository.class.getName() ); | |
+ initRepository(context); | |
String json = asFormat( Format.JSON ); | |
if ( callback != null ) | |
{ | |
@@ -68,11 +69,19 @@ | |
return json; | |
} | |
- public String asFormat( Format format ) | |
+ private String asFormat( final Format format ) | |
{ | |
PrintWriter writer = new PrintWriter( new StringWriter() ); | |
Visitor visitor = new FormattingVisitor( format, writer ); | |
repository.accept( visitor ); | |
return writer.toString(); | |
} | |
+ | |
+ private synchronized void initRepository(final ServletContext context) | |
+ { | |
+ repository = (Repository) context.getAttribute( Repository.class.getName() ); | |
+ if (repository == null) { | |
+ repository = RepositoryFinder.REPOSITORY; | |
+ } | |
+ } | |
} | |
Index: reporting/pom.xml | |
=================================================================== | |
--- reporting/pom.xml (revision 1506597) | |
+++ reporting/pom.xml (working copy) | |
@@ -23,7 +23,7 @@ | |
</parent> | |
<modelVersion>4.0.0</modelVersion> | |
<artifactId>commons-monitoring-reporting</artifactId> | |
- <name>Commons Monitoring (Sandbox) reporting</name> | |
+ <name>Commons Monitoring (Sandbox) :: Reporting</name> | |
<dependencies> | |
<dependency> | |
<groupId>org.apache.commons.monitoring</groupId> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment