KickJava   Java API By Example, From Geeks To Geeks.

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


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