增加数据源测试
This commit is contained in:
@@ -56,7 +56,7 @@ public class MybatisPlusConfig {
|
||||
private String password;
|
||||
|
||||
@Bean(name = "manageDatasource")
|
||||
public DataSource manageDatasource() {
|
||||
public DataSource manageDatasource() throws Exception {
|
||||
return DruidDataSourceUtil.createDataSource(driverClassName, url, username, password);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,47 +4,43 @@ import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class DruidDataSourceUtil {
|
||||
|
||||
private static AtomicLong nameId = new AtomicLong(0);
|
||||
|
||||
public static DruidDataSource createDataSource(String driverClassName, String url, String username, String password){
|
||||
try {
|
||||
// 数据源配置
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setDriverClassName(driverClassName);
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(username);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setInitialSize(2);
|
||||
dataSource.setMinIdle(2);
|
||||
dataSource.setMaxActive(50);
|
||||
dataSource.setTestWhileIdle(true);
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setTestOnReturn(false);
|
||||
dataSource.setValidationQuery("select 1");
|
||||
dataSource.setMaxWait(3000);
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(60000);
|
||||
dataSource.setMinEvictableIdleTimeMillis(3600000);
|
||||
// 重试3次,失败退出,源码里是errorCount > connectionErrorRetryAttempts,所以写成2就是3次、、、
|
||||
// CreateConnectionThread 源码在这个类里面
|
||||
dataSource.setConnectionErrorRetryAttempts(2);
|
||||
dataSource.setBreakAfterAcquireFailure(true);
|
||||
dataSource.setName("zyplayer-doc-db-" + nameId.incrementAndGet());
|
||||
if (url.contains("oracle")) {
|
||||
dataSource.setValidationQuery("select 1 from dual");
|
||||
}
|
||||
DruidPooledConnection connection = dataSource.getConnection(3000);
|
||||
if (connection == null) {
|
||||
throw new ConfirmException("尝试获取该数据源连接失败:" + url);
|
||||
}
|
||||
connection.recycle();
|
||||
return dataSource;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
public static DruidDataSource createDataSource(String driverClassName, String url, String username, String password) throws Exception {
|
||||
// 数据源配置
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setDriverClassName(driverClassName);
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(username);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setInitialSize(2);
|
||||
dataSource.setMinIdle(2);
|
||||
dataSource.setMaxActive(50);
|
||||
dataSource.setTestWhileIdle(true);
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setTestOnReturn(false);
|
||||
dataSource.setValidationQuery("select 1");
|
||||
dataSource.setMaxWait(3000);
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(60000);
|
||||
dataSource.setMinEvictableIdleTimeMillis(3600000);
|
||||
// 重试3次,失败退出,源码里是errorCount > connectionErrorRetryAttempts,所以写成2就是3次、、、
|
||||
// CreateConnectionThread 源码在这个类里面
|
||||
dataSource.setConnectionErrorRetryAttempts(2);
|
||||
dataSource.setBreakAfterAcquireFailure(true);
|
||||
dataSource.setName("zyplayer-doc-db-" + nameId.incrementAndGet());
|
||||
if (url.contains("oracle")) {
|
||||
dataSource.setValidationQuery("select 1 from dual");
|
||||
}
|
||||
return null;
|
||||
DruidPooledConnection connection = dataSource.getConnection(3000);
|
||||
if (connection == null) {
|
||||
throw new ConfirmException("尝试获取该数据源连接失败:" + url);
|
||||
}
|
||||
connection.recycle();
|
||||
return dataSource;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean;
|
||||
import com.zyplayer.doc.db.framework.db.bean.DatabaseRegistrationBean;
|
||||
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -46,6 +47,29 @@ public class DbDatasourceController {
|
||||
return DocDbResponseJson.ok(datasourceList);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/test")
|
||||
public ResponseJson test(DbDatasource dbDatasource) {
|
||||
// 验证新的数据源
|
||||
try {
|
||||
// 获取原始密码
|
||||
if (Objects.equals("***", dbDatasource.getSourcePassword()) && dbDatasource.getId() != null) {
|
||||
DbDatasource dbDatasourceSel = dbDatasourceService.getById(dbDatasource.getId());
|
||||
if (dbDatasourceSel != null) {
|
||||
dbDatasource.setSourcePassword(dbDatasourceSel.getSourcePassword());
|
||||
}
|
||||
}
|
||||
DatabaseFactoryBean databaseFactoryBean = DatasourceUtil.createDatabaseFactoryBean(dbDatasource);
|
||||
if (databaseFactoryBean == null) {
|
||||
return DocDbResponseJson.warn("获取数据源失败,请检查配置是否正确");
|
||||
}
|
||||
databaseFactoryBean.getDataSource().close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return DocDbResponseJson.warn(ExceptionUtils.getFullStackTrace(e));
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update")
|
||||
public ResponseJson update(DbDatasource dbDatasource) {
|
||||
if (StringUtils.isBlank(dbDatasource.getName())) {
|
||||
@@ -69,6 +93,8 @@ public class DbDatasourceController {
|
||||
Long sourceId = Optional.ofNullable(dbDatasource.getId()).orElse(0L);
|
||||
if (sourceId > 0) {
|
||||
dbDatasourceService.updateById(dbDatasource);
|
||||
// 关闭旧数据源
|
||||
databaseRegistrationBean.closeDatasource(dbDatasource.getId());
|
||||
} else {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
dbDatasource.setCreateTime(new Date());
|
||||
@@ -77,18 +103,6 @@ public class DbDatasourceController {
|
||||
dbDatasource.setYn(1);
|
||||
dbDatasourceService.save(dbDatasource);
|
||||
}
|
||||
// 关闭数据源
|
||||
databaseRegistrationBean.closeDatasource(dbDatasource.getId());
|
||||
// 验证新的数据源
|
||||
DbDatasource dbDatasourceSel = dbDatasourceService.getById(dbDatasource.getId());
|
||||
if (Objects.equals(dbDatasourceSel.getYn(), 1)) {
|
||||
// 创建新的数据源
|
||||
DatabaseFactoryBean databaseFactoryBean = DatasourceUtil.createDatabaseFactoryBean(dbDatasourceSel);
|
||||
if (databaseFactoryBean == null) {
|
||||
return DocDbResponseJson.warn("创建数据源失败,请检查配置是否正确");
|
||||
}
|
||||
databaseFactoryBean.getDataSource().close();
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,73 +11,70 @@ import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DatasourceUtil {
|
||||
private static SqlLogInterceptor sqlLogInterceptor = new SqlLogInterceptor();
|
||||
|
||||
public static DatabaseFactoryBean createDatabaseFactoryBean(DbDatasource dbDatasource){
|
||||
try {
|
||||
Resource[] resources = null;
|
||||
// 描述连接信息的对象
|
||||
DatabaseFactoryBean databaseFactoryBean = new DatabaseFactoryBean();
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
String dbUrl = dbDatasource.getSourceUrl();
|
||||
if (dbUrl.contains("mysql")) {
|
||||
// jdbc:mysql://192.168.0.1:3306/user_info?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true
|
||||
String[] urlParamArr = dbUrl.split("\\?");
|
||||
String[] urlDbNameArr = urlParamArr[0].split("/");
|
||||
if (urlDbNameArr.length >= 2) {
|
||||
databaseFactoryBean.setDbName(urlDbNameArr[urlDbNameArr.length - 1]);
|
||||
//databaseFactoryBean.setHost(urlDbNameArr[urlDbNameArr.length - 2]);
|
||||
}
|
||||
databaseFactoryBean.setDatabaseProduct(DatabaseFactoryBean.DatabaseProduct.MYSQL);
|
||||
resources = resolver.getResources("classpath:com/zyplayer/doc/db/framework/db/mapper/mysql/*.xml");
|
||||
} else if (dbUrl.contains("sqlserver")) {
|
||||
// jdbc:jtds:sqlserver://192.168.0.1:33434;socketTimeout=60;DatabaseName=user_info;
|
||||
String[] urlParamArr = dbUrl.split(";");
|
||||
//String[] urlDbNameArr = urlParamArr[0].split("/");
|
||||
//databaseFactoryBean.setHost(urlDbNameArr[urlDbNameArr.length - 1]);
|
||||
for (String urlParam : urlParamArr) {
|
||||
String[] keyValArr = urlParam.split("=");
|
||||
if (keyValArr.length >= 2 && keyValArr[0].equalsIgnoreCase("DatabaseName")) {
|
||||
databaseFactoryBean.setDbName(keyValArr[1]);
|
||||
}
|
||||
}
|
||||
databaseFactoryBean.setDatabaseProduct(DatabaseFactoryBean.DatabaseProduct.SQLSERVER);
|
||||
resources = resolver.getResources("classpath:com/zyplayer/doc/db/framework/db/mapper/sqlserver/*.xml");
|
||||
} else if (dbUrl.contains("oracle")) {
|
||||
// jdbc:oracle:thin:@127.0.0.1:1521:user_info
|
||||
// jdbc:oracle:thin:@127.0.0.1:1521/user_info
|
||||
// 代码是写好的,但还没有oracle的库让我测试过~
|
||||
String[] urlParamArr = dbUrl.split("\\?")[0].split("@");
|
||||
String[] urlDbNameArr = urlParamArr[0].split("/");
|
||||
if (urlDbNameArr.length <= 1) {
|
||||
urlDbNameArr = urlParamArr[0].split(":");
|
||||
}
|
||||
public static DatabaseFactoryBean createDatabaseFactoryBean(DbDatasource dbDatasource) throws Exception {
|
||||
Resource[] resources = null;
|
||||
// 描述连接信息的对象
|
||||
DatabaseFactoryBean databaseFactoryBean = new DatabaseFactoryBean();
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
String dbUrl = dbDatasource.getSourceUrl();
|
||||
if (dbUrl.contains("mysql")) {
|
||||
// jdbc:mysql://192.168.0.1:3306/user_info?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true
|
||||
String[] urlParamArr = dbUrl.split("\\?");
|
||||
String[] urlDbNameArr = urlParamArr[0].split("/");
|
||||
if (urlDbNameArr.length >= 2) {
|
||||
databaseFactoryBean.setDbName(urlDbNameArr[urlDbNameArr.length - 1]);
|
||||
databaseFactoryBean.setDatabaseProduct(DatabaseFactoryBean.DatabaseProduct.ORACLE);
|
||||
resources = resolver.getResources("classpath:com/zyplayer/doc/db/framework/db/mapper/oracle/*.xml");
|
||||
//databaseFactoryBean.setHost(urlDbNameArr[urlDbNameArr.length - 2]);
|
||||
}
|
||||
if (resources == null) {
|
||||
return null;
|
||||
databaseFactoryBean.setDatabaseProduct(DatabaseFactoryBean.DatabaseProduct.MYSQL);
|
||||
resources = resolver.getResources("classpath:com/zyplayer/doc/db/framework/db/mapper/mysql/*.xml");
|
||||
} else if (dbUrl.contains("sqlserver")) {
|
||||
// jdbc:jtds:sqlserver://192.168.0.1:33434;socketTimeout=60;DatabaseName=user_info;
|
||||
String[] urlParamArr = dbUrl.split(";");
|
||||
//String[] urlDbNameArr = urlParamArr[0].split("/");
|
||||
//databaseFactoryBean.setHost(urlDbNameArr[urlDbNameArr.length - 1]);
|
||||
for (String urlParam : urlParamArr) {
|
||||
String[] keyValArr = urlParam.split("=");
|
||||
if (keyValArr.length >= 2 && keyValArr[0].equalsIgnoreCase("DatabaseName")) {
|
||||
databaseFactoryBean.setDbName(keyValArr[1]);
|
||||
}
|
||||
}
|
||||
// 数据源配置
|
||||
DruidDataSource dataSource = DruidDataSourceUtil.createDataSource(dbDatasource.getDriverClassName(), dbDatasource.getSourceUrl(), dbDatasource.getSourceName(), dbDatasource.getSourcePassword());
|
||||
// 创建sqlSessionTemplate
|
||||
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
|
||||
sqlSessionFactoryBean.setDataSource(dataSource);
|
||||
sqlSessionFactoryBean.setMapperLocations(resources);
|
||||
sqlSessionFactoryBean.setPlugins(new Interceptor[]{sqlLogInterceptor});
|
||||
SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactoryBean.getObject());
|
||||
// 组装自定义的bean
|
||||
databaseFactoryBean.setId(dbDatasource.getId());
|
||||
databaseFactoryBean.setCnName(dbDatasource.getName());
|
||||
databaseFactoryBean.setDataSource(dataSource);
|
||||
databaseFactoryBean.setSqlSessionTemplate(sqlSessionTemplate);
|
||||
databaseFactoryBean.setUrl(dbUrl);
|
||||
return databaseFactoryBean;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
databaseFactoryBean.setDatabaseProduct(DatabaseFactoryBean.DatabaseProduct.SQLSERVER);
|
||||
resources = resolver.getResources("classpath:com/zyplayer/doc/db/framework/db/mapper/sqlserver/*.xml");
|
||||
} else if (dbUrl.contains("oracle")) {
|
||||
// jdbc:oracle:thin:@127.0.0.1:1521:user_info
|
||||
// jdbc:oracle:thin:@127.0.0.1:1521/user_info
|
||||
// 代码是写好的,但还没有oracle的库让我测试过~
|
||||
String[] urlParamArr = dbUrl.split("\\?")[0].split("@");
|
||||
String[] urlDbNameArr = urlParamArr[0].split("/");
|
||||
if (urlDbNameArr.length <= 1) {
|
||||
urlDbNameArr = urlParamArr[0].split(":");
|
||||
}
|
||||
databaseFactoryBean.setDbName(urlDbNameArr[urlDbNameArr.length - 1]);
|
||||
databaseFactoryBean.setDatabaseProduct(DatabaseFactoryBean.DatabaseProduct.ORACLE);
|
||||
resources = resolver.getResources("classpath:com/zyplayer/doc/db/framework/db/mapper/oracle/*.xml");
|
||||
}
|
||||
return null;
|
||||
if (resources == null) {
|
||||
return null;
|
||||
}
|
||||
// 数据源配置
|
||||
DruidDataSource dataSource = DruidDataSourceUtil.createDataSource(dbDatasource.getDriverClassName(), dbDatasource.getSourceUrl(), dbDatasource.getSourceName(), dbDatasource.getSourcePassword());
|
||||
// 创建sqlSessionTemplate
|
||||
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
|
||||
sqlSessionFactoryBean.setDataSource(dataSource);
|
||||
sqlSessionFactoryBean.setMapperLocations(resources);
|
||||
sqlSessionFactoryBean.setPlugins(new Interceptor[]{sqlLogInterceptor});
|
||||
SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactoryBean.getObject());
|
||||
// 组装自定义的bean
|
||||
databaseFactoryBean.setId(dbDatasource.getId());
|
||||
databaseFactoryBean.setCnName(dbDatasource.getName());
|
||||
databaseFactoryBean.setDataSource(dataSource);
|
||||
databaseFactoryBean.setSqlSessionTemplate(sqlSessionTemplate);
|
||||
databaseFactoryBean.setUrl(dbUrl);
|
||||
return databaseFactoryBean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +107,17 @@ public class DatabaseRegistrationBean {
|
||||
if (factoryBean != null) return factoryBean;
|
||||
DbDatasource dbDatasource = dbDatasourceService.getById(sourceId);
|
||||
if (dbDatasource == null) {
|
||||
throw new ConfirmException("未找到指定数据源配置信息:" + sourceId);
|
||||
throw new ConfirmException("未找到指定数据源配置信息");
|
||||
}
|
||||
DatabaseFactoryBean databaseFactoryBean = DatasourceUtil.createDatabaseFactoryBean(dbDatasource);
|
||||
if (databaseFactoryBean == null) {
|
||||
throw new ConfirmException("创建数据源失败:" + sourceId);
|
||||
try {
|
||||
DatabaseFactoryBean databaseFactoryBean = DatasourceUtil.createDatabaseFactoryBean(dbDatasource);
|
||||
if (databaseFactoryBean == null) {
|
||||
throw new ConfirmException("获取数据源失败");
|
||||
}
|
||||
databaseFactoryBeanMap.put(sourceId, databaseFactoryBean);
|
||||
return databaseFactoryBean;
|
||||
} catch (Exception e) {
|
||||
throw new ConfirmException("创建数据源失败", e);
|
||||
}
|
||||
databaseFactoryBeanMap.put(sourceId, databaseFactoryBean);
|
||||
return databaseFactoryBean;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,2 +1,2 @@
|
||||
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var a,i,f,l=0,s=[];l<t.length;l++)i=t[l],o[i]&&s.push(o[i][0]),o[i]=0;for(a in c)Object.prototype.hasOwnProperty.call(c,a)&&(e[a]=c[a]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={2:0};n.e=function(e){function r(){a.onerror=a.onload=null,clearTimeout(i);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],a=document.createElement("script");a.type="text/javascript",a.charset="utf-8",a.async=!0,a.timeout=12e4,n.nc&&a.setAttribute("nonce",n.nc),a.src=n.p+""+e+".js?"+{0:"3138591b4af9fb40e531",1:"1ecabc6d379552a7c3f7"}[e];var i=setTimeout(r,12e4);return a.onerror=a.onload=r,u.appendChild(a),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
||||
//# sourceMappingURL=doc-db-manifest.js.map?075412feecc8b570efae
|
||||
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={2:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"e961123b6de8434b2cc2",1:"93ce942e3bdbc7dd3435"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
||||
//# sourceMappingURL=doc-db-manifest.js.map?df9e1a3cc72f1a225176
|
||||
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="text/javascript" src="doc-db-manifest.js?075412feecc8b570efae"></script><script type="text/javascript" src="doc-db-vendor.js?1ecabc6d379552a7c3f7"></script><script type="text/javascript" src="doc-db-index.js?3138591b4af9fb40e531"></script></body>
|
||||
<script type="text/javascript" src="doc-db-manifest.js?df9e1a3cc72f1a225176"></script><script type="text/javascript" src="doc-db-vendor.js?93ce942e3bdbc7dd3435"></script><script type="text/javascript" src="doc-db-index.js?e961123b6de8434b2cc2"></script></body>
|
||||
|
||||
</html>
|
||||
|
||||
|
||||
8
zyplayer-doc-ui/db-ui/package-lock.json
generated
8
zyplayer-doc-ui/db-ui/package-lock.json
generated
@@ -239,7 +239,7 @@
|
||||
},
|
||||
"async-validator": {
|
||||
"version": "1.8.5",
|
||||
"resolved": "https://registry.npm.taobao.org/async-validator/download/async-validator-1.8.5.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fasync-validator%2Fdownload%2Fasync-validator-1.8.5.tgz",
|
||||
"resolved": "https://registry.npm.taobao.org/async-validator/download/async-validator-1.8.5.tgz?cache=0&sync_timestamp=1565685468183&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fasync-validator%2Fdownload%2Fasync-validator-1.8.5.tgz",
|
||||
"integrity": "sha1-3D4I7B/Q3dtn5ghC8CwM0c7G1/A=",
|
||||
"requires": {
|
||||
"babel-runtime": "6.x"
|
||||
@@ -2238,7 +2238,7 @@
|
||||
},
|
||||
"element-ui": {
|
||||
"version": "2.11.1",
|
||||
"resolved": "https://registry.npm.taobao.org/element-ui/download/element-ui-2.11.1.tgz?cache=0&sync_timestamp=1564126738326&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Felement-ui%2Fdownload%2Felement-ui-2.11.1.tgz",
|
||||
"resolved": "https://registry.npm.taobao.org/element-ui/download/element-ui-2.11.1.tgz",
|
||||
"integrity": "sha1-K2f57uPtouaISHPBxYnL4w2anWA=",
|
||||
"requires": {
|
||||
"async-validator": "~1.8.1",
|
||||
@@ -4646,7 +4646,7 @@
|
||||
},
|
||||
"normalize-wheel": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "http://registry.npm.taobao.org/normalize-wheel/download/normalize-wheel-1.0.1.tgz",
|
||||
"resolved": "https://registry.npm.taobao.org/normalize-wheel/download/normalize-wheel-1.0.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnormalize-wheel%2Fdownload%2Fnormalize-wheel-1.0.1.tgz",
|
||||
"integrity": "sha1-rsiGr/2wRQcNhWRH32Ls+GFG7EU="
|
||||
},
|
||||
"nth-check": {
|
||||
@@ -6041,7 +6041,7 @@
|
||||
},
|
||||
"resize-observer-polyfill": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "http://registry.npm.taobao.org/resize-observer-polyfill/download/resize-observer-polyfill-1.5.1.tgz",
|
||||
"resolved": "https://registry.npm.taobao.org/resize-observer-polyfill/download/resize-observer-polyfill-1.5.1.tgz",
|
||||
"integrity": "sha1-DpAg3T0hAkRY1OvSfiPkAmmBBGQ="
|
||||
},
|
||||
"resolve": {
|
||||
|
||||
@@ -5,6 +5,10 @@ export function queryExecuteSql(data) {
|
||||
return request({url: '/zyplayer-doc-db/executor/execute', method: 'post', data: Qs.stringify(data)});
|
||||
}
|
||||
|
||||
export function queryTestDatasource(data) {
|
||||
return request({url: '/zyplayer-doc-db/datasource/test', method: 'post', data: Qs.stringify(data)});
|
||||
}
|
||||
|
||||
export function queryTableDdl(data) {
|
||||
return request({url: '/zyplayer-doc-db/doc-db/getTableDdl', method: 'post', data: Qs.stringify(data)});
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ const service = axios.create({
|
||||
// 增加不需要验证结果的标记
|
||||
const noValidate = {
|
||||
"/zyplayer-doc-db/executor/execute": true,
|
||||
"/zyplayer-doc-db/datasource/test": true,
|
||||
};
|
||||
|
||||
service.interceptors.request.use(
|
||||
|
||||
@@ -49,6 +49,9 @@
|
||||
<el-form-item label="密码:">
|
||||
<el-input v-model="newDatasource.sourcePassword" placeholder="密码"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="测试:">
|
||||
<el-button v-on:click="testDatasource" type="primary" v-loading="testDatasourceErrLoading">测试数据源</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" style="text-align: center;">
|
||||
<el-button v-on:click="saveDatasource" type="primary">保存</el-button>
|
||||
@@ -90,12 +93,19 @@
|
||||
<el-button type="primary" v-on:click="saveUserDbSourceAuth">保存配置</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!--错误信息弹窗-->
|
||||
<el-dialog title="测试数据源失败" :visible.sync="testDatasourceErrVisible" :footer="null" width="760px">
|
||||
<div v-highlight>
|
||||
<pre><code v-html="testDatasourceErrInfo"></code></pre>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import toast from '../../common/lib/common/toast'
|
||||
import global from '../../common/config/global'
|
||||
import {queryTestDatasource} from '../../common/api/datasource'
|
||||
|
||||
var app;
|
||||
|
||||
@@ -113,6 +123,10 @@
|
||||
dbSourceAuthUserLoading: false,
|
||||
searchUserList: [],
|
||||
dbSourceAuthNewUser: "",
|
||||
// 测试数据源
|
||||
testDatasourceErrInfo: "",
|
||||
testDatasourceErrVisible: false,
|
||||
testDatasourceErrLoading: false,
|
||||
};
|
||||
},
|
||||
mounted: function () {
|
||||
@@ -208,6 +222,18 @@
|
||||
app.getDatasourceList();
|
||||
});
|
||||
},
|
||||
testDatasource() {
|
||||
this.testDatasourceErrLoading = true;
|
||||
queryTestDatasource(this.newDatasource).then(res => {
|
||||
this.testDatasourceErrLoading = false;
|
||||
if (res.errCode == 200) {
|
||||
this.$message.success("测试成功!");
|
||||
} else {
|
||||
this.testDatasourceErrVisible = true;
|
||||
this.testDatasourceErrInfo = res.errMsg || '';
|
||||
}
|
||||
});
|
||||
},
|
||||
driverClassNameChange() {
|
||||
if (this.newDatasource.driverClassName == 'com.mysql.jdbc.Driver') {
|
||||
this.urlPlaceholder = "例:jdbc:mysql://127.0.0.1:3306/user_info?useUnicode=true&characterEncoding=utf8";
|
||||
|
||||
Reference in New Issue
Block a user