Debian Codegraph @

src/main/org/h2/command/ddl/DropSynonym.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.Schema;
13 import org.h2.table.TableSynonym;
14
15 /**
16 * This class represents the statement
17 * DROP SYNONYM
18 */
19 public class DropSynonym extends SchemaOwnerCommand {
20
21 private String synonymName;
22 private boolean ifExists;
23
24 public DropSynonym(SessionLocal session, Schema schema) {
25 super(session, schema);
26 }
27
28 public void setSynonymName(String name) {
29 this.synonymName = name;
30 }
31
32 @Override
33 long update(Schema schema) {
34 TableSynonym synonym = schema.getSynonym(synonymName);
35 if (synonym == null) {
36 if (!ifExists) {
37 throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, synonymName);
38 }
39 } else {
40 getDatabase().removeSchemaObject(session, synonym);
41 }
42 return 0;
43 }
44
45 public void setIfExists(boolean ifExists) {
46 this.ifExists = ifExists;
47 }
48
49 @Override
50 public int getType() {
51 return CommandInterface.DROP_SYNONYM;
52 }
53
54 }