forked from github/dataease
feat(数据源): 支持 db2
This commit is contained in:
parent
c51a41da34
commit
ab7b7f541b
@ -12,6 +12,7 @@ public enum DatasourceTypes {
|
||||
oracle("oracle", "oracle", "oracle.jdbc.driver.OracleDriver", "\"", "\"", "\"", "\""),
|
||||
mongo("mongo", "mongodb", "com.mongodb.jdbc.MongoDriver", "`", "`", "\"", "\""),
|
||||
ck("ch", "ch", "ru.yandex.clickhouse.ClickHouseDriver", "`", "`", "'", "'"),
|
||||
db2("db2", "db2", "com.ibm.db2.jcc.DB2Driver", "\"", "\"", "\"", "\""),
|
||||
es("es", "es", "", "\"", "\"", "\"", "\""),
|
||||
redshift("redshift", "redshift", "org.postgresql.Driver", "\"", "\"", "\"", "\"");
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package io.dataease.dto.datasource;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Db2Configuration extends JdbcConfiguration {
|
||||
|
||||
private String driver = "com.ibm.db2.jcc.DB2Driver";
|
||||
private String extraParams = "";
|
||||
|
||||
public String getJdbc() {
|
||||
if(StringUtils.isEmpty(extraParams.trim())){
|
||||
return "jdbc:db2://HOSTNAME:PORT/DATABASE"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
}else {
|
||||
return "jdbc:hive2://HOSTNAME:PORT/DATABASE?EXTRA_PARAMS"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim())
|
||||
.replace("EXTRA_PARAMS", getExtraParams().trim());
|
||||
}
|
||||
}
|
||||
}
|
@ -26,4 +26,6 @@ public class SQLObj {
|
||||
private String whereField;
|
||||
private String whereAlias;
|
||||
private String whereTermAndValue;
|
||||
|
||||
private String limitFiled;
|
||||
}
|
||||
|
@ -55,6 +55,8 @@ public class ProviderFactory implements ApplicationContextAware {
|
||||
return context.getBean("redshiftQuery", QueryProvider.class);
|
||||
case hive:
|
||||
return context.getBean("hiveQuery", QueryProvider.class);
|
||||
case db2:
|
||||
return context.getBean("db2Query", QueryProvider.class);
|
||||
default:
|
||||
return context.getBean("mysqlQuery", QueryProvider.class);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
|
||||
list = fetchResult(rs);
|
||||
|
||||
if (dsr.isPageable() && dsr.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.sqlServer.name())) {
|
||||
if (dsr.isPageable() && (dsr.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.sqlServer.name()) || dsr.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.db2.name()))) {
|
||||
Integer realSize = dsr.getPage() * dsr.getPageSize() < list.size() ? dsr.getPage() * dsr.getPageSize() : list.size();
|
||||
list = list.subList((dsr.getPage() - 1) * dsr.getPageSize(), realSize);
|
||||
}
|
||||
@ -245,10 +245,10 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
List<String[]> dataList;
|
||||
List<TableFiled> fieldList;
|
||||
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(datasourceRequest.getQuery()))) {
|
||||
dataList = fetchResult(rs);
|
||||
fieldList = fetchResultField(rs, datasourceRequest);
|
||||
result.put("dataList", dataList);
|
||||
result.put("fieldList", fieldList);
|
||||
dataList = fetchResult(rs);
|
||||
result.put("dataList", dataList);
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
DataEaseException.throwException(e);
|
||||
@ -451,6 +451,13 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
driver = hiveConfiguration.getDriver();
|
||||
jdbcurl = hiveConfiguration.getJdbc();
|
||||
break;
|
||||
case db2:
|
||||
Db2Configuration db2Configuration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), Db2Configuration.class);
|
||||
username = db2Configuration.getUsername();
|
||||
password = db2Configuration.getPassword();
|
||||
driver = db2Configuration.getDriver();
|
||||
jdbcurl = db2Configuration.getJdbc();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -543,6 +550,13 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
dataSource.setDriverClassName(hiveConfiguration.getDriver());
|
||||
dataSource.setUrl(hiveConfiguration.getJdbc());
|
||||
jdbcConfiguration = hiveConfiguration;
|
||||
break;
|
||||
case db2:
|
||||
Db2Configuration db2Configuration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), Db2Configuration.class);
|
||||
dataSource.setPassword(db2Configuration.getPassword());
|
||||
dataSource.setDriverClassName(db2Configuration.getDriver());
|
||||
dataSource.setUrl(db2Configuration.getJdbc());
|
||||
jdbcConfiguration = db2Configuration;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -592,6 +606,12 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
throw new Exception(Translator.get("i18n_schema_is_empty"));
|
||||
}
|
||||
return "SELECT tablename FROM pg_tables WHERE schemaname='SCHEMA' ;".replace("SCHEMA", redshiftConfigration.getSchema());
|
||||
case db2:
|
||||
Db2Configuration db2Configuration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), Db2Configuration.class);
|
||||
if (StringUtils.isEmpty(db2Configuration.getSchema())) {
|
||||
throw new Exception(Translator.get("i18n_schema_is_empty"));
|
||||
}
|
||||
return "select TABNAME from syscat.tables WHERE TABSCHEMA ='DE_SCHEMA' AND \"TYPE\" = 'T';".replace("DE_SCHEMA", db2Configuration.getSchema());
|
||||
default:
|
||||
return "show tables;";
|
||||
}
|
||||
@ -632,6 +652,14 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
throw new Exception(Translator.get("i18n_schema_is_empty"));
|
||||
}
|
||||
return "SELECT viewname FROM pg_views WHERE schemaname='SCHEMA' ;".replace("SCHEMA", redshiftConfigration.getSchema());
|
||||
|
||||
case db2:
|
||||
Db2Configuration db2Configuration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), Db2Configuration.class);
|
||||
if (StringUtils.isEmpty(db2Configuration.getSchema())) {
|
||||
throw new Exception(Translator.get("i18n_schema_is_empty"));
|
||||
}
|
||||
return "select TABNAME from syscat.tables WHERE TABSCHEMA ='DE_SCHEMA' AND \"TYPE\" = 'V';".replace("DE_SCHEMA", db2Configuration.getSchema());
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@ -639,11 +667,14 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
|
||||
private String getSchemaSql(DatasourceRequest datasourceRequest) {
|
||||
DatasourceTypes datasourceType = DatasourceTypes.valueOf(datasourceRequest.getDatasource().getType());
|
||||
Db2Configuration db2Configuration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), Db2Configuration.class);
|
||||
switch (datasourceType) {
|
||||
case oracle:
|
||||
return "select * from all_users";
|
||||
case sqlServer:
|
||||
return "select name from sys.schemas;";
|
||||
case db2:
|
||||
return "select SCHEMANAME from syscat.SCHEMATA WHERE \"DEFINER\" ='USER';".replace("USER", db2Configuration.getUsername().toUpperCase()) ;
|
||||
case pg:
|
||||
return "SELECT nspname FROM pg_namespace;";
|
||||
case redshift:
|
||||
|
@ -0,0 +1,39 @@
|
||||
package io.dataease.provider.query.db2;
|
||||
|
||||
import io.dataease.provider.query.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.db2;
|
||||
|
||||
public class Db2Constants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = db2.getKeywordPrefix() + "%s" + db2.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + db2.getKeywordPrefix() + "%s" + db2.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "BIGINT(TIMESTAMPDIFF(2,CHAR(%s -TIMESTAMP('1970-01-01 08:00:00'))))";
|
||||
|
||||
public static final String DATE_FORMAT = "TO_CHAR(TIMESTAMP(%s),'%s')";
|
||||
|
||||
public static final String FROM_UNIXTIME = "TO_CHAR(TIMESTAMP('1970-01-01 08:00:00') +(%s)SECONDS, '%s')";
|
||||
|
||||
public static final String STR_TO_DATE = "timestamp(trim(char(%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 = "BIGINT";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "DECIMAL(20,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)";
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -769,6 +769,15 @@ public class ExtractDataService {
|
||||
inputStep = inputStep(transMeta, selectSQL);
|
||||
udjcStep = udjc(datasetTableFields, DatasourceTypes.ck);
|
||||
break;
|
||||
case db2:
|
||||
Db2Configuration db2Configuration = new Gson().fromJson(datasource.getConfiguration(), Db2Configuration.class);
|
||||
dataMeta = new DatabaseMeta("db", "DB2", "Native", db2Configuration.getHost().trim(), db2Configuration.getDataBase().trim(), db2Configuration.getPort().toString(), db2Configuration.getUsername(), db2Configuration.getPassword());
|
||||
dataMeta.setDatabaseType("DB2");
|
||||
transMeta.addDatabase(dataMeta);
|
||||
selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL);
|
||||
inputStep = inputStep(transMeta, selectSQL);
|
||||
udjcStep = udjc(datasetTableFields, DatasourceTypes.db2);
|
||||
break;
|
||||
case excel:
|
||||
inputStep = excelInputStep(datasetTable.getInfo(), datasetTableFields);
|
||||
udjcStep = udjc(datasetTableFields, DatasourceTypes.excel);
|
||||
|
BIN
drivers/jcc-11.5.6.0.jar
Normal file
BIN
drivers/jcc-11.5.6.0.jar
Normal file
Binary file not shown.
@ -198,6 +198,8 @@ export default {
|
||||
return 'AWS Redshift'
|
||||
} else if (type === 'hive') {
|
||||
return 'Apache Hive'
|
||||
} else if (type === 'db2') {
|
||||
return 'Db2'
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -104,14 +104,14 @@
|
||||
>
|
||||
<el-input v-model="form.configuration.port" autocomplete="off" type="number" min="0"/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type=='oracle' || form.type=='sqlServer' || form.type=='pg' || form.type=='redshift'">
|
||||
<el-form-item v-if="form.type=='oracle' || form.type=='sqlServer' || form.type=='pg' || form.type=='redshift' || form.type=='db2'">
|
||||
<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=='oracle' || form.type=='sqlServer' || form.type=='pg' || form.type=='redshift'"
|
||||
v-if="form.type=='oracle' || form.type=='sqlServer' || form.type=='pg' || form.type=='redshift' || form.type=='db2'"
|
||||
:label="$t('datasource.schema')"
|
||||
>
|
||||
<el-select
|
||||
@ -268,32 +268,19 @@ export default {
|
||||
}]
|
||||
},
|
||||
allTypes: [
|
||||
{
|
||||
name: 'mysql',
|
||||
label: 'MySQL',
|
||||
type: 'jdbc',
|
||||
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
|
||||
{name: 'mysql', label: 'MySQL', type: 'jdbc', extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
|
||||
},
|
||||
{name: 'hive', label: 'Apache Hive', type: 'jdbc', extraParams: ''},
|
||||
{name: 'oracle', label: 'Oracle', type: 'jdbc'},
|
||||
{name: 'sqlServer', label: 'SQL Server', type: 'jdbc', extraParams: ''},
|
||||
{name: 'pg', label: 'PostgreSQL', type: 'jdbc', extraParams: ''},
|
||||
{name: 'es', label: 'Elasticsearch', type: 'es'},
|
||||
{
|
||||
name: 'mariadb',
|
||||
label: 'MariaDB',
|
||||
type: 'jdbc',
|
||||
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
|
||||
},
|
||||
{
|
||||
name: 'ds_doris',
|
||||
label: 'Doris',
|
||||
type: 'jdbc',
|
||||
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
|
||||
},
|
||||
{name: 'mariadb', label: 'MariaDB', type: 'jdbc', extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'},
|
||||
{name: 'ds_doris', label: 'Doris', type: 'jdbc', extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'},
|
||||
{name: 'ck', label: 'ClickHouse', type: 'jdbc', extraParams: ''},
|
||||
{name: 'redshift', label: 'AWS Redshift', type: 'jdbc'},
|
||||
{ name: 'mongo', label: 'MongoDB', type: 'jdbc', extraParams: '' }
|
||||
{name: 'mongo', label: 'MongoDB', type: 'jdbc', extraParams: ''},
|
||||
{name: 'db2', label: 'Db2', type: 'jdbc', extraParams: ''}
|
||||
],
|
||||
schemas: [],
|
||||
canEdit: false,
|
||||
|
Loading…
Reference in New Issue
Block a user