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