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

COVERAGE SUMMARY FOR SOURCE FILE [CreateConstant.java]

nameclass, %method, %block, %line, %
CreateConstant.java100% (1/1)100% (6/6)94%  (77/82)96%  (22/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateConstant100% (1/1)100% (6/6)94%  (77/82)96%  (22/23)
update (): int 100% (1/1)92%  (58/63)93%  (13/14)
CreateConstant (Session, Schema): void 100% (1/1)100% (5/5)100% (2/2)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
setConstantName (String): void 100% (1/1)100% (4/4)100% (2/2)
setExpression (Expression): void 100% (1/1)100% (4/4)100% (2/2)
setIfNotExists (boolean): 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.expression.Expression;
13import org.h2.message.DbException;
14import org.h2.schema.Constant;
15import org.h2.schema.Schema;
16import org.h2.value.Value;
17 
18/**
19 * This class represents the statement
20 * CREATE CONSTANT
21 */
22public class CreateConstant extends SchemaCommand {
23 
24    private String constantName;
25    private Expression expression;
26    private boolean ifNotExists;
27 
28    public CreateConstant(Session session, Schema schema) {
29        super(session, schema);
30    }
31 
32    public void setIfNotExists(boolean ifNotExists) {
33        this.ifNotExists = ifNotExists;
34    }
35 
36    @Override
37    public int update() {
38        session.commit(true);
39        session.getUser().checkAdmin();
40        Database db = session.getDatabase();
41        if (getSchema().findConstant(constantName) != null) {
42            if (ifNotExists) {
43                return 0;
44            }
45            throw DbException.get(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName);
46        }
47        int id = getObjectId();
48        Constant constant = new Constant(getSchema(), id, constantName);
49        expression = expression.optimize(session);
50        Value value = expression.getValue(session);
51        constant.setValue(value);
52        db.addSchemaObject(session, constant);
53        return 0;
54    }
55 
56    public void setConstantName(String constantName) {
57        this.constantName = constantName;
58    }
59 
60    public void setExpression(Expression expr) {
61        this.expression = expr;
62    }
63 
64    @Override
65    public int getType() {
66        return CommandInterface.CREATE_CONSTANT;
67    }
68 
69}

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