Search in sources :

Example 1 with GetTriggerListTask

use of com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask in project cubrid-manager by CUBRID.

the class AlterTriggerAction method run.

/**
	 * edit trigger
	 * @param database
	 * @param node
	 * @return
	 */
public int run(final CubridDatabase database, final ISchemaNode node) {
    // FIXME move this logic to core module
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                Trigger trigger = null;
                if (task instanceof GetTriggerListTask) {
                    GetTriggerListTask getTriggerListTask = (GetTriggerListTask) task;
                    List<Trigger> triggerList = getTriggerListTask.getTriggerInfoList();
                    for (int i = 0; triggerList != null && i < triggerList.size(); i++) {
                        Trigger trig = triggerList.get(i);
                        if (node.getName().equals(trig.getName())) {
                            trigger = trig;
                            break;
                        }
                    }
                } else if (task instanceof JDBCGetTriggerInfoTask) {
                    JDBCGetTriggerInfoTask getTriggerInfoTask = (JDBCGetTriggerInfoTask) task;
                    trigger = getTriggerInfoTask.getTriggerInfo(node.getLabel());
                }
                if (trigger == null) {
                    openErrorBox(shell, Messages.errNameNoExist, monitor);
                    return false;
                }
                // getting comment for version after 10.0
                if (CompatibleUtil.isCommentSupports(database.getDatabaseInfo())) {
                    try {
                        SchemaComment schemaComment = SchemaCommentHandler.loadObjectDescription(database.getDatabaseInfo(), JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true), trigger.getName(), CommentType.TRIGGER);
                        trigger.setDescription(schemaComment.getDescription());
                    } catch (SQLException e) {
                        CommonUITool.openErrorBox(e.getMessage());
                    }
                }
                node.setModelObj(trigger);
            }
            return true;
        }
    };
    ITask task = null;
    if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
        task = new GetTriggerListTask(database.getServer().getServerInfo());
        ((GetTriggerListTask) task).setDbName(database.getName());
    } else {
        task = new JDBCGetTriggerInfoTask(database.getDatabaseInfo());
    }
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return IDialogConstants.CANCEL_ID;
    }
    CreateTriggerDialog dialog = new CreateTriggerDialog(getShell(), node.getDatabase(), (Trigger) node.getAdapter(Trigger.class));
    if (dialog.open() != IDialogConstants.CANCEL_ID) {
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : ITask(com.cubrid.common.core.task.ITask) JDBCGetTriggerInfoTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerInfoTask) SQLException(java.sql.SQLException) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Trigger(com.cubrid.common.core.common.model.Trigger) GetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CreateTriggerDialog(com.cubrid.common.ui.cubrid.trigger.dialog.CreateTriggerDialog) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment)

Example 2 with GetTriggerListTask

use of com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask in project cubrid-manager by CUBRID.

the class CubridTriggerFolderLoader 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().setTriggerList(null);
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        ITask task = null;
        if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
            task = new GetTriggerListTask(parent.getServer().getServerInfo());
            ((GetTriggerListTask) task).setDbName(database.getLabel());
        } else {
            task = new JDBCGetTriggerListTask(databaseInfo);
        }
        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<Trigger> triggerList = null;
        if (task instanceof GetTriggerListTask) {
            triggerList = ((GetTriggerListTask) task).getTriggerInfoList();
        } else if (task instanceof JDBCGetTriggerListTask) {
            triggerList = ((JDBCGetTriggerListTask) task).getTriggerInfoList();
        }
        if (triggerList != null && !triggerList.isEmpty()) {
            for (Trigger trigger : triggerList) {
                String id = parent.getId() + NODE_SEPARATOR + trigger.getName();
                ICubridNode triggerNode = createTriggerNode(id, trigger);
                parent.addChild(triggerNode);
            }
        }
        databaseInfo.setTriggerList(triggerList);
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) Trigger(com.cubrid.common.core.common.model.Trigger) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) JDBCGetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask) GetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) JDBCGetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask)

Example 3 with GetTriggerListTask

use of com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask in project cubrid-manager by CUBRID.

the class OpenTriggerDetailInfoPartProgress method run.

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    ITask task = null;
    if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
        task = new GetTriggerListTask(database.getServer().getServerInfo());
        ((GetTriggerListTask) task).setDbName(database.getLabel());
    } else {
        task = new JDBCGetTriggerListTask(databaseInfo);
    }
    task.execute();
    if (!task.isSuccess()) {
        LOGGER.error(task.getErrorMsg());
        return;
    }
    if (task instanceof GetTriggerListTask) {
        triggerList = ((GetTriggerListTask) task).getTriggerInfoList();
    } else if (task instanceof JDBCGetTriggerListTask) {
        triggerList = ((JDBCGetTriggerListTask) task).getTriggerInfoList();
    }
    success = true;
}
Also used : ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) JDBCGetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask) GetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask) JDBCGetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask)

Aggregations

ITask (com.cubrid.common.core.task.ITask)3 GetTriggerListTask (com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask)3 Trigger (com.cubrid.common.core.common.model.Trigger)2 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 JDBCGetTriggerListTask (com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask)2 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)1 CreateTriggerDialog (com.cubrid.common.ui.cubrid.trigger.dialog.CreateTriggerDialog)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 JDBCGetTriggerInfoTask (com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerInfoTask)1 SQLException (java.sql.SQLException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1