Skip to content

Commit

Permalink
update: 增加 where 属性构建
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouhongfa committed Aug 2, 2019
1 parent f2e8d79 commit 04c5828
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.wugui.tool.datax;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
Expand All @@ -12,11 +15,13 @@
*/
public abstract class BaseDataxPlugin implements DataxPluginInterface {

protected Logger logger = LoggerFactory.getLogger(this.getClass());

protected Map<String, Object> extraParams;


@Override
public void extraParams(Map<String, Object> extraParams) {
public void setExtraParams(Map<String, Object> extraParams) {
this.extraParams = extraParams;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class DataxJsonHelper implements DataxJsonInterface {

private BaseDataxPlugin writerPlugin;

//用于保存额外参数
private Map<String, Object> extraParams = Maps.newHashMap();

public void initReader(JobJdbcDatasource readerDatasource, List<String> readerTables, List<String> readerColumns) {
this.readerTables = readerTables;
this.readerColumns = readerColumns;
Expand All @@ -80,6 +83,7 @@ public void initReader(JobJdbcDatasource readerDatasource, List<String> readerTa
} else if (JdbcConstants.POSTGRESQL.equals(readerDbType)) {
readerPlugin = new PostgresqlReader();
}
readerPlugin.setExtraParams(extraParams);
}

public void initWriter(JobJdbcDatasource writerDatasource, List<String> writerTables, List<String> writerColumns) {
Expand Down Expand Up @@ -156,4 +160,8 @@ public Map<String, Object> buildWriter() {
public void setWriterPlugin(BaseDataxPlugin writerPlugin) {
this.writerPlugin = writerPlugin;
}

public void addWhereParams(String params) {
extraParams.put("where", params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface DataxPluginInterface {
/**
* 传递一些额外的参数
*
* @return extraParams
* @return setExtraParams
*/
void extraParams(Map<String, Object> extraParams);
void setExtraParams(Map<String, Object> extraParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ public Map<String, Object> build(DataxPluginPojo dataxPluginPojo) {
parameterObj.put("password", jobJdbcDatasource.getJdbcPassword());
//列表
parameterObj.put("column", dataxPluginPojo.getColumns());
//

//判断是否有where
if (extraParams.containsKey("where")) {
parameterObj.put("where", extraParams.get("where"));
}

Map<String, Object> connectionObj = Maps.newLinkedHashMap();
connectionObj.put("table", dataxPluginPojo.getTables());
//where
// connectionObj.put("where", "1=1");

// logger.info(extraParams.toString());
connectionObj.put("jdbcUrl", ImmutableList.of(jobJdbcDatasource.getJdbcUrl()));

parameterObj.put("connection", ImmutableList.of(connectionObj));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void buildContent() {
public void buildReader() {
DataxJsonHelper dataxJsonHelper = new DataxJsonHelper();
dataxJsonHelper.initReader(getReaderDatasource(), ImmutableList.of("datax_plugin"), ImmutableList.of("id"));
// dataxJsonHelper.addWhereParams("1=1");
Map<String, Object> reader = dataxJsonHelper.buildReader();
System.out.println(JSONUtils.formatJson(reader));
}
Expand Down

0 comments on commit 04c5828

Please sign in to comment.