Java Code Examples for java.lang.reflect.Method.getExceptionTypes()

The following are Jave code examples for showing how to use getExceptionTypes() of the java.lang.reflect.Method class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: ServerMain.java   View Source Code Vote up 6 votes
private boolean isPublicStaticVoid( Method method )
{
    // check modifiers: public static
    int modifiers =  method.getModifiers ();
    if (!Modifier.isPublic (modifiers) || !Modifier.isStatic (modifiers)) {
        logError( method.getName() + " is not public static" ) ;
        return false ;
    }

    // check return type and exceptions
    if (method.getExceptionTypes ().length != 0) {
        logError( method.getName() + " declares exceptions" ) ;
        return false ;
    }

    if (!method.getReturnType().equals (Void.TYPE)) {
        logError( method.getName() + " does not have a void return type" ) ;
        return false ;
    }

    return true ;
}
 
Example 2
Project: myfaces-trinidad   File: JavaIntrospector.java   View Source Code Vote up 6 votes
/**
 * Return true iff the given method throws the given exception.
 */
private boolean _throwsException(
  Method method,
  Class<?> exception
  )
{
  Class exs[] = method.getExceptionTypes();

  for (int i = 0; i < exs.length; i++)
  {
    if (exs[i] == exception)
    {
      return true;
    }
  }

  return false;
}
 
Example 3
Project: QDrill   File: CodeGeneratorMethod.java   View Source Code Vote up 6 votes
public CodeGeneratorMethod(Method m) {
    this.underlyingMethod = m;
    this.methodName = m.getName();
    this.returnType = m.getReturnType();
//    Paranamer para = new BytecodeReadingParanamer();
    Paranamer para = new AnnotationParanamer();
    String[] parameterNames = para.lookupParameterNames(m, true);
    if (parameterNames == null) {
      throw new RuntimeException(String.format("Unable to read the parameter names for method %s.  This is likely due to the class files not including the appropriate debugging information.  Look up java -g for more information.", m));
    }
    Class<?>[] types = m.getParameterTypes();
    if (parameterNames.length != types.length) {
      throw new RuntimeException(String.format("Unexpected number of parameter names %s.  Expected %s on method %s.", Arrays.toString(parameterNames), Arrays.toString(types), m.toGenericString()));
    }
    arguments = new CodeGeneratorArgument[parameterNames.length];
    for (int i = 0 ; i < parameterNames.length; i++) {
      arguments[i] = new CodeGeneratorArgument(parameterNames[i], types[i]);
    }
    exs = m.getExceptionTypes();
  }
 
Example 4
Project: openjdk-jdk10   File: Util.java   View Source Code Vote up 5 votes
/**
 * Verifies that the supplied method has at least one declared exception
 * type that is RemoteException or one of its superclasses.  If not,
 * then this method throws IllegalArgumentException.
 *
 * @throws IllegalArgumentException if m is an illegal remote method
 */
private static void checkMethod(Method m) {
    Class<?>[] ex = m.getExceptionTypes();
    for (int i = 0; i < ex.length; i++) {
        if (ex[i].isAssignableFrom(RemoteException.class))
            return;
    }
    throw new IllegalArgumentException(
        "illegal remote method encountered: " + m);
}
 
Example 5
Project: jDialects   File: ReflectionUtils.java   View Source Code Vote up 5 votes
/**
 * Determine whether the given method explicitly declares the given
 * exception or one of its superclasses, which means that an exception
 * of that type can be propagated as-is within a reflective invocation.
 * @param method the declaring method
 * @param exceptionType the exception to throw
 * @return {@code true} if the exception can be thrown as-is;
 * {@code false} if it needs to be wrapped
 */
public static boolean declaresException(Method method, Class<?> exceptionType) {
	Assert.notNull(method, "Method must not be null");
	Class<?>[] declaredExceptions = method.getExceptionTypes();
	for (Class<?> declaredException : declaredExceptions) {
		if (declaredException.isAssignableFrom(exceptionType)) {
			return true;
		}
	}
	return false;
}
 
Example 6
Project: OpenJSharp   File: ProxyGenerator.java   View Source Code Vote up 5 votes
/**
 * Add another method to be proxied, either by creating a new
 * ProxyMethod object or augmenting an old one for a duplicate
 * method.
 *
 * "fromClass" indicates the proxy interface that the method was
 * found through, which may be different from (a subinterface of)
 * the method's "declaring class".  Note that the first Method
 * object passed for a given name and descriptor identifies the
 * Method object (and thus the declaring class) that will be
 * passed to the invocation handler's "invoke" method for a given
 * set of duplicate methods.
 */
private void addProxyMethod(Method m, Class<?> fromClass) {
    String name = m.getName();
    Class<?>[] parameterTypes = m.getParameterTypes();
    Class<?> returnType = m.getReturnType();
    Class<?>[] exceptionTypes = m.getExceptionTypes();

    String sig = name + getParameterDescriptors(parameterTypes);
    List<ProxyMethod> sigmethods = proxyMethods.get(sig);
    if (sigmethods != null) {
        for (ProxyMethod pm : sigmethods) {
            if (returnType == pm.returnType) {
                /*
                 * Found a match: reduce exception types to the
                 * greatest set of exceptions that can thrown
                 * compatibly with the throws clauses of both
                 * overridden methods.
                 */
                List<Class<?>> legalExceptions = new ArrayList<>();
                collectCompatibleTypes(
                    exceptionTypes, pm.exceptionTypes, legalExceptions);
                collectCompatibleTypes(
                    pm.exceptionTypes, exceptionTypes, legalExceptions);
                pm.exceptionTypes = new Class<?>[legalExceptions.size()];
                pm.exceptionTypes =
                    legalExceptions.toArray(pm.exceptionTypes);
                return;
            }
        }
    } else {
        sigmethods = new ArrayList<>(3);
        proxyMethods.put(sig, sigmethods);
    }
    sigmethods.add(new ProxyMethod(name, parameterTypes, returnType,
                                   exceptionTypes, fromClass));
}
 
Example 7
Project: uavstack   File: RabbitmqIT.java   View Source Code Vote up 5 votes
private boolean needDoCap(Method method, Object[] args) {

            if (method.getExceptionTypes().length == 0
                    || !method.getExceptionTypes()[0].getName().equals(IOException.class.getName())) {
                return false;
            }
            String methodName = method.getName();
            if (queueNameIndex.containsKey(methodName) && args.length != 0) {

                if (isTempQueue((String) args[queueNameIndex.get(methodName)])) {
                    return false;
                }
            }
            return true;
        }
 
Example 8
Project: ProyectoPacientes   File: LoadBalancedConnectionProxy.java   View Source Code Vote up 5 votes
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    SQLException exceptionToThrow = SQLError.createSQLException(Messages.getString("LoadBalancedConnectionProxy.unusableConnection"),
            SQLError.SQL_STATE_INVALID_TRANSACTION_STATE, MysqlErrorNumbers.ERROR_CODE_NULL_LOAD_BALANCED_CONNECTION, true, null);
    Class<?>[] declaredException = method.getExceptionTypes();
    for (Class<?> declEx : declaredException) {
        if (declEx.isAssignableFrom(exceptionToThrow.getClass())) {
            throw exceptionToThrow;
        }
    }
    throw new IllegalStateException(exceptionToThrow.getMessage(), exceptionToThrow);
}
 
Example 9
Project: openjdk-jdk10   File: DynamicMethodMarshallerImpl.java   View Source Code Vote up 5 votes
public DynamicMethodMarshallerImpl( Method method )
{
    this.method = method ;
    ehandler = new ExceptionHandlerImpl( method.getExceptionTypes() ) ;
    needsArgumentCopy = false ;

    Class[] argTypes = method.getParameterTypes() ;
    hasArguments = argTypes.length > 0 ;
    if (hasArguments) {
        argRWs = new ReaderWriter[ argTypes.length ] ;
        for (int ctr=0; ctr<argTypes.length; ctr++ ) {
            // This could be further optimized to avoid
            // copying if argTypes contains at most one
            // immutable object type.
            if (!argTypes[ctr].isPrimitive())
                needsArgumentCopy = true ;
            argRWs[ctr] = makeReaderWriter( argTypes[ctr] ) ;
        }
    }

    Class resultType = method.getReturnType() ;
    needsResultCopy = false ;
    hasVoidResult = resultType.equals( void.class ) ;
    if (!hasVoidResult) {
        needsResultCopy = !resultType.isPrimitive() ;
        resultRW = makeReaderWriter( resultType ) ;
    }
}
 
Example 10
Project: jdk8u-jdk   File: Util.java   View Source Code Vote up 5 votes
/**
 * Verifies that the supplied method has at least one declared exception
 * type that is RemoteException or one of its superclasses.  If not,
 * then this method throws IllegalArgumentException.
 *
 * @throws IllegalArgumentException if m is an illegal remote method
 */
private static void checkMethod(Method m) {
    Class<?>[] ex = m.getExceptionTypes();
    for (int i = 0; i < ex.length; i++) {
        if (ex[i].isAssignableFrom(RemoteException.class))
            return;
    }
    throw new IllegalArgumentException(
        "illegal remote method encountered: " + m);
}
 
Example 11
Project: OpenVertretung   File: LoadBalancedConnectionProxy.java   View Source Code Vote up 5 votes
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    SQLException exceptionToThrow = SQLError.createSQLException(Messages.getString("LoadBalancedConnectionProxy.unusableConnection"),
            SQLError.SQL_STATE_INVALID_TRANSACTION_STATE, MysqlErrorNumbers.ERROR_CODE_NULL_LOAD_BALANCED_CONNECTION, true, null);
    Class<?>[] declaredException = method.getExceptionTypes();
    for (Class<?> declEx : declaredException) {
        if (declEx.isAssignableFrom(exceptionToThrow.getClass())) {
            throw exceptionToThrow;
        }
    }
    throw new IllegalStateException(exceptionToThrow.getMessage(), exceptionToThrow);
}
 
Example 12
Project: jsf-sdk   File: JavassistProxy.java   View Source Code Vote up 4 votes
private static List<String> createMethod(Class<?> interfaceClass, ClassPool mPool) {
        Method methodAry[] = interfaceClass.getMethods();
        StringBuilder sb = new StringBuilder();
        List<String> resultList = new ArrayList<String>();
        for (Method m : methodAry) {
            Class<?>[] mType = m.getParameterTypes();
            Class<?> returntype = m.getReturnType();

//            String returnString = returntype.equals(void.class) ? "void" : ReflectUtils.getBoxedClass(returntype).getCanonicalName();
            sb.append(Modifier.toString(m.getModifiers()).replace("abstract", "") + " " +
                    ReflectUtils.getName(returntype) + " " + m.getName() + "( ");
            int c = 0;

            for (Class<?> mp : mType) {
                sb.append(" " + mp.getCanonicalName() + " arg" + c + " ,");
//                sb.append(" " + ReflectUtils.getBoxedClass(mp).getCanonicalName() + " arg" + c + " ,");
                c++;
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append(")");
            Class<?> exceptions[] = m.getExceptionTypes();
            if (exceptions.length > 0) {
                sb.append(" throws ");
                for (Class<?> exception : exceptions) {
                    sb.append(exception.getCanonicalName() + " ,");
                }
                sb = sb.deleteCharAt(sb.length() - 1);
            }
            sb.append("{");

            sb.append(" Class clazz = " + interfaceClass.getCanonicalName() + ".class;");
            sb.append(" String methodName = \"" + m.getName() + "\";");
            sb.append(" Class[] paramTypes = new Class[" + c + "];");
            sb.append(" Object[] paramValues = new Object[" + c + "];");
            for (int i = 0; i < c; i++) {
                sb.append("paramValues[" + i + "] = ($w)$" + (i + 1) + ";");
//                sb.append("paramTypes[" + i + "] = arg" + i + ".getClass();");
//                sb.append("paramTypes[" + i + "] = " + ClassTypeUtils.class.getCanonicalName() + ".getClass(\""
//                                + mType[i].getCanonicalName() + "\");");
                sb.append("paramTypes[" + i + "] = " + mType[i].getCanonicalName() + ".class;");
//				sb.append("paramTypes[" + i + "] = " + (mType[i].isPrimitive() ? mType[i].getCanonicalName() + ".class;"
//                                                : "arg" + i + ".getClass();"));
            }

//            RequestMessage requestMessage = MessageBuilder.buildRequest(clazz, methodName, paramTypes, paramValues);
//            ResponseMessage responseMessage = proxyInvoker.invoke(requestMessage);
//            if(responseMessage.isError()){
//                throw responseMessage.getException();
//            }
//            return responseMessage.getResponse();

            sb.append(RequestMessage.class.getCanonicalName() + " requestMessage = " +
                    MessageBuilder.class.getCanonicalName() +
                    ".buildRequest(clazz, methodName, paramTypes, paramValues);");
            sb.append(ResponseMessage.class.getCanonicalName() + " responseMessage = " +
                    "proxyInvoker.invoke(requestMessage);");
            sb.append("if(responseMessage.isError()){ throw responseMessage.getException(); }");

            if (returntype.equals(void.class)) {
                sb.append(" return;");
            } else {
                sb.append(" return ").append(asArgument( returntype, "responseMessage.getResponse()")).append(";");
            }

            sb.append("}");
            resultList.add(sb.toString());
            sb.delete(0, sb.length());
        }
        return resultList;
    }
 
Example 13
Project: Limitart   File: ConsumerX.java   View Source Code Vote up 4 votes
/**
 * 初始化本地服务代理
 * 
 * @param packageName
 * @throws IOException
 * @throws ReflectiveOperationException
 * @throws Exception
 */
private void initRpcProxys() throws ServiceXProxyException, IOException, ReflectiveOperationException {
	clientProxys.clear();
	List<Class<?>> classesByPackage = new ArrayList<>();
	for (String temp : this.config.getServicePackages()) {
		classesByPackage.addAll(ReflectionUtil.getClassesByPackage(temp, Object.class));
	}
	for (Class<?> clazz : classesByPackage) {
		ServiceX annotation = clazz.getAnnotation(ServiceX.class);
		if (annotation == null) {
			continue;
		}
		if (!clazz.isInterface()) {
			throw new ServiceXProxyException(clazz.getName() + "RPC服务器必须是一个接口!");
		}
		// 检查参数是否符合标准
		String provider = annotation.provider();
		if (StringUtil.isEmptyOrNull(provider)) {
			throw new ServiceXProxyException("服务:" + clazz.getName() + "的提供商为空!");
		}
		String serviceName = RpcUtil.getServiceName(new RpcProviderName(provider), clazz);
		// 检查方法
		Method[] methods = clazz.getMethods();
		for (Method method : methods) {
			String methodOverloadName = ReflectionUtil.getMethodOverloadName(method);
			// 检查参数
			Class<?>[] parameterTypes = method.getParameterTypes();
			for (Class<?> paramsType : parameterTypes) {
				RpcUtil.checkParamType(paramsType);
			}
			// 检查返回参数是否合法
			RpcUtil.checkParamType(method.getReturnType());
			// 异常抛出检查
			Class<?>[] exceptionTypes = method.getExceptionTypes();
			if (exceptionTypes == null || exceptionTypes.length < 1) {
				throw new ServiceXProxyException("类" + clazz.getName() + "的方法" + methodOverloadName + "必须要抛出异常:"
						+ Exception.class.getName());
			}
			boolean exOk = false;
			for (Class<?> ex : exceptionTypes) {
				if (ex == Exception.class) {
					exOk = true;
				}
			}
			if (!exOk) {
				throw new ServiceXProxyException("类" + clazz.getName() + "的方法" + methodOverloadName + "的异常抛出必须有:"
						+ Exception.class.getName());
			}
		}
		// 创建动态代理类
		Object newProxyInstance = ReflectionUtil.newProxy(clazz,
				(InvocationHandler) (proxy, method, args) -> proxyExecute(serviceName, proxy, method.getName(),
						ReflectionUtil.getMethodOverloadName(method), args, ConsumerX.this.config.getSelector(),
						null));
		if (serviceProxyClasses.containsKey(serviceName)) {
			throw new ServiceXProxyException("服务名重复:" + serviceName);
		}
		serviceProxyClasses.put(serviceName, clazz);
		clientProxys.put(clazz, newProxyInstance);
		log.info("创建服务动态代理:" + serviceName + ",服务提供商:" + provider + ",代理实例:" + newProxyInstance);
	}
}
 
Example 14
Project: openjdk-jdk10   File: RuntimeModeler.java   View Source Code Vote up 4 votes
/**
 * models the exceptions thrown by <code>method</code> and adds them to the <code>javaMethod</code>
 * runtime model object
 * @param javaMethod the runtime model object to add the exception model objects to
 * @param method the <code>method</code> from which to find the exceptions to model
 */
protected void processExceptions(JavaMethodImpl javaMethod, Method method) {
    Action actionAnn = getAnnotation(method, Action.class);
    FaultAction[] faultActions = {};
    if(actionAnn != null)
        faultActions = actionAnn.fault();
    for (Class<?> exception : method.getExceptionTypes()) {

        //Exclude RuntimeException, RemoteException and Error etc
        if (!EXCEPTION_CLASS.isAssignableFrom(exception))
            continue;
        if (RUNTIME_EXCEPTION_CLASS.isAssignableFrom(exception) || isRemoteException(exception))
            continue;
        if (getAnnotation(exception, javax.xml.bind.annotation.XmlTransient.class) != null)
            continue;
        Class exceptionBean;
        Annotation[] anns;
        WebFault webFault = getAnnotation(exception, WebFault.class);
        Method faultInfoMethod = getWSDLExceptionFaultInfo(exception);
        ExceptionType exceptionType = ExceptionType.WSDLException;
        String namespace = targetNamespace;
        String name = exception.getSimpleName();
        String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
        if (packageName.length() == 0)
            beanPackage = JAXWS_PACKAGE_PD;
        String className = beanPackage+ name + BEAN;
        String messageName = exception.getSimpleName();
        if (webFault != null) {
            if (webFault.faultBean().length()>0)
                className = webFault.faultBean();
            if (webFault.name().length()>0)
                name = webFault.name();
            if (webFault.targetNamespace().length()>0)
                namespace = webFault.targetNamespace();
            if (webFault.messageName().length()>0)
                messageName = webFault.messageName();
        }
        if (faultInfoMethod == null)  {
            exceptionBean = getExceptionBeanClass(className, exception, name, namespace);
            exceptionType = ExceptionType.UserDefined;
            anns = getAnnotations(exceptionBean);
        } else {
            exceptionBean = faultInfoMethod.getReturnType();
            anns = getAnnotations(faultInfoMethod);
        }
        QName faultName = new QName(namespace, name);
        TypeInfo typeRef = new TypeInfo(faultName, exceptionBean, anns);
        CheckedExceptionImpl checkedException =
            new CheckedExceptionImpl(javaMethod, exception, typeRef, exceptionType);
        checkedException.setMessageName(messageName);
        checkedException.setFaultInfoGetter(faultInfoMethod);
        for(FaultAction fa: faultActions) {
            if(fa.className().equals(exception) && !fa.value().equals("")) {
                checkedException.setFaultAction(fa.value());
                break;
            }
        }
        javaMethod.addException(checkedException);
    }
}
 
Example 15
Project: OpenJSharp   File: IDLTypesUtil.java   View Source Code Vote up 4 votes
/**
 * Return true if given method is legal property accessor as defined in
 * Section 1.3.4.3 of Java2IDL spec.
 */
public boolean isPropertyAccessorMethod(Method m, Class c) {

    String methodName = m.getName();
    Class returnType  = m.getReturnType();
    Class[] parameters = m.getParameterTypes();
    Class[] exceptionTypes = m.getExceptionTypes();
    String propertyType = null;

    if( methodName.startsWith(GET_PROPERTY_PREFIX) ) {

        if((parameters.length == 0) && (returnType != Void.TYPE) &&
            !readHasCorrespondingIsProperty(m, c)) {
            propertyType = GET_PROPERTY_PREFIX;
        }

    } else if( methodName.startsWith(SET_PROPERTY_PREFIX) ) {

        if((returnType == Void.TYPE) && (parameters.length == 1)) {
            if (hasCorrespondingReadProperty(m, c, GET_PROPERTY_PREFIX) ||
                hasCorrespondingReadProperty(m, c, IS_PROPERTY_PREFIX)) {
                propertyType = SET_PROPERTY_PREFIX;
            }
        }

    } else if( methodName.startsWith(IS_PROPERTY_PREFIX) ) {
        if((parameters.length == 0) && (returnType == Boolean.TYPE) &&
            !isHasCorrespondingReadProperty(m, c)) {
            propertyType = IS_PROPERTY_PREFIX;
        }
    }

    // Some final checks that apply to all properties.
    if( propertyType != null ) {
        if(!validPropertyExceptions(m) ||
           (methodName.length() <= propertyType.length())) {
            propertyType = null;
        }
    }

    return (propertyType != null);
}
 
Example 16
Project: tomcat7   File: TrapException.java   View Source Code Vote up 4 votes
public boolean isDeclaredException(Method m, Class<?> clazz) {
    for (Class<?> cl : m.getExceptionTypes()) {
        if (cl.equals(clazz) || cl.isAssignableFrom(clazz)) return true;
    }
    return false;
}
 
Example 17
Project: openjdk-jdk10   File: IDLTypesUtil.java   View Source Code Vote up 4 votes
/**
 * Return true if given method is legal property accessor as defined in
 * Section 1.3.4.3 of Java2IDL spec.
 */
public boolean isPropertyAccessorMethod(Method m, Class c) {

    String methodName = m.getName();
    Class returnType  = m.getReturnType();
    Class[] parameters = m.getParameterTypes();
    Class[] exceptionTypes = m.getExceptionTypes();
    String propertyType = null;

    if( methodName.startsWith(GET_PROPERTY_PREFIX) ) {

        if((parameters.length == 0) && (returnType != Void.TYPE) &&
            !readHasCorrespondingIsProperty(m, c)) {
            propertyType = GET_PROPERTY_PREFIX;
        }

    } else if( methodName.startsWith(SET_PROPERTY_PREFIX) ) {

        if((returnType == Void.TYPE) && (parameters.length == 1)) {
            if (hasCorrespondingReadProperty(m, c, GET_PROPERTY_PREFIX) ||
                hasCorrespondingReadProperty(m, c, IS_PROPERTY_PREFIX)) {
                propertyType = SET_PROPERTY_PREFIX;
            }
        }

    } else if( methodName.startsWith(IS_PROPERTY_PREFIX) ) {
        if((parameters.length == 0) && (returnType == Boolean.TYPE) &&
            !isHasCorrespondingReadProperty(m, c)) {
            propertyType = IS_PROPERTY_PREFIX;
        }
    }

    // Some final checks that apply to all properties.
    if( propertyType != null ) {
        if(!validPropertyExceptions(m) ||
           (methodName.length() <= propertyType.length())) {
            propertyType = null;
        }
    }

    return (propertyType != null);
}
 
Example 18
Project: mango   File: ReferenceInvocationHandler.java   View Source Code Vote up 4 votes
private boolean checkMethodExceptionSignature(Method method) {
    Class<?>[] exps = method.getExceptionTypes();
    return exps!=null && exps.length>0;
}
 
Example 19
Project: ProyectoPacientes   File: LoadBalancedConnectionProxy.java   View Source Code Vote up 4 votes
/**
 * Proxies method invocation on the java.sql.Connection interface, trapping "close", "isClosed" and "commit/rollback" to switch connections for load
 * balancing.
 * This is the continuation of MultiHostConnectionProxy#invoke(Object, Method, Object[]).
 */
@Override
public synchronized Object invokeMore(Object proxy, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();

    if (this.isClosed && !allowedOnClosedConnection(method) && method.getExceptionTypes().length > 0) {
        if (this.autoReconnect && !this.closedExplicitly) {
            // try to reconnect first!
            this.currentConnection = null;
            pickNewConnection();
            this.isClosed = false;
            this.closedReason = null;
        } else {
            String reason = "No operations allowed after connection closed.";
            if (this.closedReason != null) {
                reason += " " + this.closedReason;
            }
            throw SQLError.createSQLException(reason, SQLError.SQL_STATE_CONNECTION_NOT_OPEN, null /* no access to a interceptor here... */);
        }
    }

    if (!this.inTransaction) {
        this.inTransaction = true;
        this.transactionStartTime = System.nanoTime();
        this.transactionCount++;
    }

    Object result = null;

    try {
        result = method.invoke(this.thisAsConnection, args);

        if (result != null) {
            if (result instanceof com.mysql.jdbc.Statement) {
                ((com.mysql.jdbc.Statement) result).setPingTarget(this);
            }
            result = proxyIfReturnTypeIsJdbcInterface(method.getReturnType(), result);
        }

    } catch (InvocationTargetException e) {
        dealWithInvocationException(e);

    } finally {
        if ("commit".equals(methodName) || "rollback".equals(methodName)) {
            this.inTransaction = false;

            // Update stats
            String host = this.connectionsToHostsMap.get(this.currentConnection);
            // avoid NPE if the connection has already been removed from connectionsToHostsMap in invalidateCurrenctConnection()
            if (host != null) {
                synchronized (this.responseTimes) {
                    Integer hostIndex = (this.hostsToListIndexMap.get(host));

                    if (hostIndex != null && hostIndex < this.responseTimes.length) {
                        this.responseTimes[hostIndex] = System.nanoTime() - this.transactionStartTime;
                    }
                }
            }
            pickNewConnection();
        }
    }

    return result;
}
 
Example 20
Project: apache-tomcat-7.0.73-with-comment   File: TrapException.java   View Source Code Vote up 4 votes
public boolean isDeclaredException(Method m, Class<?> clazz) {
    for (Class<?> cl : m.getExceptionTypes()) {
        if (cl.equals(clazz) || cl.isAssignableFrom(clazz)) return true;
    }
    return false;
}