Browse Source

优化动态数据源,取消sqlexecutor.exec 事务。

zhouhao 8 years ago
parent
commit
4a0043e45a

+ 2 - 0
hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceAutoConfiguration.java

@@ -59,6 +59,7 @@ public class DynamicDataSourceAutoConfiguration {
         dataSourceBean.getXaProperties().putAll(properties.getXa().getProperties());
         dataSourceBean.setXaDataSourceClassName(properties.getXa().getDataSourceClassName());
         dataSourceBean.setUniqueResourceName("core");
+        dataSourceBean.setMinPoolSize(StringUtils.toInt(properties.getXa().getProperties().get("minPoolSize"), 5));
         dataSourceBean.setMaxPoolSize(StringUtils.toInt(properties.getXa().getProperties().get("maxPoolSize"), 200));
         dataSourceBean.setTestQuery(properties.getXa().getProperties().get("validationQuery"));
         dataSourceBean.setBorrowConnectionTimeout(60);
@@ -107,6 +108,7 @@ public class DynamicDataSourceAutoConfiguration {
     }
 
     @Bean(name = "sqlExecutor")
+    @ConditionalOnMissingBean(DynamicDataSourceSqlExecutorService.class)
     public DynamicDataSourceSqlExecutorService sqlExecutor() {
         return new DynamicDataSourceSqlExecutorService();
     }

+ 7 - 0
hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceSqlExecutorService.java

@@ -23,6 +23,7 @@ import org.hsweb.ezorm.meta.expand.SimpleMapWrapper;
 import org.hsweb.ezorm.render.support.simple.SimpleSQL;
 import org.hsweb.web.core.datasource.DynamicDataSource;
 import org.springframework.jdbc.datasource.DataSourceUtils;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
@@ -97,6 +98,12 @@ public class DynamicDataSourceSqlExecutorService extends AbstractJdbcSqlExecutor
         return data;
     }
 
+    @Override
+    @Transactional(propagation = Propagation.NOT_SUPPORTED)
+    public void exec(SQL sql) throws SQLException {
+        super.exec(sql);
+    }
+
     public SQL create(String sql) {
         return new SimpleSQL(sql);
     }

+ 1 - 0
hsweb-web-service/hsweb-web-service-simple/src/main/java/org/hsweb/web/service/impl/form/DynamicFormServiceImpl.java

@@ -33,6 +33,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;