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

COVERAGE SUMMARY FOR SOURCE FILE [CreateRole.java]

nameclass, %method, %block, %line, %
CreateRole.java100% (1/1)100% (5/5)86%  (60/70)90%  (18/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateRole100% (1/1)100% (5/5)86%  (60/70)90%  (18/20)
update (): int 100% (1/1)82%  (46/56)85%  (11/13)
CreateRole (Session): void 100% (1/1)100% (4/4)100% (2/2)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
setIfNotExists (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setRoleName (String): void 100% (1/1)100% (4/4)100% (2/2)

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.Role;
12import org.h2.engine.Session;
13import org.h2.message.DbException;
14 
15/**
16 * This class represents the statement
17 * CREATE ROLE
18 */
19public class CreateRole extends DefineCommand {
20 
21    private String roleName;
22    private boolean ifNotExists;
23 
24    public CreateRole(Session session) {
25        super(session);
26    }
27 
28    public void setIfNotExists(boolean ifNotExists) {
29        this.ifNotExists = ifNotExists;
30    }
31 
32    public void setRoleName(String name) {
33        this.roleName = name;
34    }
35 
36    @Override
37    public int update() {
38        session.getUser().checkAdmin();
39        session.commit(true);
40        Database db = session.getDatabase();
41        if (db.findUser(roleName) != null) {
42            throw DbException.get(ErrorCode.USER_ALREADY_EXISTS_1, roleName);
43        }
44        if (db.findRole(roleName) != null) {
45            if (ifNotExists) {
46                return 0;
47            }
48            throw DbException.get(ErrorCode.ROLE_ALREADY_EXISTS_1, roleName);
49        }
50        int id = getObjectId();
51        Role role = new Role(db, id, roleName, false);
52        db.addDatabaseObject(session, role);
53        return 0;
54    }
55 
56    @Override
57    public int getType() {
58        return CommandInterface.CREATE_ROLE;
59    }
60 
61}

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