Debian Codegraph @

src/main/org/h2/engine/Mode.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.engine;
7
8 import java.sql.Types;
9 import java.util.Collections;
10 import java.util.HashMap;
11 import java.util.Set;
12 import java.util.regex.Pattern;
13
14 import org.h2.util.StringUtils;
15 import org.h2.value.DataType;
16 import org.h2.value.Value;
17
18 /**
19 * The compatibility modes. There is a fixed set of modes (for example
20 * PostgreSQL, MySQL). Each mode has different settings.
21 */
22 public class Mode {
23
24 public enum ModeEnum {
25 REGULAR, STRICT, LEGACY, DB2, Derby, MariaDB, MSSQLServer, HSQLDB, MySQL, Oracle, PostgreSQL
26 }
27
28 /**
29 * Generation of column names for expressions.
30 */
31 public enum ExpressionNames {
32 /**
33 * Use optimized SQL representation of expression.
34 */
35 OPTIMIZED_SQL,
36
37 /**
38 * Use original SQL representation of expression.
39 */
40 ORIGINAL_SQL,
41
42 /**
43 * Generate empty name.
44 */
45 EMPTY,
46
47 /**
48 * Use ordinal number of a column.
49 */
50 NUMBER,
51
52 /**
53 * Use ordinal number of a column with C prefix.
54 */
55 C_NUMBER,
56
57 /**
58 * Use function name for functions and ?column? for other expressions
59 */
60 POSTGRESQL_STYLE,
61 }
62
63 /**
64 * Generation of column names for expressions to be used in a view.
65 */
66 public enum ViewExpressionNames {
67 /**
68 * Use both specified and generated names as is.
69 */
70 AS_IS,
71
72 /**
73 * Throw exception for unspecified names.
74 */
75 EXCEPTION,
76
77 /**
78 * Use both specified and generated names as is, but replace too long
79 * generated names with {@code Name_exp_###}.
80 */
81 MYSQL_STYLE,
82 }
83
84 /**
85 * When CHAR values are right-padded with spaces.
86 */
87 public enum CharPadding {
88 /**
89 * CHAR values are always right-padded with spaces.
90 */
91 ALWAYS,
92
93 /**
94 * Spaces are trimmed from the right side of CHAR values, but CHAR
95 * values in result sets are right-padded with spaces to the declared
96 * length
97 */
98 IN_RESULT_SETS,
99
100 /**
101 * Spaces are trimmed from the right side of CHAR values.
102 */
103 NEVER
104 }
105
106 private static final HashMap<String, Mode> MODES = new HashMap<>();
107
108 // Modes are also documented in the features section
109
110 /**
111 * When enabled, aliased columns (as in SELECT ID AS I FROM TEST) return the
112 * alias (I in this case) in ResultSetMetaData.getColumnName() and 'null' in
113 * getTableName(). If disabled, the real column name (ID in this case) and
114 * table name is returned.
115 */
116 public boolean aliasColumnName;
117
118 /**
119 * When converting the scale of decimal data, the number is only converted
120 * if the new scale is smaller than the current scale. Usually, the scale is
121 * converted and 0s are added if required.
122 */
123 public boolean convertOnlyToSmallerScale;
124
125 /**
126 * Creating indexes in the CREATE TABLE statement is allowed using
127 * <code>INDEX(..)</code> or <code>KEY(..)</code>.
128 * Example: <code>create table test(id int primary key, name varchar(255),
129 * key idx_name(name));</code>
130 */
131 public boolean indexDefinitionInCreateTable;
132
133 /**
134 * Identifiers may be quoted using square brackets as in [Test].
135 */
136 public boolean squareBracketQuotedNames;
137
138 /**
139 * The system columns 'ctid' and 'oid' are supported.
140 */
141 public boolean systemColumns;
142
143 /**
144 * Determines how rows with {@code NULL} values in indexed columns are handled
145 * in unique indexes and constraints by default.
146 */
147 public NullsDistinct nullsDistinct = NullsDistinct.DISTINCT;
148
149 /**
150 * Empty strings are treated like NULL values. Useful for Oracle emulation.
151 */
152 public boolean treatEmptyStringsAsNull;
153
154 /**
155 * Support the pseudo-table SYSIBM.SYSDUMMY1.
156 */
157 public boolean sysDummy1;
158
159 /**
160 * Text can be concatenated using '+'.
161 */
162 public boolean allowPlusForStringConcat;
163
164 /**
165 * The single-argument function LOG() uses base 10 instead of E.
166 */
167 public boolean logIsLogBase10;
168
169 /**
170 * Swap the parameters of LOG() function.
171 */
172 public boolean swapLogFunctionParameters;
173
174 /**
175 * The function REGEXP_REPLACE() uses \ for back-references.
176 */
177 public boolean regexpReplaceBackslashReferences;
178
179 /**
180 * Swap the parameters of the CONVERT function.
181 */
182 public boolean swapConvertFunctionParameters;
183
184 /**
185 * can set the isolation level using WITH {RR|RS|CS|UR}
186 */
187 public boolean isolationLevelInSelectOrInsertStatement;
188
189 /**
190 * MySQL style INSERT ... ON DUPLICATE KEY UPDATE ... and INSERT IGNORE.
191 */
192 public boolean onDuplicateKeyUpdate;
193
194 /**
195 * MySQL style REPLACE INTO.
196 */
197 public boolean replaceInto;
198
199 /**
200 * PostgreSQL style INSERT ... ON CONFLICT DO NOTHING.
201 */
202 public boolean insertOnConflict;
203
204 /**
205 * Pattern describing the keys the java.sql.Connection.setClientInfo()
206 * method accepts.
207 */
208 public Pattern supportedClientInfoPropertiesRegEx;
209
210 /**
211 * Support the # for column names
212 */
213 public boolean supportPoundSymbolForColumnNames;
214
215 /**
216 * Whether IN predicate may have an empty value list.
217 */
218 public boolean allowEmptyInPredicate;
219
220 /**
221 * How to pad or trim CHAR values.
222 */
223 public CharPadding charPadding = CharPadding.ALWAYS;
224
225 /**
226 * Whether DB2 TIMESTAMP formats are allowed.
227 */
228 public boolean allowDB2TimestampFormat;
229
230 /**
231 * Discard SQLServer table hints (e.g. "SELECT * FROM table WITH (NOLOCK)")
232 */
233 public boolean discardWithTableHints;
234
235 /**
236 * If {@code true}, datetime value function return the same value within a
237 * transaction, if {@code false} datetime value functions return the same
238 * value within a command.
239 */
240 public boolean dateTimeValueWithinTransaction;
241
242 /**
243 * If {@code true} {@code 0x}-prefixed numbers are parsed as binary string
244 * literals, if {@code false} they are parsed as hexadecimal numeric values.
245 */
246 public boolean zeroExLiteralsAreBinaryStrings;
247
248 /**
249 * If {@code true} unrelated ORDER BY expression are allowed in DISTINCT
250 * queries, if {@code false} they are disallowed.
251 */
252 public boolean allowUnrelatedOrderByExpressionsInDistinctQueries;
253
254 /**
255 * If {@code true} some additional non-standard ALTER TABLE commands are allowed.
256 */
257 public boolean alterTableExtensionsMySQL;
258
259 /**
260 * If {@code true} non-standard ALTER TABLE MODIFY COLUMN is allowed.
261 */
262 public boolean alterTableModifyColumn;
263
264 /**
265 * If {@code true} non-standard ALTER TABLE MODIFY COLUMN preserves nullability when changing data type.
266 */
267 public boolean alterTableModifyColumnPreserveNullability;
268
269 /**
270 * If {@code true} MySQL table and column options are allowed
271 */
272 public boolean mySqlTableOptions;
273
274 /**
275 * If {@code true} DELETE identifier FROM is allowed
276 */
277 public boolean deleteIdentifierFrom;
278
279 /**
280 * If {@code true} TRUNCATE TABLE uses RESTART IDENTITY by default.
281 */
282 public boolean truncateTableRestartIdentity;
283
284 /**
285 * If {@code true} NEXT VALUE FOR SEQUENCE, CURRENT VALUE FOR SEQUENCE,
286 * SEQUENCE.NEXTVAL, and SEQUENCE.CURRVAL return values with DECIMAL/NUMERIC
287 * data type instead of BIGINT.
288 */
289 public boolean decimalSequences;
290
291 /**
292 * If {@code true} constructs like 'CREATE TABLE CATALOG..TABLE_NAME' are allowed,
293 * the default schema is used.
294 */
295 public boolean allowEmptySchemaValuesAsDefaultSchema;
296
297 /**
298 * If {@code true} all numeric data types may have precision and 'UNSIGNED'
299 * clause.
300 */
301 public boolean allNumericTypesHavePrecision;
302
303 /**
304 * If {@code true} 'FOR BIT DATA' clauses are allowed for character string
305 * data types.
306 */
307 public boolean forBitData;
308
309 /**
310 * If {@code true} 'CHAR' and 'BYTE' length units are allowed.
311 */
312 public boolean charAndByteLengthUnits;
313
314 /**
315 * If {@code true}, sequence.NEXTVAL and sequence.CURRVAL pseudo columns are
316 * supported.
317 */
318 public boolean nextvalAndCurrvalPseudoColumns;
319
320 /**
321 * If {@code true}, the next value expression returns different values when
322 * invoked multiple times within a row. This setting does not affect
323 * NEXTVAL() function.
324 */
325 public boolean nextValueReturnsDifferentValues;
326
327 /**
328 * If {@code true}, sequences of generated by default identity columns are
329 * updated when value is provided by user.
330 */
331 public boolean updateSequenceOnManualIdentityInsertion;
332
333 /**
334 * If {@code true}, last identity of the session is updated on insertion of
335 * a new value into identity column.
336 */
337 public boolean takeInsertedIdentity;
338
339 /**
340 * If {@code true}, last identity of the session is updated on generation of
341 * a new sequence value.
342 */
343 public boolean takeGeneratedSequenceValue;
344
345 /**
346 * If {@code true}, identity columns have DEFAULT ON NULL clause.
347 */
348 public boolean identityColumnsHaveDefaultOnNull;
349
350 /**
351 * If {@code true}, merge when matched clause may have WHERE clause.
352 */
353 public boolean mergeWhere;
354
355 /**
356 * If {@code true}, allow using from clause in update statement.
357 */
358 public boolean allowUsingFromClauseInUpdateStatement;
359
360 /**
361 * If {@code true}, referential constraints will create a unique constraint
362 * on referenced columns if it doesn't exist instead of throwing an
363 * exception.
364 */
365 public boolean createUniqueConstraintForReferencedColumns;
366
367 /**
368 * How column names are generated for expressions.
369 */
370 public ExpressionNames expressionNames = ExpressionNames.OPTIMIZED_SQL;
371
372 /**
373 * How column names are generated for views.
374 */
375 public ViewExpressionNames viewExpressionNames = ViewExpressionNames.AS_IS;
376
377 /**
378 * Whether TOP clause in SELECT queries is supported.
379 */
380 public boolean topInSelect;
381
382 /**
383 * Whether TOP clause in DML commands is supported.
384 */
385 public boolean topInDML;
386
387 /**
388 * Whether LIMIT / OFFSET clauses are supported.
389 */
390 public boolean limit;
391
392 /**
393 * Whether MINUS can be used as EXCEPT.
394 */
395 public boolean minusIsExcept;
396
397 /**
398 * Whether IDENTITY pseudo data type is supported.
399 */
400 public boolean identityDataType;
401
402 /**
403 * Whether SERIAL and BIGSERIAL pseudo data types are supported.
404 */
405 public boolean serialDataTypes;
406
407 /**
408 * Whether SQL Server-style IDENTITY clause is supported.
409 */
410 public boolean identityClause;
411
412 /**
413 * Whether MySQL-style AUTO_INCREMENT clause is supported.
414 */
415 public boolean autoIncrementClause;
416
417 /**
418 * Whether DATE data type is parsed as TIMESTAMP(0).
419 */
420 public boolean dateIsTimestamp0;
421
422 /**
423 * Whether NUMERIC and DECIMAL/DEC without parameters are parsed as DECFLOAT.
424 */
425 public boolean numericIsDecfloat;
426
427 /**
428 * An optional Set of hidden/disallowed column types.
429 * Certain DBMSs don't support all column types provided by H2, such as
430 * "NUMBER" when using PostgreSQL mode.
431 */
432 public Set<String> disallowedTypes = Collections.emptySet();
433
434 /**
435 * Custom mappings from type names to data types.
436 */
437 public HashMap<String, DataType> typeByNameMap = new HashMap<>();
438
439 /**
440 * Allow to use GROUP BY n, where n is column index in the SELECT list, similar to ORDER BY
441 */
442 public boolean groupByColumnIndex;
443
444 /**
445 * Allow to compare numeric with BOOLEAN.
446 */
447 public boolean numericWithBooleanComparison;
448
449 /**
450 * Accepts comma ',' as key/value separator in JSON_OBJECT and JSON_OBJECTAGG functions.
451 */
452 public boolean acceptsCommaAsJsonKeyValueSeparator;
453
454 private final String name;
455
456 private final ModeEnum modeEnum;
457
458 static {
459 Mode mode = new Mode(ModeEnum.REGULAR);
460 mode.allowEmptyInPredicate = true;
461 mode.dateTimeValueWithinTransaction = true;
462 mode.topInSelect = true;
463 mode.limit = true;
464 mode.minusIsExcept = true;
465 mode.identityDataType = true;
466 mode.serialDataTypes = true;
467 mode.autoIncrementClause = true;
468 add(mode);
469
470 mode = new Mode(ModeEnum.STRICT);
471 mode.dateTimeValueWithinTransaction = true;
472 add(mode);
473
474 mode = new Mode(ModeEnum.LEGACY);
475 // Features of REGULAR mode
476 mode.allowEmptyInPredicate = true;
477 mode.dateTimeValueWithinTransaction = true;
478 mode.topInSelect = true;
479 mode.limit = true;
480 mode.minusIsExcept = true;
481 mode.identityDataType = true;
482 mode.serialDataTypes = true;
483 mode.autoIncrementClause = true;
484 // Legacy identity and sequence features
485 mode.identityClause = true;
486 mode.updateSequenceOnManualIdentityInsertion = true;
487 mode.takeInsertedIdentity = true;
488 mode.identityColumnsHaveDefaultOnNull = true;
489 mode.nextvalAndCurrvalPseudoColumns = true;
490 // Legacy DML features
491 mode.topInDML = true;
492 mode.mergeWhere = true;
493 // Legacy DDL features
494 mode.createUniqueConstraintForReferencedColumns = true;
495 // Legacy numeric with boolean comparison
496 mode.numericWithBooleanComparison = true;
497 add(mode);
498
499 mode = new Mode(ModeEnum.DB2);
500 mode.aliasColumnName = true;
501 mode.sysDummy1 = true;
502 mode.isolationLevelInSelectOrInsertStatement = true;
503 // See
504 // https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/
505 // com.ibm.db2z11.doc.java/src/tpc/imjcc_r0052001.dita
506 mode.supportedClientInfoPropertiesRegEx =
507 Pattern.compile("ApplicationName|ClientAccountingInformation|" +
508 "ClientUser|ClientCorrelationToken");
509 mode.allowDB2TimestampFormat = true;
510 mode.forBitData = true;
511 mode.takeInsertedIdentity = true;
512 mode.nextvalAndCurrvalPseudoColumns = true;
513 mode.expressionNames = ExpressionNames.NUMBER;
514 mode.viewExpressionNames = ViewExpressionNames.EXCEPTION;
515 mode.limit = true;
516 mode.minusIsExcept = true;
517 mode.numericWithBooleanComparison = true;
518 add(mode);
519
520 mode = new Mode(ModeEnum.Derby);
521 mode.aliasColumnName = true;
522 mode.nullsDistinct = NullsDistinct.NOT_DISTINCT;
523 mode.sysDummy1 = true;
524 mode.isolationLevelInSelectOrInsertStatement = true;
525 // Derby does not support client info properties as of version 10.12.1.1
526 mode.supportedClientInfoPropertiesRegEx = null;
527 mode.forBitData = true;
528 mode.takeInsertedIdentity = true;
529 mode.expressionNames = ExpressionNames.NUMBER;
530 mode.viewExpressionNames = ViewExpressionNames.EXCEPTION;
531 add(mode);
532
533 mode = new Mode(ModeEnum.HSQLDB);
534 mode.allowPlusForStringConcat = true;
535 mode.identityColumnsHaveDefaultOnNull = true;
536 // HSQLDB does not support client info properties. See
537 // http://hsqldb.org/doc/apidocs/org/hsqldb/jdbc/JDBCConnection.html#setClientInfo-java.lang.String-java.lang.String-
538 mode.supportedClientInfoPropertiesRegEx = null;
539 mode.expressionNames = ExpressionNames.C_NUMBER;
540 mode.topInSelect = true;
541 mode.limit = true;
542 mode.minusIsExcept = true;
543 mode.numericWithBooleanComparison = true;
544 add(mode);
545
546 mode = new Mode(ModeEnum.MSSQLServer);
547 mode.aliasColumnName = true;
548 mode.squareBracketQuotedNames = true;
549 mode.nullsDistinct = NullsDistinct.NOT_DISTINCT;
550 mode.allowPlusForStringConcat = true;
551 mode.swapLogFunctionParameters = true;
552 mode.swapConvertFunctionParameters = true;
553 mode.supportPoundSymbolForColumnNames = true;
554 mode.discardWithTableHints = true;
555 // MS SQL Server does not support client info properties. See
556 // https://msdn.microsoft.com/en-Us/library/dd571296%28v=sql.110%29.aspx
557 mode.supportedClientInfoPropertiesRegEx = null;
558 mode.zeroExLiteralsAreBinaryStrings = true;
559 mode.truncateTableRestartIdentity = true;
560 mode.takeInsertedIdentity = true;
561 DataType dt = DataType.createNumeric(19, 4);
562 dt.type = Value.NUMERIC;
563 dt.sqlType = Types.NUMERIC;
564 dt.specialPrecisionScale = true;
565 mode.typeByNameMap.put("MONEY", dt);
566 dt = DataType.createNumeric(10, 4);
567 dt.type = Value.NUMERIC;
568 dt.sqlType = Types.NUMERIC;
569 dt.specialPrecisionScale = true;
570 mode.typeByNameMap.put("SMALLMONEY", dt);
571 mode.typeByNameMap.put("UNIQUEIDENTIFIER", DataType.getDataType(Value.UUID));
572 mode.allowEmptySchemaValuesAsDefaultSchema = true;
573 mode.expressionNames = ExpressionNames.EMPTY;
574 mode.viewExpressionNames = ViewExpressionNames.EXCEPTION;
575 mode.topInSelect = true;
576 mode.topInDML = true;
577 mode.identityClause = true;
578 mode.numericWithBooleanComparison = true;
579 add(mode);
580
581 mode = new Mode(ModeEnum.MariaDB);
582 mode.indexDefinitionInCreateTable = true;
583 mode.regexpReplaceBackslashReferences = true;
584 mode.onDuplicateKeyUpdate = true;
585 mode.replaceInto = true;
586 mode.charPadding = CharPadding.NEVER;
587 mode.supportedClientInfoPropertiesRegEx = Pattern.compile(".*");
588 mode.zeroExLiteralsAreBinaryStrings = true;
589 mode.allowUnrelatedOrderByExpressionsInDistinctQueries = true;
590 mode.alterTableExtensionsMySQL = true;
591 mode.alterTableModifyColumn = true;
592 mode.mySqlTableOptions = true;
593 mode.deleteIdentifierFrom = true;
594 mode.truncateTableRestartIdentity = true;
595 mode.allNumericTypesHavePrecision = true;
596 mode.nextValueReturnsDifferentValues = true;
597 mode.updateSequenceOnManualIdentityInsertion = true;
598 mode.takeInsertedIdentity = true;
599 mode.identityColumnsHaveDefaultOnNull = true;
600 mode.expressionNames = ExpressionNames.ORIGINAL_SQL;
601 mode.viewExpressionNames = ViewExpressionNames.MYSQL_STYLE;
602 mode.limit = true;
603 mode.autoIncrementClause = true;
604 mode.typeByNameMap.put("YEAR", DataType.getDataType(Value.SMALLINT));
605 mode.groupByColumnIndex = true;
606 mode.numericWithBooleanComparison = true;
607 mode.acceptsCommaAsJsonKeyValueSeparator = true;
608 add(mode);
609
610 mode = new Mode(ModeEnum.MySQL);
611 mode.indexDefinitionInCreateTable = true;
612 mode.regexpReplaceBackslashReferences = true;
613 mode.onDuplicateKeyUpdate = true;
614 mode.replaceInto = true;
615 mode.charPadding = CharPadding.NEVER;
616 // MySQL allows to use any key for client info entries. See
617 // https://github.com/mysql/mysql-connector-j/blob/5.1.47/src/com/mysql/jdbc/JDBC4CommentClientInfoProvider.java
618 mode.supportedClientInfoPropertiesRegEx =
619 Pattern.compile(".*");
620 mode.zeroExLiteralsAreBinaryStrings = true;
621 mode.allowUnrelatedOrderByExpressionsInDistinctQueries = true;
622 mode.alterTableExtensionsMySQL = true;
623 mode.alterTableModifyColumn = true;
624 mode.mySqlTableOptions = true;
625 mode.deleteIdentifierFrom = true;
626 mode.truncateTableRestartIdentity = true;
627 mode.allNumericTypesHavePrecision = true;
628 mode.updateSequenceOnManualIdentityInsertion = true;
629 mode.takeInsertedIdentity = true;
630 mode.identityColumnsHaveDefaultOnNull = true;
631 mode.createUniqueConstraintForReferencedColumns = true;
632 mode.expressionNames = ExpressionNames.ORIGINAL_SQL;
633 mode.viewExpressionNames = ViewExpressionNames.MYSQL_STYLE;
634 mode.limit = true;
635 mode.autoIncrementClause = true;
636 mode.typeByNameMap.put("YEAR", DataType.getDataType(Value.SMALLINT));
637 mode.groupByColumnIndex = true;
638 mode.numericWithBooleanComparison = true;
639 mode.acceptsCommaAsJsonKeyValueSeparator = true;
640 add(mode);
641
642 mode = new Mode(ModeEnum.Oracle);
643 mode.aliasColumnName = true;
644 mode.convertOnlyToSmallerScale = true;
645 mode.nullsDistinct = NullsDistinct.ALL_DISTINCT;
646 mode.treatEmptyStringsAsNull = true;
647 mode.regexpReplaceBackslashReferences = true;
648 mode.supportPoundSymbolForColumnNames = true;
649 // Oracle accepts keys of the form <namespace>.*. See
650 // https://docs.oracle.com/database/121/JJDBC/jdbcvers.htm#JJDBC29006
651 mode.supportedClientInfoPropertiesRegEx =
652 Pattern.compile(".*\\..*");
653 mode.alterTableModifyColumn = true;
654 mode.alterTableModifyColumnPreserveNullability = true;
655 mode.decimalSequences = true;
656 mode.charAndByteLengthUnits = true;
657 mode.nextvalAndCurrvalPseudoColumns = true;
658 mode.mergeWhere = true;
659 mode.minusIsExcept = true;
660 mode.expressionNames = ExpressionNames.ORIGINAL_SQL;
661 mode.viewExpressionNames = ViewExpressionNames.EXCEPTION;
662 mode.dateIsTimestamp0 = true;
663 mode.typeByNameMap.put("BINARY_FLOAT", DataType.getDataType(Value.REAL));
664 mode.typeByNameMap.put("BINARY_DOUBLE", DataType.getDataType(Value.DOUBLE));
665 add(mode);
666
667 mode = new Mode(ModeEnum.PostgreSQL);
668 mode.aliasColumnName = true;
669 mode.systemColumns = true;
670 mode.logIsLogBase10 = true;
671 mode.regexpReplaceBackslashReferences = true;
672 mode.insertOnConflict = true;
673 // PostgreSQL only supports the ApplicationName property. See
674 // https://github.com/hhru/postgres-jdbc/blob/master/postgresql-jdbc-9.2-1002.src/
675 // org/postgresql/jdbc4/AbstractJdbc4Connection.java
676 mode.supportedClientInfoPropertiesRegEx =
677 Pattern.compile("ApplicationName");
678 mode.charPadding = CharPadding.IN_RESULT_SETS;
679 mode.nextValueReturnsDifferentValues = true;
680 mode.takeGeneratedSequenceValue = true;
681 mode.expressionNames = ExpressionNames.POSTGRESQL_STYLE;
682 mode.allowUsingFromClauseInUpdateStatement = true;
683 mode.limit = true;
684 mode.serialDataTypes = true;
685 mode.numericIsDecfloat = true;
686 // Enumerate all H2 types NOT supported by PostgreSQL:
687 Set<String> disallowedTypes = new java.util.HashSet<>();
688 disallowedTypes.add("NUMBER");
689 disallowedTypes.add("TINYINT");
690 disallowedTypes.add("BLOB");
691 disallowedTypes.add("VARCHAR_IGNORECASE");
692 mode.disallowedTypes = disallowedTypes;
693 dt = DataType.getDataType(Value.JSON);
694 mode.typeByNameMap.put("JSONB", dt);
695 dt = DataType.createNumeric(19, 2);
696 dt.type = Value.NUMERIC;
697 dt.sqlType = Types.NUMERIC;
698 dt.specialPrecisionScale = true;
699 mode.typeByNameMap.put("MONEY", dt);
700 dt = DataType.getDataType(Value.INTEGER);
701 mode.typeByNameMap.put("OID", dt);
702 mode.dateTimeValueWithinTransaction = true;
703 mode.groupByColumnIndex = true;
704 add(mode);
705 }
706
707 private Mode(ModeEnum modeEnum) {
708 this.name = modeEnum.name();
709 this.modeEnum = modeEnum;
710 }
711
712 private static void add(Mode mode) {
713 MODES.put(StringUtils.toUpperEnglish(mode.name), mode);
714 }
715
716 /**
717 * Get the mode with the given name.
718 *
719 * @param name the name of the mode
720 * @return the mode object
721 */
722 public static Mode getInstance(String name) {
723 return MODES.get(StringUtils.toUpperEnglish(name));
724 }
725
726 public static Mode getRegular() {
727 return getInstance(ModeEnum.REGULAR.name());
728 }
729
730 public String getName() {
731 return name;
732 }
733
734 public ModeEnum getEnum() {
735 return this.modeEnum;
736 }
737
738 @Override
739 public String toString() {
740 return name;
741 }
742
743 }