Debian Codegraph @

src/main/org/h2/command/ddl/DropSequence.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.schema.Sequence;
14
15 /**
16 * This class represents the statement
17 * DROP SEQUENCE
18 */
19 public class DropSequence extends SchemaOwnerCommand {
20
21 private String sequenceName;
22 private boolean ifExists;
23
24 public DropSequence(SessionLocal session, Schema schema) {
25 super(session, schema);
26 }
27
28 public void setIfExists(boolean b) {
29 ifExists = b;
30 }
31
32 public void setSequenceName(String sequenceName) {
33 this.sequenceName = sequenceName;
34 }
35
36 @Override
37 long update(Schema schema) {
38 Sequence sequence = schema.findSequence(sequenceName);
39 if (sequence == null) {
40 if (!ifExists) {
41 throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName);
42 }
43 } else {
44 if (sequence.getBelongsToTable()) {
45 throw DbException.get(ErrorCode.SEQUENCE_BELONGS_TO_A_TABLE_1, sequenceName);
46 }
47 getDatabase().removeSchemaObject(session, sequence);
48 }
49 return 0;
50 }
51
52 @Override
53 public int getType() {
54 return CommandInterface.DROP_SEQUENCE;
55 }
56
57 }