Debian Codegraph @

src/main/org/h2/engine/Constants.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.ResultSet;
9
10 /**
11 * Constants are fixed values that are used in the whole database code.
12 */
13 public class Constants {
14
15 /**
16 * The build date is updated for each public release.
17 */
18 public static final String BUILD_DATE = "2023-07-04";
19
20 /**
21 * Sequential version number. Even numbers are used for official releases,
22 * odd numbers are used for development builds.
23 */
24 public static final int BUILD_ID = 220;
25
26 /**
27 * Whether this is a snapshot version.
28 */
29 public static final boolean BUILD_SNAPSHOT = false;
30
31 /**
32 * If H2 is compiled to be included in a product, this should be set to
33 * a unique vendor id (to distinguish from official releases).
34 * Additionally, a version number should be set to distinguish releases.
35 * Example: ACME_SVN1651_BUILD3
36 */
37 public static final String BUILD_VENDOR_AND_VERSION = null;
38
39 /**
40 * The TCP protocol version number 17.
41 * @since 1.4.197 (2018-03-18)
42 */
43 public static final int TCP_PROTOCOL_VERSION_17 = 17;
44
45 /**
46 * The TCP protocol version number 18.
47 * @since 1.4.198 (2019-02-22)
48 */
49 public static final int TCP_PROTOCOL_VERSION_18 = 18;
50
51 /**
52 * The TCP protocol version number 19.
53 * @since 1.4.200 (2019-10-14)
54 */
55 public static final int TCP_PROTOCOL_VERSION_19 = 19;
56
57 /**
58 * The TCP protocol version number 20.
59 * @since 2.0.202 (2021-11-25)
60 */
61 public static final int TCP_PROTOCOL_VERSION_20 = 20;
62
63 /**
64 * Minimum supported version of TCP protocol.
65 */
66 public static final int TCP_PROTOCOL_VERSION_MIN_SUPPORTED = TCP_PROTOCOL_VERSION_17;
67
68 /**
69 * Maximum supported version of TCP protocol.
70 */
71 public static final int TCP_PROTOCOL_VERSION_MAX_SUPPORTED = TCP_PROTOCOL_VERSION_20;
72
73 /**
74 * The major version of this database.
75 */
76 public static final int VERSION_MAJOR = 2;
77
78 /**
79 * The minor version of this database.
80 */
81 public static final int VERSION_MINOR = 2;
82
83 /**
84 * The lock mode that means no locking is used at all.
85 */
86 public static final int LOCK_MODE_OFF = 0;
87
88 /**
89 * The lock mode that means read locks are acquired, but they are released
90 * immediately after the statement is executed.
91 */
92 public static final int LOCK_MODE_READ_COMMITTED = 3;
93
94 /**
95 * The lock mode that means table level locking is used for reads and
96 * writes.
97 */
98 public static final int LOCK_MODE_TABLE = 1;
99
100 /**
101 * The lock mode that means table level locking is used for reads and
102 * writes. If a table is locked, System.gc is called to close forgotten
103 * connections.
104 */
105 public static final int LOCK_MODE_TABLE_GC = 2;
106
107 /**
108 * Constant meaning both numbers and text is allowed in SQL statements.
109 */
110 public static final int ALLOW_LITERALS_ALL = 2;
111
112 /**
113 * Constant meaning no literals are allowed in SQL statements.
114 */
115 public static final int ALLOW_LITERALS_NONE = 0;
116
117 /**
118 * Constant meaning only numbers are allowed in SQL statements (but no
119 * texts).
120 */
121 public static final int ALLOW_LITERALS_NUMBERS = 1;
122
123 /**
124 * SNAPSHOT isolation level of transaction.
125 */
126 public static final int TRANSACTION_SNAPSHOT = 6;
127
128 /**
129 * Whether searching in Blob values should be supported.
130 */
131 public static final boolean BLOB_SEARCH = false;
132
133 /**
134 * The minimum number of entries to keep in the cache.
135 */
136 public static final int CACHE_MIN_RECORDS = 16;
137
138 /**
139 * The default cache type.
140 */
141 public static final String CACHE_TYPE_DEFAULT = "LRU";
142
143 /**
144 * The value of the cluster setting if clustering is disabled.
145 */
146 public static final String CLUSTERING_DISABLED = "''";
147
148 /**
149 * The value of the cluster setting if clustering is enabled (the actual
150 * value is checked later).
151 */
152 public static final String CLUSTERING_ENABLED = "TRUE";
153
154 /**
155 * The database URL used when calling a function if only the column list
156 * should be returned.
157 */
158 public static final String CONN_URL_COLUMNLIST = "jdbc:columnlist:connection";
159
160 /**
161 * The database URL used when calling a function if the data should be
162 * returned.
163 */
164 public static final String CONN_URL_INTERNAL = "jdbc:default:connection";
165
166 /**
167 * The cost is calculated on rowcount + this offset,
168 * to avoid using the wrong or no index if the table
169 * contains no rows _currently_ (when preparing the statement)
170 */
171 public static final int COST_ROW_OFFSET = 1000;
172
173 /**
174 * The number of milliseconds after which to check for a deadlock if locking
175 * is not successful.
176 */
177 public static final int DEADLOCK_CHECK = 100;
178
179 /**
180 * The default port number of the HTTP server (for the H2 Console).
181 * This value is also in the documentation and in the Server javadoc.
182 */
183 public static final int DEFAULT_HTTP_PORT = 8082;
184
185 /**
186 * The default value for the LOCK_MODE setting.
187 */
188 public static final int DEFAULT_LOCK_MODE = LOCK_MODE_READ_COMMITTED;
189
190 /**
191 * The default maximum length of an LOB that is stored with the record
192 * itself, and not in a separate place.
193 */
194 public static final int DEFAULT_MAX_LENGTH_INPLACE_LOB = 256;
195
196 /**
197 * The default for the setting MAX_OPERATION_MEMORY.
198 */
199 public static final int DEFAULT_MAX_OPERATION_MEMORY = 100_000;
200
201 /**
202 * The default page size to use for new databases.
203 */
204 public static final int DEFAULT_PAGE_SIZE = 4096;
205
206 /**
207 * The default result set concurrency for statements created with
208 * Connection.createStatement() or prepareStatement(String sql).
209 */
210 public static final int DEFAULT_RESULT_SET_CONCURRENCY =
211 ResultSet.CONCUR_READ_ONLY;
212
213 /**
214 * The default port of the TCP server.
215 * This port is also used in the documentation and in the Server javadoc.
216 */
217 public static final int DEFAULT_TCP_PORT = 9092;
218
219 /**
220 * The default delay in milliseconds before the transaction log is written.
221 */
222 public static final int DEFAULT_WRITE_DELAY = 500;
223
224 /**
225 * The password is hashed this many times
226 * to slow down dictionary attacks.
227 */
228 public static final int ENCRYPTION_KEY_HASH_ITERATIONS = 1024;
229
230 /**
231 * The block of a file. It is also the encryption block size.
232 */
233 public static final int FILE_BLOCK_SIZE = 16;
234
235 /**
236 * For testing, the lock timeout is smaller than for interactive use cases.
237 * This value could be increased to about 5 or 10 seconds.
238 */
239 public static final int INITIAL_LOCK_TIMEOUT = 2000;
240
241 /**
242 * The block size for I/O operations.
243 */
244 public static final int IO_BUFFER_SIZE = 4 * 1024;
245
246 /**
247 * The block size used to compress data in the LZFOutputStream.
248 */
249 public static final int IO_BUFFER_SIZE_COMPRESS = 128 * 1024;
250
251 /**
252 * The number of milliseconds to wait between checking the .lock.db file
253 * still exists once a database is locked.
254 */
255 public static final int LOCK_SLEEP = 1000;
256
257 /**
258 * The maximum allowed length of identifiers.
259 */
260 public static final int MAX_IDENTIFIER_LENGTH = 256;
261
262 /**
263 * The maximum number of columns in a table, select statement or row value.
264 */
265 public static final int MAX_COLUMNS = 16_384;
266
267 /**
268 * The maximum allowed length for character string, binary string, and other
269 * data types based on them; excluding LOB data types.
270 * <p>
271 * This needs to be less than (2^31-8)/2 to avoid running into the limit on
272 * encoding data fields when storing rows.
273 */
274 public static final int MAX_STRING_LENGTH = 1000_000_000;
275
276 /**
277 * The maximum allowed precision of numeric data types.
278 */
279 public static final int MAX_NUMERIC_PRECISION = 100_000;
280
281 /**
282 * The maximum allowed cardinality of array.
283 */
284 public static final int MAX_ARRAY_CARDINALITY = 65_536;
285
286 /**
287 * The highest possible parameter index.
288 */
289 public static final int MAX_PARAMETER_INDEX = 100_000;
290
291 /**
292 * The memory needed by a regular object with at least one field.
293 */
294 // Java 6, 64 bit: 24
295 // Java 6, 32 bit: 12
296 public static final int MEMORY_OBJECT = 24;
297
298 /**
299 * The memory needed by an array.
300 */
301 public static final int MEMORY_ARRAY = 24;
302
303 /**
304 * The memory needed by a pointer.
305 */
306 // Java 6, 64 bit: 8
307 // Java 6, 32 bit: 4
308 public static final int MEMORY_POINTER = 8;
309
310 /**
311 * The memory needed by a Row.
312 */
313 public static final int MEMORY_ROW = 40;
314
315 /**
316 * The name prefix used for indexes that are not explicitly named.
317 */
318 public static final String PREFIX_INDEX = "INDEX_";
319
320 /**
321 * The name prefix used for synthetic nested join tables.
322 */
323 public static final String PREFIX_JOIN = "SYSTEM_JOIN_";
324
325 /**
326 * The name prefix used for primary key constraints that are not explicitly
327 * named.
328 */
329 public static final String PREFIX_PRIMARY_KEY = "PRIMARY_KEY_";
330
331 /**
332 * The name prefix used for query aliases that are not explicitly named.
333 */
334 public static final String PREFIX_QUERY_ALIAS = "QUERY_ALIAS_";
335
336 /**
337 * Every user belongs to this role.
338 */
339 public static final String PUBLIC_ROLE_NAME = "PUBLIC";
340
341 /**
342 * The number of bytes in random salt that is used to hash passwords.
343 */
344 public static final int SALT_LEN = 8;
345
346 /**
347 * The identity of INFORMATION_SCHEMA.
348 */
349 public static final int INFORMATION_SCHEMA_ID = -1;
350
351 /**
352 * The identity of PUBLIC schema.
353 */
354 public static final int MAIN_SCHEMA_ID = 0;
355
356 /**
357 * The name of the default schema.
358 */
359 public static final String SCHEMA_MAIN = "PUBLIC";
360
361 /**
362 * The identity of pg_catalog schema.
363 */
364 public static final int PG_CATALOG_SCHEMA_ID = -1_000;
365
366 /**
367 * The name of the pg_catalog schema.
368 */
369 public static final String SCHEMA_PG_CATALOG = "PG_CATALOG";
370
371 /**
372 * The default selectivity (used if the selectivity is not calculated).
373 */
374 public static final int SELECTIVITY_DEFAULT = 50;
375
376 /**
377 * The number of distinct values to keep in memory when running ANALYZE.
378 */
379 public static final int SELECTIVITY_DISTINCT_COUNT = 10_000;
380
381 /**
382 * The default directory name of the server properties file for the H2
383 * Console.
384 */
385 public static final String SERVER_PROPERTIES_DIR = "~";
386
387 /**
388 * The name of the server properties file for the H2 Console.
389 */
390 public static final String SERVER_PROPERTIES_NAME = ".h2.server.properties";
391
392 /**
393 * Queries that take longer than this number of milliseconds are written to
394 * the trace file with the level info.
395 */
396 public static final long SLOW_QUERY_LIMIT_MS = 100;
397
398 /**
399 * The database URL prefix of this database.
400 */
401 public static final String START_URL = "jdbc:h2:";
402
403 /**
404 * The file name suffix of file lock files that are used to make sure a
405 * database is open by only one process at any time.
406 */
407 public static final String SUFFIX_LOCK_FILE = ".lock.db";
408
409 /**
410 * The file name suffix of a H2 version 1.1 database file.
411 */
412 public static final String SUFFIX_OLD_DATABASE_FILE = ".data.db";
413
414 /**
415 * The file name suffix of a MVStore file.
416 */
417 public static final String SUFFIX_MV_FILE = ".mv.db";
418
419 /**
420 * The file name suffix of a new MVStore file, used when compacting a store.
421 */
422 public static final String SUFFIX_MV_STORE_NEW_FILE = ".newFile";
423
424 /**
425 * The file name suffix of a temporary MVStore file, used when compacting a
426 * store.
427 */
428 public static final String SUFFIX_MV_STORE_TEMP_FILE = ".tempFile";
429
430 /**
431 * The file name suffix of temporary files.
432 */
433 public static final String SUFFIX_TEMP_FILE = ".temp.db";
434
435 /**
436 * The file name suffix of trace files.
437 */
438 public static final String SUFFIX_TRACE_FILE = ".trace.db";
439
440 /**
441 * How often we check to see if we need to apply a throttling delay if SET
442 * THROTTLE has been used.
443 */
444 public static final int THROTTLE_DELAY = 50;
445
446 /**
447 * The database URL format in simplified Backus-Naur form.
448 */
449 public static final String URL_FORMAT = START_URL +
450 "{ {.|mem:}[name] | [file:]fileName | " +
451 "{tcp|ssl}:[//]server[:port][,server2[:port]]/name }[;key=value...]";
452
453 /**
454 * The package name of user defined classes.
455 */
456 public static final String USER_PACKAGE = "org.h2.dynamic";
457
458 /**
459 * The maximum time in milliseconds to keep the cost of a view.
460 * 10000 means 10 seconds.
461 */
462 public static final int VIEW_COST_CACHE_MAX_AGE = 10_000;
463
464 /**
465 * The name of the index cache that is used for temporary view (subqueries
466 * used as tables).
467 */
468 public static final int VIEW_INDEX_CACHE_SIZE = 64;
469
470 /**
471 * The maximum number of entries in query statistics.
472 */
473 public static final int QUERY_STATISTICS_MAX_ENTRIES = 100;
474
475 /**
476 * The minimum number of characters in web admin password.
477 */
478 public static final int MIN_WEB_ADMIN_PASSWORD_LENGTH = 12;
479
480 /**
481 * Announced version for PgServer.
482 */
483 public static final String PG_VERSION = "8.2.23";
484
485 /**
486 * The version of this product, consisting of major version, minor
487 * version, and build id.
488 */
489 public static final String VERSION;
490
491 /**
492 * The complete version number of this database, consisting of
493 * the major version, the minor version, the build id, and the build date.
494 */
495 public static final String FULL_VERSION;
496
497 static {
498 String version = VERSION_MAJOR + "." + VERSION_MINOR + '.' + BUILD_ID;
499 if (BUILD_VENDOR_AND_VERSION != null) {
500 version += '_' + BUILD_VENDOR_AND_VERSION;
501 }
502 if (BUILD_SNAPSHOT) {
503 version += "-SNAPSHOT";
504 }
505 VERSION = version;
506 FULL_VERSION = version + (" (" + BUILD_DATE + ')');
507 }
508
509 private Constants() {
510 // utility class
511 }
512
513 }