File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\AlterSchemaRename.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.Session;
13 import org.h2.message.DbException;
14 import org.h2.schema.Schema;
15 import org.h2.schema.SchemaObject;
16
17 import java.util.ArrayList;
18
19 /**
20 * This class represents the statement
21 * ALTER SCHEMA RENAME
22 */
23 public class AlterSchemaRename extends DefineCommand {
24
25 private Schema oldSchema;
26 private String newSchemaName;
27
28 public AlterSchemaRename(Session session) {
29 super(session);
30 }
31
32 public void setOldSchema(Schema schema) {
33 oldSchema = schema;
34 }
35
36 public void setNewName(String name) {
37 newSchemaName = name;
38 }
39
40 public int update() {
41 session.commit(true);
42 Database db = session.getDatabase();
43 if (!oldSchema.canDrop()) {
44 throw DbException.get(ErrorCode.SCHEMA_CAN_NOT_BE_DROPPED_1, oldSchema.getName());
45 }
46 if (db.findSchema(newSchemaName) != null || newSchemaName.equals(oldSchema.getName())) {
47 throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, newSchemaName);
48 }
49 session.getUser().checkAdmin();
50 db.renameDatabaseObject(session, oldSchema, newSchemaName);
51 ArrayList<SchemaObject> all = db.getAllSchemaObjects();
52 for (SchemaObject schemaObject : all) {
53 db.update(session, schemaObject);
54 }
55 return 0;
56 }
57
58 public int getType() {
59 return CommandInterface.ALTER_SCHEMA_RENAME;
60 }
61
62 }
63