提交 347b64ef authored 作者: taojinlong's avatar taojinlong

feat: pg

上级 23f85147
...@@ -3,6 +3,7 @@ package io.dataease.datasource.constants; ...@@ -3,6 +3,7 @@ package io.dataease.datasource.constants;
public enum DatasourceTypes { public enum DatasourceTypes {
excel("excel", "excel", "", "", "", "", ""), excel("excel", "excel", "", "", "", "", ""),
mysql("mysql", "mysql", "com.mysql.jdbc.Driver", "`", "`", "'", "'"), mysql("mysql", "mysql", "com.mysql.jdbc.Driver", "`", "`", "'", "'"),
pg("pg", "pg", "org.postgresql.Driver", "\"", "\"", "\"", "\""),
sqlServer("sqlServer", "sqlServer", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "\"", "\"", "\"", "\""), sqlServer("sqlServer", "sqlServer", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "\"", "\"", "\"", "\""),
doris("doris", "doris", "com.mysql.jdbc.Driver", "`", "`", "", ""), doris("doris", "doris", "com.mysql.jdbc.Driver", "`", "`", "", ""),
oracle("oracle", "oracle", "oracle.jdbc.driver.OracleDriver", "\"", "\"", "\"", "\""); oracle("oracle", "oracle", "oracle.jdbc.driver.OracleDriver", "\"", "\"", "\"", "\"");
......
package io.dataease.datasource.dto;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class PgConfigration extends JdbcDTO {
private String driver = "org.postgresql.Driver";
private String schema;
public String getJdbc() {
// 连接参数先写死,后边要把编码、时区等参数放到数据源的设置中
return "jdbc:postgresql://HOSTNAME:PORT/DATABASE"
.replace("HOSTNAME", getHost())
.replace("PORT", getPort().toString())
.replace("DATABASE", getDataBase());
}
}
\ No newline at end of file
...@@ -3,10 +3,7 @@ package io.dataease.datasource.provider; ...@@ -3,10 +3,7 @@ package io.dataease.datasource.provider;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.mchange.v2.c3p0.ComboPooledDataSource; import com.mchange.v2.c3p0.ComboPooledDataSource;
import io.dataease.datasource.constants.DatasourceTypes; import io.dataease.datasource.constants.DatasourceTypes;
import io.dataease.datasource.dto.MysqlConfigration; import io.dataease.datasource.dto.*;
import io.dataease.datasource.dto.OracleConfigration;
import io.dataease.datasource.dto.SqlServerConfigration;
import io.dataease.datasource.dto.TableFiled;
import io.dataease.datasource.request.DatasourceRequest; import io.dataease.datasource.request.DatasourceRequest;
import io.dataease.exception.DataEaseException; import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator; import io.dataease.i18n.Translator;
...@@ -222,8 +219,10 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -222,8 +219,10 @@ public class JdbcProvider extends DatasourceProvider {
public List<String> getSchema(DatasourceRequest datasourceRequest) throws Exception { public List<String> getSchema(DatasourceRequest datasourceRequest) throws Exception {
List<String> schemas = new ArrayList<>(); List<String> schemas = new ArrayList<>();
String queryStr = getSchemaSql(datasourceRequest); String queryStr = getSchemaSql(datasourceRequest);
System.out.println(queryStr);
Connection con = null; Connection con = null;
try { try {
System.out.println(new Gson().toJson(datasourceRequest));
con = getConnection(datasourceRequest); con = getConnection(datasourceRequest);
Statement statement = con.createStatement(); Statement statement = con.createStatement();
ResultSet resultSet = statement.executeQuery(queryStr); ResultSet resultSet = statement.executeQuery(queryStr);
...@@ -309,7 +308,7 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -309,7 +308,7 @@ public class JdbcProvider extends DatasourceProvider {
resultSet.close(); resultSet.close();
ps.close(); ps.close();
} catch (Exception e) { } catch (Exception e) {
DataEaseException.throwException(Translator.get("i18n_datasource_connect_error") + e.getMessage()); DataEaseException.throwException(e.getMessage());
} finally { } finally {
if(con != null){con.close();} if(con != null){con.close();}
} }
...@@ -433,6 +432,12 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -433,6 +432,12 @@ public class JdbcProvider extends DatasourceProvider {
props.put( "oracle.net.CONNECT_TIMEOUT" , "5000") ; props.put( "oracle.net.CONNECT_TIMEOUT" , "5000") ;
// props.put( "oracle.jdbc.ReadTimeout" , "5000" ) ; // props.put( "oracle.jdbc.ReadTimeout" , "5000" ) ;
break; break;
case pg:
PgConfigration pgConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfigration.class);
username = pgConfigration.getUsername();
password = pgConfigration.getPassword();
driver = pgConfigration.getDriver();
jdbcurl = pgConfigration.getJdbc();
default: default:
break; break;
} }
...@@ -477,6 +482,13 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -477,6 +482,13 @@ public class JdbcProvider extends DatasourceProvider {
dataSource.setPassword(oracleConfigration.getPassword()); dataSource.setPassword(oracleConfigration.getPassword());
dataSource.setJdbcUrl(oracleConfigration.getJdbc()); dataSource.setJdbcUrl(oracleConfigration.getJdbc());
break; break;
case pg:
PgConfigration pgConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfigration.class);
dataSource.setUser(pgConfigration.getUsername());
dataSource.setDriverClass(pgConfigration.getDriver());
dataSource.setPassword(pgConfigration.getPassword());
dataSource.setJdbcUrl(pgConfigration.getJdbc());
break;
default: default:
break; break;
} }
...@@ -494,6 +506,9 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -494,6 +506,9 @@ public class JdbcProvider extends DatasourceProvider {
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 sqlServerConfigration.getDataBase(); return sqlServerConfigration.getDataBase();
case pg:
PgConfigration pgConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfigration.class);
return pgConfigration.getDataBase();
default: default:
return null; return null;
} }
...@@ -517,6 +532,12 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -517,6 +532,12 @@ public class JdbcProvider extends DatasourceProvider {
throw new Exception(Translator.get("i18n_schema_is_empty")); throw new Exception(Translator.get("i18n_schema_is_empty"));
} }
return "select table_name, owner from all_tables where owner='" + oracleConfigration.getSchema() + "'"; return "select table_name, owner from all_tables where owner='" + oracleConfigration.getSchema() + "'";
case pg:
PgConfigration pgConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfigration.class);
if(StringUtils.isEmpty(pgConfigration.getSchema())){
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg%' AND tablename NOT LIKE 'sql_%' AND schemaname='SCHEMA' ;".replace("SCHEMA", pgConfigration.getSchema());
default: default:
return "show tables;"; return "show tables;";
} }
...@@ -529,6 +550,8 @@ public class JdbcProvider extends DatasourceProvider { ...@@ -529,6 +550,8 @@ public class JdbcProvider extends DatasourceProvider {
return "select * from all_users"; return "select * from all_users";
case sqlServer: case sqlServer:
return "select name from sys.schemas;"; return "select name from sys.schemas;";
case pg:
return "SELECT nspname FROM pg_namespace;";
default: default:
return "show tables;"; return "show tables;";
} }
......
...@@ -28,6 +28,8 @@ public class ProviderFactory implements ApplicationContextAware { ...@@ -28,6 +28,8 @@ public class ProviderFactory implements ApplicationContextAware {
return context.getBean("jdbc", DatasourceProvider.class); return context.getBean("jdbc", DatasourceProvider.class);
case sqlServer: case sqlServer:
return context.getBean("jdbc", DatasourceProvider.class); return context.getBean("jdbc", DatasourceProvider.class);
case pg:
return context.getBean("jdbc", DatasourceProvider.class);
default: default:
return context.getBean("jdbc", DatasourceProvider.class); return context.getBean("jdbc", DatasourceProvider.class);
} }
...@@ -42,6 +44,8 @@ public class ProviderFactory implements ApplicationContextAware { ...@@ -42,6 +44,8 @@ public class ProviderFactory implements ApplicationContextAware {
return context.getBean("dorisQuery", QueryProvider.class); return context.getBean("dorisQuery", QueryProvider.class);
case sqlServer: case sqlServer:
return context.getBean("sqlserverQuery", QueryProvider.class); return context.getBean("sqlserverQuery", QueryProvider.class);
case pg:
return context.getBean("pgQuery", QueryProvider.class);
case oracle: case oracle:
return context.getBean("oracleQuery", QueryProvider.class); return context.getBean("oracleQuery", QueryProvider.class);
default: default:
......
package io.dataease.provider.pg;
import io.dataease.provider.SQLConstants;
import static io.dataease.datasource.constants.DatasourceTypes.pg;
/**
* @Author gin
* @Date 2021/7/8 7:22 下午
*/
public class PgConstants extends SQLConstants {
public static final String KEYWORD_TABLE = pg.getKeywordPrefix() + "%s" + pg.getKeywordSuffix();
public static final String KEYWORD_FIX = "%s." + pg.getKeywordPrefix() + "%s" + pg.getKeywordSuffix();
public static final String UNIX_TIMESTAMP = "floor(extract(epoch from(( %s - timestamp '1970-01-01 00:00:00')*1000))) ";
public static final String DATE_FORMAT = "to_char(%s, %s)";
public static final String FROM_UNIXTIME = "to_timestamp(%s)";
public static final String CAST = "CAST(%s AS %s)";
public static final String DEFAULT_DATE_FORMAT = "'YYYY-MM-DD HH24:MI:SS'";
public static final String DEFAULT_INT_FORMAT = "numeric(18,0)";
public static final String DEFAULT_FLOAT_FORMAT = "numeric(18,2)";
public static final String WHERE_VALUE_NULL = "(NULL,'')";
public static final String WHERE_VALUE_VALUE = "'%s'";
public static final String AGG_COUNT = "COUNT(*)";
public static final String AGG_FIELD = "%s(%s)";
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
public static final String BRACKETS = "(%s)";
}
...@@ -379,6 +379,7 @@ public class DataSetTableService { ...@@ -379,6 +379,7 @@ public class DataSetTableService {
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
datasourceRequest.setQuery(qp.createQuerySQLWithPage(table, fields, page, pageSize, realSize, false, ds)); datasourceRequest.setQuery(qp.createQuerySQLWithPage(table, fields, page, pageSize, realSize, false, ds));
map.put("sql", datasourceRequest.getQuery()); map.put("sql", datasourceRequest.getQuery());
System.out.println(datasourceRequest.getQuery());
try { try {
data.addAll(datasourceProvider.getData(datasourceRequest)); data.addAll(datasourceProvider.getData(datasourceRequest));
} catch (Exception e) { } catch (Exception e) {
...@@ -903,7 +904,9 @@ public class DataSetTableService { ...@@ -903,7 +904,9 @@ public class DataSetTableService {
datasetTableField.setDeType(transFieldType(filed.getFieldType())); datasetTableField.setDeType(transFieldType(filed.getFieldType()));
datasetTableField.setDeExtractType(transFieldType(filed.getFieldType())); datasetTableField.setDeExtractType(transFieldType(filed.getFieldType()));
} else { } else {
System.out.println(new Gson().toJson(filed));
Integer fieldType = qp.transFieldType(filed.getFieldType()); Integer fieldType = qp.transFieldType(filed.getFieldType());
System.out.println(fieldType);
datasetTableField.setDeType(fieldType == 4 ? 2 : fieldType); datasetTableField.setDeType(fieldType == 4 ? 2 : fieldType);
datasetTableField.setDeExtractType(fieldType); datasetTableField.setDeExtractType(fieldType);
} }
...@@ -1087,6 +1090,8 @@ public class DataSetTableService { ...@@ -1087,6 +1090,8 @@ public class DataSetTableService {
List<TableFiled> fields = (List<TableFiled>) fileMap.get("fields"); List<TableFiled> fields = (List<TableFiled>) fileMap.get("fields");
List<String> newFields = fields.stream().map(TableFiled::getRemarks).collect(Collectors.toList()); List<String> newFields = fields.stream().map(TableFiled::getRemarks).collect(Collectors.toList());
List<String> oldFields = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList()); List<String> oldFields = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList());
System.out.println("oldFields: " + oldFields);
System.out.println("newFields: "+ newFields);
if (!oldFields.equals(newFields)) { if (!oldFields.equals(newFields)) {
DataEaseException.throwException(Translator.get("i18n_excel_colume_change")); DataEaseException.throwException(Translator.get("i18n_excel_colume_change"));
} }
......
...@@ -192,7 +192,7 @@ public class ExtractDataService { ...@@ -192,7 +192,7 @@ public class ExtractDataService {
dropDorisTable(DorisTableUtils.dorisTmpName(DorisTableUtils.dorisName(datasetTableId))); dropDorisTable(DorisTableUtils.dorisTmpName(DorisTableUtils.dorisName(datasetTableId)));
} finally { } finally {
deleteFile("all_scope", datasetTableId); deleteFile("all_scope", datasetTableId);
deleteFile(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getData()); // deleteFile(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getData());
} }
break; break;
...@@ -930,13 +930,15 @@ public class ExtractDataService { ...@@ -930,13 +930,15 @@ public class ExtractDataService {
} }
if (datasourceType.equals(DatasourceTypes.excel)) { if (datasourceType.equals(DatasourceTypes.excel)) {
System.out.println(Column_Fields);
tmp_code = tmp_code.replace("handleExcelIntColumn", handleExcelIntColumn).replace("Column_Fields", Column_Fields); tmp_code = tmp_code.replace("handleExcelIntColumn", handleExcelIntColumn).replace("Column_Fields", Column_Fields);
} else { } else {
tmp_code = tmp_code.replace("handleExcelIntColumn", "").replace("Column_Fields", Column_Fields); tmp_code = tmp_code.replace("handleExcelIntColumn", "").replace("Column_Fields", Column_Fields);
} }
tmp_code = tmp_code.replace("handleBinaryType", handleBinaryTypeCode); tmp_code = tmp_code.replace("handleBinaryType", handleBinaryTypeCode);
System.out.println(tmp_code);
UserDefinedJavaClassDef userDefinedJavaClassDef = new UserDefinedJavaClassDef(UserDefinedJavaClassDef.ClassType.TRANSFORM_CLASS, "Processor", tmp_code); UserDefinedJavaClassDef userDefinedJavaClassDef = new UserDefinedJavaClassDef(UserDefinedJavaClassDef.ClassType.TRANSFORM_CLASS, "Processor", tmp_code);
userDefinedJavaClassDef.setActive(true); userDefinedJavaClassDef.setActive(true);
...@@ -1019,13 +1021,13 @@ public class ExtractDataService { ...@@ -1019,13 +1021,13 @@ public class ExtractDataService {
} }
} }
private static String handleBinaryType = " \t\tif(\"FEILD\".equalsIgnoreCase(filed)){\n" + private final static String handleBinaryType = " \t\tif(\"FEILD\".equalsIgnoreCase(filed)){\n" +
" get(Fields.Out, filed).setValue(r, \"\");\n" + " get(Fields.Out, filed).setValue(r, \"\");\n" +
" get(Fields.Out, filed).getValueMeta().setType(2);\n" + " get(Fields.Out, filed).getValueMeta().setType(2);\n" +
" \t}"; " \t}";
private static String alterColumnTypeCode = " if(\"FILED\".equalsIgnoreCase(filed)){\n" + private final static String alterColumnTypeCode = " if(\"FILED\".equalsIgnoreCase(filed)){\n" +
"\t if(tmp != null && tmp.equalsIgnoreCase(\"Y\")){\n" + "\t if(tmp != null && tmp.equalsIgnoreCase(\"Y\")){\n" +
" get(Fields.Out, filed).setValue(r, 1);\n" + " get(Fields.Out, filed).setValue(r, 1);\n" +
" get(Fields.Out, filed).getValueMeta().setType(2);\n" + " get(Fields.Out, filed).getValueMeta().setType(2);\n" +
...@@ -1035,7 +1037,7 @@ public class ExtractDataService { ...@@ -1035,7 +1037,7 @@ public class ExtractDataService {
" }\n" + " }\n" +
" }\n"; " }\n";
private static String handleExcelIntColumn = " \t\tif(tmp != null && tmp.endsWith(\".0\")){\n" + private final static String handleExcelIntColumn = " \t\tif(tmp != null && tmp.endsWith(\".0\")){\n" +
" try {\n" + " try {\n" +
" Long.valueOf(tmp.substring(0, tmp.length()-2));\n" + " Long.valueOf(tmp.substring(0, tmp.length()-2));\n" +
" get(Fields.Out, filed).setValue(r, tmp.substring(0, tmp.length()-2));\n" + " get(Fields.Out, filed).setValue(r, tmp.substring(0, tmp.length()-2));\n" +
...@@ -1043,14 +1045,14 @@ public class ExtractDataService { ...@@ -1043,14 +1045,14 @@ public class ExtractDataService {
" }catch (Exception e){}\n" + " }catch (Exception e){}\n" +
" }"; " }";
private static String handleWraps = " if(tmp != null && ( tmp.contains(\"\\r\") || tmp.contains(\"\\n\"))){\n" + private final static String handleWraps = " if(tmp != null && ( tmp.contains(\"\\r\") || tmp.contains(\"\\n\"))){\n" +
"\t\t\ttmp = tmp.trim();\n" + "\t\t\ttmp = tmp.trim();\n" +
" tmp = tmp.replaceAll(\"\\r\",\" \");\n" + " tmp = tmp.replaceAll(\"\\r\",\" \");\n" +
" tmp = tmp.replaceAll(\"\\n\",\" \");\n" + " tmp = tmp.replaceAll(\"\\n\",\" \");\n" +
" get(Fields.Out, filed).setValue(r, tmp);\n" + " get(Fields.Out, filed).setValue(r, tmp);\n" +
" } "; " } ";
private static String code = "import org.pentaho.di.core.row.ValueMetaInterface;\n" + private final static String code = "import org.pentaho.di.core.row.ValueMetaInterface;\n" +
"import java.util.List;\n" + "import java.util.List;\n" +
"import java.io.File;\n" + "import java.io.File;\n" +
"import java.security.MessageDigest;\n" + "import java.security.MessageDigest;\n" +
......
...@@ -46,13 +46,13 @@ ...@@ -46,13 +46,13 @@
<el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.port')" prop="configuration.port"> <el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.port')" prop="configuration.port">
<el-input v-model="form.configuration.port" autocomplete="off" /> <el-input v-model="form.configuration.port" autocomplete="off" />
</el-form-item> </el-form-item>
<el-form-item v-if="form.type=='oracle'"> <el-form-item v-if="form.type=='oracle' || form.type=='sqlServer' || form.type=='pg'">
<el-button icon="el-icon-plus" size="mini" @click="getSchema()"> <el-button icon="el-icon-plus" size="mini" @click="getSchema()">
{{ $t('datasource.get_schema') }} {{ $t('datasource.get_schema') }}
</el-button> </el-button>
</el-form-item> </el-form-item>
<el-form-item v-if="form.type=='oracle'" :label="$t('datasource.schema')"> <el-form-item v-if="form.type=='oracle' || form.type=='sqlServer' || form.type=='pg'" :label="$t('datasource.schema')">
<el-select filterable v-model="form.configuration.schema" :placeholder="$t('datasource.please_choose_schema')" class="select-width"> <el-select filterable v-model="form.configuration.schema" :placeholder="$t('datasource.please_choose_schema')" class="select-width">
<el-option <el-option
v-for="item in schemas" v-for="item in schemas"
...@@ -64,21 +64,21 @@ ...@@ -64,21 +64,21 @@
</el-form-item> </el-form-item>
<el-form-item v-if="form.type=='sqlServer'"> <!-- <el-form-item v-if="form.type=='sqlServer'">-->
<el-button icon="el-icon-plus" size="mini" @click="getSchema()"> <!-- <el-button icon="el-icon-plus" size="mini" @click="getSchema()">-->
{{ $t('datasource.get_schema') }} <!-- {{ $t('datasource.get_schema') }}-->
</el-button> <!-- </el-button>-->
</el-form-item> <!-- </el-form-item>-->
<el-form-item v-if="form.type=='sqlServer'" :label="$t('datasource.schema')"> <!-- <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-select filterable v-model="form.configuration.schema" :placeholder="$t('datasource.please_choose_schema')" class="select-width">-->
<el-option <!-- <el-option-->
v-for="item in schemas" <!-- v-for="item in schemas"-->
:key="item" <!-- :key="item"-->
:label="item" <!-- :label="item"-->
:value="item" <!-- :value="item"-->
/> <!-- />-->
</el-select> <!-- </el-select>-->
</el-form-item> <!-- </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">
...@@ -124,7 +124,8 @@ export default { ...@@ -124,7 +124,8 @@ 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' },
{ name: 'pg', label: 'PostgreSQL', type: 'jdbc' }],
schemas: [], schemas: [],
canEdit: false, canEdit: false,
originConfiguration: {} originConfiguration: {}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论