KickJava   Java API By Example, From Geeks To Geeks.

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


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.message.Message;
12 import org.h2.schema.Schema;
13 import org.h2.table.TableLink;
14
15
16 /**
17  * @author Thomas
18  */

19
20 public class CreateLinkedTable extends SchemaCommand {
21
22     private String JavaDoc tableName;
23     private String JavaDoc driver, url, user, password, originalTable;
24     private boolean ifNotExists;
25     private String JavaDoc comment;
26
27     public CreateLinkedTable(Session session, Schema schema) {
28         super(session, schema);
29     }
30
31     public void setTableName(String JavaDoc tableName) {
32         this.tableName = tableName;
33     }
34
35     public void setDriver(String JavaDoc driver) {
36         this.driver = driver;
37     }
38
39     public void setOriginalTable(String JavaDoc originalTable) {
40         this.originalTable = originalTable;
41     }
42
43     public void setPassword(String JavaDoc password) {
44         this.password = password;
45     }
46
47     public void setUrl(String JavaDoc url) {
48         this.url = url;
49     }
50
51     public void setUser(String JavaDoc user) {
52         this.user = user;
53     }
54
55     public void setIfNotExists(boolean ifNotExists) {
56         this.ifNotExists = ifNotExists;
57     }
58
59     public int update() throws SQLException JavaDoc {
60         session.commit();
61         Database db = session.getDatabase();
62         session.getUser().checkAdmin();
63         if(getSchema().findTableOrView(session, tableName)!=null) {
64             if (ifNotExists) {
65                 return 0;
66             }
67             throw Message.getSQLException(Message.TABLE_OR_VIEW_ALREADY_EXISTS_1,
68                     tableName);
69         }
70         int id = getObjectId(false, true);
71         TableLink table = new TableLink(getSchema(), id, tableName, driver, url, user, password, originalTable);
72         table.setComment(comment);
73         db.addSchemaObject(session, table);
74         return 0;
75     }
76
77     public void setComment(String JavaDoc comment) {
78         this.comment = comment;
79     }
80
81 }
82
Popular Tags