All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ibatis.solon.integration.MybatisMapperInterceptor Maven / Gradle / Ivy

There is a newer version: 3.0.0-M4
Show newest version
package org.apache.ibatis.solon.integration;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Mybatis Mapper Interceptor
 *
 * @author noear
 * @since 1.6
 */
public class MybatisMapperInterceptor implements InvocationHandler {
    SqlSessionFactory factory;
    Class mapperClz;

    public MybatisMapperInterceptor(SqlSessionFactory factory, Class mapperClz) {
        this.factory = factory;
        this.mapperClz = mapperClz;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        try (SqlSession session = factory.openSession(true)) {
            Object mapper = session.getMapper(mapperClz);
            return method.invoke(mapper, args);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy