Example usage for org.springframework.cglib.proxy MethodProxy invoke

List of usage examples for org.springframework.cglib.proxy MethodProxy invoke

Introduction

In this page you can find the example usage for org.springframework.cglib.proxy MethodProxy invoke.

Prototype

public Object invoke(Object obj, Object[] args) throws Throwable 

Source Link

Document

Invoke the original method, on a different object of the same type.

Usage

From source file:net.kaczmarzyk.spring.data.jpa.web.EnhancerUtil.java

@SuppressWarnings("unchecked")
static <T> T wrapWithIfaceImplementation(final Class<T> iface, final Specification<Object> targetSpec) {
    Enhancer enhancer = new Enhancer();
    enhancer.setInterfaces(new Class[] { iface });
    enhancer.setCallback(new MethodInterceptor() {
        @Override//from ww  w  . j a  v a2  s .  c o m
        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
            if ("toString".equals(method.getName())) {
                return iface.getSimpleName() + "[" + proxy.invoke(targetSpec, args) + "]";
            }
            return proxy.invoke(targetSpec, args);
        }
    });

    return (T) enhancer.create();
}

From source file:org.reindeer.redis.jedis.JedisCallback.java

@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
    Jedis jedis = null;/*w ww . j  ava  2s. c  o m*/
    filterMethod(method);
    try {
        jedis = jedisHolder.get();
        return methodProxy.invoke(jedis, objects);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        throw e;
    } finally {
        release(jedis);
    }
}

From source file:org.reindeer.redis.shard.ShardedJedisCallback.java

@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
    ShardedJedis jedis;/*from   w  w w. j  a  v a  2 s.c o  m*/
    boolean status = jedisHolder.hasShardJedis();
    if (!status) {
        throw new UnsupportedOperationException("ShardedJedis proxy need use @Redis annotation.");
    }
    try {
        jedis = jedisHolder.getShardedJedis();
        return methodProxy.invoke(jedis, objects);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        throw e;
    }
}