提交 c983b661 authored 作者: taojinlong's avatar taojinlong

feat: sqlserver

上级 74b849d0
...@@ -8,6 +8,7 @@ import lombok.Setter; ...@@ -8,6 +8,7 @@ import lombok.Setter;
@Setter @Setter
public class SqlServerConfigration extends JdbcDTO { public class SqlServerConfigration extends JdbcDTO {
private String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; private String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private String schema;
public String getJdbc(){ public String getJdbc(){
return "jdbc:sqlserver://HOSTNAME:PORT;DatabaseName=DATABASE".replace("HOSTNAME", getHost()).replace("PORT", getPort().toString()).replace("DATABASE", getDataBase()); return "jdbc:sqlserver://HOSTNAME:PORT;DatabaseName=DATABASE".replace("HOSTNAME", getHost()).replace("PORT", getPort().toString()).replace("DATABASE", getDataBase());
......
...@@ -42,20 +42,25 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -42,20 +42,25 @@ public class JdbcProvider extends DatasourceProvider {
public List<String[]> getData(DatasourceRequest dsr) throws Exception { public List<String[]> getData(DatasourceRequest dsr) throws Exception {
List<String[]> list = new LinkedList<>(); List<String[]> list = new LinkedList<>();
Connection connection = null; Connection connection = null;
try { connection = getConnectionFromPool(dsr);
connection = getConnectionFromPool(dsr); Statement stat = connection.createStatement();
Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(dsr.getQuery());
ResultSet rs = stat.executeQuery(dsr.getQuery()); System.out.println(rs == null);
list = fetchResult(rs); list = fetchResult(rs);
} catch (SQLException e) { // try {
DataEaseException.throwException(e); // connection = getConnectionFromPool(dsr);
} catch (Exception e) { // Statement stat = connection.createStatement();
DataEaseException.throwException(e); // ResultSet rs = stat.executeQuery(dsr.getQuery());
} finally { // list = fetchResult(rs);
if(connection != null){ // } catch (SQLException e) {
connection.close(); // DataEaseException.throwException(e);
} // } catch (Exception e) {
} // DataEaseException.throwException(e);
// } finally {
// if(connection != null){
// connection.close();
// }
// }
return list; return list;
} }
...@@ -102,18 +107,23 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -102,18 +107,23 @@ public class JdbcProvider extends DatasourceProvider {
List<String[]> list = new LinkedList<>(); List<String[]> list = new LinkedList<>();
ResultSetMetaData metaData = rs.getMetaData(); ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount(); int columnCount = metaData.getColumnCount();
System.out.println("columnCount: " + columnCount);
while (rs.next()) { while (rs.next()) {
String[] row = new String[columnCount]; String[] row = new String[columnCount];
for (int j = 0; j < columnCount; j++) { for (int j = 0; j < columnCount; j++) {
int columType = metaData.getColumnType(j + 1); int columType = metaData.getColumnType(j + 1);
switch (columType) { switch (columType) {
case Types.DATE: case Types.DATE:
row[j] = rs.getDate(j + 1).toString(); if(rs.getDate(j + 1) != null){
row[j] = rs.getDate(j + 1).toString();
}
break; break;
default: default:
row[j] = rs.getString(j + 1); row[j] = rs.getString(j + 1);
break; break;
} }
System.out.println(j + " " + columType + " " + row[j]);
} }
list.add(row); list.add(row);
} }
...@@ -506,7 +516,9 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -506,7 +516,9 @@ public class JdbcProvider extends DatasourceProvider {
return "show tables;"; return "show tables;";
case sqlServer: case sqlServer:
SqlServerConfigration sqlServerConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), SqlServerConfigration.class); SqlServerConfigration sqlServerConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), SqlServerConfigration.class);
return "SELECT TABLE_NAME FROM DATABASE.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';".replace("DATABASE", sqlServerConfigration.getDataBase()); return "SELECT TABLE_NAME FROM DATABASE.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'DS_SCHEMA' ;"
.replace("DATABASE", sqlServerConfigration.getDataBase())
.replace("DS_SCHEMA", sqlServerConfigration.getSchema());
case oracle: case oracle:
OracleConfigration oracleConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), OracleConfigration.class); OracleConfigration oracleConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), OracleConfigration.class);
if(StringUtils.isEmpty(oracleConfigration.getSchema())){ if(StringUtils.isEmpty(oracleConfigration.getSchema())){
...@@ -523,6 +535,8 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -523,6 +535,8 @@ public class JdbcProvider extends DatasourceProvider {
switch (datasourceType) { switch (datasourceType) {
case oracle: case oracle:
return "select * from all_users"; return "select * from all_users";
case sqlServer:
return "select name from sys.schemas;";
default: default:
return "show tables;"; return "show tables;";
} }
......
...@@ -378,6 +378,7 @@ public class DataSetTableService { ...@@ -378,6 +378,7 @@ public class DataSetTableService {
String table = dataTableInfoDTO.getTable(); String table = dataTableInfoDTO.getTable();
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
datasourceRequest.setQuery(qp.createQuerySQLWithPage(table, fields, page, pageSize, realSize, false)); datasourceRequest.setQuery(qp.createQuerySQLWithPage(table, fields, page, pageSize, realSize, false));
System.out.println(datasourceRequest.getQuery());
map.put("sql", datasourceRequest.getQuery()); map.put("sql", datasourceRequest.getQuery());
try { try {
data.addAll(datasourceProvider.getData(datasourceRequest)); data.addAll(datasourceProvider.getData(datasourceRequest));
......
...@@ -63,6 +63,23 @@ ...@@ -63,6 +63,23 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item v-if="form.type=='sqlServer'">
<el-button icon="el-icon-plus" size="mini" @click="getSchema()">
{{ $t('datasource.get_schema') }}
</el-button>
</el-form-item>
<el-form-item v-if="form.type=='sqlServer'" :label="$t('datasource.schema')">
<el-select filterable v-model="form.configuration.schema" :placeholder="$t('datasource.please_choose_schema')" class="select-width">
<el-option
v-for="item in schemas"
:key="item"
:label="item"
:value="item"
/>
</el-select>
</el-form-item>
</el-form> </el-form>
<div v-if="canEdit" slot="footer" class="dialog-footer"> <div v-if="canEdit" slot="footer" class="dialog-footer">
<el-button v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)" @click="validaDatasource">{{ $t('commons.validate') }}</el-button> <el-button v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)" @click="validaDatasource">{{ $t('commons.validate') }}</el-button>
...@@ -107,7 +124,7 @@ export default { ...@@ -107,7 +124,7 @@ export default {
}, },
allTypes: [{ name: 'mysql', label: 'MySQL', type: 'jdbc' }, allTypes: [{ name: 'mysql', label: 'MySQL', type: 'jdbc' },
{ name: 'oracle', label: 'Oracle', type: 'jdbc' }, { name: 'oracle', label: 'Oracle', type: 'jdbc' },
{ name: 'sqlserver', label: 'SQLSERVER', type: 'jdbc' }], { name: 'sqlServer', label: 'SQLSERVER', type: 'jdbc' }],
schemas: [], schemas: [],
canEdit: false, canEdit: false,
originConfiguration: {} originConfiguration: {}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论