Search in sources :

Example 1 with ShardingJdbcException

use of com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException in project sharding-jdbc by dangdangdotcom.

the class VisitorLogProxy method enhance.

/**
     * 打印SQL解析调用树.
     * 
     * @param target 待增强类
     * @param <T> 泛型
     * @return 增强后的新类的对象
     */
@SuppressWarnings("unchecked")
public static <T> T enhance(final Class<T> target) {
    if (log.isTraceEnabled()) {
        Enhancer result = new Enhancer();
        result.setSuperclass(target);
        result.setCallback(new VisitorHandler());
        return (T) result.create();
    } else {
        try {
            return target.newInstance();
        } catch (final InstantiationException | IllegalAccessException ex) {
            log.error("create Visitor exception: {}", ex);
            throw new ShardingJdbcException(ex);
        }
    }
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer) ShardingJdbcException(com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException)

Example 2 with ShardingJdbcException

use of com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException in project sharding-jdbc by dangdangdotcom.

the class ParameterList method recordMethodInvocation.

/**
     * 使用索引记录方法调用.
     * 
     * @param index 索引
     * @param methodName 方法名称
     * @param argumentTypes 参数类型
     * @param arguments 参数
     */
public final void recordMethodInvocation(final int index, final String methodName, final Class<?>[] argumentTypes, final Object[] arguments) {
    jdbcMethodInvocations.ensureCapacity(index);
    int max = jdbcMethodInvocations.size();
    while (max++ <= index - 1) {
        jdbcMethodInvocations.add(null);
    }
    try {
        jdbcMethodInvocations.set(index - 1, new JdbcMethodInvocation(targetClass.getMethod(methodName, argumentTypes), arguments));
    } catch (final NoSuchMethodException ex) {
        throw new ShardingJdbcException(ex);
    }
}
Also used : ShardingJdbcException(com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException)

Aggregations

ShardingJdbcException (com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException)2 Enhancer (net.sf.cglib.proxy.Enhancer)1