File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\engine\Mode.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.engine;
8
9 import java.util.HashMap;
10 import org.h2.util.New;
11 import org.h2.util.StringUtils;
12
13 /**
14 * The compatibility modes. There is a fixed set of modes (for example
15 * PostgreSQL, MySQL). Each mode has different settings.
16 */
17 public class Mode {
18
19 /**
20 * The name of the default mode.
21 */
22 static final String REGULAR = "REGULAR";
23
24 private static final HashMap<String, Mode> MODES = New.hashMap();
25
26 // Modes are also documented in the features section
27
28 /**
29 * When enabled, aliased columns (as in SELECT ID AS I FROM TEST) return the
30 * alias (I in this case) in ResultSetMetaData.getColumnName() and 'null' in
31 * getTableName(). If disabled, the real column name (ID in this case) and
32 * table name is returned.
33 */
34 public boolean aliasColumnName;
35
36 /**
37 * When inserting data, if a column is defined to be NOT NULL and NULL is
38 * inserted, then a 0 (or empty string, or the current timestamp for
39 * timestamp columns) value is used. Usually, this operation is not allowed
40 * and an exception is thrown.
41 */
42 public boolean convertInsertNullToZero;
43
44 /**
45 * When converting the scale of decimal data, the number is only converted
46 * if the new scale is smaller than the current scale. Usually, the scale is
47 * converted and 0s are added if required.
48 */
49 public boolean convertOnlyToSmallerScale;
50
51 /**
52 * Creating indexes in the CREATE TABLE statement is allowed using
53 * <code>INDEX(..)</code> or <code>KEY(..)</code>.
54 * Example: <code>create table test(id int primary key, name varchar(255),
55 * key idx_name(name));</code>
56 */
57 public boolean indexDefinitionInCreateTable;
58
59 /**
60 * Meta data calls return identifiers in lower case.
61 */
62 public boolean lowerCaseIdentifiers;
63
64 /**
65 * Concatenation with NULL results in NULL. Usually, NULL is treated as an
66 * empty string if only one of the operands is NULL, and NULL is only
67 * returned if both operands are NULL.
68 */
69 public boolean nullConcatIsNull;
70
71 /**
72 * Identifiers may be quoted using square brackets as in [Test].
73 */
74 public boolean squareBracketQuotedNames;
75
76 /**
77 * Support for the syntax
78 * [OFFSET .. ROW|ROWS] [FETCH FIRST .. ROW|ROWS ONLY]
79 * as an alternative for LIMIT .. OFFSET.
80 */
81 public boolean supportOffsetFetch;
82
83 /**
84 * The system columns 'CTID' and 'OID' are supported.
85 */
86 public boolean systemColumns;
87
88 /**
89 * For unique indexes, NULL is distinct. That means only one row with NULL
90 * in one of the columns is allowed.
91 */
92 public boolean uniqueIndexSingleNull;
93
94 /**
95 * When using unique indexes, multiple rows with NULL in all columns
96 * are allowed, however it is not allowed to have multiple rows with the
97 * same values otherwise.
98 */
99 public boolean uniqueIndexSingleNullExceptAllColumnsAreNull;
100
101 /**
102 * Support the pseudo-table SYSIBM.SYSDUMMY1.
103 */
104 public boolean sysDummy1;
105
106 /**
107 * Text can be concatenated using '+'.
108 */
109 public boolean allowPlusForStringConcat;
110
111 /**
112 * The function LOG() uses base 10 instead of E.
113 */
114 public boolean logIsLogBase10;
115
116 private final String name;
117
118 static {
119 Mode mode = new Mode(REGULAR);
120 mode.nullConcatIsNull = true;
121 add(mode);
122
123 mode = new Mode("DB2");
124 mode.aliasColumnName = true;
125 mode.supportOffsetFetch = true;
126 mode.sysDummy1 = true;
127 add(mode);
128
129 mode = new Mode("Derby");
130 mode.aliasColumnName = true;
131 mode.uniqueIndexSingleNull = true;
132 mode.supportOffsetFetch = true;
133 mode.sysDummy1 = true;
134 add(mode);
135
136 mode = new Mode("HSQLDB");
137 mode.aliasColumnName = true;
138 mode.convertOnlyToSmallerScale = true;
139 mode.nullConcatIsNull = true;
140 mode.uniqueIndexSingleNull = true;
141 mode.allowPlusForStringConcat = true;
142 add(mode);
143
144 mode = new Mode("MSSQLServer");
145 mode.aliasColumnName = true;
146 mode.squareBracketQuotedNames = true;
147 mode.uniqueIndexSingleNull = true;
148 mode.allowPlusForStringConcat = true;
149 add(mode);
150
151 mode = new Mode("MySQL");
152 mode.convertInsertNullToZero = true;
153 mode.indexDefinitionInCreateTable = true;
154 mode.lowerCaseIdentifiers = true;
155 add(mode);
156
157 mode = new Mode("Oracle");
158 mode.aliasColumnName = true;
159 mode.uniqueIndexSingleNullExceptAllColumnsAreNull = true;
160 add(mode);
161
162 mode = new Mode("PostgreSQL");
163 mode.aliasColumnName = true;
164 mode.nullConcatIsNull = true;
165 mode.supportOffsetFetch = true;
166 mode.systemColumns = true;
167 mode.logIsLogBase10 = true;
168 add(mode);
169 }
170
171 private Mode(String name) {
172 this.name = name;
173 }
174
175 private static void add(Mode mode) {
176 MODES.put(StringUtils.toUpperEnglish(mode.name), mode);
177 }
178
179 /**
180 * Get the mode with the given name.
181 *
182 * @param name the name of the mode
183 * @return the mode object
184 */
185 public static Mode getInstance(String name) {
186 return MODES.get(StringUtils.toUpperEnglish(name));
187 }
188
189 public String getName() {
190 return name;
191 }
192
193 }
194