update: 增加 where 属性构建

This commit is contained in:
zhouhongfa 2019-08-03 00:28:29 +08:00
parent f2e8d7919e
commit 04c58285aa
5 changed files with 25 additions and 6 deletions

View File

@ -1,5 +1,8 @@
package com.wugui.tool.datax;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
/**
@ -12,11 +15,13 @@ import java.util.Map;
*/
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;
}

View File

@ -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;
@ -80,6 +83,7 @@ public class DataxJsonHelper implements DataxJsonInterface {
} else if (JdbcConstants.POSTGRESQL.equals(readerDbType)) {
readerPlugin = new PostgresqlReader();
}
readerPlugin.setExtraParams(extraParams);
}
public void initWriter(JobJdbcDatasource writerDatasource, List<String> writerTables, List<String> writerColumns) {
@ -156,4 +160,8 @@ public class DataxJsonHelper implements DataxJsonInterface {
public void setWriterPlugin(BaseDataxPlugin writerPlugin) {
this.writerPlugin = writerPlugin;
}
public void addWhereParams(String params) {
extraParams.put("where", params);
}
}

View File

@ -37,7 +37,7 @@ public interface DataxPluginInterface {
/**
* 传递一些额外的参数
*
* @return extraParams
* @return setExtraParams
*/
void extraParams(Map<String, Object> extraParams);
void setExtraParams(Map<String, Object> extraParams);
}

View File

@ -32,11 +32,16 @@ public abstract class BaseReaderPlugin extends BaseDataxPlugin {
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));

View File

@ -68,6 +68,7 @@ public class DataxJsonHelperTest {
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));
}