File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\CreateLinkedTable.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.table.TableLink;
16
17 /**
18 * This class represents the statement
19 * CREATE LINKED TABLE
20 */
21 public class CreateLinkedTable extends SchemaCommand {
22
23 private String tableName;
24 private String driver, url, user, password, originalSchema, originalTable;
25 private boolean ifNotExists;
26 private String comment;
27 private boolean emitUpdates;
28 private boolean force;
29 private boolean temporary;
30 private boolean globalTemporary;
31 private boolean readOnly;
32
33 public CreateLinkedTable(Session session, Schema schema) {
34 super(session, schema);
35 }
36
37 public void setTableName(String tableName) {
38 this.tableName = tableName;
39 }
40
41 public void setDriver(String driver) {
42 this.driver = driver;
43 }
44
45 public void setOriginalTable(String originalTable) {
46 this.originalTable = originalTable;
47 }
48
49 public void setPassword(String password) {
50 this.password = password;
51 }
52
53 public void setUrl(String url) {
54 this.url = url;
55 }
56
57 public void setUser(String user) {
58 this.user = user;
59 }
60
61 public void setIfNotExists(boolean ifNotExists) {
62 this.ifNotExists = ifNotExists;
63 }
64
65 public int update() {
66 session.commit(true);
67 Database db = session.getDatabase();
68 session.getUser().checkAdmin();
69 if (getSchema().findTableOrView(session, tableName) != null) {
70 if (ifNotExists) {
71 return 0;
72 }
73 throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1,
74 tableName);
75 }
76 int id = getObjectId();
77 TableLink table = getSchema().createTableLink(id, tableName, driver, url,
78 user, password, originalSchema, originalTable, emitUpdates, force);
79 table.setTemporary(temporary);
80 table.setGlobalTemporary(globalTemporary);
81 table.setComment(comment);
82 table.setReadOnly(readOnly);
83 if (temporary && !globalTemporary) {
84 session.addLocalTempTable(table);
85 } else {
86 db.addSchemaObject(session, table);
87 }
88 return 0;
89 }
90
91 public void setEmitUpdates(boolean emitUpdates) {
92 this.emitUpdates = emitUpdates;
93 }
94
95 public void setComment(String comment) {
96 this.comment = comment;
97 }
98
99 public void setForce(boolean force) {
100 this.force = force;
101 }
102
103 public void setTemporary(boolean temp) {
104 this.temporary = temp;
105 }
106
107 public void setGlobalTemporary(boolean globalTemp) {
108 this.globalTemporary = globalTemp;
109 }
110
111 public void setReadOnly(boolean readOnly) {
112 this.readOnly = readOnly;
113 }
114
115 public void setOriginalSchema(String originalSchema) {
116 this.originalSchema = originalSchema;
117 }
118
119 public int getType() {
120 return CommandInterface.CREATE_LINKED_TABLE;
121 }
122
123 }
124