File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\DropTrigger.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.ddl;
8
9 import org.h2.command.CommandInterface;
10 import org.h2.constant.ErrorCode;
11 import org.h2.engine.Database;
12 import org.h2.engine.Right;
13 import org.h2.engine.Session;
14 import org.h2.message.DbException;
15 import org.h2.schema.Schema;
16 import org.h2.schema.TriggerObject;
17 import org.h2.table.Table;
18
19 /**
20 * This class represents the statement
21 * DROP TRIGGER
22 */
23 public class DropTrigger extends SchemaCommand {
24
25 private String triggerName;
26 private boolean ifExists;
27
28 public DropTrigger(Session session, Schema schema) {
29 super(session, schema);
30 }
31
32 public void setIfExists(boolean b) {
33 ifExists = b;
34 }
35
36 public void setTriggerName(String triggerName) {
37 this.triggerName = triggerName;
38 }
39
40 public int update() {
41 session.commit(true);
42 Database db = session.getDatabase();
43 TriggerObject trigger = getSchema().findTrigger(triggerName);
44 if (trigger == null) {
45 if (!ifExists) {
46 throw DbException.get(ErrorCode.TRIGGER_NOT_FOUND_1, triggerName);
47 }
48 } else {
49 Table table = trigger.getTable();
50 session.getUser().checkRight(table, Right.ALL);
51 db.removeSchemaObject(session, trigger);
52 }
53 return 0;
54 }
55
56 public int getType() {
57 return CommandInterface.DROP_TRIGGER;
58 }
59
60 }
61