Search in sources :

Example 1 with GetExecuteCasRunnerContentResultTask

use of com.cubrid.cubridmanager.core.logs.task.GetExecuteCasRunnerContentResultTask in project cubrid-manager by CUBRID.

the class SqlLogAnalyzeResultDialog method createGroupQuery.

/**
	 * This method initializes groupQuery
	 */
private void createGroupQuery() {
    GridData gridData22 = new GridData(GridData.FILL_HORIZONTAL);
    gridData22.heightHint = 26;
    gridData22.widthHint = 122;
    GridData gridData21 = new GridData(GridData.FILL_BOTH);
    gridData21.horizontalSpan = 3;
    gridData21.widthHint = 432;
    gridData21.heightHint = 150;
    GridData gridData11 = new GridData(GridData.FILL_BOTH);
    gridData11.horizontalSpan = 3;
    gridData11.widthHint = 432;
    gridData11.heightHint = 250;
    GridLayout gridLayout2 = new GridLayout();
    gridLayout2.numColumns = 3;
    gridLayout2.horizontalSpacing = 45;
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.verticalSpan = 2;
    Group groupQuery = new Group(composite, SWT.NONE);
    groupQuery.setText("");
    groupQuery.setLayout(gridLayout2);
    groupQuery.setLayoutData(gridData);
    Label label1 = new Label(groupQuery, SWT.NONE);
    label1.setText(Messages.labelLogContents);
    textQuery = new Text(groupQuery, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    textQuery.setEditable(true);
    textQuery.setLayoutData(gridData11);
    Label label2 = new Label(groupQuery, SWT.NONE);
    label2.setText(Messages.labelExecuteResult);
    textQueryResult = new Text(groupQuery, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    textQueryResult.setLayoutData(gridData21);
    buttonRunOriginalQuery = new Button(groupQuery, SWT.NONE);
    buttonRunOriginalQuery.setEnabled(false);
    buttonRunOriginalQuery.setText(Messages.buttonExecuteOriginalQuery);
    Label dummy5 = new Label(groupQuery, SWT.NONE);
    dummy5.setLayoutData(gridData22);
    buttonRunOriginalQuery.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            String queryString = textQuery.getText();
            LogInfo logInfo = null;
            String targetBroker = null;
            if (node.getId().indexOf("Sql log/") < 0) {
                targetBroker = node.getParent().getLabel();
            } else {
                targetBroker = node.getParent().getParent().getLabel();
            }
            logInfo = (LogInfo) node.getAdapter(LogInfo.class);
            List<String> allDatabaseList = node.getServer().getServerInfo().getAllDatabaseList();
            BrokerInfos brokerInfos = node.getServer().getServerInfo().getBrokerInfos();
            CasRunnerConfigDialog casRunnerConfigDialog = new CasRunnerConfigDialog(getShell());
            casRunnerConfigDialog.setLogstring(queryString);
            casRunnerConfigDialog.setBrokerInfos(brokerInfos);
            casRunnerConfigDialog.setAllDatabaseList(allDatabaseList);
            casRunnerConfigDialog.setLogInfo(logInfo);
            casRunnerConfigDialog.setTargetBroker(targetBroker);
            casRunnerConfigDialog.create();
            if (casRunnerConfigDialog.open() == Dialog.OK) {
                final GetExecuteCasRunnerContentResultTask task = new GetExecuteCasRunnerContentResultTask(node.getServer().getServerInfo());
                task.setBrokerName(CasRunnerConfigDialog.getBrokerName());
                task.setUserName(CasRunnerConfigDialog.getUserName());
                task.setPasswd(CasRunnerConfigDialog.getPassword());
                task.setNumThread(CasRunnerConfigDialog.getNumThread());
                task.setRepeatCount(casRunnerConfigDialog.getNumRepeatCount());
                String isShowqueryresult = "";
                String isShowqueryplan = "";
                if (casRunnerConfigDialog.isShowqueryresult()) {
                    isShowqueryresult = "yes";
                    isShowqueryplan = casRunnerConfigDialog.isShowqueryresult() ? "yes" : "no";
                } else {
                    isShowqueryresult = "no";
                    isShowqueryplan = "no";
                }
                task.setShowQueryResult(isShowqueryresult);
                task.setShowQueryResult(isShowqueryplan);
                task.setDbName(CasRunnerConfigDialog.getDbname());
                task.setExecuteLogFile("no");
                String[] queryStringArr = queryString.split("\\r\\n");
                task.setLogstring(queryStringArr);
                TaskExecutor taskExecutor = new CommonTaskExec(Messages.loadSqlLogExecResultTaskName);
                taskExecutor.addTask(task);
                new ExecTaskWithProgress(taskExecutor).exec();
                if (taskExecutor.isSuccess()) {
                    GetExecuteCasRunnerResultInfo getExecuteCasRunnerResultInfo = (GetExecuteCasRunnerResultInfo) task.getContent();
                    StringBuffer result = new StringBuffer("");
                    for (int i = 0, n = getExecuteCasRunnerResultInfo.getResult().size(); i < n; i++) {
                        result.append(getExecuteCasRunnerResultInfo.getResult().get(i) + "\n");
                    }
                    String logPath = null;
                    String totalResultNum = null;
                    logPath = getExecuteCasRunnerResultInfo.getQueryResultFile();
                    totalResultNum = getExecuteCasRunnerResultInfo.getQueryResultFileNum();
                    if (queryString.length() > 0) {
                        textQueryResult.setText(result.toString());
                        if (casRunnerConfigDialog.isShowqueryresult()) {
                            CasRunnerResultViewDialog casRunnerResultViewDialog = new CasRunnerResultViewDialog(getShell());
                            casRunnerResultViewDialog.create();
                            casRunnerResultViewDialog.connectInit(logPath, CasRunnerConfigDialog.getDbname(), node);
                            casRunnerResultViewDialog.setTotalResultNum(Integer.parseInt(totalResultNum));
                            casRunnerResultViewDialog.getShell().setSize(665, 555);
                            casRunnerResultViewDialog.open();
                        }
                    }
                }
            }
        }
    });
    buttonSaveToFile = new Button(groupQuery, SWT.NONE);
    buttonSaveToFile.setEnabled(false);
    buttonSaveToFile.setText(Messages.buttonSaveLogString);
    buttonSaveToFile.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            String savedFilename = saveAsFile();
            if (isBlank(savedFilename)) {
                return;
            }
            if (analyzeCasLogResultList == null || analyzeCasLogResultList.getLogFileInfoList() == null) {
                return;
            }
            AnalyzeCasLogResultInfo analyzeCasLogResultInfo = (AnalyzeCasLogResultInfo) (analyzeCasLogResultList.getLogFileInfoList().get(currentResultIndex));
            if (savedFilename.length() > 0) {
                analyzeCasLogResultInfo.setSavedFileName(savedFilename);
            }
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) LogInfo(com.cubrid.cubridmanager.core.logs.model.LogInfo) GetExecuteCasRunnerResultInfo(com.cubrid.cubridmanager.core.logs.model.GetExecuteCasRunnerResultInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GetExecuteCasRunnerContentResultTask(com.cubrid.cubridmanager.core.logs.task.GetExecuteCasRunnerContentResultTask) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AnalyzeCasLogResultInfo(com.cubrid.cubridmanager.core.logs.model.AnalyzeCasLogResultInfo) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) AnalyzeCasLogResultList(com.cubrid.cubridmanager.core.logs.model.AnalyzeCasLogResultList) List(java.util.List)

Aggregations

CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)1 AnalyzeCasLogResultInfo (com.cubrid.cubridmanager.core.logs.model.AnalyzeCasLogResultInfo)1 AnalyzeCasLogResultList (com.cubrid.cubridmanager.core.logs.model.AnalyzeCasLogResultList)1 GetExecuteCasRunnerResultInfo (com.cubrid.cubridmanager.core.logs.model.GetExecuteCasRunnerResultInfo)1 LogInfo (com.cubrid.cubridmanager.core.logs.model.LogInfo)1 GetExecuteCasRunnerContentResultTask (com.cubrid.cubridmanager.core.logs.task.GetExecuteCasRunnerContentResultTask)1 List (java.util.List)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1