Search in sources :

Example 6 with CommonSQLExcuterTask

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

the class EditProcedureDialog 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, procParamsListData, database);
            if (addDlg.open() == IDialogConstants.OK_ID) {
                // add
                procParamsListData.add(model);
                procParamsTableViewer.refresh();
                for (int i = 0; i < procParamsTableViewer.getTable().getColumnCount(); i++) {
                    procParamsTableViewer.getTable().getColumn(i).pack();
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    } else if (buttonId == BUTTON_EDIT_ID) {
        // edit
        int index = procParamsTable.getSelectionIndex();
        if (index < 0) {
            return;
        }
        Map<String, String> map = procParamsListData.get(index);
        AddFuncParamsDialog editDlg = new AddFuncParamsDialog(getShell(), map, sqlTypeMap, javaTypeMap, false, procParamsListData, database);
        if (editDlg.open() == IDialogConstants.OK_ID) {
            procParamsTableViewer.refresh();
            for (int i = 0; i < procParamsTableViewer.getTable().getColumnCount(); i++) {
                procParamsTableViewer.getTable().getColumn(i).pack();
            }
        }
    } else if (buttonId == BUTTON_UP_ID) {
        // up
        int index = procParamsTable.getSelectionIndex();
        if (index <= 0) {
            return;
        }
        Map<String, String> map = procParamsListData.get(index);
        Map<String, String> preMap = procParamsListData.get(index - 1);
        procParamsListData.set(index - 1, map);
        procParamsListData.set(index, preMap);
        procParamsTableViewer.refresh();
    } else if (buttonId == BUTTON_DOWN_ID) {
        // down
        int index = procParamsTable.getSelectionIndex();
        if (index < 0 || index >= procParamsListData.size() - 1) {
            return;
        }
        Map<String, String> map = procParamsListData.get(index);
        Map<String, String> nextMap = procParamsListData.get(index + 1);
        procParamsListData.set(index + 1, map);
        procParamsListData.set(index, nextMap);
        procParamsTableViewer.refresh();
    } else if (buttonId == BUTTON_DROP_ID) {
        // drop
        int index = procParamsTable.getSelectionIndex();
        if (index < 0) {
            return;
        }
        procParamsListData.remove(index);
        procParamsTableViewer.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()) {
            procedureName = procNameText.getText();
            CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
            if (!newFlag) {
                String dropSql = "DROP PROCEDURE " + QuerySyntax.escapeKeyword(procNameText.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) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 7 with CommonSQLExcuterTask

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

the class CreateViewDialog method buttonPressed.

protected void buttonPressed(int buttonId) {
    if (buttonId == BUTTON_ADD_ID) {
        // add
        AddQueryDialog addDlg = new AddQueryDialog(parentComp.getShell(), true, -1, this);
        if (addDlg.open() == IDialogConstants.OK_ID) {
            queryTableViewer.getTable().setSelection(queryTableViewer.getTable().getItemCount() - 1);
            querydescText.setText(formatSql(queryTableViewer.getTable().getItem(queryTableViewer.getTable().getItemCount() - 1).getText()));
        }
        queryTableViewer.getTable().getColumn(0).setWidth(200);
        setButtonStatus();
        valid();
        return;
    } else if (buttonId == BUTTON_DROP_ID) {
        // delete
        int index = queryTableViewer.getTable().getSelectionIndex();
        queryListData.remove(index);
        queryTableViewer.refresh();
        if (queryListData.size() > index) {
            queryTableViewer.getTable().setSelection(index);
            querydescText.setText(formatSql(queryTableViewer.getTable().getItem(index).getText()));
        } else if (index > 0) {
            queryTableViewer.getTable().setSelection(index - 1);
            querydescText.setText(formatSql(queryTableViewer.getTable().getItem(index - 1).getText()));
        } else {
            queryTableViewer.getTable().setSelection(index - 1);
            querydescText.setText("");
        }
        validateResult(null, false, -1);
        setButtonStatus();
        valid();
        return;
    } else if (buttonId == BUTTON_EDIT_ID) {
        StringBuffer sb = new StringBuffer();
        int index = queryTableViewer.getTable().getSelectionIndex();
        sb.append(queryListData.get(index).get("0"));
        AddQueryDialog addDlg = new AddQueryDialog(parentComp.getShell(), false, index, this);
        if (addDlg.open() == IDialogConstants.OK_ID) {
            // add
            queryTableViewer.getTable().setSelection(index);
            String sql = queryTableViewer.getTable().getItem(index).getText();
            querydescText.setText(formatSql(sql));
        }
        setButtonStatus();
        valid();
        return;
    } else if (buttonId == IDialogConstants.OK_ID) {
        if (!valid()) {
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        owner = ownerCombo.getText();
        Map<String, ClassAuthorizations> authMap = getDropViewAuthorizations();
        CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
        String dropSql = makeDropSQLScript();
        if (dropSql.length() > 0) {
            dropSql = DatabaseInfo.wrapShardQuery(databaseInfo, dropSql);
            task.addSqls(dropSql);
        }
        String sql = makeCreateSQLScript();
        sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
        task.addSqls(sql);
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        String ownerOld = dbInfo.getAuthLoginedDbUserInfo().getName();
        String ownerNew = ownerCombo.getText();
        boolean isSameOwner = StringUtil.isEqualIgnoreCase(ownerOld, ownerNew);
        if (!isSameOwner) {
            sql = makeChangeOwnerSQLScript();
            sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
            task.addCallSqls(sql);
        }
        addGrantAuthSQLScriptToTask(authMap, tableText.getText(), task);
        execTask(-1, new ITask[] { task }, true, getParentShell());
        if (task.getErrorMsg() != null) {
            return;
        }
        String title = com.cubrid.common.ui.common.Messages.titleSuccess;
        String message = isNewTableFlag ? Messages.msgSuccessCreateView : Messages.msgSuccessEditView;
        CommonUITool.openInformationBox(title, message);
    }
    viewName = tableText.getText();
    super.buttonPressed(buttonId);
}
Also used : ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with CommonSQLExcuterTask

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

the class CommonSqlExcuteTaskTest method testCommonSqlExcuteTask.

public void testCommonSqlExcuteTask() {
    String tableName = "assdfafa";
    GetAllClassListTask classTask = new GetAllClassListTask(databaseInfo);
    classTask.setTableName(tableName);
    classTask.getClassInfoTaskExcute();
    ClassInfo classInfo = classTask.getClassInfo();
    CommonSQLExcuterTask task1 = new CommonSQLExcuterTask(databaseInfo);
    if (classInfo == null) {
        task1.addSqls("create table " + tableName);
        task1.addCallSqls("call change_owner ('" + tableName + "','public') on class db_authorizations");
    } else {
        task1.addCallSqls("call change_owner ('" + tableName + "','public') on class db_authorizations");
    }
    task1.addSqls("create table " + "tableName");
    task1.addCallSqls("call change_owner ('" + "tableName" + "','public') on class db_authorizations");
    task1.execute();
    //assertEquals(null, task1.getErrorMsg());
    task1 = new CommonSQLExcuterTask(databaseInfo);
    task1.addSqls("drop table assdfafa");
    task1.addSqls("drop table tableName");
    task1.execute();
    System.out.println(task1.getErrorMsg());
    assertEquals(null, task1.getErrorMsg());
    task1.setErrorMsg("err");
    task1.execute();
    final CommonSQLExcuterTask task3 = new CommonSQLExcuterTask(databaseInfo);
    task3.cancel();
    task3.execute();
}
Also used : GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 9 with CommonSQLExcuterTask

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

the class GetSPInfoListTaskTest method testCommonSqlExcuteTask.

public void testCommonSqlExcuteTask() {
    CommonSQLExcuterTask task1 = new CommonSQLExcuterTask(databaseInfo);
    task1.addSqls("CREATE FUNCTION \"sssssss\"(\"sss\" CHAR) RETURN CHAR AS LANGUAGE JAVA NAME '111.d(java.sql.Timestamp) return java.lang.String'");
    task1.execute();
    assertEquals(null, task1.getErrorMsg());
    GetSPInfoListTask task = new GetSPInfoListTask(databaseInfo);
    task.setSpName("sssssss");
    task.setSpType(SPType.FUNCTION);
    task.execute();
    assertTrue(task.getSPInfoList().size() == 1);
    assertEquals(false, task.isCancel());
    task = new GetSPInfoListTask(databaseInfo);
    task.setSpType(SPType.FUNCTION);
    task.execute();
    assertTrue(task.getSPInfoList().size() == 1);
    assertEquals(false, task.isCancel());
    task = new GetSPInfoListTask(databaseInfo);
    task.execute();
    assertTrue(task.getSPInfoList().size() == 1);
    assertEquals(false, task.isCancel());
    task1 = new CommonSQLExcuterTask(databaseInfo);
    task1.addSqls("CREATE PROCEDURE \"aaaa\"(\"a\" BIGINT,\"v\" OUT BIGINT,\"r\" INOUT BIGINT) AS LANGUAGE JAVA NAME 'a.a(java.lang.String,java.lang.String,java.lang.String)'");
    task1.execute();
    final GetSPInfoListTask task2 = new GetSPInfoListTask(databaseInfo);
    task2.setSpName("aaaa");
    task2.setSpType(SPType.PROCEDURE);
    task2.execute();
    task1 = new CommonSQLExcuterTask(databaseInfo);
    task1.addSqls("drop FUNCTION \"sssssss\"");
    task1.execute();
    assertEquals(null, task1.getErrorMsg());
    task1 = new CommonSQLExcuterTask(databaseInfo);
    task1.addSqls("drop PROCEDURE \"aaaa\"");
    task1.execute();
    task.setErrorMsg("err");
    task.execute();
    final GetSPInfoListTask task3 = new GetSPInfoListTask(databaseInfo);
    task3.cancel();
    task3.execute();
}
Also used : CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

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