EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.command.ddl]

COVERAGE SUMMARY FOR SOURCE FILE [DropUser.java]

nameclass, %method, %block, %line, %
DropUser.java100% (1/1)100% (6/6)100% (81/81)100% (26/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DropUser100% (1/1)100% (6/6)100% (81/81)100% (26/26)
DropUser (Session): void 100% (1/1)100% (4/4)100% (2/2)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
isTransactional (): boolean 100% (1/1)100% (2/2)100% (1/1)
setIfExists (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setUserName (String): void 100% (1/1)100% (4/4)100% (2/2)
update (): int 100% (1/1)100% (65/65)100% (18/18)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.command.ddl;
7 
8import org.h2.api.ErrorCode;
9import org.h2.command.CommandInterface;
10import org.h2.engine.Database;
11import org.h2.engine.Session;
12import org.h2.engine.User;
13import org.h2.message.DbException;
14 
15/**
16 * This class represents the statement
17 * DROP USER
18 */
19public class DropUser extends DefineCommand {
20 
21    private boolean ifExists;
22    private String userName;
23 
24    public DropUser(Session session) {
25        super(session);
26    }
27 
28    public void setIfExists(boolean b) {
29        ifExists = b;
30    }
31 
32    public void setUserName(String userName) {
33        this.userName = userName;
34    }
35 
36    @Override
37    public int update() {
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 DbException.get(ErrorCode.USER_NOT_FOUND_1, userName);
45            }
46        } else {
47            if (user == session.getUser()) {
48                int adminUserCount = 0;
49                for (User u : db.getAllUsers()) {
50                    if (u.isAdmin()) {
51                        adminUserCount++;
52                    }
53                }
54                if (adminUserCount == 1) {
55                    throw DbException.get(ErrorCode.CANNOT_DROP_CURRENT_USER);
56                }
57            }
58            user.checkOwnsNoSchemas();
59            db.removeDatabaseObject(session, user);
60        }
61        return 0;
62    }
63 
64    @Override
65    public boolean isTransactional() {
66        return false;
67    }
68 
69    @Override
70    public int getType() {
71        return CommandInterface.DROP_USER;
72    }
73 
74}

[all classes][org.h2.command.ddl]
EMMA 2.0.5312 (C) Vladimir Roubtsov