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