KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > command > ddl > AlterIndexRename


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.command.ddl;
6
7 import java.sql.SQLException JavaDoc;
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 JavaDoc 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 JavaDoc name) {
30         newIndexName = name;
31     }
32
33     public int update() throws SQLException JavaDoc {
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