From 3f2e656c35936a6cb0f6b22d9b1fc79ca6d182f5 Mon Sep 17 00:00:00 2001 From: zhouhao Date: Sun, 16 Oct 2016 20:00:01 +0800 Subject: [PATCH] 2.1-SNAPSHOT --- hsweb-web-bean/README.md | 17 ++ hsweb-web-bean/pom.xml | 2 +- .../web/bean/po/system/SystemVersion.java | 115 ++++++++ .../hsweb/web/bean/po/template/Template.java | 3 - .../hsweb-web-concurrent-cache/pom.xml | 2 +- .../hsweb-web-concurrent-lock/pom.xml | 2 +- hsweb-web-concurrent/pom.xml | 2 +- hsweb-web-controller/pom.xml | 2 +- hsweb-web-core/pom.xml | 2 +- .../main/java/org/hsweb/web/core/Install.java | 4 +- .../web/core/datasource/DataSourceHolder.java | 91 ++++++ .../web/core/datasource/DatabaseType.java | 65 +++++ .../core/datasource/DynamicDataSource.java | 6 +- .../datasource/DynamicDataSourceHolder.java | 39 --- hsweb-web-dao/hsweb-web-dao-api/pom.xml | 2 +- hsweb-web-dao/hsweb-web-dao-mybatis/README.md | 2 +- hsweb-web-dao/hsweb-web-dao-mybatis/pom.xml | 2 +- ...ion.java => MyBatisAutoConfiguration.java} | 39 ++- .../mybatis/MybatisDaoAutoConfiguration.java | 5 + .../hsweb/web/mybatis/MybatisProperties.java | 101 +++++++ .../hsweb/web/mybatis/builder/SqlBuilder.java | 43 +++ ...micDataSourceSqlSessionFactoryBuilder.java | 2 +- .../dynamic/DynamicSqlSessionFactory.java | 4 +- .../mapper/{oracle => }/basic/BasicMapper.xml | 10 +- .../classified/ClassifiedMapper.xml | 0 .../{mysql => }/config/ConfigMapper.xml | 0 .../datasource/DataSourceMapper.xml | 0 .../mapper/{oracle => }/form/FormMapper.xml | 0 .../{mysql => }/history/HistoryMapper.xml | 0 .../{oracle => }/module/ModuleMapper.xml | 0 .../{mysql => }/module/ModuleMetaMapper.xml | 0 .../mapper/mysql/basic/BasicMapper.xml | 74 ----- .../mapper/mysql/basic/BasicMapper.xml.old | 214 -------------- .../mybatis/mapper/mysql/form/FormMapper.xml | 93 ------- .../mapper/mysql/module/ModuleMapper.xml | 53 ---- .../mybatis/mapper/mysql/user/UserMapper.xml | 62 ----- .../mapper/oracle/basic/BasicMapper.xml.old | 245 ---------------- .../oracle/classified/ClassifiedMapper.xml | 52 ---- .../mapper/oracle/config/ConfigMapper.xml | 49 ---- .../oracle/datasource/DataSourceMapper.xml | 52 ---- .../mapper/oracle/history/HistoryMapper.xml | 53 ---- .../mapper/oracle/module/ModuleMetaMapper.xml | 51 ---- .../mapper/oracle/plan/QueryPlanMapper.xml | 65 ----- .../oracle/profile/UserProfileMapper.xml | 48 ---- .../oracle/quartz/QuartzJobHistoryMapper.xml | 63 ----- .../mapper/oracle/quartz/QuartzJobMapper.xml | 67 ----- .../oracle/resource/ResourcesMapper.xml | 53 ---- .../mybatis/mapper/oracle/role/RoleMapper.xml | 48 ---- .../mapper/oracle/role/RoleModuleMapper.xml | 62 ----- .../mapper/oracle/role/UserRoleMapper.xml | 57 ---- .../oracle/script/DynamicScriptMapper.xml | 52 ---- .../mapper/oracle/template/TemplateMapper.xml | 97 ------- .../{mysql => }/plan/QueryPlanMapper.xml | 0 .../{mysql => }/profile/UserProfileMapper.xml | 0 .../quartz/QuartzJobHistoryMapper.xml | 0 .../{mysql => }/quartz/QuartzJobMapper.xml | 0 .../{mysql => }/resource/ResourcesMapper.xml | 0 .../mapper/{mysql => }/role/RoleMapper.xml | 0 .../{mysql => }/role/RoleModuleMapper.xml | 0 .../{mysql => }/role/UserRoleMapper.xml | 0 .../script/DynamicScriptMapper.xml | 0 .../{mysql => }/template/TemplateMapper.xml | 0 .../mapper/{oracle => }/user/UserMapper.xml | 0 hsweb-web-dao/pom.xml | 2 +- hsweb-web-datasource/pom.xml | 2 +- .../DynamicDataSourceAutoConfiguration.java | 19 +- .../dynamic/DynamicDataSourceProperties.java | 262 ++++++++++++++++++ .../dynamic/DynamicDataSourceServiceImpl.java | 74 +++-- .../dynamic/DynamicXaDataSourceImpl.java | 30 +- .../spring-configuration-metadata.json | 35 +++ .../hsweb-web-oauth2-controller/pom.xml | 2 +- .../hsweb-web-oauth2-core/pom.xml | 2 +- .../hsweb-web-oauth2-mybatis/pom.xml | 2 +- .../hsweb-web-oauth2-service-simple/pom.xml | 2 +- .../hsweb-web-oauth2-simple/pom.xml | 2 +- hsweb-web-oauth2/pom.xml | 2 +- .../hsweb-web-service-api/pom.xml | 2 +- .../datasource/DynamicDataSourceService.java | 4 +- .../hsweb-web-service-simple/pom.xml | 18 +- .../impl/datasource/DatasourceTests.java | 9 +- .../hsweb/web/service/impl/lock/LockTest.java | 34 --- .../template/TemplateServiceImplTest.java | 71 +---- .../src/test/resources/application.yml | 52 +--- hsweb-web-service/pom.xml | 2 +- hsweb-web-websocket/pom.xml | 2 +- hsweb-web-workflow/pom.xml | 2 +- pom.xml | 7 +- 87 files changed, 921 insertions(+), 1890 deletions(-) create mode 100644 hsweb-web-bean/README.md create mode 100644 hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/system/SystemVersion.java create mode 100644 hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DataSourceHolder.java create mode 100644 hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DatabaseType.java delete mode 100644 hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSourceHolder.java rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/{dynamic/DynamicDataSourceMyBatisAutoConfiguration.java => MyBatisAutoConfiguration.java} (68%) create mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MybatisProperties.java create mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/builder/SqlBuilder.java rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{oracle => }/basic/BasicMapper.xml (74%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/classified/ClassifiedMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/config/ConfigMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/datasource/DataSourceMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{oracle => }/form/FormMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/history/HistoryMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{oracle => }/module/ModuleMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/module/ModuleMetaMapper.xml (100%) delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/basic/BasicMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/basic/BasicMapper.xml.old delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/form/FormMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/module/ModuleMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/user/UserMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/basic/BasicMapper.xml.old delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/classified/ClassifiedMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/config/ConfigMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/datasource/DataSourceMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/history/HistoryMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/module/ModuleMetaMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/plan/QueryPlanMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/profile/UserProfileMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/quartz/QuartzJobHistoryMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/quartz/QuartzJobMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/resource/ResourcesMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/RoleMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/RoleModuleMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/UserRoleMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/script/DynamicScriptMapper.xml delete mode 100644 hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/template/TemplateMapper.xml rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/plan/QueryPlanMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/profile/UserProfileMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/quartz/QuartzJobHistoryMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/quartz/QuartzJobMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/resource/ResourcesMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/role/RoleMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/role/RoleModuleMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/role/UserRoleMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/script/DynamicScriptMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{mysql => }/template/TemplateMapper.xml (100%) rename hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/{oracle => }/user/UserMapper.xml (100%) create mode 100644 hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceProperties.java create mode 100644 hsweb-web-datasource/src/main/resources/META-INF/spring-configuration-metadata.json diff --git a/hsweb-web-bean/README.md b/hsweb-web-bean/README.md new file mode 100644 index 000000000..09454fb74 --- /dev/null +++ b/hsweb-web-bean/README.md @@ -0,0 +1,17 @@ +## 实体类模块,通用bean,po,和自定义验证器 + +### 目录结构 + +```bash +--------src/main/java +---------------------org.hsweb.web.bean +----------------------------common # 通用bean,如增删改查通用参数 +------------------------------po # 各个功能的po实体 +----------------------------validator # 自定义hibernate-validator +-----------------resources/system +---------------------------------install.sql #首次启动时执行的sql +``` + +### 说明 +po对象都应该继承[GenericPo](src/main/java/org/hsweb/web/bean/po/GenericPo.java) +GenericPo 的泛型为主键的类型,hsweb建议使用String类型,通过createUID()方法手动生成id diff --git a/hsweb-web-bean/pom.xml b/hsweb-web-bean/pom.xml index 079088b78..70b106014 100644 --- a/hsweb-web-bean/pom.xml +++ b/hsweb-web-bean/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 hsweb-web-bean diff --git a/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/system/SystemVersion.java b/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/system/SystemVersion.java new file mode 100644 index 000000000..6414767ab --- /dev/null +++ b/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/system/SystemVersion.java @@ -0,0 +1,115 @@ +/* + * 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.bean.po.system; + +public class SystemVersion implements Comparable { + public String name; + public String comment; + public String website; + public int majorVersion = 1; + public int minorVersion = 0; + public int revisionVersion = 0; + public boolean snapshot; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getWebsite() { + return website; + } + + public void setWebsite(String website) { + this.website = website; + } + + public int getMajorVersion() { + return majorVersion; + } + + public void setMajorVersion(int majorVersion) { + this.majorVersion = majorVersion; + } + + public int getMinorVersion() { + return minorVersion; + } + + public void setMinorVersion(int minorVersion) { + this.minorVersion = minorVersion; + } + + public int getRevisionVersion() { + return revisionVersion; + } + + public void setRevisionVersion(int revisionVersion) { + this.revisionVersion = revisionVersion; + } + + public boolean isSnapshot() { + return snapshot; + } + + public void setSnapshot(boolean snapshot) { + this.snapshot = snapshot; + } + + @Override + public int compareTo(SystemVersion o) { + if (null == o) return -1; + if (o.getMajorVersion() > this.getMajorVersion()) return -1; + if (o.getMajorVersion() == this.getMajorVersion()) { + if (o.getMinorVersion() > this.getMinorVersion()) return -1; + if (o.getMinorVersion() == this.getMinorVersion()) { + if (o.getRevisionVersion() > this.getRevisionVersion()) return -1; + if (o.getRevisionVersion() == this.getRevisionVersion()) return 0; + return 1; + } else { + return 1; + } + } else { + return 1; + } + } + + public static void main(String[] args) { + SystemVersion systemVersion = new SystemVersion(); + systemVersion.setMajorVersion(2); + systemVersion.setMinorVersion(2); + systemVersion.setRevisionVersion(1); + + SystemVersion systemVersion2 = new SystemVersion(); + systemVersion2.setMajorVersion(3); + systemVersion2.setMinorVersion(2); + systemVersion2.setRevisionVersion(1); + + System.out.println(systemVersion.compareTo(systemVersion2)); + } +} diff --git a/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/template/Template.java b/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/template/Template.java index 7b8b4bf10..ce34a27c4 100644 --- a/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/template/Template.java +++ b/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/template/Template.java @@ -4,9 +4,6 @@ import org.hsweb.web.bean.po.GenericPo; import java.util.List; -/** - * Created by zhouhao on 16-5-19. - */ public class Template extends GenericPo { private String name; diff --git a/hsweb-web-concurrent/hsweb-web-concurrent-cache/pom.xml b/hsweb-web-concurrent/hsweb-web-concurrent-cache/pom.xml index 44cf187d9..9d3f24090 100644 --- a/hsweb-web-concurrent/hsweb-web-concurrent-cache/pom.xml +++ b/hsweb-web-concurrent/hsweb-web-concurrent-cache/pom.xml @@ -5,7 +5,7 @@ hsweb-web-concurrent org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 hsweb-web-concurrent-cache diff --git a/hsweb-web-concurrent/hsweb-web-concurrent-lock/pom.xml b/hsweb-web-concurrent/hsweb-web-concurrent-lock/pom.xml index f2d5e9c89..e05658f71 100644 --- a/hsweb-web-concurrent/hsweb-web-concurrent-lock/pom.xml +++ b/hsweb-web-concurrent/hsweb-web-concurrent-lock/pom.xml @@ -5,7 +5,7 @@ hsweb-web-concurrent org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 hsweb-web-concurrent-lock diff --git a/hsweb-web-concurrent/pom.xml b/hsweb-web-concurrent/pom.xml index fd55f044c..0feaa50b6 100644 --- a/hsweb-web-concurrent/pom.xml +++ b/hsweb-web-concurrent/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 pom diff --git a/hsweb-web-controller/pom.xml b/hsweb-web-controller/pom.xml index ed53dcbcf..6240ffc33 100644 --- a/hsweb-web-controller/pom.xml +++ b/hsweb-web-controller/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 hsweb-web-controller diff --git a/hsweb-web-core/pom.xml b/hsweb-web-core/pom.xml index df01e2712..b0332cf6a 100644 --- a/hsweb-web-core/pom.xml +++ b/hsweb-web-core/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 hsweb-web-core diff --git a/hsweb-web-core/src/main/java/org/hsweb/web/core/Install.java b/hsweb-web-core/src/main/java/org/hsweb/web/core/Install.java index 416aed15a..b1e04966b 100644 --- a/hsweb-web-core/src/main/java/org/hsweb/web/core/Install.java +++ b/hsweb-web-core/src/main/java/org/hsweb/web/core/Install.java @@ -19,13 +19,11 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.util.Assert; import javax.annotation.PostConstruct; +import javax.sql.DataSource; import java.io.*; import java.util.ArrayList; import java.util.List; -/** - * Created by zhouhao on 16-4-23. - */ @Configuration @EnableConfigurationProperties({DataSourceProperties.class}) @AutoConfigureAfter({DataSourceAutoConfiguration.class}) diff --git a/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DataSourceHolder.java b/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DataSourceHolder.java new file mode 100644 index 000000000..10ae88389 --- /dev/null +++ b/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DataSourceHolder.java @@ -0,0 +1,91 @@ +/* + * 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.core.datasource; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + +@Component +public class DataSourceHolder { + + private static DynamicDataSource dynamicDataSource; + + private static DataSource defaultDataSource; + + private static DatabaseType defaultDatabaseType; + + @Autowired(required = false) + private DataSource dataSource; + + @PostConstruct + public void init() throws SQLException { + if (null != dataSource) { + Connection connection = null; + try { + connection = dataSource.getConnection(); + install(dataSource, DatabaseType.fromJdbcUrl(connection.getMetaData().getURL())); + dataSource = null; + } finally { + if (null != connection) + connection.close(); + } + } + } + + public static DataSource getActiveSource() { + if (dynamicDataSource != null) { + return dynamicDataSource.getActiveDataSource(); + } + return defaultDataSource; + } + + public static DatabaseType getActiveDatabaseType() { + if (dynamicDataSource != null) { + return dynamicDataSource.getActiveDataBaseType(); + } + return defaultDatabaseType; + } + + public static DataSource getDefaultDataSource() { + return defaultDataSource; + } + + public static DatabaseType getDefaultDatabaseType() { + return defaultDatabaseType; + } + + public static void install(DynamicDataSource dynamicDataSource) { + if (DataSourceHolder.dynamicDataSource != null) { + throw new UnsupportedOperationException(); + } + DataSourceHolder.dynamicDataSource = dynamicDataSource; + } + + public static void install(DataSource dataSource, DatabaseType databaseType) { + if (DataSourceHolder.defaultDataSource != null) { + throw new UnsupportedOperationException(); + } + DataSourceHolder.defaultDataSource = dataSource; + DataSourceHolder.defaultDatabaseType = databaseType; + } +} diff --git a/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DatabaseType.java b/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DatabaseType.java new file mode 100644 index 000000000..391b49e83 --- /dev/null +++ b/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DatabaseType.java @@ -0,0 +1,65 @@ +/* + * 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.core.datasource; + +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +public enum DatabaseType { + unknown(null, null, null), + mysql("com.mysql.jdbc.Driver", "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource", "select 1"), + h2("org.h2.Driver", "org.h2.jdbcx.JdbcDataSource", "select 1"), + oracle("oracle.jdbc.driver.OracleDriver", "oracle.jdbc.xa.client.OracleXADataSource", "select 1 from dual"); + + DatabaseType(String driverClassName, String xaDataSourceClassName, String testQuery) { + this.driverClassName = driverClassName; + this.testQuery = testQuery; + this.xaDataSourceClassName = xaDataSourceClassName; + } + + private final String testQuery; + + private final String driverClassName; + + private final String xaDataSourceClassName; + + public String getDriverClassName() { + return driverClassName; + } + + public String getXaDataSourceClassName() { + return xaDataSourceClassName; + } + + public String getTestQuery() { + return testQuery; + } + + public static DatabaseType fromJdbcUrl(String url) { + if (StringUtils.hasLength(url)) { + Assert.isTrue(url.startsWith("jdbc"), "URL must start with 'jdbc'"); + String urlWithoutPrefix = url.substring("jdbc".length()).toLowerCase(); + for (DatabaseType driver : values()) { + String prefix = ":" + driver.name().toLowerCase() + ":"; + if (driver != unknown && urlWithoutPrefix.startsWith(prefix)) { + return driver; + } + } + } + return unknown; + } +} \ No newline at end of file diff --git a/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSource.java b/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSource.java index 9f3e99b77..310078e21 100644 --- a/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSource.java +++ b/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSource.java @@ -23,15 +23,11 @@ import org.springframework.transaction.support.TransactionSynchronizationManager import javax.sql.CommonDataSource; import javax.sql.DataSource; -/** - * @author zhouhao - */ public interface DynamicDataSource extends DataSource { String DATA_SOURCE_FLAG = "data-source-id"; String DATA_SOURCE_FLAG_LAST = "data-source-id-last"; - static void useLast() { use(ThreadLocalUtils.get(DATA_SOURCE_FLAG_LAST)); } @@ -55,4 +51,6 @@ public interface DynamicDataSource extends DataSource { } DataSource getActiveDataSource(); + + DatabaseType getActiveDataBaseType(); } diff --git a/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSourceHolder.java b/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSourceHolder.java deleted file mode 100644 index 39e0b1377..000000000 --- a/hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSourceHolder.java +++ /dev/null @@ -1,39 +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.core.datasource; - - -import javax.sql.DataSource; - -public class DynamicDataSourceHolder { - - private static DynamicDataSource dynamicDataSource; - - public static DataSource getActiveSource() { - if (dynamicDataSource != null) { - return dynamicDataSource.getActiveDataSource(); - } - return null; - } - - public static void install(DynamicDataSource dynamicDataSource) { - if (DynamicDataSourceHolder.dynamicDataSource != null) { - throw new UnsupportedOperationException(); - } - DynamicDataSourceHolder.dynamicDataSource = dynamicDataSource; - } -} diff --git a/hsweb-web-dao/hsweb-web-dao-api/pom.xml b/hsweb-web-dao/hsweb-web-dao-api/pom.xml index 361d02451..4e6f4bc21 100644 --- a/hsweb-web-dao/hsweb-web-dao-api/pom.xml +++ b/hsweb-web-dao/hsweb-web-dao-api/pom.xml @@ -5,7 +5,7 @@ hsweb-web-dao org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 hsweb-web-dao-api diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/README.md b/hsweb-web-dao/hsweb-web-dao-mybatis/README.md index 1688a61a6..23830a9e3 100644 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/README.md +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/README.md @@ -10,7 +10,7 @@ org.hsweb hsweb-web-dao-mybatis - 2.0-SNAPSHOT + 2.1-SNAPSHOT ``` diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/pom.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/pom.xml index 68f9250cf..d2b4b955e 100644 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/pom.xml +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/pom.xml @@ -5,7 +5,7 @@ hsweb-web-dao org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 hsweb-web-dao-mybatis diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicDataSourceMyBatisAutoConfiguration.java b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MyBatisAutoConfiguration.java similarity index 68% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicDataSourceMyBatisAutoConfiguration.java rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MyBatisAutoConfiguration.java index 16c5fb9b8..890f7d472 100644 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicDataSourceMyBatisAutoConfiguration.java +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MyBatisAutoConfiguration.java @@ -14,14 +14,16 @@ * limitations under the License. */ -package org.hsweb.web.mybatis.dynamic; +package org.hsweb.web.mybatis; import org.apache.ibatis.mapping.DatabaseIdProvider; import org.apache.ibatis.plugin.Interceptor; import org.apache.ibatis.session.SqlSessionFactory; +import org.hsweb.web.core.datasource.DataSourceHolder; import org.hsweb.web.datasource.dynamic.DynamicDataSourceAutoConfiguration; +import org.hsweb.web.mybatis.MybatisProperties; +import org.hsweb.web.mybatis.dynamic.DynamicDataSourceSqlSessionFactoryBuilder; import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.boot.autoconfigure.MybatisProperties; import org.mybatis.spring.boot.autoconfigure.SpringBootVFS; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -30,16 +32,23 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.util.StringUtils; import javax.sql.DataSource; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; @Configuration @AutoConfigureAfter(DynamicDataSourceAutoConfiguration.class) @EnableConfigurationProperties(MybatisProperties.class) -@ConditionalOnProperty(prefix = "mybatis", value = "dynamic-datasource") -public class DynamicDataSourceMyBatisAutoConfiguration { +public class MyBatisAutoConfiguration { @Autowired private MybatisProperties properties; @@ -51,12 +60,23 @@ public class DynamicDataSourceMyBatisAutoConfiguration { private ResourceLoader resourceLoader = new DefaultResourceLoader(); @Autowired(required = false) - private DatabaseIdProvider databaseIdProvider; + private DatabaseIdProvider databaseIdProvider = new DatabaseIdProvider() { + @Override + public void setProperties(Properties p) { + + } + + @Override + public String getDatabaseId(DataSource dataSource) throws SQLException { + return DataSourceHolder.getActiveDatabaseType().name(); + } + }; @Bean(name = "sqlSessionFactory") public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); - factory.setSqlSessionFactoryBuilder(new DynamicDataSourceSqlSessionFactoryBuilder()); + if (properties.isDynamicDatasource()) + factory.setSqlSessionFactoryBuilder(new DynamicDataSourceSqlSessionFactoryBuilder()); factory.setDataSource(dataSource); factory.setVfs(SpringBootVFS.class); if (StringUtils.hasText(this.properties.getConfig())) { @@ -70,8 +90,13 @@ public class DynamicDataSourceMyBatisAutoConfiguration { factory.setDatabaseIdProvider(this.databaseIdProvider); } factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage()); - factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage()); + String typeHandlers = "org.hsweb.web.mybatis.handler"; + if (this.properties.getTypeHandlersPackage() != null) { + typeHandlers = typeHandlers + ";" + this.properties.getTypeHandlersPackage(); + } + factory.setTypeHandlersPackage(typeHandlers); factory.setMapperLocations(this.properties.resolveMapperLocations()); return factory.getObject(); } + } diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MybatisDaoAutoConfiguration.java b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MybatisDaoAutoConfiguration.java index d9401c1c4..7d538002f 100644 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MybatisDaoAutoConfiguration.java +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MybatisDaoAutoConfiguration.java @@ -1,9 +1,12 @@ package org.hsweb.web.mybatis; +import org.hsweb.web.datasource.dynamic.DynamicDataSourceAutoConfiguration; import org.hsweb.web.mybatis.utils.ResultMapsUtils; import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -12,6 +15,8 @@ import javax.annotation.PostConstruct; @Configuration @ComponentScan(basePackages = {"org.hsweb.web.mybatis"}) @MapperScan(basePackages = {"org.hsweb.web.dao"}) +@AutoConfigureAfter(DynamicDataSourceAutoConfiguration.class) +@EnableConfigurationProperties(MybatisProperties.class) public class MybatisDaoAutoConfiguration { @Autowired diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MybatisProperties.java b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MybatisProperties.java new file mode 100644 index 000000000..00a0ca195 --- /dev/null +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/MybatisProperties.java @@ -0,0 +1,101 @@ +/* + * 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.mybatis; + +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; + +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +public class MybatisProperties extends org.mybatis.spring.boot.autoconfigure.MybatisProperties { + private static final String defaultMapperLocation = "classpath*:org/hsweb/web/dao/impl/mybatis/mapper/**/*.xml"; + private String type = "oracle"; + private boolean dynamicDatasource = false; + private String[] mapperLocationExcludes = null; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String[] getMapperLocationExcludes() { + return mapperLocationExcludes; + } + + public void setMapperLocationExcludes(String[] mapperLocationExcludes) { + this.mapperLocationExcludes = mapperLocationExcludes; + } + + public boolean isDynamicDatasource() { + return dynamicDatasource; + } + + public void setDynamicDatasource(boolean dynamicDatasource) { + this.dynamicDatasource = dynamicDatasource; + } + + @Override + public String[] getMapperLocations() { + return super.getMapperLocations(); + } + + public Resource[] resolveMapperLocations() { + Map resources = new HashMap<>(); + Set locations; + + if (this.getMapperLocations() == null) + locations = new HashSet<>(); + else + locations = Arrays.stream(getMapperLocations()).collect(Collectors.toSet()); + locations.add(defaultMapperLocation); + for (String mapperLocation : locations) { + Resource[] mappers; + try { + mappers = new PathMatchingResourcePatternResolver().getResources(mapperLocation); + for (Resource mapper : mappers) { + resources.put(mapper.getURL().toString(), mapper); + } + } catch (IOException e) { + } + } + if (mapperLocationExcludes != null && mapperLocationExcludes.length > 0) + + { + for (String mapperLocationExclude : mapperLocationExcludes) { + try { + Resource[] excludesMappers = new PathMatchingResourcePatternResolver().getResources(mapperLocationExclude); + for (Resource excludesMapper : excludesMappers) { + resources.remove(excludesMapper.getURL().toString()); + } + } catch (IOException e) { + } + } + } + + Resource[] mapperLocations = new Resource[resources.size()]; + mapperLocations = resources.values(). + + toArray(mapperLocations); + return mapperLocations; + } + +} diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/builder/SqlBuilder.java b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/builder/SqlBuilder.java new file mode 100644 index 000000000..f23f820d4 --- /dev/null +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/builder/SqlBuilder.java @@ -0,0 +1,43 @@ +/* + * 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.mybatis.builder; + +import org.hsweb.web.core.datasource.DataSourceHolder; +import org.hsweb.web.core.datasource.DatabaseType; + +/** + * @author zhouhao + */ +public class SqlBuilder { + private static boolean dynamic; + + public static final Object current() { + DatabaseType type = dynamic + ? DataSourceHolder.getActiveDatabaseType() + : DataSourceHolder.getDefaultDatabaseType(); + switch (type) { + case mysql: + return MysqlParamBuilder.instance(); + default: + return DefaultSqlParamBuilder.instance(); + } + } + + public static void setDynamic(boolean dynamic) { + SqlBuilder.dynamic = dynamic; + } +} diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicDataSourceSqlSessionFactoryBuilder.java b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicDataSourceSqlSessionFactoryBuilder.java index 2c44506ba..4fbc1f396 100644 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicDataSourceSqlSessionFactoryBuilder.java +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicDataSourceSqlSessionFactoryBuilder.java @@ -23,6 +23,6 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder; public class DynamicDataSourceSqlSessionFactoryBuilder extends SqlSessionFactoryBuilder { @Override public SqlSessionFactory build(Configuration config) { - return new DynamicSqlSessionFactory(config); + return new DynamicSqlSessionFactory(config); } } diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicSqlSessionFactory.java b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicSqlSessionFactory.java index bd41b699c..414c26fb2 100644 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicSqlSessionFactory.java +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/dynamic/DynamicSqlSessionFactory.java @@ -25,7 +25,7 @@ import org.apache.ibatis.session.defaults.DefaultSqlSession; import org.apache.ibatis.transaction.Transaction; import org.apache.ibatis.transaction.TransactionFactory; import org.apache.ibatis.transaction.managed.ManagedTransactionFactory; -import org.hsweb.web.core.datasource.DynamicDataSourceHolder; +import org.hsweb.web.core.datasource.DataSourceHolder; import javax.sql.DataSource; import java.sql.Connection; @@ -91,7 +91,7 @@ public class DynamicSqlSessionFactory implements SqlSessionFactory { try { final Environment environment = getConfiguration().getEnvironment(); final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); - DataSource ds = DynamicDataSourceHolder.getActiveSource(); + DataSource ds = DataSourceHolder.getActiveSource(); if (ds == null) ds = environment.getDataSource(); tx = transactionFactory.newTransaction(ds, level, autoCommit); final Executor executor = getConfiguration().newExecutor(tx, execType); diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/basic/BasicMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/basic/BasicMapper.xml similarity index 74% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/basic/BasicMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/basic/BasicMapper.xml index 3b1cc1949..386f563ab 100644 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/basic/BasicMapper.xml +++ b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/basic/BasicMapper.xml @@ -5,24 +5,24 @@ - ${@org.hsweb.web.mybatis.builder.DefaultSqlParamBuilder@instance().buildWhere(resultMapId,tableName,#this['_parameter'].terms)} + ${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildWhere(resultMapId,tableName,#this['_parameter'].terms)} - ${@org.hsweb.web.mybatis.builder.DefaultSqlParamBuilder@instance().buildSelectFields(resultMapId,tableName,#this['_parameter'])} + ${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildSelectFields(resultMapId,tableName,#this['_parameter'])} - ${@org.hsweb.web.mybatis.builder.DefaultSqlParamBuilder@instance().buildUpdateFields(resultMapId,#this['_parameter'])} + ${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildUpdateFields(resultMapId,#this['_parameter'])} - ${@org.hsweb.web.mybatis.builder.DefaultSqlParamBuilder@instance().buildOrder(resultMapId,tableName,#this['_parameter'])} + ${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildOrder(resultMapId,tableName,#this['_parameter'])} @@ -49,7 +49,7 @@ - insert into ${tableName} ${@org.hsweb.web.mybatis.builder.DefaultSqlParamBuilder@instance().buildInsertSql(resultMapId,#this['_parameter'])} + insert into ${tableName} ${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildInsertSql(resultMapId,#this['_parameter'])} diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/classified/ClassifiedMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/classified/ClassifiedMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/classified/ClassifiedMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/classified/ClassifiedMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/config/ConfigMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/config/ConfigMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/config/ConfigMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/config/ConfigMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/datasource/DataSourceMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/datasource/DataSourceMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/datasource/DataSourceMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/datasource/DataSourceMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/form/FormMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/form/FormMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/form/FormMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/form/FormMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/history/HistoryMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/history/HistoryMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/history/HistoryMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/history/HistoryMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/module/ModuleMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/module/ModuleMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/module/ModuleMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/module/ModuleMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/module/ModuleMetaMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/module/ModuleMetaMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/module/ModuleMetaMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/module/ModuleMetaMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/basic/BasicMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/basic/BasicMapper.xml deleted file mode 100644 index c6a14e61b..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/basic/BasicMapper.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - ${@org.hsweb.web.mybatis.builder.MysqlParamBuilder@instance().buildWhere(resultMapId,tableName,#this['_parameter'].terms)} - - - - - ${@org.hsweb.web.mybatis.builder.MysqlParamBuilder@instance().buildSelectFields(resultMapId,tableName,#this['_parameter'])} - - - - - - ${@org.hsweb.web.mybatis.builder.MysqlParamBuilder@instance().buildUpdateFields(resultMapId,#this['_parameter'])} - - - - - - ${@org.hsweb.web.mybatis.builder.MysqlParamBuilder@instance().buildOrder(resultMapId,tableName,#this['_parameter'])} - - - - - select - - from ${tableName} - - - - - - - - - delete ${tableName} from ${tableName} - - - - 1=2 - - - - - - - insert into ${tableName} ${@org.hsweb.web.mybatis.builder.MysqlParamBuilder@instance().buildInsertSql(resultMapId,#this['_parameter'])} - - - - - update ${tableName} - - - - - u_id=#{data.id} - - - - - - - select count(0) as "total" from ${tableName} - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/basic/BasicMapper.xml.old b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/basic/BasicMapper.xml.old deleted file mode 100644 index c50a535e6..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/basic/BasicMapper.xml.old +++ /dev/null @@ -1,214 +0,0 @@ - - - - - ${@org.hsweb.web.mybatis.builder.DefaultSqlParamBuilder@instance().buildWhere($fieldsInfo,#this['_parameter'].terms)} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${$tableName}.${item} as `${item}` - - - - - - - - - ${$tableName}.${item} as `${item}` - - - - * - - * - - - - - - - - - - - `${item}`=#{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - - `${item}`= #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - - `${item}`=#{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - - - - - - - `${item}` - - - - - `${item}` - - - - `${item}` - - - - - - - - - - - #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - - - - - - - - order by ${$tableName}.${item} - - - - ${sortOrder} - - - - - - - select - - from ${$tableName} - - - - - - - - - - insert into ${$tableName} - - values - - - - - - update ${$tableName} - - - - - - u_id=#{data.u_id} - - - - - - - select count(0) as "total" from ${$tableName} - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/form/FormMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/form/FormMapper.xml deleted file mode 100644 index d53528bae..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/form/FormMapper.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/module/ModuleMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/module/ModuleMapper.xml deleted file mode 100644 index aafab9b01..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/module/ModuleMapper.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/user/UserMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/user/UserMapper.xml deleted file mode 100644 index b66e8403f..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/user/UserMapper.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - update s_user set password=#{password,jdbcType=VARCHAR} where u_id = #{id} - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/basic/BasicMapper.xml.old b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/basic/BasicMapper.xml.old deleted file mode 100644 index dc273c6a8..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/basic/BasicMapper.xml.old +++ /dev/null @@ -1,245 +0,0 @@ - - - - - ${@org.hsweb.web.mybatis.builder.DefaultSqlParamBuilder@instance().buildWhere($fieldsInfo,#this['_parameter'].terms)} - - - ${@org.hsweb.web.mybatis.builder.DefaultSqlParamBuilder@instance().buildSelectFields($fieldsInfo,#this['_parameter'])} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${item}=#{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - - ${item}= #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - - ${item}=#{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - - - - - - - ${item} - - - - - ${item} - - - - ${item} - - - - - - - - - - - #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}} - - - - - - - - - - - - - - order by${$tableName}.${item} - - - - ${sortOrder} - - - - - - - select - - from ${$tableName} - - - - - - - - - - insert into ${$tableName} - - values - - - - - - update ${$tableName} - - - - - - u_id=#{data.u_id} - - - - - - - select count(0) as "total" from ${$tableName} - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/classified/ClassifiedMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/classified/ClassifiedMapper.xml deleted file mode 100644 index 2d591c7b7..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/classified/ClassifiedMapper.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/config/ConfigMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/config/ConfigMapper.xml deleted file mode 100644 index f11d10b0c..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/config/ConfigMapper.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/datasource/DataSourceMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/datasource/DataSourceMapper.xml deleted file mode 100644 index 98502270e..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/datasource/DataSourceMapper.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/history/HistoryMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/history/HistoryMapper.xml deleted file mode 100644 index 0ac3ae45c..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/history/HistoryMapper.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/module/ModuleMetaMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/module/ModuleMetaMapper.xml deleted file mode 100644 index 2b1193875..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/module/ModuleMetaMapper.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/plan/QueryPlanMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/plan/QueryPlanMapper.xml deleted file mode 100644 index 67b781536..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/plan/QueryPlanMapper.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/profile/UserProfileMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/profile/UserProfileMapper.xml deleted file mode 100644 index 0d42485ac..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/profile/UserProfileMapper.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/quartz/QuartzJobHistoryMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/quartz/QuartzJobHistoryMapper.xml deleted file mode 100644 index d3492b940..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/quartz/QuartzJobHistoryMapper.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/quartz/QuartzJobMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/quartz/QuartzJobMapper.xml deleted file mode 100644 index 52734215f..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/quartz/QuartzJobMapper.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/resource/ResourcesMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/resource/ResourcesMapper.xml deleted file mode 100644 index 60f35face..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/resource/ResourcesMapper.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/RoleMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/RoleMapper.xml deleted file mode 100644 index 690631532..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/RoleMapper.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/RoleModuleMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/RoleModuleMapper.xml deleted file mode 100644 index 78b799fbf..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/RoleModuleMapper.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - delete from s_role_modules where role_id=#{role_id} - - - - delete from s_role_modules where module_id=#{module_id} - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/UserRoleMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/UserRoleMapper.xml deleted file mode 100644 index e42cd17bd..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/role/UserRoleMapper.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - delete from s_user_role where user_id=#{userId} - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/script/DynamicScriptMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/script/DynamicScriptMapper.xml deleted file mode 100644 index f53eec0ed..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/script/DynamicScriptMapper.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/template/TemplateMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/template/TemplateMapper.xml deleted file mode 100644 index 60c02eac1..000000000 --- a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/template/TemplateMapper.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/plan/QueryPlanMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/plan/QueryPlanMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/plan/QueryPlanMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/plan/QueryPlanMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/profile/UserProfileMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/profile/UserProfileMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/profile/UserProfileMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/profile/UserProfileMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/quartz/QuartzJobHistoryMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/quartz/QuartzJobHistoryMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/quartz/QuartzJobHistoryMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/quartz/QuartzJobHistoryMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/quartz/QuartzJobMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/quartz/QuartzJobMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/quartz/QuartzJobMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/quartz/QuartzJobMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/resource/ResourcesMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/resource/ResourcesMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/resource/ResourcesMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/resource/ResourcesMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/role/RoleMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/role/RoleMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/role/RoleMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/role/RoleMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/role/RoleModuleMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/role/RoleModuleMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/role/RoleModuleMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/role/RoleModuleMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/role/UserRoleMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/role/UserRoleMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/role/UserRoleMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/role/UserRoleMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/script/DynamicScriptMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/script/DynamicScriptMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/script/DynamicScriptMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/script/DynamicScriptMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/template/TemplateMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/template/TemplateMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/template/TemplateMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/template/TemplateMapper.xml diff --git a/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/user/UserMapper.xml b/hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/user/UserMapper.xml similarity index 100% rename from hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/user/UserMapper.xml rename to hsweb-web-dao/hsweb-web-dao-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/user/UserMapper.xml diff --git a/hsweb-web-dao/pom.xml b/hsweb-web-dao/pom.xml index 7665e7dfc..337b2c775 100644 --- a/hsweb-web-dao/pom.xml +++ b/hsweb-web-dao/pom.xml @@ -21,7 +21,7 @@ hsweb-framework org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 pom diff --git a/hsweb-web-datasource/pom.xml b/hsweb-web-datasource/pom.xml index 4a0aaba58..0dc487ea2 100644 --- a/hsweb-web-datasource/pom.xml +++ b/hsweb-web-datasource/pom.xml @@ -21,7 +21,7 @@ hsweb-framework org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 diff --git a/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceAutoConfiguration.java b/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceAutoConfiguration.java index f445dc4d3..c60fea5dd 100644 --- a/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceAutoConfiguration.java +++ b/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceAutoConfiguration.java @@ -20,11 +20,11 @@ import com.atomikos.icatch.jta.UserTransactionImp; import com.atomikos.icatch.jta.UserTransactionManager; import com.atomikos.jdbc.AtomikosDataSourceBean; import org.hsweb.web.core.datasource.DynamicDataSource; -import org.hsweb.web.core.datasource.DynamicDataSourceHolder; +import org.hsweb.web.core.datasource.DataSourceHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -36,11 +36,12 @@ import javax.transaction.SystemException; @Configuration @ConditionalOnMissingBean(DynamicDataSource.class) +@EnableConfigurationProperties(DynamicDataSourceProperties.class) @ComponentScan("org.hsweb.web.datasource.dynamic") public class DynamicDataSourceAutoConfiguration { @Autowired - private DataSourceProperties properties; + private DynamicDataSourceProperties properties; /** * 默认数据库链接 @@ -49,18 +50,14 @@ public class DynamicDataSourceAutoConfiguration { @Bean(initMethod = "init", name = "dataSource", destroyMethod = "close") public DataSource dataSource() { AtomikosDataSourceBean dataSourceBean = new AtomikosDataSourceBean(); - dataSourceBean.getXaProperties().putAll(properties.getXa().getProperties()); - dataSourceBean.setXaDataSourceClassName(properties.getXa().getDataSourceClassName()); - dataSourceBean.setUniqueResourceName("core"); - dataSourceBean.setMinPoolSize(5); - dataSourceBean.setMaxPoolSize(200); + properties.putProperties(dataSourceBean); return dataSourceBean; } @Bean(name = "dynamicDataSource") public DynamicXaDataSourceImpl dynamicXaDataSource(@Qualifier("dataSource") DataSource dataSource) { - DynamicXaDataSourceImpl dynamicXaDataSource = new DynamicXaDataSourceImpl(dataSource); - DynamicDataSourceHolder.install(dynamicXaDataSource); + DynamicXaDataSourceImpl dynamicXaDataSource = new DynamicXaDataSourceImpl(dataSource, properties.getType()); + DataSourceHolder.install(dynamicXaDataSource); return dynamicXaDataSource; } @@ -74,7 +71,7 @@ public class DynamicDataSourceAutoConfiguration { @Bean public UserTransactionImp userTransaction() throws SystemException { UserTransactionImp userTransactionImp = new UserTransactionImp(); - userTransactionImp.setTransactionTimeout(300); + userTransactionImp.setTransactionTimeout(properties.getTransactionTimeout()); return userTransactionImp; } diff --git a/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceProperties.java b/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceProperties.java new file mode 100644 index 000000000..d632ab497 --- /dev/null +++ b/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceProperties.java @@ -0,0 +1,262 @@ +/* + * 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.datasource.dynamic; + +import com.atomikos.jdbc.AtomikosDataSourceBean; +import org.hsweb.web.core.datasource.DatabaseType; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; + +import java.sql.SQLException; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +/** + * @author zhouhao + * @see com.atomikos.jdbc.AbstractDataSourceBean + * @since 2.1 + */ +@ConfigurationProperties(prefix = "hsweb.dynamicDatasource") +public class DynamicDataSourceProperties + implements BeanClassLoaderAware, InitializingBean { + private static final List supportDatasourceType; + private String name = "core"; + private DatabaseType type = DatabaseType.h2; + private String datasourceName = null; + private String username = "sa"; + private String password = ""; + private String url = "jdbc:h2:file:./data/h2db;DB_CLOSE_ON_EXIT=FALSE"; + private String testQuery = null; + private int loginTimeout = -1; + private int maxLifetime = -1; + private int minPoolSize = 2; + private int maxPoolSize = 20; + private int borrowConnectionTimeout = 30; + private int reapTimeout = 0; + private int maxIdleTime = 60; + private int maintenanceInterval = 60; + private int defaultIsolationLevel = -1; + private int transactionTimeout = 300; + private Properties properties = null; + private ClassLoader classLoader = null; + + static { + supportDatasourceType = new LinkedList<>(); + supportDatasourceType.add("com.alibaba.druid.pool.xa.DruidXADataSource"); + } + + public int getTransactionTimeout() { + return transactionTimeout; + } + + public void setTransactionTimeout(int transactionTimeout) { + this.transactionTimeout = transactionTimeout; + } + + public String getDatasourceName() { + return datasourceName; + } + + public void setDatasourceName(String datasourceName) { + this.datasourceName = datasourceName; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public DatabaseType getType() { + if (type == null) { + type = DatabaseType.fromJdbcUrl(getUrl()); + } + return type; + } + + public void setType(DatabaseType type) { + this.type = type; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getTestQuery() { + return testQuery; + } + + public void setTestQuery(String testQuery) { + this.testQuery = testQuery; + } + + public int getLoginTimeout() { + return loginTimeout; + } + + public void setLoginTimeout(int loginTimeout) { + this.loginTimeout = loginTimeout; + } + + public int getMaxLifetime() { + return maxLifetime; + } + + public void setMaxLifetime(int maxLifetime) { + this.maxLifetime = maxLifetime; + } + + public int getMinPoolSize() { + return minPoolSize; + } + + public void setMinPoolSize(int minPoolSize) { + this.minPoolSize = minPoolSize; + } + + public int getMaxPoolSize() { + return maxPoolSize; + } + + public void setMaxPoolSize(int maxPoolSize) { + this.maxPoolSize = maxPoolSize; + } + + public int getBorrowConnectionTimeout() { + return borrowConnectionTimeout; + } + + public void setBorrowConnectionTimeout(int borrowConnectionTimeout) { + this.borrowConnectionTimeout = borrowConnectionTimeout; + } + + public int getReapTimeout() { + return reapTimeout; + } + + public void setReapTimeout(int reapTimeout) { + this.reapTimeout = reapTimeout; + } + + public int getMaxIdleTime() { + return maxIdleTime; + } + + public void setMaxIdleTime(int maxIdleTime) { + this.maxIdleTime = maxIdleTime; + } + + public int getMaintenanceInterval() { + return maintenanceInterval; + } + + public void setMaintenanceInterval(int maintenanceInterval) { + this.maintenanceInterval = maintenanceInterval; + } + + public int getDefaultIsolationLevel() { + return defaultIsolationLevel; + } + + public void setDefaultIsolationLevel(int defaultIsolationLevel) { + this.defaultIsolationLevel = defaultIsolationLevel; + } + + public Properties getProperties() { + if (properties == null) { + properties = new Properties(); + } + properties.put("username", getUsername()); + properties.put("password", getPassword()); + properties.put("url", getUrl()); + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + @Override + public void afterPropertiesSet() throws Exception { + if (datasourceName == null) { + datasourceName = lookupSupportDatasourceName(); + } + if (!StringUtils.hasText(testQuery)) testQuery = getType().getTestQuery(); + } + + public String lookupSupportDatasourceName() throws ClassNotFoundException { + for (String dsClass : supportDatasourceType) { + try { + ClassUtils.forName(dsClass, classLoader); + return dsClass; + } catch (ClassNotFoundException e) { + } + } + return getType().getXaDataSourceClassName(); + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } + + public void putProperties(AtomikosDataSourceBean dataSourceBean) { + dataSourceBean.setXaProperties(this.getProperties()); + dataSourceBean.setXaDataSourceClassName(this.getDatasourceName()); + dataSourceBean.setUniqueResourceName(this.getName()); + dataSourceBean.setMinPoolSize(this.getMinPoolSize()); + dataSourceBean.setMaxPoolSize(this.getMaxPoolSize()); + dataSourceBean.setTestQuery(this.getTestQuery()); + dataSourceBean.setBorrowConnectionTimeout(this.getBorrowConnectionTimeout()); + dataSourceBean.setMaintenanceInterval(this.getMaintenanceInterval()); + dataSourceBean.setDefaultIsolationLevel(this.getDefaultIsolationLevel()); + dataSourceBean.setMaxLifetime(this.getMaxLifetime()); + dataSourceBean.setMaxIdleTime(this.getMaxIdleTime()); + dataSourceBean.setReapTimeout(this.getReapTimeout()); + try { + dataSourceBean.setLoginTimeout(this.getLoginTimeout()); + } catch (SQLException e) { + } + } + +} diff --git a/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceServiceImpl.java b/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceServiceImpl.java index 3602c2d4d..055099d20 100644 --- a/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceServiceImpl.java +++ b/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicDataSourceServiceImpl.java @@ -18,8 +18,11 @@ package org.hsweb.web.datasource.dynamic; import com.atomikos.jdbc.AtomikosDataSourceBean; import com.atomikos.jdbc.AtomikosSQLException; +import org.apache.commons.beanutils.BeanUtilsBean; +import org.apache.commons.beanutils.PropertyUtilsBean; import org.hsweb.concurrent.lock.LockFactory; import org.hsweb.web.bean.po.datasource.DataSource; +import org.hsweb.web.core.datasource.DatabaseType; import org.hsweb.web.core.datasource.DynamicDataSource; import org.hsweb.web.core.exception.NotFoundException; import org.hsweb.web.service.datasource.DataSourceService; @@ -27,6 +30,7 @@ import org.hsweb.web.service.datasource.DynamicDataSourceService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.stereotype.Service; @@ -35,6 +39,8 @@ import javax.annotation.PreDestroy; import javax.annotation.Resource; import java.io.Closeable; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -60,6 +66,11 @@ public class DynamicDataSourceServiceImpl implements DynamicDataSourceService { return getCache(id).getDataSource(); } + @Override + public String getDataBaseType(String id) { + return getCache(id).getDatabaseType().name(); + } + @Override @PreDestroy public void destroyAll() throws Exception { @@ -109,7 +120,8 @@ public class DynamicDataSourceServiceImpl implements DynamicDataSourceService { } //加载datasource到缓存 javax.sql.DataSource dataSource = createDataSource(old); - cacheInfo = new CacheInfo(old.getHash(), dataSource); + DatabaseType databaseType = DatabaseType.fromJdbcUrl(old.getUrl()); + cacheInfo = new CacheInfo(old.getHash(), dataSource, databaseType); cache.put(id, cacheInfo); } finally { try { @@ -123,32 +135,33 @@ public class DynamicDataSourceServiceImpl implements DynamicDataSourceService { } } - @Autowired - private DataSourceProperties properties; - protected javax.sql.DataSource createDataSource(DataSource dataSource) { - AtomikosDataSourceBean dataSourceBean = new AtomikosDataSourceBean(); - Properties xaProperties = new Properties(); - if (dataSource.getProperties() != null) - xaProperties.putAll(dataSource.getProperties()); - if (dataSource.getDriver().contains("mysql")) { - dataSourceBean.setXaDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"); - xaProperties.put("pinGlobalTxToPhysicalConnection", true); - xaProperties.put("user", dataSource.getUsername()); - xaProperties.put("password", dataSource.getPassword()); - xaProperties.put("url", dataSource.getUrl()); - } else { - dataSourceBean.setXaDataSourceClassName(properties.getXa().getDataSourceClassName()); - xaProperties.put("username", dataSource.getUsername()); - xaProperties.put("password", dataSource.getPassword()); - xaProperties.put("url", dataSource.getUrl()); - xaProperties.put("driverClassName", dataSource.getDriver()); + DynamicDataSourceProperties properties = new DynamicDataSourceProperties(); + properties.setName("ds_" + dataSource.getId()); + properties.setBeanClassLoader(this.getClass().getClassLoader()); + properties.setUsername(dataSource.getUsername()); + properties.setPassword(dataSource.getPassword()); + properties.setUrl(dataSource.getUrl()); + properties.setType(DatabaseType.fromJdbcUrl(dataSource.getUrl())); + properties.setTestQuery(dataSource.getTestSql()); + try { + properties.afterPropertiesSet(); + } catch (Exception e) { + throw new RuntimeException(e); } - dataSourceBean.setXaProperties(xaProperties); - dataSourceBean.setUniqueResourceName("ds_" + dataSource.getId()); - dataSourceBean.setMaxPoolSize(200); - dataSourceBean.setMinPoolSize(5); - dataSourceBean.setBorrowConnectionTimeout(60); + Map otherProperties = dataSource.getProperties(); + if (otherProperties != null) { + PropertyUtilsBean propertyUtilsBean = BeanUtilsBean.getInstance().getPropertyUtils(); + otherProperties.forEach((k, v) -> { + try { + propertyUtilsBean.setProperty(properties, k, v); + } catch (Exception e) { + logger.warn("设置动态数据源配置失败", e); + } + }); + } + AtomikosDataSourceBean dataSourceBean = new AtomikosDataSourceBean(); + properties.putProperties(dataSourceBean); boolean[] success = new boolean[1]; //异步初始化 new Thread(() -> { @@ -183,13 +196,14 @@ public class DynamicDataSourceServiceImpl implements DynamicDataSourceService { } class CacheInfo { - int hash; - + int hash; + DatabaseType databaseType; javax.sql.DataSource dataSource; - public CacheInfo(int hash, javax.sql.DataSource dataSource) { + public CacheInfo(int hash, javax.sql.DataSource dataSource, DatabaseType type) { this.hash = hash; this.dataSource = dataSource; + this.databaseType = type; } public int getHash() { @@ -199,6 +213,10 @@ public class DynamicDataSourceServiceImpl implements DynamicDataSourceService { public javax.sql.DataSource getDataSource() { return dataSource; } + + public DatabaseType getDatabaseType() { + return databaseType; + } } } diff --git a/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicXaDataSourceImpl.java b/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicXaDataSourceImpl.java index 7289e82ad..7d3f5ec42 100644 --- a/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicXaDataSourceImpl.java +++ b/hsweb-web-datasource/src/main/java/org/hsweb/web/datasource/dynamic/DynamicXaDataSourceImpl.java @@ -17,11 +17,13 @@ package org.hsweb.web.datasource.dynamic; import com.atomikos.jdbc.AtomikosDataSourceBean; +import org.hsweb.web.core.datasource.DatabaseType; import org.hsweb.web.core.datasource.DynamicDataSource; import org.hsweb.web.service.datasource.DynamicDataSourceService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.datasource.AbstractDataSource; +import org.springframework.util.Assert; import javax.sql.DataSource; import javax.sql.XAConnection; @@ -32,12 +34,15 @@ import java.sql.SQLException; public class DynamicXaDataSourceImpl extends AbstractDataSource implements DynamicDataSource, XADataSource, Closeable { private Logger logger = LoggerFactory.getLogger(DynamicDataSource.class); - private javax.sql.DataSource defaultDataSource; - + private javax.sql.DataSource defaultDataSource; + private DatabaseType defaultDatabaseType; protected DynamicDataSourceService dynamicDataSourceService; - public DynamicXaDataSourceImpl(javax.sql.DataSource defaultDataSource) { + public DynamicXaDataSourceImpl(javax.sql.DataSource defaultDataSource, DatabaseType defaultDatabaseType) { + Assert.notNull(defaultDataSource); + Assert.notNull(defaultDatabaseType); this.defaultDataSource = defaultDataSource; + this.defaultDatabaseType = defaultDatabaseType; } @Override @@ -59,6 +64,15 @@ public class DynamicXaDataSourceImpl extends AbstractDataSource implements Dynam return dataSource; } + @Override + public DatabaseType getActiveDataBaseType() { + String sourceId = DynamicDataSource.getActiveDataSourceId(); + if (sourceId == null || dynamicDataSourceService == null) return defaultDatabaseType; + String type = dynamicDataSourceService.getDataBaseType(sourceId); + if (type == null) return defaultDatabaseType; + return DatabaseType.valueOf(type); + } + public XADataSource getActiveXADataSource() { DataSource activeDs = getActiveDataSource(); XADataSource xaDataSource; @@ -72,11 +86,8 @@ public class DynamicXaDataSourceImpl extends AbstractDataSource implements Dynam return xaDataSource; } - public void setDefaultDataSource(DataSource defaultDataSource) { - this.defaultDataSource = defaultDataSource; - } - - public void setDynamicDataSourceService(DynamicDataSourceService dynamicDataSourceService) { + public synchronized void setDynamicDataSourceService(DynamicDataSourceService dynamicDataSourceService) { + if (this.dynamicDataSourceService != null) throw new UnsupportedOperationException(); this.dynamicDataSourceService = dynamicDataSourceService; } @@ -92,7 +103,8 @@ public class DynamicXaDataSourceImpl extends AbstractDataSource implements Dynam public void close() { try { - dynamicDataSourceService.destroyAll(); + if (dynamicDataSourceService != null) + dynamicDataSourceService.destroyAll(); } catch (Exception e) { logger.error("close datasource error", e); } diff --git a/hsweb-web-datasource/src/main/resources/META-INF/spring-configuration-metadata.json b/hsweb-web-datasource/src/main/resources/META-INF/spring-configuration-metadata.json new file mode 100644 index 000000000..970c67f45 --- /dev/null +++ b/hsweb-web-datasource/src/main/resources/META-INF/spring-configuration-metadata.json @@ -0,0 +1,35 @@ +{ + "groups": [ + { + "name": "hsweb.dynamic-datasource", + "type": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties", + "sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties" + } + ], + "properties": [ + { + "name": "hsweb.dynamic-datasource.name", + "type": "java.lang.String", + "sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties" + } + ], + "hints": [ + { + "name": "hsweb.dynamic-datasource.type", + "values": [ + { + "value": "h2", + "description": "use h2 database." + }, + { + "value": "mysql", + "description": "use mysql database." + }, + { + "value": "oracle", + "description": "use oracle database." + } + ] + } + ] +} \ No newline at end of file diff --git a/hsweb-web-oauth2/hsweb-web-oauth2-controller/pom.xml b/hsweb-web-oauth2/hsweb-web-oauth2-controller/pom.xml index 4733aed31..56e1a9430 100644 --- a/hsweb-web-oauth2/hsweb-web-oauth2-controller/pom.xml +++ b/hsweb-web-oauth2/hsweb-web-oauth2-controller/pom.xml @@ -21,7 +21,7 @@ hsweb-web-oauth2 org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 diff --git a/hsweb-web-oauth2/hsweb-web-oauth2-core/pom.xml b/hsweb-web-oauth2/hsweb-web-oauth2-core/pom.xml index 5c2a08e04..fdfd1157a 100644 --- a/hsweb-web-oauth2/hsweb-web-oauth2-core/pom.xml +++ b/hsweb-web-oauth2/hsweb-web-oauth2-core/pom.xml @@ -21,7 +21,7 @@ hsweb-web-oauth2 org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 diff --git a/hsweb-web-oauth2/hsweb-web-oauth2-mybatis/pom.xml b/hsweb-web-oauth2/hsweb-web-oauth2-mybatis/pom.xml index 752591764..6f79a070a 100644 --- a/hsweb-web-oauth2/hsweb-web-oauth2-mybatis/pom.xml +++ b/hsweb-web-oauth2/hsweb-web-oauth2-mybatis/pom.xml @@ -21,7 +21,7 @@ hsweb-web-oauth2 org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 diff --git a/hsweb-web-oauth2/hsweb-web-oauth2-service-simple/pom.xml b/hsweb-web-oauth2/hsweb-web-oauth2-service-simple/pom.xml index 32f68e2c4..9f5e9c1ad 100644 --- a/hsweb-web-oauth2/hsweb-web-oauth2-service-simple/pom.xml +++ b/hsweb-web-oauth2/hsweb-web-oauth2-service-simple/pom.xml @@ -21,7 +21,7 @@ hsweb-web-oauth2 org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 diff --git a/hsweb-web-oauth2/hsweb-web-oauth2-simple/pom.xml b/hsweb-web-oauth2/hsweb-web-oauth2-simple/pom.xml index fe773aab2..4efdd5da9 100644 --- a/hsweb-web-oauth2/hsweb-web-oauth2-simple/pom.xml +++ b/hsweb-web-oauth2/hsweb-web-oauth2-simple/pom.xml @@ -21,7 +21,7 @@ hsweb-web-oauth2 org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 diff --git a/hsweb-web-oauth2/pom.xml b/hsweb-web-oauth2/pom.xml index f57e3d6b0..e0f536aa8 100644 --- a/hsweb-web-oauth2/pom.xml +++ b/hsweb-web-oauth2/pom.xml @@ -21,7 +21,7 @@ hsweb-framework org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 diff --git a/hsweb-web-service/hsweb-web-service-api/pom.xml b/hsweb-web-service/hsweb-web-service-api/pom.xml index b691a97e8..db38a8ed0 100644 --- a/hsweb-web-service/hsweb-web-service-api/pom.xml +++ b/hsweb-web-service/hsweb-web-service-api/pom.xml @@ -5,7 +5,7 @@ hsweb-web-service org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 hsweb-web-service-api diff --git a/hsweb-web-service/hsweb-web-service-api/src/main/java/org/hsweb/web/service/datasource/DynamicDataSourceService.java b/hsweb-web-service/hsweb-web-service-api/src/main/java/org/hsweb/web/service/datasource/DynamicDataSourceService.java index 49f1c20d5..b8530d122 100644 --- a/hsweb-web-service/hsweb-web-service-api/src/main/java/org/hsweb/web/service/datasource/DynamicDataSourceService.java +++ b/hsweb-web-service/hsweb-web-service-api/src/main/java/org/hsweb/web/service/datasource/DynamicDataSourceService.java @@ -25,6 +25,8 @@ public interface DynamicDataSourceService { DataSource getDataSource(String id); - void destroyAll()throws Exception; + String getDataBaseType(String id); + + void destroyAll() throws Exception; } diff --git a/hsweb-web-service/hsweb-web-service-simple/pom.xml b/hsweb-web-service/hsweb-web-service-simple/pom.xml index db1e42741..ea6af46d9 100644 --- a/hsweb-web-service/hsweb-web-service-simple/pom.xml +++ b/hsweb-web-service/hsweb-web-service-simple/pom.xml @@ -5,7 +5,7 @@ hsweb-web-service org.hsweb - 2.0-SNAPSHOT + 2.1-SNAPSHOT 4.0.0 @@ -18,6 +18,10 @@ hsweb-web-datasource test + + org.mockito + mockito-all + org.quartz-scheduler @@ -30,11 +34,11 @@ spring-context-support - - org.springframework.boot - spring-boot-starter-redis - test - + + + + + javax.el @@ -74,7 +78,7 @@ com.alibaba druid - 1.0.25 + 1.0.26 test diff --git a/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/datasource/DatasourceTests.java b/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/datasource/DatasourceTests.java index ebc20ab5d..cda223c38 100644 --- a/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/datasource/DatasourceTests.java +++ b/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/datasource/DatasourceTests.java @@ -22,6 +22,7 @@ import org.hsweb.web.bean.po.datasource.DataSource; import org.hsweb.web.core.Install; import org.hsweb.web.core.datasource.DynamicDataSource; import org.hsweb.web.service.datasource.DataSourceService; +import org.hsweb.web.service.form.FormService; import org.hsweb.web.service.impl.AbstractTestCase; import org.hsweb.web.service.user.UserService; import org.junit.Before; @@ -46,6 +47,10 @@ public class DatasourceTests extends AbstractTestCase { private UserService userService; @Resource Install install; + + @Resource + private FormService formService; + @PostConstruct public void init() { testService.setSqlExecutor(sqlExecutor); @@ -76,12 +81,12 @@ public class DatasourceTests extends AbstractTestCase { //使用test数据源进行查询 DynamicDataSource.use("test"); userService.select(QueryParam.build()); - } @Test public void testGetFieldList() throws Exception { - testService.test(); + formService.select(QueryParam.build()); + System.out.println(1); } } diff --git a/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/lock/LockTest.java b/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/lock/LockTest.java index 22805c3e8..4eacc3ad8 100644 --- a/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/lock/LockTest.java +++ b/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/lock/LockTest.java @@ -16,22 +16,11 @@ package org.hsweb.web.service.impl.lock; -import org.hsweb.concureent.cache.RedisCacheManagerAutoConfig; import org.hsweb.concurrent.lock.LockFactory; -import org.hsweb.web.bean.po.user.User; import org.hsweb.web.service.impl.AbstractTestCase; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataAccessException; -import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.core.RedisCallback; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; import javax.annotation.Resource; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; @@ -41,29 +30,6 @@ public class LockTest extends AbstractTestCase { @Resource private LockFactory lockFactory; - @Autowired - private RedisTemplate redisTemplate; - - @Test - public void testCache() { - redisTemplate.execute((RedisCallback) connection -> { - for (int i = 0; i < 50000; i++) { - User user = new User(); - user.setName("test" + i); - try { - JdkSerializationRedisSerializer s = new JdkSerializationRedisSerializer(); - connection.lPush("test".getBytes(), s.serialize(user)); - } catch (Exception e) { - e.printStackTrace(); - } - } - return null; - }); - long l = System.currentTimeMillis(); - System.out.println(redisTemplate.opsForList().range("test", 0, -1).size()); - System.out.println(System.currentTimeMillis() - l); - } - @Test public void testLock() throws InterruptedException { Lock lock = lockFactory.createLock("test_lock"); diff --git a/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/template/TemplateServiceImplTest.java b/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/template/TemplateServiceImplTest.java index c3aaf700f..a663243a3 100644 --- a/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/template/TemplateServiceImplTest.java +++ b/hsweb-web-service/hsweb-web-service-simple/src/test/java/org/hsweb/web/service/impl/template/TemplateServiceImplTest.java @@ -2,80 +2,37 @@ package org.hsweb.web.service.impl.template; import org.hsweb.web.bean.common.QueryParam; import org.hsweb.web.bean.po.template.Template; -import org.hsweb.web.service.impl.AbstractTestCase; +import org.hsweb.web.dao.template.TemplateMapper; import org.hsweb.web.service.template.TemplateService; -import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.springframework.test.annotation.Rollback; -import org.springframework.transaction.annotation.Transactional; +import org.mockito.Mock; +import org.mockito.MockSettings; +import org.mockito.MockitoAnnotations; -import javax.annotation.Resource; - -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Created by zhouhao on 16-5-23. */ -@Rollback -@Transactional -public class TemplateServiceImplTest extends AbstractTestCase { +public class TemplateServiceImplTest { - @Resource + @Mock private TemplateService templateService; - private String templateId; - @Before public void setUp() throws Exception { - Template template = new Template(); - template.setName("test"); - template.setCssLinks(Arrays.asList("http://***/template.css", "/test.css")); - template.setScriptLinks(Arrays.asList("http://***/template.js", "/test.js")); - template.setTemplate("你好:{{user.name}}"); - template.setType("default"); - templateService.insert(template); - templateId = template.getId(); - testDeploy(); + MockitoAnnotations.initMocks(this); + TemplateMapper templateMapper = mock(TemplateMapper.class); + System.out.println(templateMapper.select(QueryParam.build())); + System.out.println(templateMapper.insert(null)); } @Test - public void testCreateNewVersion() throws Exception { - String id = templateService.createNewVersion(templateId); - Template newVersion = templateService.selectByPk(id); - Assert.assertEquals(newVersion.getVersion(), 1); - Assert.assertEquals(newVersion.getCssLinks().size(), 2); - Assert.assertEquals(newVersion.getScriptLinks().size(), 2); - Assert.assertEquals(newVersion.getTemplate(), "你好:{{user.name}}"); + public void test() { + System.out.println(templateService.insert(null)); } - @Test - public void testSelectLatestList() throws Exception { - List