1 5 package org.h2.command.ddl; 6 7 import java.sql.SQLException ; 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 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 triggerName) { 31 this.triggerName = triggerName; 32 } 33 34 public int update() throws SQLException { 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 |