Bläddra i källkod

删除无用代码。

zhouhao 8 år sedan
förälder
incheckning
983f60002d

+ 1 - 1
README.md

@@ -33,7 +33,7 @@
 3. 演示项目源码:[hsweb-platform](https://github.com/hs-web/hsweb-platform)
 
 # 许可
-[apache2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
+[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0.html)
 
 # 加入hsweb
 <a target="_blank" href="http://shang.qq.com/wpa/qunwpa?idkey=3d66b5dd14991d7645af694e7649b373f3a9ce1216131094c78cb2348d542c41">

+ 0 - 7
hsweb-web-controller/src/main/java/org/hsweb/web/controller/datasource/DataSourceController.java

@@ -16,7 +16,6 @@
 
 package org.hsweb.web.controller.datasource;
 
-import org.hsweb.web.bean.common.QueryParam;
 import org.hsweb.web.bean.po.datasource.DataSource;
 import org.hsweb.web.controller.GenericController;
 import org.hsweb.web.core.authorize.annotation.Authorize;
@@ -64,10 +63,4 @@ public class DataSourceController extends GenericController<DataSource, String>
         return ResponseMessage.ok();
     }
 
-    @RequestMapping(value = "/test/{id}", method = RequestMethod.GET)
-    @Authorize(action = "R")
-    @AccessLogger("测试连接")
-    public ResponseMessage testConnection(@PathVariable("id") String id) {
-        return ResponseMessage.ok(dataSourceService.testConnection(id));
-    }
 }

+ 8 - 5
hsweb-web-core/src/main/java/org/hsweb/web/core/authorize/validator/SimpleAuthorizeValidator.java

@@ -1,16 +1,18 @@
 package org.hsweb.web.core.authorize.validator;
 
+import org.hsweb.commons.StringUtils;
+import org.hsweb.expands.script.engine.DynamicScriptEngine;
+import org.hsweb.expands.script.engine.DynamicScriptEngineFactory;
+import org.hsweb.web.bean.po.user.User;
 import org.hsweb.web.core.authorize.AuthorizeValidator;
 import org.hsweb.web.core.authorize.AuthorizeValidatorConfig;
 import org.hsweb.web.core.authorize.ExpressionScopeBean;
 import org.hsweb.web.core.authorize.annotation.Authorize;
-import org.hsweb.web.bean.po.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.hsweb.commons.StringUtils;
-import org.hsweb.expands.script.engine.DynamicScriptEngine;
-import org.hsweb.expands.script.engine.DynamicScriptEngineFactory;
 
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * 权限验证器
@@ -62,6 +64,7 @@ public class SimpleAuthorizeValidator implements AuthorizeValidator {
                     return StringUtils.isTrue(engine.execute(expression.getId(), var).getResult());
                 });
         }
+
         return access;
     }
 

+ 1 - 1
hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSource.java

@@ -53,5 +53,5 @@ public interface DynamicDataSource extends DataSource {
         useDefault(true);
     }
 
-    CommonDataSource getActiveDataSource();
+    DataSource getActiveDataSource();
 }

+ 11 - 1
hsweb-web-service-impl-common/pom.xml

@@ -13,6 +13,11 @@
     <dependencies>
 
         <!--test-->
+        <dependency>
+            <groupId>org.hsweb</groupId>
+            <artifactId>hsweb-web-datasource</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>javax.el</groupId>
             <artifactId>el-api</artifactId>
@@ -41,10 +46,15 @@
             <artifactId>h2</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>druid</artifactId>
-            <version>1.0.5</version>
+            <version>1.0.25</version>
             <scope>test</scope>
         </dependency>
 

+ 0 - 52
hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/DynamicDataSourceAutoConfiguration.java

@@ -1,52 +0,0 @@
-/*
- * Copyright 2015-2016 http://hsweb.me
- *
- * 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 org.hsweb.web.service.impl;
-
-import org.hsweb.web.service.impl.datasource.DynamicDataSourceImpl;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
-import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import javax.sql.DataSource;
-
-/**
- * Created by zhouhao on 16-4-20.
- */
-@Configuration
-public class DynamicDataSourceAutoConfiguration {
-
-    @Autowired
-    private DataSourceProperties properties;
-
-    @Bean
-    @ConfigurationProperties(prefix = DataSourceProperties.PREFIX)
-    public DataSource dataSource() {
-        DataSourceBuilder factory = DataSourceBuilder
-                .create(this.properties.getClassLoader())
-                .driverClassName(this.properties.getDriverClassName())
-                .url(this.properties.getUrl()).username(this.properties.getUsername())
-                .password(this.properties.getPassword());
-        if (this.properties.getType() != null) {
-            factory.type(this.properties.getType());
-        }
-        return new DynamicDataSourceImpl(factory.build());
-    }
-
-}

+ 0 - 35
hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/datasource/DataSourceServiceImpl.java

@@ -66,18 +66,6 @@ public class DataSourceServiceImpl extends AbstractServiceImpl<DataSource, Strin
         return this.dataSourceMapper;
     }
 
-    @Override
-    public javax.sql.DataSource createDataSource(String id) {
-        DataSource dataSource = selectByPk(id);
-        DataSourceBuilder builder = DataSourceBuilder.create()
-                .driverClassName(dataSource.getDriver())
-                .url(dataSource.getUrl())
-                .username(dataSource.getUsername())
-                .password(dataSource.getPassword())
-                .type(properties.getType());
-        return builder.build();
-    }
-
     @Override
     @Cacheable(value = CACHE_NAME, key = "'id:'+#id")
     @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
@@ -130,27 +118,4 @@ public class DataSourceServiceImpl extends AbstractServiceImpl<DataSource, Strin
         return super.delete(id);
     }
 
-    @Override
-    public boolean testConnection(String id) {
-        DataSource old = selectByPk(id);
-        assertNotNull(old, "数据源不存在");
-        javax.sql.DataSource dataSource = createDataSource(id);
-        AbstractJdbcSqlExecutor sqlExecutor = new AbstractJdbcSqlExecutor() {
-            @Override
-            public Connection getConnection() {
-                return DataSourceUtils.getConnection(dataSource);
-            }
-
-            @Override
-            public void releaseConnection(Connection connection) throws SQLException {
-                DataSourceUtils.releaseConnection(connection, dataSource);
-            }
-        };
-        try {
-            sqlExecutor.exec(new SimpleSQL(old.getTestSql()));
-            return true;
-        } catch (SQLException e) {
-            return false;
-        }
-    }
 }

+ 4 - 1
hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/form/DynamicFormServiceImpl.java

@@ -41,7 +41,6 @@ import java.io.OutputStream;
 import java.sql.JDBCType;
 import java.sql.SQLException;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * Created by zhouhao on 16-4-14.
@@ -455,4 +454,8 @@ public class DynamicFormServiceImpl implements DynamicFormService, ExpressionSco
         return result;
     }
 
+
+    public static void main(String[] args) {
+        Arrays.asList(1,2,3).forEach(System.out::println);
+    }
 }

+ 0 - 10
hsweb-web-service-interface/src/main/java/org/hsweb/web/service/datasource/DataSourceService.java

@@ -25,18 +25,8 @@ import org.hsweb.web.service.GenericService;
  */
 public interface DataSourceService extends GenericService<DataSource, String> {
 
-    /**
-     * 根据数据源ID,创建数据源实例
-     *
-     * @param id 数据源ID
-     * @return 数据源实例
-     */
-    javax.sql.DataSource createDataSource(String id);
-
     void enable(String id);
 
     void disable(String id);
 
-    boolean testConnection(String id);
-
 }

+ 1 - 5
hsweb-web-service-interface/src/main/java/org/hsweb/web/service/datasource/DynamicDataSourceService.java

@@ -16,10 +16,7 @@
 
 package org.hsweb.web.service.datasource;
 
-import org.hsweb.ezorm.executor.SqlExecutor;
-
 import javax.sql.DataSource;
-import javax.sql.XADataSource;
 
 /**
  * @author zhouhao
@@ -28,7 +25,6 @@ public interface DynamicDataSourceService {
 
     DataSource getDataSource(String id);
 
-    SqlExecutor getSqlExecutor(String id);
+    void destroyAll()throws Exception;
 
-    Object getTransactionManager(String id);
 }

+ 7 - 1
pom.xml

@@ -20,6 +20,7 @@
         <module>hsweb-web-concurrent</module>
         <module>hsweb-web-crawler</module>
         <module>hsweb-web-oauth2</module>
+        <module>hsweb-web-datasource</module>
     </modules>
 
     <properties>
@@ -37,7 +38,7 @@
         <fastjson.version>1.2.6</fastjson.version>
 
         <h2.version>1.4.191</h2.version>
-        <mysql.version>5.1.38</mysql.version>
+        <mysql.version>5.1.39</mysql.version>
         <cglib.version>3.2.2</cglib.version>
         <aspectj.version>1.6.12</aspectj.version>
         <hibernate.validator.version>5.1.1.Final</hibernate.validator.version>
@@ -158,6 +159,11 @@
                 <version>1.0.2</version>
             </dependency>
 
+            <dependency>
+                <groupId>org.hsweb</groupId>
+                <artifactId>hsweb-web-datasource</artifactId>
+                <version>${project.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.hsweb</groupId>
                 <artifactId>hsweb-web-oauth2-core</artifactId>