Debian Codegraph @

src/main/org/h2/command/ddl/AlterDomainRename.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.engine.SessionLocal;
11 import org.h2.message.DbException;
12 import org.h2.schema.Domain;
13 import org.h2.schema.Schema;
14
15 /**
16 * This class represents the statement
17 * ALTER DOMAIN RENAME
18 */
19 public class AlterDomainRename extends AlterDomain {
20
21 private String newDomainName;
22
23 public AlterDomainRename(SessionLocal session, Schema schema) {
24 super(session, schema);
25 }
26
27 public void setNewDomainName(String name) {
28 newDomainName = name;
29 }
30
31 @Override
32 long update(Schema schema, Domain domain) {
33 Domain d = schema.findDomain(newDomainName);
34 if (d != null) {
35 if (domain != d) {
36 throw DbException.get(ErrorCode.DOMAIN_ALREADY_EXISTS_1, newDomainName);
37 }
38 if (newDomainName.equals(domain.getName())) {
39 return 0;
40 }
41 }
42 getDatabase().renameSchemaObject(session, domain, newDomainName);
43 forAllDependencies(session, domain, null, null, false);
44 return 0;
45 }
46
47 @Override
48 public int getType() {
49 return CommandInterface.ALTER_DOMAIN_RENAME;
50 }
51
52 }