File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\table\TableBase.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.table;
8
9 import org.h2.command.ddl.CreateTableData;
10 import org.h2.util.StatementBuilder;
11 import org.h2.util.StringUtils;
12
13 /**
14 * The base class of a regular table, or a user defined table.
15 *
16 * @author Thomas Mueller
17 * @author Sergi Vladykin
18 */
19 public abstract class TableBase extends Table {
20
21 /**
22 * The table engine used (null for regular tables).
23 */
24 private final String tableEngine;
25
26 private final boolean globalTemporary;
27
28 public TableBase(CreateTableData data) {
29 super(data.schema, data.id, data.tableName, data.persistIndexes, data.persistData);
30 this.tableEngine = data.tableEngine;
31 this.globalTemporary = data.globalTemporary;
32 setTemporary(data.temporary);
33 Column[] cols = new Column[data.columns.size()];
34 data.columns.toArray(cols);
35 setColumns(cols);
36 }
37
38 public String getDropSQL() {
39 return "DROP TABLE IF EXISTS " + getSQL() + " CASCADE";
40 }
41
42 public String getCreateSQL() {
43 StatementBuilder buff = new StatementBuilder("CREATE ");
44 if (isTemporary()) {
45 if (isGlobalTemporary()) {
46 buff.append("GLOBAL ");
47 } else {
48 buff.append("LOCAL ");
49 }
50 buff.append("TEMPORARY ");
51 } else if (isPersistIndexes()) {
52 buff.append("CACHED ");
53 } else {
54 buff.append("MEMORY ");
55 }
56 buff.append("TABLE ");
57 if (isHidden) {
58 buff.append("IF NOT EXISTS ");
59 }
60 buff.append(getSQL());
61 if (comment != null) {
62 buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
63 }
64 buff.append("(\n ");
65 for (Column column : columns) {
66 buff.appendExceptFirst(",\n ");
67 buff.append(column.getCreateSQL());
68 }
69 buff.append("\n)");
70 if (tableEngine != null) {
71 buff.append("\nENGINE \"");
72 buff.append(tableEngine);
73 buff.append('\"');
74 }
75 if (!isPersistIndexes() && !isPersistData()) {
76 buff.append("\nNOT PERSISTENT");
77 }
78 if (isHidden) {
79 buff.append("\nHIDDEN");
80 }
81 return buff.toString();
82 }
83
84 public boolean isGlobalTemporary() {
85 return globalTemporary;
86 }
87
88 }
89