Debian Codegraph @

src/main/org/h2/command/ddl/AlterTable.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.engine.Right;
10 import org.h2.engine.SessionLocal;
11 import org.h2.message.DbException;
12 import org.h2.schema.Schema;
13 import org.h2.table.Table;
14
15 /**
16 * The base class for ALTER TABLE commands.
17 */
18 public abstract class AlterTable extends SchemaCommand {
19
20 String tableName;
21
22 boolean ifTableExists;
23
24 AlterTable(SessionLocal session, Schema schema) {
25 super(session, schema);
26 }
27
28 public final void setTableName(String tableName) {
29 this.tableName = tableName;
30 }
31
32 public final void setIfTableExists(boolean b) {
33 ifTableExists = b;
34 }
35
36 @Override
37 public final long update() {
38 Table table = getSchema().findTableOrView(session, tableName);
39 if (table == null) {
40 if (ifTableExists) {
41 return 0;
42 }
43 throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableName);
44 }
45 session.getUser().checkTableRight(table, Right.SCHEMA_OWNER);
46 return update(table);
47 }
48
49 abstract long update(Table table);
50
51 }