Search in sources :

Example 1 with GetSPInfoListTask

use of com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask in project cubrid-manager by CUBRID.

the class EditProcedureAction method run.

/**
	 * Open the EditProcedureDialog and edit procedure
	 */
public void run() {
    // FIXME logic code move to core module
    Object[] objArr = this.getSelectedObj();
    if (!isSupported(objArr)) {
        this.setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objArr[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_PROCEDURE.equals(((ISchemaNode) objArr[0]).getType())) {
        node = (ISchemaNode) objArr[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
        return;
    }
    final GetSPInfoListTask task = new GetSPInfoListTask(database.getDatabaseInfo());
    task.setSpName(node.getName());
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<SPInfo> list = task.getSPInfoList();
    if (list.size() > 1) {
        CommonUITool.openErrorBox(shell, Messages.errDuplicateName);
        return;
    }
    if (list.isEmpty()) {
        CommonUITool.openErrorBox(shell, Messages.errNotExistName);
        return;
    }
    EditProcedureDialog dlg = new EditProcedureDialog(shell);
    dlg.setDatabase(database);
    dlg.setNewFlag(false);
    dlg.setSpInfo(list.get(0));
    if (dlg.open() == IDialogConstants.OK_ID) {
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) EditProcedureDialog(com.cubrid.common.ui.cubrid.procedure.dialog.EditProcedureDialog) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

Example 2 with GetSPInfoListTask

use of com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask in project cubrid-manager by CUBRID.

the class CubridFunctionFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            database.getDatabaseInfo().setSpFunctionInfoList(null);
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetSPInfoListTask task = new GetSPInfoListTask(databaseInfo);
        task.setSpType(SPType.FUNCTION);
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        List<SPInfo> spInfoList = task.getSPInfoList();
        DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        boolean isDBA = false;
        String loginUserName = "";
        if (userInfo != null && userInfo.isDbaAuthority()) {
            isDBA = true;
        }
        if (userInfo != null) {
            loginUserName = userInfo.getName();
        }
        List<SPInfo> authSpInfoList = new ArrayList<SPInfo>();
        if (spInfoList != null && !spInfoList.isEmpty()) {
            for (SPInfo spInfo : spInfoList) {
                if (!isDBA && !loginUserName.equalsIgnoreCase(spInfo.getOwner())) {
                    continue;
                }
                authSpInfoList.add(spInfo);
                String id = parent.getId() + NODE_SEPARATOR + spInfo.getSpName();
                ICubridNode spNode = createFunctionNode(id, spInfo);
                parent.addChild(spNode);
            }
        }
        databaseInfo.setSpFunctionInfoList(authSpInfoList);
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) ArrayList(java.util.ArrayList) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

Example 3 with GetSPInfoListTask

use of com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask in project cubrid-manager by CUBRID.

the class CubridProcedureFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            database.getDatabaseInfo().setSpProcedureInfoList(null);
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetSPInfoListTask task = new GetSPInfoListTask(databaseInfo);
        task.setSpType(SPType.PROCEDURE);
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        List<SPInfo> spInfoList = task.getSPInfoList();
        DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        boolean isDBA = false;
        String loginUserName = "";
        if (userInfo != null && userInfo.isDbaAuthority()) {
            isDBA = true;
        }
        if (userInfo != null) {
            loginUserName = userInfo.getName();
        }
        List<SPInfo> authSpInfoList = new ArrayList<SPInfo>();
        if (spInfoList != null && !spInfoList.isEmpty()) {
            for (SPInfo spInfo : spInfoList) {
                if (!isDBA && !loginUserName.equalsIgnoreCase(spInfo.getOwner())) {
                    continue;
                }
                authSpInfoList.add(spInfo);
                String id = parent.getId() + NODE_SEPARATOR + spInfo.getSpName();
                ICubridNode spNode = createProcedureNode(id, spInfo);
                parent.addChild(spNode);
            }
        }
        databaseInfo.setSpProcedureInfoList(authSpInfoList);
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) ArrayList(java.util.ArrayList) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

Example 4 with GetSPInfoListTask

use of com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask in project cubrid-manager by CUBRID.

the class EditFunctionAction method run.

/**
	 * Open the EditFunctionDialog and edit function
	 */
public void run() {
    Object[] objArr = this.getSelectedObj();
    if (!isSupported(objArr)) {
        this.setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objArr[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_FUNCTION.equals(((ISchemaNode) objArr[0]).getType())) {
        node = (ISchemaNode) objArr[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
        return;
    }
    final GetSPInfoListTask task = new GetSPInfoListTask(database.getDatabaseInfo());
    task.setSpName(node.getName());
    TaskExecutor taskExcutor = new CommonTaskExec(getText());
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<SPInfo> list = task.getSPInfoList();
    if (list.size() > 1) {
        CommonUITool.openErrorBox(shell, Messages.errDuplicateName);
        return;
    }
    if (list.isEmpty()) {
        CommonUITool.openErrorBox(shell, Messages.errNotExistName);
        return;
    }
    EditFunctionDialog dlg = new EditFunctionDialog(shell);
    dlg.setDatabase(database);
    dlg.setNewFlag(false);
    dlg.setSpInfo(list.get(0));
    if (dlg.open() == IDialogConstants.OK_ID) {
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) EditFunctionDialog(com.cubrid.common.ui.cubrid.procedure.dialog.EditFunctionDialog) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

Example 5 with GetSPInfoListTask

use of com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask 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

GetSPInfoListTask (com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)5 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)4 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)4 SPInfo (com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo)4 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)2 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)2 ArrayList (java.util.ArrayList)2 Shell (org.eclipse.swt.widgets.Shell)2 EditFunctionDialog (com.cubrid.common.ui.cubrid.procedure.dialog.EditFunctionDialog)1 EditProcedureDialog (com.cubrid.common.ui.cubrid.procedure.dialog.EditProcedureDialog)1 CommonSQLExcuterTask (com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask)1