KickJava   Java API By Example, From Geeks To Geeks.

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


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.engine.User;
12 import org.h2.message.Message;
13
14 public class DropUser extends DefineCommand {
15
16     private boolean ifExists;
17     private String JavaDoc userName;
18
19     public DropUser(Session session) {
20         super(session);
21     }
22
23     public void setIfExists(boolean b) {
24         ifExists = b;
25     }
26
27     public void setUserName(String JavaDoc userName) {
28         this.userName = userName;
29     }
30
31     public int update() throws SQLException JavaDoc {
32         session.getUser().checkAdmin();
33         session.commit();
34         Database db = session.getDatabase();
35         User user = db.findUser(userName);
36         if(user == null) {
37             if(!ifExists) {
38                 throw Message.getSQLException(Message.USER_NOT_FOUND_1, userName);
39             }
40         } else {
41             if(user == session.getUser()) {
42                 throw Message.getSQLException(Message.CANT_DROP_CURRENT_USER);
43             }
44             db.removeDatabaseObject(session, user);
45         }
46         return 0;
47     }
48
49     public boolean isTransactional() {
50         return false;
51     }
52
53 }
54
Popular Tags