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

COVERAGE SUMMARY FOR SOURCE FILE [DropView.java]

nameclass, %method, %block, %line, %
DropView.java100% (1/1)100% (6/6)99%  (115/116)100% (25.9/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DropView100% (1/1)100% (6/6)99%  (115/116)100% (25.9/26)
DropView (Session, Schema): void 100% (1/1)93%  (14/15)98%  (2.9/3)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
setDropAction (int): void 100% (1/1)100% (4/4)100% (2/2)
setIfExists (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setViewName (String): void 100% (1/1)100% (4/4)100% (2/2)
update (): int 100% (1/1)100% (87/87)100% (16/16)

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.ConstraintReferential;
11import org.h2.engine.DbObject;
12import org.h2.engine.Right;
13import org.h2.engine.Session;
14import org.h2.message.DbException;
15import org.h2.schema.Schema;
16import org.h2.table.Table;
17import org.h2.table.TableView;
18 
19/**
20 * This class represents the statement
21 * DROP VIEW
22 */
23public class DropView extends SchemaCommand {
24 
25    private String viewName;
26    private boolean ifExists;
27    private int dropAction;
28 
29    public DropView(Session session, Schema schema) {
30        super(session, schema);
31        dropAction = session.getDatabase().getSettings().dropRestrict ?
32                ConstraintReferential.RESTRICT :
33                ConstraintReferential.CASCADE;
34    }
35 
36    public void setIfExists(boolean b) {
37        ifExists = b;
38    }
39 
40    public void setDropAction(int dropAction) {
41        this.dropAction = dropAction;
42    }
43 
44    public void setViewName(String viewName) {
45        this.viewName = viewName;
46    }
47 
48    @Override
49    public int update() {
50        session.commit(true);
51        Table view = getSchema().findTableOrView(session, viewName);
52        if (view == null) {
53            if (!ifExists) {
54                throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
55            }
56        } else {
57            if (!Table.VIEW.equals(view.getTableType())) {
58                throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
59            }
60            session.getUser().checkRight(view, Right.ALL);
61 
62            if (dropAction == ConstraintReferential.RESTRICT) {
63                for (DbObject child : view.getChildren()) {
64                    if (child instanceof TableView) {
65                        throw DbException.get(ErrorCode.CANNOT_DROP_2, viewName, child.getName());
66                    }
67                }
68            }
69 
70            view.lock(session, true, true);
71            session.getDatabase().removeSchemaObject(session, view);
72        }
73        return 0;
74    }
75 
76    @Override
77    public int getType() {
78        return CommandInterface.DROP_VIEW;
79    }
80 
81}

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