Skip to content

Add vfsImpl property in SqlSessionFactoryBean #105

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

Merged
merged 1 commit into from
Feb 2, 2016
Merged
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
28 changes: 22 additions & 6 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 @@ -425,15 +437,19 @@ 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 (this.vfs != null) {
configuration.setVfsImpl(this.vfs);
}

if (xmlConfigBuilder != null) {
try {
xmlConfigBuilder.parse();
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
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