1 5 package org.h2.command.ddl; 6 7 import java.sql.SQLException ; 8 9 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 public class AlterTableRenameColumn extends DefineCommand { 18 19 private Table table; 20 private Column column; 21 private String newName; 22 23 public AlterTableRenameColumn(Session session) { 24 super(session); 25 } 26 27 public void setTable(Table table) { 28 this.table = table; 29 } 30 31 public void setColumn(Column column) { 32 this.column = column; 33 } 34 35 public void setNewColumnName(String newName) { 36 this.newName = newName; 37 } 38 39 public int update() throws SQLException { 40 session.commit(); 41 Database db = session.getDatabase(); 42 session.getUser().checkRight(table, Right.ALL); 43 table.checkSupportAlter(); 44 table.renameColumn(column, newName); 45 table.setModified(); 46 db.update(session, table); 47 ObjectArray children = table.getChildren(); 48 for(int i=0; i<children.size(); i++) { 49 DbObject child = (DbObject) children.get(i); 50 if(child.getCreateSQL() != null) { 51 db.update(session, child); 52 } 53 } 54 return 0; 55 } 56 57 } 58 | Popular Tags |