01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.command.dml;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.command.ddl.SchemaCommand;
11: import org.h2.engine.Right;
12: import org.h2.engine.Session;
13: import org.h2.message.Message;
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: /**
24: * Enable the referential integrity.
25: */
26: public static final int REFERENTIAL_INTEGRITY_TRUE = 0;
27:
28: /**
29: * Disable the referential integrity.
30: */
31: public static final int REFERENTIAL_INTEGRITY_FALSE = 1;
32:
33: private String tableName;
34: private final int type;
35: private boolean checkExisting;
36:
37: public AlterTableSet(Session session, Schema schema, int type) {
38: super (session, schema);
39: this .type = type;
40: }
41:
42: public void setCheckExisting(boolean b) {
43: this .checkExisting = b;
44: }
45:
46: public boolean isTransactional() {
47: return true;
48: }
49:
50: public void setTableName(String tableName) {
51: this .tableName = tableName;
52: }
53:
54: public int update() throws SQLException {
55: Table table = getSchema().getTableOrView(session, tableName);
56: session.getUser().checkRight(table, Right.ALL);
57: table.lock(session, true, true);
58: switch (type) {
59: case REFERENTIAL_INTEGRITY_TRUE:
60: table.setCheckForeignKeyConstraints(session, true,
61: checkExisting);
62: break;
63: case REFERENTIAL_INTEGRITY_FALSE:
64: table.setCheckForeignKeyConstraints(session, false, false);
65: break;
66: default:
67: throw Message.getInternalError("type=" + type);
68: }
69: return 0;
70: }
71:
72: }
|