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