Skip to content

Spring boot war vfs issue #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: java
sudo: false
jdk:
- oraclejdk8
- oraclejdk7
Expand Down
30 changes: 16 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
<parent>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-parent</artifactId>
<version>24</version>
<version>26</version>
<relativePath />
</parent>

<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
<version>1.2.4</version>
<packaging>jar</packaging>

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

<contributors>
Expand Down Expand Up @@ -78,7 +79,7 @@
<url>http://github.com/mybatis/spring</url>
<connection>scm:git:ssh://github.com/mybatis/spring.git</connection>
<developerConnection>scm:git:ssh://[email protected]/mybatis/spring.git</developerConnection>
<tag>mybatis-spring-1.2.3</tag>
<tag>mybatis-spring-1.2.4</tag>
</scm>
<issueManagement>
<system>GitHub Issue Management</system>
Expand All @@ -90,8 +91,9 @@
</ciManagement>
<distributionManagement>
<site>
<id>github</id>
<url>gitsite:[email protected]/mybatis/spring.git</url>
<id>gh-pages</id>
<name>Mybatis GitHub Pages</name>
<url>git:ssh://[email protected]/mybatis/spring.git?gh-pages#</url>
</site>
</distributionManagement>

Expand All @@ -101,15 +103,15 @@
<gcu.product>Spring</gcu.product>
<osgi.import>org.springframework.batch.*;resolution:=optional,*</osgi.import>
<osgi.dynamicImport>*</osgi.dynamicImport>
<spring.version>3.2.13.RELEASE</spring.version>
<spring.version>4.2.4.RELEASE</spring.version>
</properties>

<dependencies>
<!-- Compile dependencies -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<scope>provided</scope>
</dependency>

Expand All @@ -129,7 +131,7 @@
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-infrastructure</artifactId>
<version>3.0.4.RELEASE</version>
<version>3.0.6.RELEASE</version>
<scope>provided</scope>
</dependency>

Expand All @@ -145,21 +147,21 @@
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.11.1.1</version>
<version>10.12.1.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>3.0.11</version>
<version>3.1.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.1</version>
<version>3.2.0</version>
<scope>test</scope>
</dependency>

Expand All @@ -173,7 +175,7 @@
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-bmunit</artifactId>
<version>3.0.1</version>
<version>3.0.3</version>
<scope>test</scope>
</dependency>

Expand All @@ -187,7 +189,7 @@
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>test</scope>
</dependency>

Expand Down
41 changes: 29 additions & 12 deletions src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.ibatis.builder.xml.XMLConfigBuilder;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.executor.ErrorContext;
import org.apache.ibatis.io.VFS;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.mapping.DatabaseIdProvider;
Expand Down Expand Up @@ -64,7 +65,8 @@
* @author Putthibong Boonbong
* @author Hunter Presnall
* @author Eduardo Macarron
*
* @author Eddú Meléndez
*
* @see #setConfigLocation
* @see #setDataSource
* @version $Id$
Expand Down Expand Up @@ -107,13 +109,15 @@ public class SqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, In
//issue #19. No default provider.
private DatabaseIdProvider databaseIdProvider;

private Class<? extends VFS> vfs;

private ObjectFactory objectFactory;

private ObjectWrapperFactory objectWrapperFactory;

/**
* Sets the ObjectFactory.
*
*
* @since 1.1.2
* @param objectFactory
*/
Expand All @@ -123,7 +127,7 @@ public void setObjectFactory(ObjectFactory objectFactory) {

/**
* Sets the ObjectWrapperFactory.
*
*
* @since 1.1.2
* @param objectWrapperFactory
*/
Expand All @@ -143,7 +147,7 @@ public DatabaseIdProvider getDatabaseIdProvider() {

/**
* Sets the DatabaseIdProvider.
* As of version 1.2.2 this variable is not initialized by default.
* As of version 1.2.2 this variable is not initialized by default.
*
* @since 1.1.0
* @param databaseIdProvider
Expand All @@ -152,6 +156,14 @@ public void setDatabaseIdProvider(DatabaseIdProvider databaseIdProvider) {
this.databaseIdProvider = databaseIdProvider;
}

public Class<? extends VFS> getVfs() {
return this.vfs;
}

public void setVfs(Class<? extends VFS> vfs) {
this.vfs = vfs;
}

/**
* Mybatis plugin list.
*
Expand Down Expand Up @@ -376,6 +388,10 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
configuration.setObjectWrapperFactory(this.objectWrapperFactory);
}

if (this.vfs != null) {
configuration.setVfsImpl(this.vfs);
}

if (hasLength(this.typeAliasesPackage)) {
String[] typeAliasPackageArray = tokenizeToStringArray(this.typeAliasesPackage,
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
Expand Down Expand Up @@ -426,6 +442,15 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
}
}

if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls
try {
configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
} catch (SQLException e) {
throw new NestedIOException("Failed getting a databaseId", e);
}
}


if (xmlConfigBuilder != null) {
try {
xmlConfigBuilder.parse();
Expand All @@ -446,14 +471,6 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {

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

if (this.databaseIdProvider != null) {
try {
configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
} catch (SQLException e) {
throw new NestedIOException("Failed getting a databaseId", e);
}
}

if (!isEmpty(this.mapperLocations)) {
for (Resource mapperLocation : this.mapperLocations) {
if (mapperLocation == null) {
Expand Down
36 changes: 29 additions & 7 deletions src/main/java/org/mybatis/spring/SqlSessionTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.dao.support.PersistenceExceptionTranslator;

/**
Expand Down Expand Up @@ -68,12 +69,12 @@
* @author Putthibong Boonbong
* @author Hunter Presnall
* @author Eduardo Macarron
*
*
* @see SqlSessionFactory
* @see MyBatisExceptionTranslator
* @version $Id$
*/
public class SqlSessionTemplate implements SqlSession {
public class SqlSessionTemplate implements SqlSession, DisposableBean {

private final SqlSessionFactory sqlSessionFactory;

Expand Down Expand Up @@ -370,11 +371,32 @@ public List<BatchResult> flushStatements() {
}

/**
* Proxy needed to route MyBatis method calls to the proper SqlSession got
* from Spring's Transaction Manager
* It also unwraps exceptions thrown by {@code Method#invoke(Object, Object...)} to
* pass a {@code PersistenceException} to the {@code PersistenceExceptionTranslator}.
*/
* Allow gently dispose bean:
* <pre>
* {@code
*
* <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
* <constructor-arg index="0" ref="sqlSessionFactory" />
* </bean>
* }
*</pre>
*
* The implementation of {@link DisposableBean} forces spring context to use {@link DisposableBean#destroy()} method instead of {@link SqlSessionTemplate#close()} to shutdown gently.
*
* @see SqlSessionTemplate#close()
* @see org.springframework.beans.factory.support.DisposableBeanAdapter#inferDestroyMethodIfNecessary
* @see org.springframework.beans.factory.support.DisposableBeanAdapter#CLOSE_METHOD_NAME
*/
@Override
public void destroy() throws Exception {
}

/**
* Proxy needed to route MyBatis method calls to the proper SqlSession got
* from Spring's Transaction Manager
* It also unwraps exceptions thrown by {@code Method#invoke(Object, Object...)} to
* pass a {@code PersistenceException} to the {@code PersistenceExceptionTranslator}.
*/
private class SqlSessionInterceptor implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {

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

definition.getPropertyValues().add("addToConfig", this.addToConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ public class MapperFactoryBean<T> extends SqlSessionDaoSupport implements Factor

private boolean addToConfig = true;


public MapperFactoryBean() {
}

public MapperFactoryBean(Class<T> mapperInterface) {
this.mapperInterface = mapperInterface;
}

public MapperFactoryBean() {
}

/**
* {@inheritDoc}
*/
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/mybatis/spring/ExecutorInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ final class ExecutorInterceptor implements Interceptor {

private boolean closed;

@Override
public Object intercept(Invocation invocation) throws Throwable {
if ("commit".equals(invocation.getMethod().getName())) {
++this.commitCount;
Expand All @@ -58,10 +59,12 @@ public Object intercept(Invocation invocation) throws Throwable {
return invocation.proceed();
}

@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}

@Override
public void setProperties(Properties properties) {
// do nothing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;

import org.apache.ibatis.io.JBoss6VFS;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
Expand Down Expand Up @@ -136,6 +137,7 @@ public void testSetConfigLocation() throws Exception {
assertSame(factory.getConfiguration().getEnvironment().getDataSource(), dataSource);
assertSame(factory.getConfiguration().getEnvironment().getTransactionFactory().getClass(),
org.mybatis.spring.transaction.SpringManagedTransactionFactory.class);
assertSame(factory.getConfiguration().getVfsImpl(), JBoss6VFS.class);

// properties explicitly set differently than the defaults in the config xml
assertFalse(factory.getConfiguration().isCacheEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public static class AppConfigWithCustomMapperFactoryBean {

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

@Override
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry definitionRegistry) {
return beanDefinition.getBeanClassName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static class AsynchAfterCompletionInvocationHandler implements
this.target = target;
}

@Override
public Object invoke(final Object proxy, final Method method,
final Object[] args) throws Throwable {
if ("afterCompletion".equals(method.getName())) {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/mybatis/spring/config/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private void assertBeanNotLoaded(String name) {

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

@Override
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry definitionRegistry) {
return beanDefinition.getBeanClassName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
// implementation of MapperInterface to test conflicting types
final class MapperImplementation implements MapperInterface {
@Override
public void method() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private void assertBeanNotLoaded(String name) {

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

@Override
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry definitionRegistry) {
return beanDefinition.getBeanClassName();
}
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/mybatis/spring/mybatis-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<setting name="cacheEnabled" value="false" />
<setting name="useGeneratedKeys" value="true" />
<setting name="defaultExecutorType" value="REUSE" />
<setting name="vfsImpl" value="org.apache.ibatis.io.JBoss6VFS"/>
</settings>

<mappers>
Expand Down
Loading