File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\DropSchema.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.ddl;
8
9 import org.h2.command.CommandInterface;
10 import org.h2.constant.ErrorCode;
11 import org.h2.engine.Database;
12 import org.h2.engine.Session;
13 import org.h2.message.DbException;
14 import org.h2.schema.Schema;
15
16 /**
17 * This class represents the statement
18 * DROP SCHEMA
19 */
20 public class DropSchema extends DefineCommand {
21
22 private String schemaName;
23 private boolean ifExists;
24
25 public DropSchema(Session session) {
26 super(session);
27 }
28
29 public void setSchemaName(String name) {
30 this.schemaName = name;
31 }
32
33 public int update() {
34 session.getUser().checkAdmin();
35 session.commit(true);
36 Database db = session.getDatabase();
37 Schema schema = db.findSchema(schemaName);
38 if (schema == null) {
39 if (!ifExists) {
40 throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
41 }
42 } else {
43 if (!schema.canDrop()) {
44 throw DbException.get(ErrorCode.SCHEMA_CAN_NOT_BE_DROPPED_1, schemaName);
45 }
46 db.removeDatabaseObject(session, schema);
47 }
48 return 0;
49 }
50
51 public void setIfExists(boolean ifExists) {
52 this.ifExists = ifExists;
53 }
54
55 public int getType() {
56 return CommandInterface.DROP_SCHEMA;
57 }
58
59 }
60