Debian Codegraph @

src/main/org/h2/command/ddl/DropTrigger.java

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