File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\AlterTableDropConstraint.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.ddl;
8
9 import org.h2.command.CommandInterface;
10 import org.h2.constant.ErrorCode;
11 import org.h2.constraint.Constraint;
12 import org.h2.engine.Right;
13 import org.h2.engine.Session;
14 import org.h2.message.DbException;
15 import org.h2.schema.Schema;
16
17 /**
18 * This class represents the statement
19 * ALTER TABLE DROP CONSTRAINT
20 */
21 public class AlterTableDropConstraint extends SchemaCommand {
22
23 private String constraintName;
24 private final boolean ifExists;
25
26 public AlterTableDropConstraint(Session session, Schema schema, boolean ifExists) {
27 super(session, schema);
28 this.ifExists = ifExists;
29 }
30
31 public void setConstraintName(String string) {
32 constraintName = string;
33 }
34
35 public int update() {
36 session.commit(true);
37 Constraint constraint = getSchema().findConstraint(session, constraintName);
38 if (constraint == null) {
39 if (!ifExists) {
40 throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, constraintName);
41 }
42 } else {
43 session.getUser().checkRight(constraint.getTable(), Right.ALL);
44 session.getUser().checkRight(constraint.getRefTable(), Right.ALL);
45 session.getDatabase().removeSchemaObject(session, constraint);
46 }
47 return 0;
48 }
49
50 public int getType() {
51 return CommandInterface.ALTER_TABLE_DROP_CONSTRAINT;
52 }
53
54 }
55