Search in sources :

Example 1 with AddTriggerTask

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

the class CreateTriggerDialog method executeBySocket.

/**
	 *
	 * Execute to add or alter trigger by socket
	 *
	 * @param buttonId int
	 */
private void executeBySocket(int buttonId) {
    // FIXME remove
    String taskName = null;
    String message = null;
    ITask executedTask = null;
    if (buttonId == IDialogConstants.OK_ID) {
        String eventType = getEventType();
        String triggerEventTargetTable = triggerTargetTableCombo.getText().trim();
        String triggerEventTargetColumn = triggerTargetColumnCombo.getText().trim();
        AddTriggerTask task = new AddTriggerTask(database.getServer().getServerInfo());
        task.setDbName(database.getName());
        task.setTriggerName("\"" + triggerName + "\"");
        String eventTime = getEventTime();
        task.setConditionTime(TriggerConditionTime.eval(eventTime));
        task.setEventType(TriggerEvent.eval(eventType));
        String triggerActionType = getActionType();
        String triggerAction = triggerActionText.getText().trim();
        String crChar = "\r";
        String nlChar = "\n";
        triggerAction = triggerAction.replaceAll(crChar, "");
        triggerAction = triggerAction.replaceAll(nlChar, " ");
        task.setAction(Trigger.TriggerAction.eval(triggerActionType), triggerAction);
        if (triggerEventTargetTable.length() > 0) {
            if (triggerEventTargetColumn.length() > 0) {
                task.setEventTarget("\"" + triggerEventTargetTable + "\"(\"" + triggerEventTargetColumn + "\")");
            } else {
                task.setEventTarget("\"" + triggerEventTargetTable + "\"");
            }
        }
        String actionTime = getActionTime();
        if (!actionTime.equals(Messages.actionTimeDefault)) {
            // action time selected
            task.setActionTime(TriggerActionTime.eval(actionTime));
        }
        String triggerCondition = triggerConditionText.getText().trim();
        triggerCondition = triggerCondition.replaceAll(crChar, "");
        triggerCondition = triggerCondition.replaceAll(nlChar, " ");
        task.setCondition(triggerCondition);
        String triggerStatus = this.getStatus();
        task.setStatus(TriggerStatus.eval(triggerStatus));
        String strPriority = triggerPriorityText.getText();
        task.setPriority(strPriority);
        taskName = Messages.bind(Messages.addTriggerTaskName, triggerName);
        message = Messages.newTriggerSuccess;
        executedTask = task;
    } else if (buttonId == ALTER_TRIGGER_OK_ID) {
        AlterTriggerTask task = new AlterTriggerTask(database.getServer().getServerInfo());
        task.setDbName(database.getName());
        task.setTriggerName(trigger.getName());
        String triggerStatus = this.getStatus();
        task.setStatus(TriggerStatus.eval(triggerStatus));
        String strPriority = triggerPriorityText.getText();
        task.setPriority(strPriority);
        taskName = Messages.bind(Messages.alterTriggerTaskName, trigger.getName());
        message = Messages.alterTriggerSuccess;
        executedTask = task;
    }
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(executedTask);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (taskExecutor.isSuccess()) {
        setReturnCode(buttonId);
        close();
        CommonUITool.openInformationBox(Messages.msgInformation, message);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ITask(com.cubrid.common.core.task.ITask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) AddTriggerTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.AddTriggerTask) AlterTriggerTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.AlterTriggerTask)

Aggregations

ITask (com.cubrid.common.core.task.ITask)1 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 AddTriggerTask (com.cubrid.cubridmanager.core.cubrid.trigger.task.AddTriggerTask)1 AlterTriggerTask (com.cubrid.cubridmanager.core.cubrid.trigger.task.AlterTriggerTask)1