KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > command > ddl > DropTrigger


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.command.ddl;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.engine.Database;
10 import org.h2.engine.Right;
11 import org.h2.engine.Session;
12 import org.h2.message.Message;
13 import org.h2.schema.Schema;
14 import org.h2.schema.TriggerObject;
15 import org.h2.table.Table;
16
17 public class DropTrigger extends SchemaCommand {
18
19     private String JavaDoc triggerName;
20     private boolean ifExists;
21     
22     public DropTrigger(Session session, Schema schema) {
23         super(session, schema);
24     }
25
26     public void setIfExists(boolean b) {
27         ifExists = b;
28     }
29
30     public void setTriggerName(String JavaDoc triggerName) {
31         this.triggerName = triggerName;
32     }
33
34     public int update() throws SQLException JavaDoc {
35         session.commit();
36         Database db = session.getDatabase();
37         TriggerObject trigger = getSchema().findTrigger(triggerName);
38         if(trigger == null) {
39             if(!ifExists) {
40                 throw Message.getSQLException(Message.TRIGGER_NOT_FOUND_1, triggerName);
41             }
42         } else {
43             Table table = trigger.getTable();
44             session.getUser().checkRight(table, Right.ALL);
45             db.removeSchemaObject(session, trigger);
46         }
47         return 0;
48     }
49
50 }
51
Popular Tags