Debian Codegraph @

src/main/org/h2/command/ddl/AlterDomainDropConstraint.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.command.ddl;
7
8 import org.h2.api.ErrorCode;
9 import org.h2.command.CommandInterface;
10 import org.h2.constraint.Constraint;
11 import org.h2.constraint.Constraint.Type;
12 import org.h2.constraint.ConstraintDomain;
13 import org.h2.engine.SessionLocal;
14 import org.h2.message.DbException;
15 import org.h2.schema.Domain;
16 import org.h2.schema.Schema;
17
18 /**
19 * This class represents the statement ALTER DOMAIN DROP CONSTRAINT
20 */
21 public class AlterDomainDropConstraint extends AlterDomain {
22
23 private String constraintName;
24 private final boolean ifConstraintExists;
25
26 public AlterDomainDropConstraint(SessionLocal session, Schema schema, boolean ifConstraintExists) {
27 super(session, schema);
28 this.ifConstraintExists = ifConstraintExists;
29 }
30
31 public void setConstraintName(String string) {
32 constraintName = string;
33 }
34
35 @Override
36 long update(Schema schema, Domain domain) {
37 Constraint constraint = schema.findConstraint(session, constraintName);
38 if (constraint == null || constraint.getConstraintType() != Type.DOMAIN
39 || ((ConstraintDomain) constraint).getDomain() != domain) {
40 if (!ifConstraintExists) {
41 throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, constraintName);
42 }
43 } else {
44 getDatabase().removeSchemaObject(session, constraint);
45 }
46 return 0;
47 }
48
49 @Override
50 public int getType() {
51 return CommandInterface.ALTER_DOMAIN_DROP_CONSTRAINT;
52 }
53
54 }