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.Right; 11 import org.h2.engine.Session; 12 import org.h2.message.Message; 13 import org.h2.schema.Schema; 14 import org.h2.table.Table; 15 16 17 20 public class AlterTableRename extends SchemaCommand { 21 22 private Table oldTable; 23 private String newTableName; 24 25 public AlterTableRename(Session session, Schema schema) { 26 super(session, schema); 27 } 28 29 public void setOldTable(Table table) { 30 oldTable = table; 31 } 32 33 public void setNewTableName(String name) { 34 newTableName = name; 35 } 36 37 public int update() throws SQLException { 38 session.commit(); 39 Database db = session.getDatabase(); 40 if(getSchema().findTableOrView(session, newTableName) != null || newTableName.equals(oldTable.getName())) { 41 throw Message.getSQLException(Message.TABLE_OR_VIEW_ALREADY_EXISTS_1, newTableName); 42 } 43 session.getUser().checkRight(oldTable, Right.ALL); 44 if(oldTable.getTemporary()) { 45 throw Message.getUnsupportedException(); 47 } 48 db.renameSchemaObject(session, oldTable, newTableName); 49 return 0; 50 } 51 52 } 53 | Popular Tags |