File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\CreateSchema.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.engine.User;
14 import org.h2.message.DbException;
15 import org.h2.schema.Schema;
16
17 /**
18 * This class represents the statement
19 * CREATE SCHEMA
20 */
21 public class CreateSchema extends DefineCommand {
22
23 private String schemaName;
24 private String authorization;
25 private boolean ifNotExists;
26
27 public CreateSchema(Session session) {
28 super(session);
29 }
30
31 public void setIfNotExists(boolean ifNotExists) {
32 this.ifNotExists = ifNotExists;
33 }
34
35 public int update() {
36 session.getUser().checkAdmin();
37 session.commit(true);
38 Database db = session.getDatabase();
39 User user = db.getUser(authorization);
40 user.checkAdmin();
41 if (db.findSchema(schemaName) != null) {
42 if (ifNotExists) {
43 return 0;
44 }
45 throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, schemaName);
46 }
47 int id = getObjectId();
48 Schema schema = new Schema(db, id, schemaName, user, false);
49 db.addDatabaseObject(session, schema);
50 return 0;
51 }
52
53 public void setSchemaName(String name) {
54 this.schemaName = name;
55 }
56
57 public void setAuthorization(String userName) {
58 this.authorization = userName;
59 }
60
61 public int getType() {
62 return CommandInterface.CREATE_SCHEMA;
63 }
64
65 }
66