01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.command.ddl;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.constant.ErrorCode;
11: import org.h2.engine.Right;
12: import org.h2.engine.Session;
13: import org.h2.message.Message;
14: import org.h2.schema.Schema;
15: import org.h2.table.Table;
16:
17: /**
18: * This class represents the statement
19: * DROP VIEW
20: */
21: public class DropView extends SchemaCommand {
22:
23: private String viewName;
24: private boolean ifExists;
25:
26: public DropView(Session session, Schema schema) {
27: super (session, schema);
28: }
29:
30: public void setIfExists(boolean b) {
31: ifExists = b;
32: }
33:
34: public void setViewName(String viewName) {
35: this .viewName = viewName;
36: }
37:
38: public int update() throws SQLException {
39: // TODO rights: what rights are required to drop a view?
40: session.commit(true);
41: Table view = getSchema().findTableOrView(session, viewName);
42: if (view == null) {
43: if (!ifExists) {
44: throw Message.getSQLException(
45: ErrorCode.VIEW_NOT_FOUND_1, viewName);
46: }
47: } else {
48: if (!view.getTableType().equals(Table.VIEW)) {
49: throw Message.getSQLException(
50: ErrorCode.VIEW_NOT_FOUND_1, viewName);
51: }
52: session.getUser().checkRight(view, Right.ALL);
53: view.lock(session, true, true);
54: session.getDatabase().removeSchemaObject(session, view);
55: }
56: return 0;
57: }
58:
59: }
|