use of com.qlangtech.tis.plugin.ds.DBConfig in project plugins by qlangtech.
the class ClickHouseSinkFactory method createSinkFunction.
@Override
public Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> createSinkFunction(IDataxProcessor dataxProcessor) {
Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> sinkFuncs = Maps.newHashMap();
IDataxProcessor.TableAlias tableName = null;
DataXClickhouseWriter dataXWriter = (DataXClickhouseWriter) dataxProcessor.getWriter(null);
Objects.requireNonNull(dataXWriter, "dataXWriter can not be null");
IDataxReader reader = dataxProcessor.getReader(null);
List<ISelectedTab> tabs = reader.getSelectedTabs();
ClickHouseDataSourceFactory dsFactory = dataXWriter.getDataSourceFactory();
DBConfig dbConfig = dsFactory.getDbConfig();
for (Map.Entry<String, IDataxProcessor.TableAlias> tabAliasEntry : dataxProcessor.getTabAlias().entrySet()) {
tableName = tabAliasEntry.getValue();
Objects.requireNonNull(tableName, "tableName can not be null");
if (StringUtils.isEmpty(tableName.getFrom())) {
throw new IllegalStateException("tableName.getFrom() can not be empty");
}
AtomicReference<SinkFunction<DTO>> sinkFuncRef = new AtomicReference<>();
final IDataxProcessor.TableAlias tabName = tableName;
AtomicReference<Object[]> exceptionLoader = new AtomicReference<>();
final String targetTabName = tableName.getTo();
dbConfig.vistDbURL(false, (dbName, jdbcUrl) -> {
try {
Optional<ISelectedTab> selectedTab = tabs.stream().filter((tab) -> StringUtils.equals(tabName.getFrom(), tab.getName())).findFirst();
if (!selectedTab.isPresent()) {
throw new IllegalStateException("target table:" + tabName.getFrom() + " can not find matched table in:[" + tabs.stream().map((t) -> t.getName()).collect(Collectors.joining(",")) + "]");
}
/**
* 需要先初始化表starrocks目标库中的表
*/
dataXWriter.initWriterTable(targetTabName, Collections.singletonList(jdbcUrl));
sinkFuncRef.set(createSinkFunction(dbName, targetTabName, selectedTab.get(), jdbcUrl, dsFactory));
} catch (Throwable e) {
exceptionLoader.set(new Object[] { jdbcUrl, e });
}
});
if (exceptionLoader.get() != null) {
Object[] error = exceptionLoader.get();
throw new RuntimeException((String) error[0], (Throwable) error[1]);
}
Objects.requireNonNull(sinkFuncRef.get(), "sinkFunc can not be null");
sinkFuncs.put(tableName, sinkFuncRef.get());
}
if (sinkFuncs.size() < 1) {
throw new IllegalStateException("size of sinkFuncs can not be small than 1");
}
return sinkFuncs;
}
use of com.qlangtech.tis.plugin.ds.DBConfig in project plugins by qlangtech.
the class StarRocksSinkFactory method createSinkFunction.
@Override
public Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> createSinkFunction(IDataxProcessor dataxProcessor) {
Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> sinkFuncs = Maps.newHashMap();
IDataxProcessor.TableAlias tableName = null;
// Map<String, IDataxProcessor.TableAlias> tabAlias = dataxProcessor.getTabAlias();
BasicDorisStarRocksWriter dataXWriter = (BasicDorisStarRocksWriter) dataxProcessor.getWriter(null);
Objects.requireNonNull(dataXWriter, "dataXWriter can not be null");
BasicDorisStarRocksWriter.Separator separator = dataXWriter.getSeparator();
IDataxReader reader = dataxProcessor.getReader(null);
List<ISelectedTab> tabs = reader.getSelectedTabs();
DorisSourceFactory dsFactory = dataXWriter.getDataSourceFactory();
DBConfig dbConfig = dsFactory.getDbConfig();
Map<String, IDataxProcessor.TableAlias> selectedTabs = dataxProcessor.getTabAlias();
if (MapUtils.isEmpty(selectedTabs)) {
throw new IllegalStateException("selectedTabs can not be empty");
}
for (Map.Entry<String, IDataxProcessor.TableAlias> tabAliasEntry : selectedTabs.entrySet()) {
tableName = tabAliasEntry.getValue();
Objects.requireNonNull(tableName, "tableName can not be null");
if (StringUtils.isEmpty(tableName.getFrom())) {
throw new IllegalStateException("tableName.getFrom() can not be empty");
}
AtomicReference<SinkFunction<DTO>> sinkFuncRef = new AtomicReference<>();
final IDataxProcessor.TableAlias tabName = tableName;
AtomicReference<Object[]> exceptionLoader = new AtomicReference<>();
final String targetTabName = tableName.getTo();
dbConfig.vistDbURL(false, (dbName, jdbcUrl) -> {
try {
Optional<ISelectedTab> selectedTab = tabs.stream().filter((tab) -> StringUtils.equals(tabName.getFrom(), tab.getName())).findFirst();
if (!selectedTab.isPresent()) {
throw new IllegalStateException("target table:" + tabName.getFrom() + " can not find matched table in:[" + tabs.stream().map((t) -> t.getName()).collect(Collectors.joining(",")) + "]");
}
/**
* 需要先初始化表starrocks目标库中的表
*/
dataXWriter.initWriterTable(targetTabName, Collections.singletonList(jdbcUrl));
sinkFuncRef.set(createSinkFunction(dbName, targetTabName, selectedTab.get(), jdbcUrl, dsFactory, separator));
} catch (Throwable e) {
exceptionLoader.set(new Object[] { jdbcUrl, e });
}
});
if (exceptionLoader.get() != null) {
Object[] error = exceptionLoader.get();
throw new RuntimeException((String) error[0], (Throwable) error[1]);
}
Objects.requireNonNull(sinkFuncRef.get(), "sinkFunc can not be null");
sinkFuncs.put(tableName, sinkFuncRef.get());
}
if (sinkFuncs.size() < 1) {
throw new IllegalStateException("size of sinkFuncs can not be small than 1");
}
return sinkFuncs;
}
use of com.qlangtech.tis.plugin.ds.DBConfig in project tis by qlangtech.
the class DBConfigParser method main.
public static void main(String[] args) throws Exception {
File f = new File("./db_config.txt");
String content = FileUtils.readFileToString(f, "utf8");
// System.out.println(content);
DBTokenizer tokenizer = new DBTokenizer(content);
tokenizer.parse();
// for (Token t : ) {
// System.out.println(t.getContent() + " "
// + t.getToken());
// }
DBConfigParser parser = new DBConfigParser(tokenizer.getTokenBuffer());
DBConfig db = parser.startParser();
System.out.println("hostDesc:" + parser.hostDesc);
System.out.println("type:" + db.getDbType());
System.out.println("name:" + db.getName());
// System.out.println("getPassword:" + db.getPassword());
// System.out.println("getPort:" + db.getPort());
// System.out.println("UserName:" + db.getUserName());
StringBuffer dbdesc = new StringBuffer();
for (Map.Entry<String, List<String>> e : db.getDbEnum().entrySet()) {
dbdesc.append(e.getKey()).append(":");
for (String dbName : e.getValue()) {
dbdesc.append(dbName).append(",");
}
dbdesc.append("\n");
}
System.out.println(dbdesc.toString());
}
use of com.qlangtech.tis.plugin.ds.DBConfig in project tis by qlangtech.
the class DBConfigParser method parseDBEnum.
/**
* Parse the dbnode description to struct Object
*
* @param dbName
* @param dbNodeDesc
* @return
*/
public static Map<String, List<String>> parseDBEnum(String dbName, String dbNodeDesc) {
if (StringUtils.isEmpty(dbNodeDesc)) {
throw new IllegalArgumentException("param dbNodeDesc can not be null");
}
if (StringUtils.isEmpty(dbName)) {
throw new IllegalArgumentException("param dbName can not be null");
}
DBTokenizer tokenizer = new DBTokenizer(ScannerPatterns.HOST_KEY + ":" + dbNodeDesc);
tokenizer.parse();
DBConfigParser parser = new DBConfigParser(tokenizer.getTokenBuffer());
parser.dbConfigResult.setName(dbName);
parser.parseHostDesc();
DBConfig db = parser.dbConfigResult;
return db.getDbEnum();
}
use of com.qlangtech.tis.plugin.ds.DBConfig in project tis by qlangtech.
the class JavaCompilerProcess method main.
public static void main(String[] args) throws Exception {
File rootDir = new File("D:\\j2ee_solution\\import_pj\\ibator_koubei\\ibator_koubei\\targett\\src\\main");
File classpathDir = new File("D:/j2ee_solution/tis-ibatis/target/dependency/");
DBConfig dbConfig = new DBConfig();
dbConfig.setName("shop");
JavaCompilerProcess compilerProcess = new JavaCompilerProcess(dbConfig, rootDir, classpathDir);
compilerProcess.compileAndBuildJar();
// JarFile jarFile = new JarFile(
// "D:\\j2ee_solution\\mvn_repository\\com\\dfire\\tis\\tis-ibatis\\2.0\\tis-ibatis-2.0.jar");
// JarEntry next = null;
// Enumeration<JarEntry> entries = jarFile.entries();
// InputStream input = null;
// while (entries.hasMoreElements()) {
// next = entries.nextElement();
//
// System.out.println(next.getName() + ",input is dir:" + next.isDirectory());
//
// }
// jarFile.close();
}
Aggregations