diff --git a/src/main/java/com/alibaba/druid/support/ibatis/SpringIbatisBeanNameAutoProxyCreator.java b/src/main/java/com/alibaba/druid/support/ibatis/SpringIbatisBeanNameAutoProxyCreator.java new file mode 100644 index 0000000000..1697d567a5 --- /dev/null +++ b/src/main/java/com/alibaba/druid/support/ibatis/SpringIbatisBeanNameAutoProxyCreator.java @@ -0,0 +1,64 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.support.ibatis; + +import java.util.ArrayList; +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.BeanNameAutoProxyCreator; + +import com.ibatis.sqlmap.client.SqlMapClient; +import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient; + +@SuppressWarnings({ "serial", "deprecation" }) +public class SpringIbatisBeanNameAutoProxyCreator extends BeanNameAutoProxyCreator implements SpringIbatisBeanNameAutoProxyCreatorMBean { + + private final static Log LOG = LogFactory.getLog(SpringIbatisBeanNameAutoProxyCreator.class); + + private final List proxyBeanNames = new ArrayList(); + + public List getProxyBeanNames() { + return proxyBeanNames; + } + + @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); + } + } + +} diff --git a/src/main/java/com/alibaba/druid/support/ibatis/SpringIbatisBeanNameAutoProxyCreatorMBean.java b/src/main/java/com/alibaba/druid/support/ibatis/SpringIbatisBeanNameAutoProxyCreatorMBean.java new file mode 100644 index 0000000000..36d83e0f0e --- /dev/null +++ b/src/main/java/com/alibaba/druid/support/ibatis/SpringIbatisBeanNameAutoProxyCreatorMBean.java @@ -0,0 +1,23 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.support.ibatis; + +import java.util.List; + + +public interface SpringIbatisBeanNameAutoProxyCreatorMBean { + List getProxyBeanNames(); +}