File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\AlterTableRenameColumn.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.ddl;
8
9 import org.h2.command.CommandInterface;
10 import org.h2.engine.Database;
11 import org.h2.engine.DbObject;
12 import org.h2.engine.Right;
13 import org.h2.engine.Session;
14 import org.h2.table.Column;
15 import org.h2.table.Table;
16
17 /**
18 * This class represents the statement
19 * ALTER TABLE ALTER COLUMN RENAME
20 */
21 public class AlterTableRenameColumn extends DefineCommand {
22
23 private Table table;
24 private Column column;
25 private String newName;
26
27 public AlterTableRenameColumn(Session session) {
28 super(session);
29 }
30
31 public void setTable(Table table) {
32 this.table = table;
33 }
34
35 public void setColumn(Column column) {
36 this.column = column;
37 }
38
39 public void setNewColumnName(String newName) {
40 this.newName = newName;
41 }
42
43 public int update() {
44 session.commit(true);
45 Database db = session.getDatabase();
46 session.getUser().checkRight(table, Right.ALL);
47 table.checkSupportAlter();
48 table.renameColumn(column, newName);
49 table.setModified();
50 db.update(session, table);
51 for (DbObject child : table.getChildren()) {
52 if (child.getCreateSQL() != null) {
53 db.update(session, child);
54 }
55 }
56 return 0;
57 }
58
59 public int getType() {
60 return CommandInterface.ALTER_TABLE_ALTER_COLUMN_RENAME;
61 }
62
63 }
64