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.ddl;
07:
08: import java.sql.SQLException;
09: import org.h2.engine.Database;
10: import org.h2.engine.DbObject;
11: import org.h2.engine.Right;
12: import org.h2.engine.Session;
13: import org.h2.table.Column;
14: import org.h2.table.Table;
15: import org.h2.util.ObjectArray;
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() throws SQLException {
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: ObjectArray children = table.getChildren();
52: for (int i = 0; i < children.size(); i++) {
53: DbObject child = (DbObject) children.get(i);
54: if (child.getCreateSQL() != null) {
55: db.update(session, child);
56: }
57: }
58: return 0;
59: }
60:
61: }
|