Search in sources :

Example 11 with GetAllClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask in project cubrid-manager by CUBRID.

the class EditUserAction method doRun.

/**
	 * Perform do run
	 *
	 * @param node
	 */
public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    EditUserDialog dlg = new EditUserDialog(shell);
    Connection con = null;
    try {
        con = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo(), con);
        final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo(), con);
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo(), con);
        DbUserInfoList userListInfo = null;
        try {
            userListInfo = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
            return;
        }
        boolean isSuccess = dlg.execTask(-1, new ITask[] { classInfoTask, partitionTask }, getShell());
        if (!isSuccess) {
            return;
        }
        dlg.setUserListInfo(userListInfo);
        dlg.setDatabase(database);
        dlg.setUserName(node.getName());
        dlg.setPartitionClassMap(partitionTask.getPartitionClassMap());
        dlg.setNewFlag(false);
        GetUserAuthorizationsTask privilegeTask = new GetUserAuthorizationsTask(database.getDatabaseInfo(), con);
        try {
            for (DbUserInfo userInfo : userListInfo.getUserList()) {
                userInfo.setUserAuthorizations(privilegeTask.getUserAuthorizations(userInfo.getName()));
            }
        } catch (Exception e) {
            LOGGER.error("get user failed", e);
            return;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        QueryUtil.freeQuery(con);
    }
    if (dlg.open() == IDialogConstants.OK_ID) {
        if (database.getServer() != null) {
            persisteManager.updateDBPassword(database.getServer().getServerName(), database.getServer().getHostAddress(), database.getServer().getMonPort(), database.getDatabaseInfo().getDbName(), database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName(), dlg.getInputtedPassword(), database.isAutoSavePassword());
        }
        CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
        if (navigationView != null) {
            TreeViewer treeViewer = navigationView.getViewer();
            if (treeViewer != null) {
                DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
                if (userInfo != null && userInfo.getName().equalsIgnoreCase(node.getName())) {
                    CommonUITool.openInformationBox(Messages.titleLogout, Messages.msgLogoutInfomation);
                    database.setLogined(false);
                    database.setAutoSavePassword(false);
                    CubridNodeChangedEvent event = new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT);
                    CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                    database.removeAllChild();
                    treeViewer.refresh(database, true);
                } else {
                    CommonUITool.refreshNavigatorTree(treeViewer, node.getParent());
                    setEnabled(false);
                }
            }
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        persisteManager.savaAllServers();
        persisteManager.saveAllGroupNodes();
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Connection(java.sql.Connection) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) EditUserDialog(com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog) GetUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 12 with GetAllClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask in project cubrid-manager by CUBRID.

the class EditUserDialog method execTask.

public boolean execTask(final int buttonId, final ITask[] tasks, Shell shell) {
    final Display display = Display.getCurrent();
    TaskExecutor taskExecutor = new TaskExecutor() {

        public boolean exec(IProgressMonitor monitor) {
            for (ITask task : tasks) {
                if (task instanceof GetAllClassListTask) {
                    setAllClassInfoList(((GetAllClassListTask) task).getAllClassInfoList());
                } else {
                    task.execute();
                }
                if (openErrorBox(null, task.getErrorMsg(), monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            if (!monitor.isCanceled()) {
                display.syncExec(new Runnable() {

                    public void run() {
                        if (buttonId > 0) {
                            setReturnCode(buttonId);
                            close();
                        }
                    }
                });
            }
            return true;
        }
    };
    for (ITask task : tasks) {
        taskExecutor.addTask(task);
    }
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    return taskExecutor.isSuccess();
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) Display(org.eclipse.swt.widgets.Display)

Example 13 with GetAllClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask in project cubrid-manager by CUBRID.

the class AddUserAction method doRun.

/**
	 * Perform do run
	 *
	 * @param node
	 */
public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    //		if (database.getDatabaseInfo().isHAMode()) {
    //			CommonUITool.openErrorBox(Messages.errNoSupportInHA);
    //			return;
    //		}
    String childId = database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridNodeLoader.USERS_FOLDER_ID;
    ICubridNode folderNode = database.getChild(childId);
    if (folderNode == null) {
        return;
    }
    EditUserDialog dlg = new EditUserDialog(getShell());
    Connection con = null;
    try {
        con = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo(), con);
        final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo(), con);
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo(), con);
        DbUserInfoList userListInfo = null;
        try {
            userListInfo = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
            return;
        }
        boolean isSuccess = dlg.execTask(-1, new ITask[] { classInfoTask, partitionTask }, getShell());
        if (!isSuccess) {
            return;
        }
        dlg.setUserListInfo(userListInfo);
        dlg.setDatabase(database);
        dlg.setUserName(node.getName());
        dlg.setPartitionClassMap(partitionTask.getPartitionClassMap());
        dlg.setNewFlag(true);
        GetUserAuthorizationsTask privilegeTask = new GetUserAuthorizationsTask(database.getDatabaseInfo(), con);
        try {
            for (DbUserInfo userInfo : userListInfo.getUserList()) {
                if (userInfo.getName().equals(node.getName())) {
                    userInfo.setUserAuthorizations(privilegeTask.getUserAuthorizations(userInfo.getName()));
                }
            }
        } catch (Exception e) {
            LOGGER.error("get user failed", e);
            return;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        QueryUtil.freeQuery(con);
    }
    if (dlg.open() == IDialogConstants.OK_ID) {
        //Don't count the child
        if (!folderNode.getLoader().isLoaded()) {
            return;
        }
        CubridNavigatorView navigatorView = CubridNavigatorView.findNavigationView();
        if (navigatorView != null) {
            TreeViewer treeViewer = navigatorView.getViewer();
            if (treeViewer != null) {
                CubridNodeChangedEvent event = new CubridNodeChangedEvent(folderNode, CubridNodeChangedEventType.NODE_REFRESH);
                CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
            } else {
                CommonUITool.refreshNavigatorTree(treeViewer, node.getParent());
                setEnabled(false);
            }
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Connection(java.sql.Connection) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) EditUserDialog(com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog) GetUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 14 with GetAllClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask 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 15 with GetAllClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask in project cubrid-manager by CUBRID.

the class EditViewAction method run.

/**
	 * run edit view
	 * @param ISchemaNode viewNode
	 * @param database CubridDatabase
	 */
public int run(CubridDatabase database, ISchemaNode node) {
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, false);
    GetAllClassListTask getAllClassListTask = new GetAllClassListTask(database.getDatabaseInfo());
    getAllClassListTask.setTableName(node.getName());
    GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(database.getDatabaseInfo());
    getAllDBVclassTask.setClassName(node.getName());
    GetAllAttrTask getAllAttrTask = new GetAllAttrTask(database.getDatabaseInfo());
    getAllAttrTask.setClassName(node.getName());
    JDBCGetAllDbUserTask getAllDbUserTask = new JDBCGetAllDbUserTask(database.getDatabaseInfo());
    dialog.execTask(-1, new ITask[] { getAllClassListTask, getAllDBVclassTask, getAllAttrTask, getAllDbUserTask }, true, getShell());
    if (getAllClassListTask.getErrorMsg() != null || getAllDBVclassTask.getErrorMsg() != null || getAllAttrTask.getErrorMsg() != null || getAllDbUserTask.getErrorMsg() != null || getAllClassListTask.isCancel() || getAllDBVclassTask.isCancel() || getAllAttrTask.isCancel() || getAllDbUserTask.isCancel()) {
        return IDialogConstants.CANCEL_ID;
    }
    ClassInfo classInfo = getAllClassListTask.getClassInfo();
    List<String> vclassList = getAllDBVclassTask.getAllVclassList();
    List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
    List<String> dbUserList = getAllDbUserTask.getDbUserList();
    dialog.setAttrList(attrList);
    dialog.setClassInfo(classInfo);
    dialog.setVclassList(vclassList);
    dialog.setDbUserList(dbUserList);
    if (dialog.open() == IDialogConstants.OK_ID) {
        String viewName = node.getName();
        String newViewName = dialog.getNewViewName();
        String owner = dialog.getOwner();
        node.getDatabase().getDatabaseInfo().removeSchema(viewName);
        ISelectionProvider provider = getSelectionProvider();
        TreeViewer treeViewer = (TreeViewer) provider;
        if (!viewName.equals(newViewName)) {
            ClassInfo newClassInfo = (ClassInfo) node.getAdapter(ClassInfo.class);
            newClassInfo.setClassName(newViewName);
            newClassInfo.setOwnerName(owner);
            node.setId(node.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newViewName);
            node.setLabel(newViewName);
            treeViewer.refresh(node, true);
        }
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node.getParent());
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        /*Broadcast the view changed*/
        QueryEditorUtil.fireSchemaNodeChanged(node);
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Aggregations

GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)17 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)10 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)7 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)7 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)6 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)5 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)5 GetAllPartitionClassTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask)5 ITask (com.cubrid.common.core.task.ITask)4 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)4 GetUserListTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)3 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)3 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)3 DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)3 GetUserAuthorizationsTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask)3