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

COVERAGE SUMMARY FOR SOURCE FILE [CreateSchema.java]

nameclass, %method, %block, %line, %
CreateSchema.java100% (1/1)100% (6/6)93%  (70/75)96%  (22/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateSchema100% (1/1)100% (6/6)93%  (70/75)96%  (22/23)
update (): int 100% (1/1)91%  (52/57)93%  (13/14)
CreateSchema (Session): void 100% (1/1)100% (4/4)100% (2/2)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
setAuthorization (String): void 100% (1/1)100% (4/4)100% (2/2)
setIfNotExists (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setSchemaName (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.Session;
12import org.h2.engine.User;
13import org.h2.message.DbException;
14import org.h2.schema.Schema;
15 
16/**
17 * This class represents the statement
18 * CREATE SCHEMA
19 */
20public class CreateSchema extends DefineCommand {
21 
22    private String schemaName;
23    private String authorization;
24    private boolean ifNotExists;
25 
26    public CreateSchema(Session session) {
27        super(session);
28    }
29 
30    public void setIfNotExists(boolean ifNotExists) {
31        this.ifNotExists = ifNotExists;
32    }
33 
34    @Override
35    public int update() {
36        session.getUser().checkSchemaAdmin();
37        session.commit(true);
38        Database db = session.getDatabase();
39        User user = db.getUser(authorization);
40        // during DB startup, the Right/Role records have not yet been loaded
41        if (!db.isStarting()) {
42            user.checkSchemaAdmin();
43        }
44        if (db.findSchema(schemaName) != null) {
45            if (ifNotExists) {
46                return 0;
47            }
48            throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, schemaName);
49        }
50        int id = getObjectId();
51        Schema schema = new Schema(db, id, schemaName, user, false);
52        db.addDatabaseObject(session, schema);
53        return 0;
54    }
55 
56    public void setSchemaName(String name) {
57        this.schemaName = name;
58    }
59 
60    public void setAuthorization(String userName) {
61        this.authorization = userName;
62    }
63 
64    @Override
65    public int getType() {
66        return CommandInterface.CREATE_SCHEMA;
67    }
68 
69}

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