包优化,数据库文档增加oracle支持
This commit is contained in:
@@ -12,8 +12,6 @@ import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
import java.sql.DatabaseMetaData;
|
||||
|
||||
public class DatasourceUtil {
|
||||
private static SqlLogInterceptor sqlLogInterceptor = new SqlLogInterceptor();
|
||||
|
||||
@@ -39,33 +37,31 @@ public class DatasourceUtil {
|
||||
// CreateConnectionThread 源码在这个类里面
|
||||
dataSource.setConnectionErrorRetryAttempts(2);
|
||||
dataSource.setBreakAfterAcquireFailure(true);
|
||||
dataSource.setName("zyplayer-doc-db" + dbDatasource.getId());
|
||||
dataSource.setName("zyplayer-doc-db-" + dbDatasource.getId());
|
||||
DruidPooledConnection connection = dataSource.getConnection(3000);
|
||||
if (connection == null) {
|
||||
throw new ConfirmException("尝试获取该数据源连接失败:" + dbDatasource.getSourceUrl());
|
||||
}
|
||||
// 描述连接信息的对象
|
||||
DatabaseFactoryBean databaseFactoryBean = new DatabaseFactoryBean();
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
String productName = metaData.getDatabaseProductName().toLowerCase();
|
||||
Resource[] resources = null;
|
||||
String dbUrl = dbDatasource.getSourceUrl();
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
if (productName.contains("mysql")) {
|
||||
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.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 (productName.contains("sql server")) {
|
||||
} 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]);
|
||||
//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")) {
|
||||
@@ -74,6 +70,18 @@ public class DatasourceUtil {
|
||||
}
|
||||
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");
|
||||
}
|
||||
connection.recycle();
|
||||
if (resources == null) {
|
||||
|
||||
@@ -13,7 +13,6 @@ public class DatabaseFactoryBean {
|
||||
private DruidDataSource dataSource;
|
||||
private SqlSessionTemplate sqlSessionTemplate;
|
||||
private String url;
|
||||
private String host;
|
||||
private String dbName;
|
||||
private String cnName;
|
||||
private DatabaseProduct databaseProduct;
|
||||
@@ -35,7 +34,7 @@ public class DatabaseFactoryBean {
|
||||
}
|
||||
|
||||
public static enum DatabaseProduct {
|
||||
MYSQL, SQLSERVER
|
||||
MYSQL, SQLSERVER, ORACLE
|
||||
}
|
||||
|
||||
public DruidDataSource getDataSource() {
|
||||
@@ -54,14 +53,6 @@ public class DatabaseFactoryBean {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
<select id="getDatabaseList" resultType="com.zyplayer.doc.db.framework.db.dto.DatabaseInfoDto">
|
||||
select TABLE_SCHEMA dbName
|
||||
from information_schema.tables
|
||||
<!--排除系统库-->
|
||||
where TABLE_SCHEMA != 'information_schema'
|
||||
group by TABLE_SCHEMA
|
||||
</select>
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zyplayer.doc.db.framework.db.mapper.base.BaseMapper">
|
||||
|
||||
<resultMap id="TableColumnDescDtoMap" type="com.zyplayer.doc.db.framework.db.dto.TableColumnDescDto" >
|
||||
<result column="NAME" property="name" jdbcType="VARCHAR" />
|
||||
<result column="ISIDENITY" property="isidenity" jdbcType="VARCHAR" />
|
||||
<result column="TYPE" property="type" jdbcType="VARCHAR" />
|
||||
<result column="NULLABLE" property="nullable" jdbcType="VARCHAR" />
|
||||
<result column="LENGTH" property="length" jdbcType="VARCHAR" />
|
||||
<result column="ISPRAMARY" property="ispramary" jdbcType="VARCHAR" />
|
||||
<result column="DESCRIPTION" property="description" jdbcType="VARCHAR" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="QueryTableColumnDescDtoMap" type="com.zyplayer.doc.db.framework.db.dto.QueryTableColumnDescDto" >
|
||||
<result column="TABLE_NAME" property="tableName" jdbcType="VARCHAR" />
|
||||
<result column="COLUMN_NAME" property="columnName" jdbcType="VARCHAR" />
|
||||
<result column="DESCRIPTION" property="description" jdbcType="VARCHAR" />
|
||||
</resultMap>
|
||||
|
||||
<!--想用的话就来补充下方法体吧~-->
|
||||
|
||||
<select id="getDatabaseList" resultType="com.zyplayer.doc.db.framework.db.dto.DatabaseInfoDto">
|
||||
SELECT 1
|
||||
</select>
|
||||
|
||||
<select id="getTableStatus" resultType="com.zyplayer.doc.db.controller.vo.TableStatusVo">
|
||||
select 1
|
||||
</select>
|
||||
|
||||
<select id="getTableList" resultType="com.zyplayer.doc.db.framework.db.dto.TableInfoDto">
|
||||
SELECT 1
|
||||
</select>
|
||||
|
||||
<select id="getTableColumnList" resultMap="TableColumnDescDtoMap">
|
||||
select 1
|
||||
</select>
|
||||
|
||||
<select id="getTableColumnDescList" resultMap="TableColumnDescDtoMap">
|
||||
select 1
|
||||
</select>
|
||||
|
||||
<select id="getTableAndColumnBySearch" resultMap="QueryTableColumnDescDtoMap">
|
||||
select 1
|
||||
</select>
|
||||
|
||||
<select id="getTableDescList" resultType="com.zyplayer.doc.db.framework.db.dto.TableDescDto">
|
||||
select 1
|
||||
</select>
|
||||
|
||||
<insert id="updateTableDesc">
|
||||
select 1
|
||||
</insert>
|
||||
|
||||
<insert id="updateTableColumnDesc">
|
||||
select 1
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.zyplayer.doc.db.framework.db.mapper.oracle;
|
||||
|
||||
/**
|
||||
* oracle数据库的mapper持有对象
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月8日
|
||||
*/
|
||||
public interface OracleMapper {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user