add ibatis wrapper

This commit is contained in:
wenshao 2012-12-05 18:53:29 +08:00
parent c07c55ff9e
commit dc417b547a
11 changed files with 812 additions and 3 deletions

3
.gitignore vendored
View File

@ -10,4 +10,5 @@
out/
*.ipr
*.iws
*.iml
*.iml
/bin

View File

@ -279,7 +279,8 @@ public class ConfigFilter extends FilterAdapter {
}
}
private InputStream getFileAsStream(String filePath) throws FileNotFoundException {
@SuppressWarnings("resource")
private InputStream getFileAsStream(String filePath) throws FileNotFoundException {
InputStream inStream = null;
File file = new File(filePath);
if (file.exists()) {

View File

@ -36,7 +36,6 @@ import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
@SuppressWarnings({ "restriction" })
public class DruidStat {
private static final String LOCAL_CONNECTOR_ADDRESS_PROP = "com.sun.management.jmxremote.localConnectorAddress";

View File

@ -0,0 +1,129 @@
package com.alibaba.druid.support.ibatis;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
import com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl;
import com.ibatis.sqlmap.engine.scope.SessionScope;
public class IbatisUtils {
private static Log LOG = LogFactory.getLog(IbatisUtils.class);
private static boolean VERSION_2_3_4 = false;
private static Method methodGetId = null;
private static Method methodGetResource = null;
static {
try {
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass("com.ibatis.sqlmap.engine.mapping.result.AutoResultMap");
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (method.equals("setResultObjectValues")) { // ibatis 2.3.4 add method 'setResultObjectValues'
VERSION_2_3_4 = true;
break;
}
}
} catch (Throwable e) {
// skip
}
}
public static boolean isVersion2_3_4() {
return VERSION_2_3_4;
}
public static SqlMapExecutor setClientImpl(SqlMapExecutor session, SqlMapClientImplWrapper clientImplWrapper) {
if (session == null || clientImplWrapper == null) {
return session;
}
if (session.getClass() == SqlMapSessionImpl.class) {
SqlMapSessionImpl sessionImpl = (SqlMapSessionImpl) session;
set(sessionImpl, clientImplWrapper);
}
return session;
}
/**
* 通过反射的方式得到id能够兼容2.3.0和2.3.4
*
* @return
*/
protected static String createId(Object statement) {
try {
if (methodGetId == null) {
Class<?> clazz = statement.getClass();
methodGetId = clazz.getMethod("getId");
}
Object returnValue = methodGetId.invoke(statement);
if (returnValue == null) {
return null;
}
return returnValue.toString();
} catch (Exception ex) {
LOG.error("createIdError", ex);
return null;
}
}
/**
* 通过反射的方式得到resource能够兼容2.3.0和2.3.4
*
* @return
*/
protected static String createResource(Object statement) {
try {
if (methodGetResource == null) {
methodGetResource = statement.getClass().getMethod("getResource");
}
return (String) methodGetResource.invoke(statement);
} catch (Exception ex) {
return null;
}
}
private static Field sessionField;
public static void set(SqlMapSessionImpl session, SqlMapClientImpl client) {
if (sessionField == null) {
for (Field field : SqlMapSessionImpl.class.getDeclaredFields()) {
if (field.getName().equals("session") || field.getName().equals("sessionScope")) {
sessionField = field;
sessionField.setAccessible(true);
break;
}
}
}
if (sessionField != null) {
SessionScope sessionScope;
try {
sessionScope = (SessionScope) sessionField.get(session);
if (sessionScope != null) {
if (sessionScope.getSqlMapClient() != null && sessionScope.getSqlMapClient().getClass() == SqlMapClientImpl.class) {
sessionScope.setSqlMapClient(client);
}
if (sessionScope.getSqlMapExecutor() != null && sessionScope.getSqlMapExecutor().getClass() == SqlMapClientImpl.class) {
sessionScope.setSqlMapExecutor(client);
}
if (sessionScope.getSqlMapTxMgr() != null && sessionScope.getSqlMapTxMgr().getClass() == SqlMapClientImpl.class) {
sessionScope.setSqlMapTxMgr(client);
}
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
}
}

View File

@ -0,0 +1,128 @@
package com.alibaba.druid.support.ibatis;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.util.Assert;
import org.springframework.util.PatternMatchUtils;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;
/**
* 类BeanTypeAutoProxyCreator.java的实现描述使用配置类型代替Springframework中配置名称的实现
*
* @author hualiang.lihl 2011-12-31 上午10:48:20
*/
@SuppressWarnings("deprecation")
public class SpringIbatisBeanTypeAutoProxyCreator extends AbstractAutoProxyCreator implements InitializingBean, ApplicationContextAware, SpringIbatisBeanTypeAutoProxyCreatorMBean {
private final static Log LOG = LogFactory.getLog(SpringIbatisBeanTypeAutoProxyCreator.class);
private static final long serialVersionUID = -9094985530794052264L;
private Class<?> targetBeanType = SqlMapClient.class;
private ApplicationContext context;
private List<String> beanNames = new ArrayList<String>();
private final List<String> proxyBeanNames = new ArrayList<String>();
/**
* @param targetClass the targetClass to set
*/
public void setTargetBeanType(Class<?> targetClass) {
this.targetBeanType = targetClass;
}
public void setApplicationContext(ApplicationContext context) throws BeansException {
this.context = context;
}
/**
* Identify as bean to proxy if the bean name is in the configured list of names.
*/
@SuppressWarnings("rawtypes")
protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, TargetSource targetSource) {
for (Iterator<String> it = this.beanNames.iterator(); it.hasNext();) {
String mappedName = (String) it.next();
if (FactoryBean.class.isAssignableFrom(beanClass)) {
if (!mappedName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) {
continue;
}
mappedName = mappedName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length());
}
if (isMatch(beanName, mappedName)) {
return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
}
}
return DO_NOT_PROXY;
}
@SuppressWarnings({ "rawtypes" })
protected Object createProxy(Class beanClass, String beanName, Object[] specificInterceptors,
TargetSource targetSource) {
try {
Object target = targetSource.getTarget();
if (target instanceof SqlMapClientWrapper) {
proxyBeanNames.add(beanName);
return target;
}
if (target instanceof SqlMapClient) {
proxyBeanNames.add(beanName);
return new SqlMapClientWrapper((ExtendedSqlMapClient) target);
}
return super.createProxy(beanClass, beanName, specificInterceptors, targetSource);
} catch (Throwable ex) {
LOG.error(ex.getMessage(), ex);
return super.createProxy(beanClass, beanName, specificInterceptors, targetSource);
}
}
/**
* Return if the given bean name matches the mapped name.
* <p>
* The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality. Can be
* overridden in subclasses.
*
* @param beanName the bean name to check
* @param mappedName the name in the configured list of names
* @return if the names match
* @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
*/
protected boolean isMatch(String beanName, String mappedName) {
return PatternMatchUtils.simpleMatch(mappedName, beanName);
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(targetBeanType, "targetType cannot be null");
String[] beanNames = context.getBeanNamesForType(targetBeanType);
for (String name : beanNames) {
this.beanNames.add(name);
}
}
public List<String> getBeanNames() {
return beanNames;
}
public List<String> getProxyBeanNames() {
return proxyBeanNames;
}
}

View File

@ -0,0 +1,8 @@
package com.alibaba.druid.support.ibatis;
import java.util.List;
public interface SpringIbatisBeanTypeAutoProxyCreatorMBean {
List<String> getProxyBeanNames();
}

View File

@ -0,0 +1,185 @@
package com.alibaba.druid.support.ibatis;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import com.ibatis.common.util.PaginatedList;
import com.ibatis.sqlmap.client.SqlMapSession;
import com.ibatis.sqlmap.client.event.RowHandler;
import com.ibatis.sqlmap.engine.execution.BatchException;
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
import com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl;
@SuppressWarnings("deprecation")
public class SqlMapClientImplWrapper extends SqlMapClientImpl {
private SqlMapClientImpl raw;
private static Method getLocalSqlMapSessionMethod = null;
public SqlMapClientImplWrapper(SqlMapClientImpl raw){
super(raw.getDelegate());
this.raw = raw;
}
protected SqlMapSessionWrapper getLocalSqlMapSessionWrapper() {
try {
if (getLocalSqlMapSessionMethod == null) {
getLocalSqlMapSessionMethod = raw.getClass().getDeclaredMethod("getLocalSqlMapSession");
getLocalSqlMapSessionMethod.setAccessible(true);
}
SqlMapSessionImpl sessionImpl = (SqlMapSessionImpl) getLocalSqlMapSessionMethod.invoke(raw);
IbatisUtils.set(sessionImpl, this);
return new SqlMapSessionWrapper(raw, sessionImpl);
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
public SqlMapSession openSession(Connection conn) {
SqlMapSession session = raw.openSession(conn);
IbatisUtils.setClientImpl(session, this);
return new SqlMapSessionWrapper(raw, session);
}
public SqlMapSession getSession() {
SqlMapSession session = raw.getSession();
IbatisUtils.setClientImpl(session, this);
return new SqlMapSessionWrapper(raw, session);
}
// /////
public Object insert(String id, Object param) throws SQLException {
return getLocalSqlMapSessionWrapper().insert(id, param);
}
public Object insert(String id) throws SQLException {
return getLocalSqlMapSessionWrapper().insert(id);
}
public int update(String id, Object param) throws SQLException {
return getLocalSqlMapSessionWrapper().update(id, param);
}
public int update(String id) throws SQLException {
return getLocalSqlMapSessionWrapper().update(id);
}
public int delete(String id, Object param) throws SQLException {
return getLocalSqlMapSessionWrapper().delete(id, param);
}
public int delete(String id) throws SQLException {
return getLocalSqlMapSessionWrapper().delete(id);
}
public Object queryForObject(String id, Object paramObject) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForObject(id, paramObject);
}
public Object queryForObject(String id) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForObject(id);
}
public Object queryForObject(String id, Object paramObject, Object resultObject) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForObject(id, paramObject, resultObject);
}
@SuppressWarnings("rawtypes")
public List queryForList(String id, Object paramObject) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForList(id, paramObject);
}
@SuppressWarnings("rawtypes")
public List queryForList(String id) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForList(id);
}
@SuppressWarnings("rawtypes")
public List queryForList(String id, Object paramObject, int skip, int max) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForList(id, paramObject, skip, max);
}
@SuppressWarnings("rawtypes")
public List queryForList(String id, int skip, int max) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForList(id, skip, max);
}
/**
* @deprecated All paginated list features have been deprecated
*/
public PaginatedList queryForPaginatedList(String id, Object paramObject, int pageSize) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForPaginatedList(id, paramObject, pageSize);
}
/**
* @deprecated All paginated list features have been deprecated
*/
public PaginatedList queryForPaginatedList(String id, int pageSize) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForPaginatedList(id, pageSize);
}
@SuppressWarnings("rawtypes")
public Map queryForMap(String id, Object paramObject, String keyProp) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForMap(id, paramObject, keyProp);
}
@SuppressWarnings("rawtypes")
public Map queryForMap(String id, Object paramObject, String keyProp, String valueProp) throws SQLException {
return getLocalSqlMapSessionWrapper().queryForMap(id, paramObject, keyProp, valueProp);
}
public void queryWithRowHandler(String id, Object paramObject, RowHandler rowHandler) throws SQLException {
getLocalSqlMapSessionWrapper().queryWithRowHandler(id, paramObject, rowHandler);
}
public void queryWithRowHandler(String id, RowHandler rowHandler) throws SQLException {
getLocalSqlMapSessionWrapper().queryWithRowHandler(id, rowHandler);
}
public void startTransaction() throws SQLException {
getLocalSqlMapSessionWrapper().startTransaction();
}
public void startTransaction(int transactionIsolation) throws SQLException {
getLocalSqlMapSessionWrapper().startTransaction(transactionIsolation);
}
public void commitTransaction() throws SQLException {
getLocalSqlMapSessionWrapper().commitTransaction();
}
public void endTransaction() throws SQLException {
try {
getLocalSqlMapSessionWrapper().endTransaction();
} finally {
getLocalSqlMapSessionWrapper().close();
}
}
public void startBatch() throws SQLException {
getLocalSqlMapSessionWrapper().startBatch();
}
public int executeBatch() throws SQLException {
return getLocalSqlMapSessionWrapper().executeBatch();
}
@SuppressWarnings("rawtypes")
public List executeBatchDetailed() throws SQLException, BatchException {
return getLocalSqlMapSessionWrapper().executeBatchDetailed();
}
public void setUserConnection(Connection connection) throws SQLException {
try {
getLocalSqlMapSessionWrapper().setUserConnection(connection);
} finally {
if (connection == null) {
getLocalSqlMapSessionWrapper().close();
}
}
}
}

View File

@ -0,0 +1,112 @@
package com.alibaba.druid.support.ibatis;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapSession;
import com.ibatis.sqlmap.engine.execution.SqlExecutor;
import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;
import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;
import com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory;
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
@SuppressWarnings("deprecation")
public class SqlMapClientWrapper extends SqlMapExecutorWrapper implements SqlMapClient, ExtendedSqlMapClient {
protected final ExtendedSqlMapClient client;
public SqlMapClientWrapper(ExtendedSqlMapClient client){
super(client, client);
this.client = client;
}
public ExtendedSqlMapClient getClient() {
return this.client;
}
public void startTransaction() throws SQLException {
client.startTransaction();
}
public void startTransaction(int transactionIsolation) throws SQLException {
client.startTransaction(transactionIsolation);
}
public void commitTransaction() throws SQLException {
client.commitTransaction();
}
public void endTransaction() throws SQLException {
client.endTransaction();
}
public void setUserConnection(Connection connnection) throws SQLException {
client.setUserConnection(connnection);
}
public Connection getUserConnection() throws SQLException {
return client.getUserConnection();
}
public Connection getCurrentConnection() throws SQLException {
return client.getCurrentConnection();
}
public DataSource getDataSource() {
return client.getDataSource();
}
public SqlMapSession openSession() {
SqlMapSession session = client.openSession();
IbatisUtils.setClientImpl(session, clientImplWrapper);
return new SqlMapSessionWrapper(client, session);
}
public SqlMapSession openSession(Connection conn) {
SqlMapSession session = client.openSession(conn);
IbatisUtils.setClientImpl(session, clientImplWrapper);
return new SqlMapSessionWrapper(client, session);
}
public SqlMapSession getSession() {
SqlMapSession session = client.getSession();
IbatisUtils.setClientImpl(session, clientImplWrapper);
return new SqlMapSessionWrapper(client, session);
}
public void flushDataCache() {
client.flushDataCache();
}
public void flushDataCache(String cacheId) {
client.flushDataCache(cacheId);
}
public MappedStatement getMappedStatement(String id) {
return client.getMappedStatement(id);
}
public boolean isLazyLoadingEnabled() {
return client.isLazyLoadingEnabled();
}
public boolean isEnhancementEnabled() {
return client.isEnhancementEnabled();
}
public SqlExecutor getSqlExecutor() {
return client.getSqlExecutor();
}
public SqlMapExecutorDelegate getDelegate() {
return client.getDelegate();
}
public ResultObjectFactory getResultObjectFactory() {
return client.getResultObjectFactory();
}
}

View File

@ -0,0 +1,186 @@
package com.alibaba.druid.support.ibatis;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import com.ibatis.common.util.PaginatedList;
import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.ibatis.sqlmap.client.event.RowHandler;
import com.ibatis.sqlmap.engine.execution.BatchException;
import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
@SuppressWarnings("deprecation")
public class SqlMapExecutorWrapper implements SqlMapExecutor {
private SqlMapExecutor executor;
protected final SqlMapClientImpl clientImpl;
protected final SqlMapClientImplWrapper clientImplWrapper;
public SqlMapExecutorWrapper(ExtendedSqlMapClient client, SqlMapExecutor executor){
this.executor = executor;
this.clientImpl = client.getClass() == SqlMapClientImpl.class ? (SqlMapClientImpl) client : null;
this.clientImplWrapper = clientImpl != null ? new SqlMapClientImplWrapper(clientImpl) : null;
}
public Object insert(String id, Object parameterObject) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
return executor.insert(id, parameterObject);
}
public Object insert(String id) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
return executor.insert(id);
}
public int update(String id, Object parameterObject) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
int effectedRowCount = executor.update(id, parameterObject);
return effectedRowCount;
}
public int update(String id) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
int effectedRowCount = executor.update(id);
return effectedRowCount;
}
public int delete(String id, Object parameterObject) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
int effectedRowCount = executor.delete(id, parameterObject);
return effectedRowCount;
}
public int delete(String id) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
int effectedRowCount = executor.delete(id);
return effectedRowCount;
}
public Object queryForObject(String id, Object parameterObject) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
Object object = executor.queryForObject(id, parameterObject);
return object;
}
public Object queryForObject(String id) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
Object object = executor.queryForObject(id);
return object;
}
public Object queryForObject(String id, Object parameterObject, Object resultObject) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
Object object = executor.queryForObject(id, parameterObject, resultObject);
return object;
}
@SuppressWarnings("rawtypes")
public List queryForList(String id, Object parameterObject) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
List list = executor.queryForList(id, parameterObject);
return list;
}
@SuppressWarnings("rawtypes")
public List queryForList(String id) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
List list = executor.queryForList(id);
return list;
}
@SuppressWarnings("rawtypes")
public List queryForList(String id, Object parameterObject, int skip, int max) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
List list = executor.queryForList(id, parameterObject, skip, max);
return list;
}
@SuppressWarnings("rawtypes")
public List queryForList(String id, int skip, int max) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
List list = executor.queryForList(id, skip, max);
return list;
}
public void queryWithRowHandler(String id, Object parameterObject, RowHandler rowHandler) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
executor.queryWithRowHandler(id, parameterObject, rowHandler);
}
public void queryWithRowHandler(String id, RowHandler rowHandler) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
executor.queryWithRowHandler(id, rowHandler);
}
public PaginatedList queryForPaginatedList(String id, Object parameterObject, int pageSize) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
PaginatedList list = executor.queryForPaginatedList(id, parameterObject, pageSize);
return list;
}
public PaginatedList queryForPaginatedList(String id, int pageSize) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
PaginatedList list = executor.queryForPaginatedList(id, pageSize);
return list;
}
@SuppressWarnings("rawtypes")
public Map queryForMap(String id, Object parameterObject, String keyProp) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
Map map = executor.queryForMap(id, parameterObject, keyProp);
return map;
}
@SuppressWarnings("rawtypes")
public Map queryForMap(String id, Object parameterObject, String keyProp, String valueProp) throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
Map map = executor.queryForMap(id, parameterObject, keyProp, valueProp);
return map;
}
public void startBatch() throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
executor.startBatch();
}
public int executeBatch() throws SQLException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
return executor.executeBatch();
}
@SuppressWarnings("rawtypes")
public List executeBatchDetailed() throws SQLException, BatchException {
IbatisUtils.setClientImpl(executor, clientImplWrapper);
return executor.executeBatchDetailed();
}
}

View File

@ -0,0 +1,56 @@
package com.alibaba.druid.support.ibatis;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.ibatis.sqlmap.client.SqlMapSession;
import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;
@SuppressWarnings("deprecation")
public class SqlMapSessionWrapper extends SqlMapExecutorWrapper implements SqlMapSession {
private SqlMapSession session;
public SqlMapSessionWrapper(ExtendedSqlMapClient client, SqlMapSession session){
super(client, session);
this.session = session;
}
public void startTransaction() throws SQLException {
session.startTransaction();
}
public void startTransaction(int transactionIsolation) throws SQLException {
session.startTransaction(transactionIsolation);
}
public void commitTransaction() throws SQLException {
session.commitTransaction();
}
public void endTransaction() throws SQLException {
session.endTransaction();
}
public void setUserConnection(Connection connnection) throws SQLException {
session.setUserConnection(connnection);
}
@Deprecated
public Connection getUserConnection() throws SQLException {
return session.getUserConnection();
}
public Connection getCurrentConnection() throws SQLException {
return session.getCurrentConnection();
}
public DataSource getDataSource() {
return session.getDataSource();
}
public void close() {
session.close();
}
}

View File

@ -18,5 +18,9 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/
<property name="mapperInterface" value="com.alibaba.druid.bvt.pool.SpringMybatisFilterTest$UserMapper" />
</bean>
<bean class="com.alibaba.druid.support.ibatis.SpringIbatisBeanTypeAutoProxyCreator" >
<property name="targetClass" value="com.ibatis.sqlmap.client.SqlMapClient" />
</bean>
<import resource="classpath:com/alibaba/druid/pool/dataSource.xml"/>
</beans>