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

COVERAGE SUMMARY FOR SOURCE FILE [AlterTableDropConstraint.java]

nameclass, %method, %block, %line, %
AlterTableDropConstraint.java100% (1/1)100% (4/4)100% (59/59)100% (15/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AlterTableDropConstraint100% (1/1)100% (4/4)100% (59/59)100% (15/15)
AlterTableDropConstraint (Session, Schema, boolean): void 100% (1/1)100% (8/8)100% (3/3)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
setConstraintName (String): void 100% (1/1)100% (4/4)100% (2/2)
update (): int 100% (1/1)100% (45/45)100% (9/9)

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.constraint.Constraint;
11import org.h2.engine.Right;
12import org.h2.engine.Session;
13import org.h2.message.DbException;
14import org.h2.schema.Schema;
15 
16/**
17 * This class represents the statement
18 * ALTER TABLE DROP CONSTRAINT
19 */
20public class AlterTableDropConstraint extends SchemaCommand {
21 
22    private String constraintName;
23    private final boolean ifExists;
24 
25    public AlterTableDropConstraint(Session session, Schema schema,
26            boolean ifExists) {
27        super(session, schema);
28        this.ifExists = ifExists;
29    }
30 
31    public void setConstraintName(String string) {
32        constraintName = string;
33    }
34 
35    @Override
36    public int update() {
37        session.commit(true);
38        Constraint constraint = getSchema().findConstraint(session, constraintName);
39        if (constraint == null) {
40            if (!ifExists) {
41                throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, constraintName);
42            }
43        } else {
44            session.getUser().checkRight(constraint.getTable(), Right.ALL);
45            session.getUser().checkRight(constraint.getRefTable(), Right.ALL);
46            session.getDatabase().removeSchemaObject(session, constraint);
47        }
48        return 0;
49    }
50 
51    @Override
52    public int getType() {
53        return CommandInterface.ALTER_TABLE_DROP_CONSTRAINT;
54    }
55 
56}

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