1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.command.dml; |
7 | |
8 | import org.h2.command.CommandInterface; |
9 | import org.h2.command.ddl.SchemaCommand; |
10 | import org.h2.engine.Right; |
11 | import org.h2.engine.Session; |
12 | import org.h2.message.DbException; |
13 | import org.h2.schema.Schema; |
14 | import org.h2.table.Table; |
15 | |
16 | /** |
17 | * This class represents the statement |
18 | * ALTER TABLE SET |
19 | */ |
20 | public class AlterTableSet extends SchemaCommand { |
21 | |
22 | private String tableName; |
23 | private final int type; |
24 | |
25 | private final boolean value; |
26 | private boolean checkExisting; |
27 | |
28 | public AlterTableSet(Session session, Schema schema, int type, boolean value) { |
29 | super(session, schema); |
30 | this.type = type; |
31 | this.value = value; |
32 | } |
33 | |
34 | public void setCheckExisting(boolean b) { |
35 | this.checkExisting = b; |
36 | } |
37 | |
38 | @Override |
39 | public boolean isTransactional() { |
40 | return true; |
41 | } |
42 | |
43 | public void setTableName(String tableName) { |
44 | this.tableName = tableName; |
45 | } |
46 | |
47 | @Override |
48 | public int update() { |
49 | Table table = getSchema().getTableOrView(session, tableName); |
50 | session.getUser().checkRight(table, Right.ALL); |
51 | table.lock(session, true, true); |
52 | switch(type) { |
53 | case CommandInterface.ALTER_TABLE_SET_REFERENTIAL_INTEGRITY: |
54 | table.setCheckForeignKeyConstraints(session, value, value ? |
55 | checkExisting : false); |
56 | break; |
57 | default: |
58 | DbException.throwInternalError("type="+type); |
59 | } |
60 | return 0; |
61 | } |
62 | |
63 | @Override |
64 | public int getType() { |
65 | return type; |
66 | } |
67 | |
68 | } |