KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc 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 JavaDoc viewName) {
29         this.viewName = viewName;
30     }
31
32     public int update() throws SQLException JavaDoc {
33         // TODO rights: what rights are required to drop a view?
34
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