use of com.cubrid.common.ui.cubrid.table.dialog.imp.ImportDataEditorInput in project cubrid-manager by CUBRID.
the class FavoriteQueryNavigatorView method executeSql.
/**
* Execute selected queries
*/
private void executeSql() {
CubridDatabase cubridDatabase = getCurrentDatabase();
if (cubridDatabase == null || cubridDatabase.getDatabaseInfo() == null) {
CommonUITool.openErrorBox(com.cubrid.common.ui.query.Messages.errNoConnectionBatchRun);
return;
}
// Judge the file is exist
int[] indexes = tv.getTable().getSelectionIndices();
List<Map<String, String>> list = FavoriteQueryPersistUtil.getInstance().getListData();
for (int i = 0; i < indexes.length; i++) {
Map<String, String> item = list.get(indexes[i]);
String filename = item.get("1");
String fullpath = item.get("4") + File.separator + filename;
if (!new File(fullpath).exists()) {
String msg = Messages.bind(com.cubrid.common.ui.query.Messages.errFileNotExist, fullpath);
CommonUITool.openErrorBox(msg);
return;
}
}
String targetDbName = cubridDatabase.getDatabaseInfo().getDbName() + "@" + cubridDatabase.getServer().getServerInfo().getHostAddress();
String msg = Messages.bind(com.cubrid.common.ui.query.Messages.msgDoYouWantExecuteSql, targetDbName);
if (!CommonUITool.openConfirmBox(msg)) {
return;
}
String charset = StringUtil.getDefaultCharset();
ImportConfig importConfig = new ImportConfig();
importConfig.setImportType(ImportConfig.IMPORT_FROM_SQL);
importConfig.setThreadCount(1);
importConfig.setCommitLine(100);
Set<String> charsets = new HashSet<String>();
for (int i = 0; i < indexes.length; i++) {
Map<String, String> item = list.get(indexes[i]);
String filename = item.get("1");
String fullpath = item.get("4") + File.separator + filename;
charset = item.get("5");
if (StringUtil.isEmpty(charset)) {
charset = StringUtil.getDefaultCharset();
} else {
charsets.add(charset);
}
TableConfig fileConfig = new TableConfig(filename);
fileConfig.setFilePath(fullpath);
fileConfig.setFileType(TableConfig.TYPE_DATA);
importConfig.addTableConfig(fileConfig);
}
importConfig.setFilesCharset(charset);
if (charsets.size() > 1) {
msg = Messages.bind(com.cubrid.common.ui.query.Messages.msgDoYouWantExecuteWithNotSameCharset, charset);
if (!CommonUITool.openConfirmBox(msg)) {
return;
}
}
ImportDataEditorInput input = new ImportDataEditorInput();
input.setDatabase(cubridDatabase);
input.setImportConfig(importConfig);
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, ImportDataViewPart.ID);
} catch (Exception e) {
CommonUITool.openErrorBox(Display.getCurrent().getActiveShell(), e.getMessage());
}
}
Aggregations