-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.apache.tomcat.jdbc.pool;\r
-\r
-\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.lang.reflect.Method;\r
-import java.sql.SQLException;\r
-/**\r
- * Interceptor that traps any unhandled exception types and throws an exception that has been declared by the method\r
- * called, or throw a SQLException if it is declared.\r
- * If the caught exception is not declared, and the method doesn't throw SQLException, then this interceptor will\r
- * throw a RuntimeException\r
- * @author fhanik\r
- *\r
- */\r
-public class TrapException extends JdbcInterceptor {\r
-\r
- \r
- public TrapException() {\r
- }\r
-\r
- @Override\r
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {\r
- try {\r
- return super.invoke(proxy, method, args);\r
- }catch (Exception t) {\r
- Throwable exception = t;\r
- if (t instanceof InvocationTargetException) {\r
- exception = t.getCause()!=null?t.getCause():t;\r
- } \r
- Class<?> exceptionClass = exception.getClass();\r
- if (!isDeclaredException(method, exceptionClass)) {\r
- if (isDeclaredException(method,SQLException.class)) {\r
- SQLException sqlx = new SQLException("Uncaught underlying exception.");\r
- sqlx.initCause(exception);\r
- exception = sqlx;\r
- } else {\r
- RuntimeException rx = new RuntimeException("Uncaught underlying exception.");\r
- rx.initCause(exception);\r
- exception = rx;\r
- }\r
- }\r
- throw exception;\r
- }\r
- \r
- }\r
- \r
- public boolean isDeclaredException(Method m, Class<?> clazz) {\r
- for (Class<?> cl : m.getExceptionTypes()) {\r
- if (cl.equals(clazz) || cl.isAssignableFrom(clazz)) return true;\r
- }\r
- return false;\r
- }\r
- \r
- /**\r
- * no-op for this interceptor. no state is stored.\r
- */\r
- @Override\r
- public void reset(ConnectionPool parent, PooledConnection con) {\r
- // NOOP\r
- }\r
- \r
-}\r
+/*
+ * 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.tomcat.jdbc.pool;
+
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+/**
+ * Interceptor that traps any unhandled exception types and throws an exception that has been declared by the method
+ * called, or throw a SQLException if it is declared.
+ * If the caught exception is not declared, and the method doesn't throw SQLException, then this interceptor will
+ * throw a RuntimeException
+ * @author fhanik
+ *
+ */
+public class TrapException extends JdbcInterceptor {
+
+
+ public TrapException() {
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ try {
+ return super.invoke(proxy, method, args);
+ }catch (Exception t) {
+ Throwable exception = t;
+ if (t instanceof InvocationTargetException) {
+ exception = t.getCause()!=null?t.getCause():t;
+ }
+ Class<?> exceptionClass = exception.getClass();
+ if (!isDeclaredException(method, exceptionClass)) {
+ if (isDeclaredException(method,SQLException.class)) {
+ SQLException sqlx = new SQLException("Uncaught underlying exception.");
+ sqlx.initCause(exception);
+ exception = sqlx;
+ } else {
+ RuntimeException rx = new RuntimeException("Uncaught underlying exception.");
+ rx.initCause(exception);
+ exception = rx;
+ }
+ }
+ throw exception;
+ }
+
+ }
+
+ public boolean isDeclaredException(Method m, Class<?> clazz) {
+ for (Class<?> cl : m.getExceptionTypes()) {
+ if (cl.equals(clazz) || cl.isAssignableFrom(clazz)) return true;
+ }
+ return false;
+ }
+
+ /**
+ * no-op for this interceptor. no state is stored.
+ */
+ @Override
+ public void reset(ConnectionPool parent, PooledConnection con) {
+ // NOOP
+ }
+
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.apache.tomcat.jdbc.test;\r
-\r
-import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;\r
-\r
-public class Bug50571 extends DefaultTestCase{\r
- \r
- public Bug50571(String name) {\r
- super(name);\r
- }\r
- \r
- @Override\r
- public void setUp() throws Exception {\r
- super.setUp();\r
- this.datasource.setUrl("jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE");\r
- this.datasource.setJdbcInterceptors(ConnectionState.class.getName());\r
- this.datasource.setDefaultTransactionIsolation(-55);\r
- this.datasource.setInitialSize(1);\r
- }\r
- \r
- public void testBug50571() throws Exception {\r
- this.datasource.getConnection().close();\r
- }\r
-}\r
+/*
+ * 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.tomcat.jdbc.test;
+
+import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
+
+public class Bug50571 extends DefaultTestCase{
+
+ public Bug50571(String name) {
+ super(name);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ this.datasource.setUrl("jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE");
+ this.datasource.setJdbcInterceptors(ConnectionState.class.getName());
+ this.datasource.setDefaultTransactionIsolation(-55);
+ this.datasource.setInitialSize(1);
+ }
+
+ public void testBug50571() throws Exception {
+ this.datasource.getConnection().close();
+ }
+}
-<?xml version="1.0" encoding="UTF-8"?>\r
-<!--\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
--->\r
-<project>\r
- <modelVersion>4.0.0</modelVersion>\r
- <groupId>org.apache.tomcat</groupId>\r
- <artifactId>tomcat-jdbc</artifactId>\r
- <version>@MAVEN.DEPLOY.VERSION@</version>\r
- <description>Tomcat JDBC Pool Package</description>\r
- <dependencies>\r
- <dependency>\r
- <groupId>org.apache.tomcat</groupId>\r
- <artifactId>tomcat-jdbc</artifactId>\r
- <version>@MAVEN.DEPLOY.VERSION@</version>\r
- <scope>compile</scope>\r
- </dependency>\r
- </dependencies>\r
-</project> \r
+<?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>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jdbc</artifactId>
+ <version>@MAVEN.DEPLOY.VERSION@</version>
+ <description>Tomcat JDBC Pool Package</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jdbc</artifactId>
+ <version>@MAVEN.DEPLOY.VERSION@</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>