use of com.cubrid.common.core.common.model.Trigger 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;
}
use of com.cubrid.common.core.common.model.Trigger in project cubrid-manager by CUBRID.
the class TriggerDashboardEditorPart method editTrigger.
/**
* editTrigger
*/
public void editTrigger() {
TableItem[] items = triggersDetailInfoTable.getTable().getSelection();
if (items.length != 0) {
TableItem item = items[0];
Trigger trigger = (Trigger) item.getData();
Set<String> typeSet = new HashSet<String>();
typeSet.add(NodeType.TRIGGER);
ICubridNode triggerNode = CommonUITool.findNode(database, typeSet, trigger.getName());
if (triggerNode != null) {
AlterTriggerAction action = (AlterTriggerAction) ActionManager.getInstance().getAction(AlterTriggerAction.ID);
if (action.run(database, (ISchemaNode) triggerNode) == IDialogConstants.OK_ID) {
refresh();
}
}
} else {
CommonUITool.openWarningBox(Messages.errTriggerNoSelection);
}
}
use of com.cubrid.common.core.common.model.Trigger in project cubrid-manager by CUBRID.
the class JDBCGetTriggerInfoTaskTest method testGetTriggerInfo.
/**
* Test method for
* {@link com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerInfoTask#getTriggerInfo(java.lang.String)}
* .
*/
public void testGetTriggerInfo() {
JDBCGetTriggerInfoTask task = new JDBCGetTriggerInfoTask(databaseInfo);
Trigger trigger = task.getTriggerInfo(testTriggerName.toLowerCase());
assertNotNull(trigger);
assertEquals(testTriggerName.toLowerCase(), trigger.getName());
task = new JDBCGetTriggerInfoTask(databaseInfo);
task.cancel();
task.getTriggerInfo(testTriggerName.toLowerCase());
assertNotNull(task.getErrorMsg());
}
use of com.cubrid.common.core.common.model.Trigger in project cubrid-manager by CUBRID.
the class MultiTriggerTest method test0.
//before insert+Reject
public void test0() throws Exception {
createTestTableAndTrigger("drop.trigger0.txt");
createTestTableAndTrigger("trigger0.txt");
GetTriggerListTask task = new GetTriggerListTask(serverInfo);
task.setDbName(testDbName);
task.execute();
assertTrue(task.isSuccess());
List<Trigger> triggerList = task.getTriggerInfoList();
// Trigger testTrigger1 = getTestTrigger(triggerList, "testtrigger1");
Trigger testTrigger2 = getTestTrigger(triggerList, "testtrigger2");
Trigger testTrigger3 = getTestTrigger(triggerList, "testtrigger3");
Trigger testTrigger4 = getTestTrigger(triggerList, "testtrigger4");
Trigger testTrigger5 = getTestTrigger(triggerList, "testtrigger5");
Trigger testTrigger6 = getTestTrigger(triggerList, "testtrigger6");
Trigger testTrigger7 = getTestTrigger(triggerList, "testtrigger7");
Trigger testTrigger8 = getTestTrigger(triggerList, "testtrigger8");
Trigger testTrigger9 = getTestTrigger(triggerList, "testtrigger9");
// assertEquals(null, testTrigger1.getConditionTime());
assertEquals(null, testTrigger2.getConditionTime());
assertEquals(null, testTrigger3.getConditionTime());
assertEquals(null, testTrigger4.getConditionTime());
assertEquals(null, testTrigger5.getConditionTime());
assertEquals(null, testTrigger6.getConditionTime());
assertEquals(null, testTrigger7.getConditionTime());
assertEquals(null, testTrigger8.getConditionTime());
assertEquals(null, testTrigger9.getConditionTime());
// assertEquals("BEFORE", testTrigger1.getActionTime());
assertEquals("AFTER", testTrigger2.getActionTime());
assertEquals("DEFERRED", testTrigger3.getActionTime());
assertEquals("AFTER", testTrigger4.getActionTime());
assertEquals("AFTER", testTrigger5.getActionTime());
assertEquals("DEFERRED", testTrigger6.getActionTime());
assertEquals("DEFERRED", testTrigger7.getActionTime());
assertEquals("AFTER", testTrigger8.getActionTime());
assertEquals("DEFERRED", testTrigger9.getActionTime());
}
use of com.cubrid.common.core.common.model.Trigger in project cubrid-manager by CUBRID.
the class JDBCGetTriggerListTask method execute.
/**
* Execute select sql.
*/
public void execute() {
try {
if (errorMsg != null && errorMsg.trim().length() > 0) {
return;
}
if (connection == null || connection.isClosed()) {
errorMsg = Messages.error_getConnection;
return;
}
stmt = connection.createStatement();
// select count(*) from db_user d where
// {'DBA'} SUBSETEQ
// (SELECT SET{CURRENT_USER}+COALESCE(SUM(SET{t.g.name}), SET{})
// FROM db_user u, TABLE(groups) AS t(g)
// WHERE u.name = d.name)
// and d.name=CURRENT_USER
String sql = "SELECT t.*, c.target_class_name" + " FROM db_trigger t, db_trig c" + " WHERE t.name=c.trigger_name";
// [TOOLS-2425]Support shard broker
sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
rs = stmt.executeQuery(sql);
while (rs.next()) {
Trigger trigger = new Trigger();
trigger.setName(rs.getString("name"));
trigger.setConditionTime(getConditionTime(rs.getInt("condition_time")));
trigger.setEventType(getEventType(rs.getInt("event")));
trigger.setTarget_class(rs.getString("target_class_name"));
trigger.setTarget_att(rs.getString("target_attribute"));
trigger.setCondition(rs.getString("condition"));
trigger.setActionTime(getActionTime(rs.getInt("action_time")));
trigger.setAction(getAction(rs.getInt("action_type"), rs.getString("action_definition")));
trigger.setStatus(getStatus(rs.getInt("status")));
trigger.setPriority(rs.getString("priority"));
triggers.add(trigger);
}
} catch (SQLException e) {
errorMsg = e.getMessage();
if (errorMsg.indexOf("Select is not authorized on db_trigger") >= 0) {
errorMsg = "";
}
LOGGER.error(e.getMessage(), e);
} finally {
finish();
}
}
Aggregations