com.xxdb.route.AutoFitTableAppender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dolphindb-javaapi Show documentation
Show all versions of dolphindb-javaapi Show documentation
The messaging and data conversion protocol between Java and DolphinDB server
package com.xxdb.route;
import com.xxdb.DBConnection;
import com.xxdb.data.*;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class AutoFitTableAppender {
enum APPEND_ACTION {fitColumnType}
String dbUrl_;
String tableName_;
boolean async_;
DBConnection con_;
APPEND_ACTION _action;
public AutoFitTableAppender(String dbUrl, String tableName, DBConnection conn) {
this.dbUrl_ = dbUrl;
this.tableName_ = tableName;
this.con_ = conn;
this._action = APPEND_ACTION.fitColumnType;
}
public AutoFitTableAppender(String dbUrl, String tableName, DBConnection conn, APPEND_ACTION action) {
this.dbUrl_ = dbUrl;
this.tableName_ = tableName;
this.con_ = conn;
this._action = action;
}
public String getDTString(Entity.DATA_TYPE type) {
switch (type) {
case DT_ANY:
return "ANY";
case DT_BLOB:
return "BLOB";
case DT_BOOL:
return "BOOL";
case DT_BYTE:
return "BYTE";
case DT_CODE:
return "CODE";
case DT_COMPRESS:
return "COMPRESSED";
case DT_DATASOURCE:
return "DATASOURCE";
case DT_DATE:
return "DATE";
case DT_DATEHOUR:
return "DATEHOUR";
case DT_DATEMINUTE:
return "DATEMINUTE";
case DT_DATETIME:
return "DATETIME";
case DT_DICTIONARY:
return "DICTIONARY";
case DT_DOUBLE:
return "DOUBLE";
case DT_FLOAT:
return "FLOAT";
case DT_FUNCTIONDEF:
return "FUNCTIONDEF";
case DT_HANDLE:
return "HANDLE";
case DT_INT:
return "INT";
case DT_INT128:
return "INT128";
case DT_IPADDR:
return "IPADDR";
case DT_LONG:
return "LONG";
case DT_MINUTE:
return "MINUTE";
case DT_MONTH:
return "MONTH";
case DT_NANOTIME:
return "NANOTIME";
case DT_NANOTIMESTAMP:
return "NANOTIMESTAMP";
case DT_OBJECT:
return "OBJECT";
case DT_STRING:
return "STRING";
case DT_RESOURCE:
return "RESOURCE";
case DT_SECOND:
return "SECOND";
case DT_SHORT:
return "SHORT";
case DT_SYMBOL:
return "SYMBOL";
case DT_TIME:
return "TIME";
case DT_TIMESTAMP:
return "TIMESTAMP";
case DT_UUID:
return "UUID";
case DT_VOID:
return "VOID";
}
return "Unrecognized type";
}
public Entity append(BasicTable table) {
Entity ret=new BasicBoolean(false);
try {
String runScript;
if(dbUrl_=="")
runScript="schema(" + tableName_ + ")";
else
runScript="schema(loadTable(\"" + dbUrl_ + "\",\"" + tableName_ + "\"))";
ret = con_.run(runScript);
int columns = table.columns();
BasicTable schema = (BasicTable)((BasicDictionary)ret).get(new BasicString("colDefs"));
BasicStringVector typeList = (BasicStringVector) schema.getColumn("typeString");
BasicStringVector nameList = (BasicStringVector) schema.getColumn("name");
List colName = new ArrayList<>();
List cols = new ArrayList<>();
for(int i=0;i param = new ArrayList();
BasicTable paramTable = new BasicTable(colName, cols);
param.add(paramTable);
if(dbUrl_=="")
ret = con_.run("append!{" + tableName_ + "}", param);
else
ret = con_.run("append!{loadTable(\"" + dbUrl_ + "\",\"" + tableName_ + "\"), }", param);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ret;
}
}