Skip to content

Commit c8ecb3c

Browse files
committed
Cherripicking #59, #78 && #105
1 parent 8ab51b7 commit c8ecb3c

19 files changed

+123
-39
lines changed

pom.xml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
<parent>
2121
<groupId>org.mybatis</groupId>
2222
<artifactId>mybatis-parent</artifactId>
23-
<version>24</version>
23+
<version>26</version>
24+
<relativePath />
2425
</parent>
2526

2627
<artifactId>mybatis-spring</artifactId>
27-
<version>1.2.3</version>
28+
<version>1.2.4-SNAPSHOT</version>
2829
<packaging>jar</packaging>
2930

3031
<name>mybatis-spring</name>
31-
<description>An easy-to-use Spring3 bridge for MyBatis sql mapping framework.</description>
32+
<description>An easy-to-use Spring bridge for MyBatis sql mapping framework.</description>
3233
<url>http://www.mybatis.org/spring/</url>
3334

3435
<contributors>
@@ -69,7 +70,7 @@
6970
</contributor>
7071

7172
<contributor>
72-
<name>Tomáš Piňos</name>
73+
<name>Tom&#225;&#353; Pi&#328;os</name>
7374
<email>[email protected]</email>
7475
</contributor>
7576
</contributors>
@@ -78,7 +79,7 @@
7879
<url>http://github.com/mybatis/spring</url>
7980
<connection>scm:git:ssh://github.com/mybatis/spring.git</connection>
8081
<developerConnection>scm:git:ssh://[email protected]/mybatis/spring.git</developerConnection>
81-
<tag>mybatis-spring-1.2.3</tag>
82+
<tag>HEAD</tag>
8283
</scm>
8384
<issueManagement>
8485
<system>GitHub Issue Management</system>
@@ -90,8 +91,9 @@
9091
</ciManagement>
9192
<distributionManagement>
9293
<site>
93-
<id>github</id>
94-
<url>gitsite:[email protected]/mybatis/spring.git</url>
94+
<id>gh-pages</id>
95+
<name>Mybatis GitHub Pages</name>
96+
<url>git:ssh://[email protected]/mybatis/spring.git?gh-pages#</url>
9597
</site>
9698
</distributionManagement>
9799

@@ -101,15 +103,15 @@
101103
<gcu.product>Spring</gcu.product>
102104
<osgi.import>org.springframework.batch.*;resolution:=optional,*</osgi.import>
103105
<osgi.dynamicImport>*</osgi.dynamicImport>
104-
<spring.version>3.2.13.RELEASE</spring.version>
106+
<spring.version>4.2.4.RELEASE</spring.version>
105107
</properties>
106108

107109
<dependencies>
108110
<!-- Compile dependencies -->
109111
<dependency>
110112
<groupId>org.mybatis</groupId>
111113
<artifactId>mybatis</artifactId>
112-
<version>3.3.0</version>
114+
<version>3.4.0-SNAPSHOT</version>
113115
<scope>provided</scope>
114116
</dependency>
115117

@@ -129,7 +131,7 @@
129131
<dependency>
130132
<groupId>org.springframework.batch</groupId>
131133
<artifactId>spring-batch-infrastructure</artifactId>
132-
<version>3.0.4.RELEASE</version>
134+
<version>3.0.6.RELEASE</version>
133135
<scope>provided</scope>
134136
</dependency>
135137

@@ -145,21 +147,21 @@
145147
<dependency>
146148
<groupId>org.apache.derby</groupId>
147149
<artifactId>derby</artifactId>
148-
<version>10.11.1.1</version>
150+
<version>10.12.1.1</version>
149151
<scope>test</scope>
150152
</dependency>
151153

152154
<dependency>
153155
<groupId>ognl</groupId>
154156
<artifactId>ognl</artifactId>
155-
<version>3.0.11</version>
157+
<version>3.1.2</version>
156158
<scope>test</scope>
157159
</dependency>
158160

159161
<dependency>
160162
<groupId>cglib</groupId>
161163
<artifactId>cglib</artifactId>
162-
<version>3.1</version>
164+
<version>3.2.0</version>
163165
<scope>test</scope>
164166
</dependency>
165167

@@ -173,7 +175,7 @@
173175
<dependency>
174176
<groupId>org.jboss.byteman</groupId>
175177
<artifactId>byteman-bmunit</artifactId>
176-
<version>3.0.1</version>
178+
<version>3.0.3</version>
177179
<scope>test</scope>
178180
</dependency>
179181

@@ -187,7 +189,7 @@
187189
<dependency>
188190
<groupId>org.hsqldb</groupId>
189191
<artifactId>hsqldb</artifactId>
190-
<version>2.3.2</version>
192+
<version>2.3.3</version>
191193
<scope>test</scope>
192194
</dependency>
193195

src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.ibatis.builder.xml.XMLConfigBuilder;
3030
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
3131
import org.apache.ibatis.executor.ErrorContext;
32+
import org.apache.ibatis.io.VFS;
3233
import org.apache.ibatis.logging.Log;
3334
import org.apache.ibatis.logging.LogFactory;
3435
import org.apache.ibatis.mapping.DatabaseIdProvider;
@@ -64,7 +65,8 @@
6465
* @author Putthibong Boonbong
6566
* @author Hunter Presnall
6667
* @author Eduardo Macarron
67-
*
68+
* @author Eddú Meléndez
69+
*
6870
* @see #setConfigLocation
6971
* @see #setDataSource
7072
* @version $Id$
@@ -107,13 +109,15 @@ public class SqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, In
107109
//issue #19. No default provider.
108110
private DatabaseIdProvider databaseIdProvider;
109111

112+
private Class<? extends VFS> vfs;
113+
110114
private ObjectFactory objectFactory;
111115

112116
private ObjectWrapperFactory objectWrapperFactory;
113117

114118
/**
115119
* Sets the ObjectFactory.
116-
*
120+
*
117121
* @since 1.1.2
118122
* @param objectFactory
119123
*/
@@ -123,7 +127,7 @@ public void setObjectFactory(ObjectFactory objectFactory) {
123127

124128
/**
125129
* Sets the ObjectWrapperFactory.
126-
*
130+
*
127131
* @since 1.1.2
128132
* @param objectWrapperFactory
129133
*/
@@ -143,7 +147,7 @@ public DatabaseIdProvider getDatabaseIdProvider() {
143147

144148
/**
145149
* Sets the DatabaseIdProvider.
146-
* As of version 1.2.2 this variable is not initialized by default.
150+
* As of version 1.2.2 this variable is not initialized by default.
147151
*
148152
* @since 1.1.0
149153
* @param databaseIdProvider
@@ -152,6 +156,14 @@ public void setDatabaseIdProvider(DatabaseIdProvider databaseIdProvider) {
152156
this.databaseIdProvider = databaseIdProvider;
153157
}
154158

159+
public Class<? extends VFS> getVfs() {
160+
return this.vfs;
161+
}
162+
163+
public void setVfs(Class<? extends VFS> vfs) {
164+
this.vfs = vfs;
165+
}
166+
155167
/**
156168
* Mybatis plugin list.
157169
*
@@ -426,6 +438,18 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
426438
}
427439
}
428440

441+
if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls
442+
try {
443+
configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
444+
} catch (SQLException e) {
445+
throw new NestedIOException("Failed getting a databaseId", e);
446+
}
447+
}
448+
449+
if (this.vfs != null) {
450+
configuration.setVfsImpl(this.vfs);
451+
}
452+
429453
if (xmlConfigBuilder != null) {
430454
try {
431455
xmlConfigBuilder.parse();
@@ -446,14 +470,6 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
446470

447471
configuration.setEnvironment(new Environment(this.environment, this.transactionFactory, this.dataSource));
448472

449-
if (this.databaseIdProvider != null) {
450-
try {
451-
configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
452-
} catch (SQLException e) {
453-
throw new NestedIOException("Failed getting a databaseId", e);
454-
}
455-
}
456-
457473
if (!isEmpty(this.mapperLocations)) {
458474
for (Resource mapperLocation : this.mapperLocations) {
459475
if (mapperLocation == null) {

src/main/java/org/mybatis/spring/SqlSessionTemplate.java

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.List;
2929
import java.util.Map;
3030

31+
import org.apache.ibatis.cursor.Cursor;
3132
import org.apache.ibatis.exceptions.PersistenceException;
3233
import org.apache.ibatis.executor.BatchResult;
3334
import org.apache.ibatis.session.Configuration;
@@ -36,6 +37,7 @@
3637
import org.apache.ibatis.session.RowBounds;
3738
import org.apache.ibatis.session.SqlSession;
3839
import org.apache.ibatis.session.SqlSessionFactory;
40+
import org.springframework.beans.factory.DisposableBean;
3941
import org.springframework.dao.support.PersistenceExceptionTranslator;
4042

4143
/**
@@ -68,12 +70,12 @@
6870
* @author Putthibong Boonbong
6971
* @author Hunter Presnall
7072
* @author Eduardo Macarron
71-
*
73+
*
7274
* @see SqlSessionFactory
7375
* @see MyBatisExceptionTranslator
7476
* @version $Id$
7577
*/
76-
public class SqlSessionTemplate implements SqlSession {
78+
public class SqlSessionTemplate implements SqlSession, DisposableBean {
7779

7880
private final SqlSessionFactory sqlSessionFactory;
7981

@@ -370,11 +372,32 @@ public List<BatchResult> flushStatements() {
370372
}
371373

372374
/**
373-
* Proxy needed to route MyBatis method calls to the proper SqlSession got
374-
* from Spring's Transaction Manager
375-
* It also unwraps exceptions thrown by {@code Method#invoke(Object, Object...)} to
376-
* pass a {@code PersistenceException} to the {@code PersistenceExceptionTranslator}.
377-
*/
375+
* Allow gently dispose bean:
376+
* <pre>
377+
* {@code
378+
*
379+
* <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
380+
* <constructor-arg index="0" ref="sqlSessionFactory" />
381+
* </bean>
382+
* }
383+
*</pre>
384+
*
385+
* The implementation of {@link DisposableBean} forces spring context to use {@link DisposableBean#destroy()} method instead of {@link SqlSessionTemplate#close()} to shutdown gently.
386+
*
387+
* @see SqlSessionTemplate#close()
388+
* @see org.springframework.beans.factory.support.DisposableBeanAdapter#inferDestroyMethodIfNecessary
389+
* @see org.springframework.beans.factory.support.DisposableBeanAdapter#CLOSE_METHOD_NAME
390+
*/
391+
@Override
392+
public void destroy() throws Exception {
393+
}
394+
395+
/**
396+
* Proxy needed to route MyBatis method calls to the proper SqlSession got
397+
* from Spring's Transaction Manager
398+
* It also unwraps exceptions thrown by {@code Method#invoke(Object, Object...)} to
399+
* pass a {@code PersistenceException} to the {@code PersistenceExceptionTranslator}.
400+
*/
378401
private class SqlSessionInterceptor implements InvocationHandler {
379402
@Override
380403
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -410,4 +433,16 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
410433
}
411434
}
412435

436+
public <T> Cursor<T> selectCursor(String statement) {
437+
return null;
438+
}
439+
440+
public <T> Cursor<T> selectCursor(String statement, Object parameter) {
441+
return null;
442+
}
443+
444+
public <T> Cursor<T> selectCursor(String statement, Object parameter, RowBounds rowBounds) {
445+
return null;
446+
}
447+
413448
}

src/main/java/org/mybatis/spring/mapper/ClassPathMapperScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
184184

185185
// the mapper interface is the original class of the bean
186186
// but, the actual class of the bean is MapperFactoryBean
187-
definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());
187+
definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName()); // issue #59
188188
definition.setBeanClass(this.mapperFactoryBean.getClass());
189189

190190
definition.getPropertyValues().add("addToConfig", this.addToConfig);

src/main/java/org/mybatis/spring/mapper/MapperFactoryBean.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ public class MapperFactoryBean<T> extends SqlSessionDaoSupport implements Factor
5858

5959
private boolean addToConfig = true;
6060

61-
61+
public MapperFactoryBean() {
62+
}
63+
6264
public MapperFactoryBean(Class<T> mapperInterface) {
6365
this.mapperInterface = mapperInterface;
6466
}
6567

66-
public MapperFactoryBean() {
67-
}
68-
6968
/**
7069
* {@inheritDoc}
7170
*/

src/test/java/org/mybatis/spring/ExecutorInterceptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ final class ExecutorInterceptor implements Interceptor {
4646

4747
private boolean closed;
4848

49+
@Override
4950
public Object intercept(Invocation invocation) throws Throwable {
5051
if ("commit".equals(invocation.getMethod().getName())) {
5152
++this.commitCount;
@@ -58,10 +59,12 @@ public Object intercept(Invocation invocation) throws Throwable {
5859
return invocation.proceed();
5960
}
6061

62+
@Override
6163
public Object plugin(Object target) {
6264
return Plugin.wrap(target, this);
6365
}
6466

67+
@Override
6568
public void setProperties(Properties properties) {
6669
// do nothing
6770
}

src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.math.BigDecimal;
2121
import java.math.BigInteger;
2222

23+
import org.apache.ibatis.io.JBoss6VFS;
2324
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
2425
import org.apache.ibatis.reflection.factory.ObjectFactory;
2526
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
@@ -136,6 +137,7 @@ public void testSetConfigLocation() throws Exception {
136137
assertSame(factory.getConfiguration().getEnvironment().getDataSource(), dataSource);
137138
assertSame(factory.getConfiguration().getEnvironment().getTransactionFactory().getClass(),
138139
org.mybatis.spring.transaction.SpringManagedTransactionFactory.class);
140+
assertSame(factory.getConfiguration().getVfsImpl(), JBoss6VFS.class);
139141

140142
// properties explicitly set differently than the defaults in the config xml
141143
assertFalse(factory.getConfiguration().isCacheEnabled());

src/test/java/org/mybatis/spring/annotation/MapperScanTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ public static class AppConfigWithCustomMapperFactoryBean {
290290

291291
public static class BeanNameGenerator implements org.springframework.beans.factory.support.BeanNameGenerator {
292292

293+
@Override
293294
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry definitionRegistry) {
294295
return beanDefinition.getBeanClassName();
295296
}

src/test/java/org/mybatis/spring/asyncsynchronization/AsyncAfterCompletionHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static class AsynchAfterCompletionInvocationHandler implements
4848
this.target = target;
4949
}
5050

51+
@Override
5152
public Object invoke(final Object proxy, final Method method,
5253
final Object[] args) throws Throwable {
5354
if ("afterCompletion".equals(method.getName())) {

src/test/java/org/mybatis/spring/config/NamespaceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ private void assertBeanNotLoaded(String name) {
211211

212212
public static class BeanNameGenerator implements org.springframework.beans.factory.support.BeanNameGenerator {
213213

214+
@Override
214215
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry definitionRegistry) {
215216
return beanDefinition.getBeanClassName();
216217
}

0 commit comments

Comments
 (0)