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.index.Index; 13 import org.h2.message.Message; 14 import org.h2.schema.Schema; 15 16 public class AlterIndexRename extends SchemaCommand { 17 18 private Index oldIndex; 19 private String newIndexName; 20 21 public AlterIndexRename(Session session, Schema schema) { 22 super(session, schema); 23 } 24 25 public void setOldIndex(Index index) { 26 oldIndex = index; 27 } 28 29 public void setNewName(String name) { 30 newIndexName = name; 31 } 32 33 public int update() throws SQLException { 34 session.commit(); 35 Database db = session.getDatabase(); 36 if(getSchema().findIndex(newIndexName) != null || newIndexName.equals(oldIndex.getName())) { 37 throw Message.getSQLException(Message.INDEX_ALREADY_EXISTS_1, newIndexName); 38 } 39 session.getUser().checkRight(oldIndex.getTable(), Right.ALL); 40 db.renameSchemaObject(session, oldIndex, newIndexName); 41 return 0; 42 } 43 44 } 45 | Popular Tags |