Java Code Examples for com.jfinal.aop.Invocation#getMethod()

The following examples show how to use com.jfinal.aop.Invocation#getMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParaValidateInterceptor.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void intercept(Invocation inv) {

    Method method = inv.getMethod();


    EmptyValidate emptyParaValidate = method.getAnnotation(EmptyValidate.class);
    if (emptyParaValidate != null && !validateEmpty(inv, emptyParaValidate)) {
        return;
    }

    CaptchaValidate captchaValidate = method.getAnnotation(CaptchaValidate.class);
    if (captchaValidate != null && !validateCaptache(inv, captchaValidate)) {
        return;
    }

    inv.invoke();
}
 
Example 2
Source File: SeataGlobalTransactionalInterceptor.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void intercept(Invocation inv) {
    if (!JbootSeataManager.me().isEnable()) {
        inv.invoke();
        return;
    }
    Method method = inv.getMethod();
    final SeataGlobalTransactional globalTrxAnno = method.getAnnotation(SeataGlobalTransactional.class);
    final SeataGlobalLock globalLockAnno = method.getAnnotation(SeataGlobalLock.class);
    try {
        if (globalTrxAnno != null) {
            handleGlobalTransaction(inv, globalTrxAnno);
        } else if (globalLockAnno != null) {
            handleGlobalLock(inv);
        } else {
            inv.invoke();
        }
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

}
 
Example 3
Source File: JbootCachePutInterceptor.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void intercept(Invocation inv) {

    //先执行,之后再保存数据
    inv.invoke();

    Method method = inv.getMethod();
    CachePut cachePut = method.getAnnotation(CachePut.class);
    if (cachePut == null) {
        return;
    }

    Object data = inv.getReturnValue();

    String unless = AnnotationUtil.get(cachePut.unless());
    if (Utils.isUnless(unless, method, inv.getArgs())) {
        return;
    }

    Class targetClass = inv.getTarget().getClass();
    String cacheName = AnnotationUtil.get(cachePut.name());
    Utils.ensureCachenameAvailable(method, targetClass, cacheName);
    String cacheKey = Utils.buildCacheKey(AnnotationUtil.get(cachePut.key()), targetClass, method, inv.getArgs());

    Utils.putDataToCache(cachePut.liveSeconds(),cacheName,cacheKey,data);
}
 
Example 4
Source File: JbootCacheEvictInterceptor.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void intercept(Invocation inv) {

    Method method = inv.getMethod();

    CacheEvict cacheEvict = method.getAnnotation(CacheEvict.class);
    if (cacheEvict == null) {
        inv.invoke();
        return;
    }

    Class targetClass = inv.getTarget().getClass();

    if (cacheEvict.beforeInvocation()) {
        Utils.doCacheEvict(inv.getArgs(), targetClass, method, cacheEvict);
    }

    inv.invoke();

    if (!cacheEvict.beforeInvocation()) {
        Utils.doCacheEvict(inv.getArgs(), targetClass, method, cacheEvict);
    }
}
 
Example 5
Source File: JbootCachesEvictInterceptor.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public void intercept(Invocation inv) {

    Method method = inv.getMethod();

    CachesEvict cachesEvict = method.getAnnotation(CachesEvict.class);
    if (cachesEvict == null) {
        inv.invoke();
        return;
    }

    CacheEvict[] evicts = cachesEvict.value();
    List<CacheEvict> beforeInvocations = null;
    List<CacheEvict> afterInvocations = null;

    for (CacheEvict evict : evicts) {
        if (evict.beforeInvocation()) {
            if (beforeInvocations == null) {
                beforeInvocations = new ArrayList<>();
            }
            beforeInvocations.add(evict);
        } else {
            if (afterInvocations == null) {
                afterInvocations = new ArrayList<>();
            }
            afterInvocations.add(evict);
        }
    }

    Class targetClass = inv.getTarget().getClass();
    try {
        doCachesEvict(inv.getArgs(), targetClass, method, beforeInvocations);
        inv.invoke();
    } finally {
        doCachesEvict(inv.getArgs(), targetClass, method, afterInvocations);
    }
}
 
Example 6
Source File: AbstractSentinelProccesser.java    From jboot with Apache License 2.0 4 votes vote down vote up
protected Method resolveMethod(Invocation inv) {
    return inv.getMethod();
}
 
Example 7
Source File: JbootCacheInterceptor.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public void intercept(Invocation inv) {

    Method method = inv.getMethod();
    Cacheable cacheable = method.getAnnotation(Cacheable.class);
    if (cacheable == null) {
        inv.invoke();
        return;
    }

    String unlessString = AnnotationUtil.get(cacheable.unless());
    if (Utils.isUnless(unlessString, method, inv.getArgs())) {
        inv.invoke();
        return;
    }

    Class targetClass = inv.getTarget().getClass();
    String cacheName = AnnotationUtil.get(cacheable.name());
    Utils.ensureCachenameAvailable(method, targetClass, cacheName);
    String cacheKey = Utils.buildCacheKey(AnnotationUtil.get(cacheable.key()), targetClass, method, inv.getArgs());

    Object data = AopCache.get(cacheName, cacheKey);
    if (data != null) {
        if (NULL_VALUE.equals(data)) {
            inv.setReturnValue(null);
        } else if (cacheable.returnCopyEnable()) {
            inv.setReturnValue(getCopyObject(inv, data));
        } else {
            inv.setReturnValue(data);
        }
    } else {
        inv.invoke();
        data = inv.getReturnValue();
        if (data != null) {

            Utils.putDataToCache(cacheable.liveSeconds(), cacheName, cacheKey, data);

            //当启用返回 copy 值的时候,返回的内容应该是一个进行copy之后的值
            if (cacheable.returnCopyEnable()) {
                inv.setReturnValue(getCopyObject(inv, data));
            }

        } else if (cacheable.nullCacheEnable()) {
            Utils.putDataToCache(cacheable.liveSeconds(), cacheName, cacheKey, NULL_VALUE);
        }
    }
}