File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\dml\AlterTableSet.java.html

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