KickJava   Java API By Example, From Geeks To Geeks.

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


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.Session;
11 import org.h2.engine.User;
12 import org.h2.message.Message;
13 import org.h2.schema.Schema;
14
15 public class CreateSchema extends DefineCommand {
16
17     private String JavaDoc schemaName;
18     private String JavaDoc authorization;
19     private boolean ifNotExists;
20     
21     public CreateSchema(Session session) {
22         super(session);
23     }
24     
25     public void setIfNotExists(boolean ifNotExists) {
26         this.ifNotExists = ifNotExists;
27     }
28
29     public int update() throws SQLException JavaDoc {
30         session.getUser().checkAdmin();
31         session.commit();
32         Database db = session.getDatabase();
33         User user = db.getUser(authorization);
34         user.checkAdmin();
35         if(db.findSchema(schemaName) != null) {
36             if (ifNotExists) {
37                 return 0;
38             }
39             throw Message.getSQLException(Message.SCHEMA_ALREADY_EXISTS_1, schemaName);
40         }
41         int id = getObjectId(true, true);
42         Schema schema = new Schema(db, id, schemaName, user, false);
43         db.addDatabaseObject(session, schema);
44         return 0;
45     }
46
47     public void setSchemaName(String JavaDoc name) {
48         this.schemaName = name;
49     }
50
51     public void setAuthorization(String JavaDoc userName) {
52         this.authorization = userName;
53     }
54
55 }
56
57
Popular Tags