File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\AlterIndexRename.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.ddl;
8
9 import org.h2.command.CommandInterface;
10 import org.h2.constant.ErrorCode;
11 import org.h2.engine.Database;
12 import org.h2.engine.Right;
13 import org.h2.engine.Session;
14 import org.h2.index.Index;
15 import org.h2.message.DbException;
16 import org.h2.schema.Schema;
17
18 /**
19 * This class represents the statement
20 * ALTER INDEX RENAME
21 */
22 public class AlterIndexRename extends DefineCommand {
23
24 private Index oldIndex;
25 private String newIndexName;
26
27 public AlterIndexRename(Session session) {
28 super(session);
29 }
30
31 public void setOldIndex(Index index) {
32 oldIndex = index;
33 }
34
35 public void setNewName(String name) {
36 newIndexName = name;
37 }
38
39 public int update() {
40 session.commit(true);
41 Database db = session.getDatabase();
42 Schema schema = oldIndex.getSchema();
43 if (schema.findIndex(session, newIndexName) != null || newIndexName.equals(oldIndex.getName())) {
44 throw DbException.get(ErrorCode.INDEX_ALREADY_EXISTS_1, newIndexName);
45 }
46 session.getUser().checkRight(oldIndex.getTable(), Right.ALL);
47 db.renameSchemaObject(session, oldIndex, newIndexName);
48 return 0;
49 }
50
51 public int getType() {
52 return CommandInterface.ALTER_INDEX_RENAME;
53 }
54
55 }
56