Search in sources :

Example 1 with CommonSQLExcuterTask

use of com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask in project cubrid-manager by CUBRID.

the class EditFunctionDialog method buttonPressed.

/**
	 * When press button,call it
	 *
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == BUTTON_ADD_ID) {
        Map<String, String> model = new HashMap<String, String>();
        try {
            AddFuncParamsDialog addDlg = new AddFuncParamsDialog(getShell(), model, sqlTypeMap, javaTypeMap, true, funcParamsListData, database);
            if (addDlg.open() == IDialogConstants.OK_ID) {
                // add
                funcParamsListData.add(model);
                funcParamsTableViewer.refresh();
                for (int i = 0; i < funcParamsTableViewer.getTable().getColumnCount(); i++) {
                    funcParamsTableViewer.getTable().getColumn(i).pack();
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    } else if (buttonId == BUTTON_EDIT_ID) {
        // edit
        int index = funcParamsTable.getSelectionIndex();
        if (index < 0) {
            return;
        }
        Map<String, String> map = funcParamsListData.get(index);
        AddFuncParamsDialog editDlg = new AddFuncParamsDialog(getShell(), map, sqlTypeMap, javaTypeMap, false, funcParamsListData, database);
        if (editDlg.open() == IDialogConstants.OK_ID) {
            funcParamsTableViewer.refresh();
            for (int i = 0; i < funcParamsTableViewer.getTable().getColumnCount(); i++) {
                funcParamsTableViewer.getTable().getColumn(i).pack();
            }
        }
    } else if (buttonId == BUTTON_UP_ID) {
        // up
        int index = funcParamsTable.getSelectionIndex();
        if (index <= 0) {
            return;
        }
        Map<String, String> map = funcParamsListData.get(index);
        Map<String, String> preMap = funcParamsListData.get(index - 1);
        funcParamsListData.set(index - 1, map);
        funcParamsListData.set(index, preMap);
        funcParamsTableViewer.refresh();
    } else if (buttonId == BUTTON_DOWN_ID) {
        // down
        int index = funcParamsTable.getSelectionIndex();
        if (index < 0 || index >= funcParamsListData.size() - 1) {
            return;
        }
        Map<String, String> map = funcParamsListData.get(index);
        Map<String, String> nextMap = funcParamsListData.get(index + 1);
        funcParamsListData.set(index + 1, map);
        funcParamsListData.set(index, nextMap);
        funcParamsTableViewer.refresh();
    } else if (buttonId == BUTTON_DROP_ID) {
        // drop
        int index = funcParamsTable.getSelectionIndex();
        if (index < 0) {
            return;
        }
        funcParamsListData.remove(index);
        funcParamsTableViewer.refresh();
        getButton(BUTTON_EDIT_ID).setEnabled(false);
        getButton(BUTTON_UP_ID).setEnabled(false);
        getButton(BUTTON_DOWN_ID).setEnabled(false);
        getButton(BUTTON_DROP_ID).setEnabled(false);
    } else if (buttonId == IDialogConstants.OK_ID) {
        if (valid()) {
            CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
            functionName = funcNameText.getText();
            if (!newFlag) {
                String dropSql = "DROP FUNCTION " + QuerySyntax.escapeKeyword(funcNameText.getText());
                task.addSqls(dropSql);
            }
            task.addSqls(getSQLScript());
            execute(IDialogConstants.OK_ID, new ITask[] { task });
        }
        return;
    }
    super.buttonPressed(buttonId);
}
Also used : ITask(com.cubrid.common.core.task.ITask) HashMap(java.util.HashMap) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 2 with CommonSQLExcuterTask

use of com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask in project cubrid-manager by CUBRID.

the class DropTriggerAction method run.

public void run(ISchemaNode[] nodeArray) {
    // FIXME move this logic to core module
    if (nodeArray == null) {
        LOGGER.error("The nodeArray is a null.");
        return;
    }
    List<String> triggerNameList = new ArrayList<String>();
    StringBuffer bf = new StringBuffer();
    for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
        DefaultSchemaNode trigger = (DefaultSchemaNode) nodeArray[i];
        triggerNameList.add(trigger.getName());
        if (i == 0) {
            bf.append(trigger.getName());
        }
    }
    if (nodeArray.length > 1) {
        bf.append(", ...");
    }
    String cfmMsg = Messages.bind(Messages.dropTriggerWarnMSG1, nodeArray.length, bf.toString());
    boolean ret = CommonUITool.openConfirmBox(cfmMsg);
    if (!ret) {
        return;
    }
    ISchemaNode triggerNode = (ISchemaNode) nodeArray[0];
    CommonSQLExcuterTask task = new CommonSQLExcuterTask(triggerNode.getDatabase().getDatabaseInfo());
    for (String triggerName : triggerNameList) {
        String sql = "DROP TRIGGER " + QuerySyntax.escapeKeyword(triggerName);
        task.addSqls(sql);
    }
    String taskName = Messages.bind(Messages.dropTriggerTaskName, bf.toString());
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    String title = com.cubrid.common.ui.common.Messages.titleSuccess;
    String msg = Messages.dropTriggerSuccessMsg;
    CommonUITool.openInformationBox(title, msg);
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = triggerNode.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
            parent.removeChild((ISchemaNode) nodeArray[i]);
        }
        viewer.remove(parent, nodeArray);
        viewer.setSelection(new StructuredSelection(parent), true);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Example 3 with CommonSQLExcuterTask

use of com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask in project cubrid-manager by CUBRID.

the class DeleteProcedureAction method run.

public void run() {
    // FIXME logic code move to core module
    Object[] objects = this.getSelectedObj();
    if (objects == null || !isSupported(objects)) {
        this.setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objects[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_PROCEDURE.equals(((ISchemaNode) objects[0]).getType())) {
        node = (ISchemaNode) objects[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
        return;
    }
    if (!CommonUITool.openConfirmBox(shell, Messages.msgSureDropProcedure)) {
        return;
    }
    CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
    String sql = " DROP PROCEDURE " + QuerySyntax.escapeKeyword(node.getName());
    task.addSqls(sql);
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = node.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; objects != null && i < objects.length; i++) {
            parent.removeChild((ISchemaNode) objects[i]);
        }
        viewer.remove(parent, objects);
        viewer.setSelection(new StructuredSelection(parent), true);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with CommonSQLExcuterTask

use of com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask in project cubrid-manager by CUBRID.

the class TableEditorPart method okPressed.

protected void okPressed() {
    if (!verifyTableName()) {
        return;
    }
    if (columnsTable.getItemCount() == 0) {
        CommonUITool.openErrorBox(Messages.noAttributes);
        return;
    }
    String message = (oldSchemaInfo == null) ? Messages.msgCreateTableConfirm : Messages.msgAlterTableConfirm;
    if (!CommonUITool.openConfirmBox(message)) {
        return;
    }
    tableName = tableNameText.getText();
    owner = ownerCombo.getText();
    String tableDesc = tableDescText.getText();
    newSchemaInfo.setClassname(tableName);
    newSchemaInfo.setOwner(owner);
    newSchemaInfo.setDescription(tableDesc);
    if (reuseOIDBtn != null) {
        newSchemaInfo.setReuseOid(reuseOIDBtn.getSelection());
    }
    DatabaseInfo dbInfo = database.getDatabaseInfo();
    CommonSQLExcuterTask commonSqlTask = new CommonSQLExcuterTask(dbInfo);
    schemaDDL.setEndLineChar("$$$$");
    String ddlStr = null;
    if (isNewTableFlag) {
        ddlStr = schemaDDL.getSchemaDDL(newSchemaInfo);
    } else {
        ddlStr = schemaDDL.getSchemaDDL(oldSchemaInfo, newSchemaInfo);
    }
    boolean isExecuteCommonSqlTask = false;
    String[] sqlStr = ddlStr.split("\\$\\$\\$\\$");
    for (String sql : sqlStr) {
        String trimSql = sql.trim();
        if (trimSql.length() > 0 && !trimSql.startsWith("--")) {
            if (dbInfo.isShard()) {
                sql = dbInfo.wrapShardQuery(sql);
            }
            commonSqlTask.addSqls(sql);
            isExecuteCommonSqlTask = true;
        }
    }
    // do with table user change
    String changeOwnerDDL = getChangeOwnerDDL();
    if (StringUtil.isNotEmpty(changeOwnerDDL)) {
        changeOwnerDDL = dbInfo.wrapShardQuery(changeOwnerDDL);
        commonSqlTask.addCallSqls(changeOwnerDDL);
        isExecuteCommonSqlTask = true;
    }
    schemaDDL.setEndLineChar(";");
    // do with column null attribute change
    List<String[]> nullAttrChangedColumnList = getNotNullChangedColumn();
    // if the column is null value, when set this column for not null,need
    // change these null value for default value
    List<String> nullToDefaultChangedColumnList = new ArrayList<String>();
    List<String> defaultValList = new ArrayList<String>();
    if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
        for (Iterator<String[]> it = nullAttrChangedColumnList.iterator(); it.hasNext(); ) {
            String[] column = it.next();
            if (!Boolean.parseBoolean(column[1])) {
                continue;
            }
            nullToDefaultChangedColumnList.add(column[0]);
        }
        // if the column is null value, when set this column for not null,do
        // not need change these null value for default value
        List<String> keepNullValueColList = new ArrayList<String>();
        for (Iterator<String> it = nullToDefaultChangedColumnList.iterator(); it.hasNext(); ) {
            String nullColumn = it.next();
            DBAttribute dBAttribute = newSchemaInfo.getDBAttributeByName(nullColumn, false);
            if (dBAttribute == null) {
                continue;
            }
            String defaultVal = dBAttribute.getDefault();
            boolean isUnique = dBAttribute.isUnique();
            if (isUnique) {
                keepNullValueColList.add(nullColumn);
                it.remove();
            } else {
                if (defaultVal == null) {
                    keepNullValueColList.add(nullColumn);
                    it.remove();
                    continue;
                } else {
                    FormatDataResult result = DBAttrTypeFormatter.formatForInput(dBAttribute.getType(), defaultVal, false);
                    if (result.isSuccess()) {
                        defaultValList.add(result.getFormatResult());
                    }
                }
            }
        }
        String msg = Messages.bind(Messages.confirmSetDef, nullToDefaultChangedColumnList);
        if (!nullToDefaultChangedColumnList.isEmpty() && (!CommonUITool.openConfirmBox(msg))) {
            return;
        }
        msg = Messages.bind(Messages.confirmKeepNull, keepNullValueColList);
        if (!keepNullValueColList.isEmpty() && (!CommonUITool.openConfirmBox(msg))) {
            return;
        }
    }
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(this);
    boolean hasChanges = isExecuteCommonSqlTask || !nullAttrChangedColumnList.isEmpty() || !nullToDefaultChangedColumnList.isEmpty();
    if (hasChanges) {
        if (isExecuteCommonSqlTask) {
            taskJobExec.addTask(commonSqlTask);
        }
        if (database == null || newSchemaInfo == null) {
            return;
        }
        // change all table data from null value to default value
        int nullColSize = nullToDefaultChangedColumnList.size();
        for (int colIndex = 0; colIndex < nullColSize; colIndex++) {
            UpdateNullToDefault updateNullToDefault = new UpdateNullToDefault(dbInfo);
            updateNullToDefault.setTable(tableName);
            updateNullToDefault.setColumn(nullToDefaultChangedColumnList.get(colIndex));
            updateNullToDefault.setDefaultValue(defaultValList.get(colIndex));
            taskJobExec.addTask(updateNullToDefault);
        }
    }
    List<UpdateDescriptionTask> updateDescriptionTaskList = getUpdateDescriptionTaskList(dbInfo);
    for (UpdateDescriptionTask task : updateDescriptionTaskList) {
        taskJobExec.addTask(task);
    }
    if (taskJobExec.getTaskCount() > 0) {
        String serverName = database.getServer().getName();
        String dbName = database.getDatabaseInfo().getDbName();
        String title = getSite().getShell().getText();
        jobName = title + " - " + tableName + "@" + dbName;
        JobFamily jobFamily = new JobFamily();
        jobFamily.setServerName(serverName);
        jobFamily.setDbName(dbName);
        taskJobExec.schedule(jobName, jobFamily, true, Job.SHORT);
    } else {
        getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
    }
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Constraint(com.cubrid.common.core.common.model.Constraint) FormatDataResult(com.cubrid.cubridmanager.core.cubrid.table.model.FormatDataResult) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) UpdateNullToDefault(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateNullToDefault) UpdateDescriptionTask(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateDescriptionTask)

Example 5 with CommonSQLExcuterTask

use of com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask in project cubrid-manager by CUBRID.

the class DeleteFunctionAction method run.

public void run() {
    // FIXME logic code move to core module
    Object[] objects = this.getSelectedObj();
    if (objects == null || !isSupported(objects)) {
        setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objects[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_FUNCTION.equals(((ISchemaNode) objects[0]).getType())) {
        node = (ISchemaNode) objects[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectFunction);
        return;
    }
    if (!CommonUITool.openConfirmBox(shell, Messages.msgSureDropFunction)) {
        return;
    }
    CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
    for (Object object : objects) {
        node = (ISchemaNode) object;
        String sql = "DROP FUNCTION " + QuerySyntax.escapeKeyword(node.getName());
        task.addSqls(sql);
    }
    TaskExecutor taskExcutor = new CommonTaskExec(getText());
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = node.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; objects != null && i < objects.length; i++) {
            parent.removeChild((ISchemaNode) objects[i]);
        }
        viewer.remove(parent, objects);
        viewer.setSelection(new StructuredSelection(parent), true);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

CommonSQLExcuterTask (com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask)9 ITask (com.cubrid.common.core.task.ITask)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)3 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)3 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)3 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 Shell (org.eclipse.swt.widgets.Shell)2 Constraint (com.cubrid.common.core.common.model.Constraint)1 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)1 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)1