Search in sources :

Example 1 with ImportConfig

use of com.cubrid.common.ui.cubrid.table.dialog.imp.ImportConfig 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());
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) ImportConfig(com.cubrid.common.ui.cubrid.table.dialog.imp.ImportConfig) TableConfig(com.cubrid.common.ui.cubrid.table.dialog.imp.TableConfig) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) ImportDataEditorInput(com.cubrid.common.ui.cubrid.table.dialog.imp.ImportDataEditorInput) Map(java.util.Map) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

ImportConfig (com.cubrid.common.ui.cubrid.table.dialog.imp.ImportConfig)1 ImportDataEditorInput (com.cubrid.common.ui.cubrid.table.dialog.imp.ImportDataEditorInput)1 TableConfig (com.cubrid.common.ui.cubrid.table.dialog.imp.TableConfig)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Point (org.eclipse.swt.graphics.Point)1 PartInitException (org.eclipse.ui.PartInitException)1