KickJava   Java API By Example, From Geeks To Geeks.

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


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.Database;
10 import org.h2.engine.Session;
11 import org.h2.message.Message;
12 import org.h2.schema.Schema;
13
14 public class DropSchema extends DefineCommand {
15     
16     private String JavaDoc schemaName;
17     private boolean ifExists;
18
19     public DropSchema(Session session) {
20         super(session);
21     }
22
23     public void setSchemaName(String JavaDoc name) {
24         this.schemaName = name;
25     }
26
27     public int update() throws SQLException JavaDoc {
28         session.getUser().checkAdmin();
29         session.commit();
30         Database db = session.getDatabase();
31         Schema schema = db.findSchema(schemaName);
32         if(schema == null) {
33             if(!ifExists) {
34                 throw Message.getSQLException(Message.SCHEMA_NOT_FOUND_1, schemaName);
35             }
36         } else {
37             if(!schema.canDrop()) {
38                 throw Message.getSQLException(Message.SCHEMA_CAN_NOT_BE_DROPPED_1, schemaName);
39             }
40             db.removeDatabaseObject(session, schema);
41         }
42         return 0;
43     }
44
45     public void setIfExists(boolean ifExists) {
46         this.ifExists = ifExists;
47     }
48     
49 }
50
Popular Tags