File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\constant\SysProperties.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.constant;
8
9 import org.h2.message.TraceSystem;
10 import org.h2.util.MathUtils;
11 import org.h2.util.Utils;
12
13 /**
14 * The constants defined in this class are initialized from system properties.
15 * Some system properties are per machine settings, and others are as a last
16 * resort and temporary solution to work around a problem in the application or
17 * database engine. Also, there are system properties to enable features that
18 * are not yet fully tested or that are not backward compatible.
19 * <p>
20 * System properties can be set when starting the virtual machine:
21 * </p>
22 *
23 * <pre>
24 * java -Dh2.baseDir=/temp
25 * </pre>
26 *
27 * They can be set within the application, but this must be done before loading
28 * any classes of this database (before loading the JDBC driver):
29 *
30 * <pre>
31 * System.setProperty(&quot;h2.baseDir&quot;, &quot;/temp&quot;);
32 * </pre>
33 */
34 public class SysProperties {
35
36 /**
37 * INTERNAL
38 */
39 public static final String H2_SCRIPT_DIRECTORY = "h2.scriptDirectory";
40
41 /**
42 * INTERNAL
43 */
44 public static final String H2_BROWSER = "h2.browser";
45
46 /**
47 * System property <code>file.encoding</code> (default: Cp1252).<br />
48 * It is usually set by the system and is the default encoding used for the
49 * RunScript and CSV tool.
50 */
51 public static final String FILE_ENCODING = Utils.getProperty("file.encoding", "Cp1252");
52
53 /**
54 * System property <code>file.separator</code> (default: /).<br />
55 * It is usually set by the system, and used to build absolute file names.
56 */
57 public static final String FILE_SEPARATOR = Utils.getProperty("file.separator", "/");
58
59 /**
60 * System property <code>java.specification.version</code>.<br />
61 * It is set by the system. Examples: 1.4, 1.5, 1.6.
62 */
63 public static final String JAVA_SPECIFICATION_VERSION = Utils.getProperty("java.specification.version", "1.4");
64
65 /**
66 * System property <code>line.separator</code> (default: \n).<br />
67 * It is usually set by the system, and used by the script and trace tools.
68 */
69 public static final String LINE_SEPARATOR = Utils.getProperty("line.separator", "\n");
70
71 /**
72 * System property <code>user.home</code> (empty string if not set).<br />
73 * It is usually set by the system, and used as a replacement for ~ in file
74 * names.
75 */
76 public static final String USER_HOME = Utils.getProperty("user.home", "");
77
78 /**
79 * System property <code>h2.allowedClasses</code> (default: *).<br />
80 * Comma separated list of class names or prefixes.
81 */
82 public static final String ALLOWED_CLASSES = Utils.getProperty("h2.allowedClasses", "*");
83
84 /**
85 * System property <code>h2.browser</code> (default: null).<br />
86 * The preferred browser to use. If not set, the default browser is used.
87 * For Windows, to use the Internet Explorer, set this property to 'explorer'.
88 * For Mac OS, if the default browser is not Safari and you want to use Safari,
89 * use: <code>java -Dh2.browser="open,-a,Safari,%url" ...</code>.
90 */
91 public static final String BROWSER = Utils.getProperty(H2_BROWSER, null);
92
93 /**
94 * System property <code>h2.enableAnonymousSSL</code> (default: true).<br />
95 * When using SSL connection, the anonymous cipher suite
96 * SSL_DH_anon_WITH_RC4_128_MD5 should be enabled.
97 */
98 public static final boolean ENABLE_ANONYMOUS_SSL = Utils.getProperty("h2.enableAnonymousSSL", true);
99
100 /**
101 * System property <code>h2.bindAddress</code> (default: null).<br />
102 * The bind address to use.
103 */
104 public static final String BIND_ADDRESS = Utils.getProperty("h2.bindAddress", null);
105
106 /**
107 * System property <code>h2.check</code> (default: true).<br />
108 * Assertions in the database engine.
109 */
110 //## CHECK ##
111 public static final boolean CHECK = Utils.getProperty("h2.check", true);
112 /*/
113 public static final boolean CHECK = false;
114 //*/
115
116 /**
117 * System property <code>h2.check2</code> (default: true).<br />
118 * Additional assertions in the database engine.
119 */
120 //## CHECK ##
121 public static final boolean CHECK2 = Utils.getProperty("h2.check2", false);
122 /*/
123 public static final boolean CHECK2 = false;
124 //*/
125
126 /**
127 * System property <code>h2.clientTraceDirectory</code> (default:
128 * trace.db/).<br />
129 * Directory where the trace files of the JDBC client are stored (only for
130 * client / server).
131 */
132 public static final String CLIENT_TRACE_DIRECTORY = Utils.getProperty("h2.clientTraceDirectory", "trace.db/");
133
134 /**
135 * System property <code>h2.collatorCacheSize</code> (default: 32000).<br />
136 * The cache size for collation keys (in elements). Used when a collator has
137 * been set for the database.
138 */
139 public static final int COLLATOR_CACHE_SIZE = Utils.getProperty("h2.collatorCacheSize", 32000);
140
141 /**
142 * System property <code>h2.consoleStream</code> (default: true).<br />
143 * H2 Console: stream query results.
144 */
145 public static final boolean CONSOLE_STREAM = Utils.getProperty("h2.consoleStream", true);
146
147 /**
148 * System property <code>h2.dataSourceTraceLevel</code> (default: 1).<br />
149 * The trace level of the data source implementation. Default is 1 for
150 * error.
151 */
152 public static final int DATASOURCE_TRACE_LEVEL = Utils.getProperty("h2.dataSourceTraceLevel", TraceSystem.ERROR);
153
154 /**
155 * System property <code>h2.delayWrongPasswordMin</code> (default: 250).<br />
156 * The minimum delay in milliseconds before an exception is thrown for using
157 * the wrong user name or password. This slows down brute force attacks. The
158 * delay is reset to this value after a successful login. Unsuccessful
159 * logins will double the time until DELAY_WRONG_PASSWORD_MAX.
160 * To disable the delay, set this system property to 0.
161 */
162 public static final int DELAY_WRONG_PASSWORD_MIN = Utils.getProperty("h2.delayWrongPasswordMin", 250);
163
164 /**
165 * System property <code>h2.delayWrongPasswordMax</code> (default: 4000).<br />
166 * The maximum delay in milliseconds before an exception is thrown for using
167 * the wrong user name or password. This slows down brute force attacks. The
168 * delay is reset after a successful login. The value 0 means there is no
169 * maximum delay.
170 */
171 public static final int DELAY_WRONG_PASSWORD_MAX = Utils.getProperty("h2.delayWrongPasswordMax", 4000);
172
173 /**
174 * System property <code>h2.lobCloseBetweenReads</code> (default: false).<br />
175 * Close LOB files between read operations.
176 */
177 public static boolean lobCloseBetweenReads = Utils.getProperty("h2.lobCloseBetweenReads", false);
178
179 /**
180 * System property <code>h2.lobFilesPerDirectory</code> (default: 256).<br />
181 * Maximum number of LOB files per directory.
182 */
183 public static final int LOB_FILES_PER_DIRECTORY = Utils.getProperty("h2.lobFilesPerDirectory", 256);
184
185 /**
186 * System property <code>h2.lobInDatabase</code> (default: true).<br />
187 * Store LOB files in the database.
188 */
189 public static final boolean LOB_IN_DATABASE = Utils.getProperty("h2.lobInDatabase", true);
190
191 /**
192 * System property <code>h2.lobClientMaxSizeMemory</code> (default:
193 * 1048576).<br />
194 * The maximum size of a LOB object to keep in memory on the client side
195 * when using the server mode.
196 */
197 public static final int LOB_CLIENT_MAX_SIZE_MEMORY = Utils.getProperty("h2.lobClientMaxSizeMemory", 1024 * 1024);
198
199 /**
200 * System property <code>h2.maxFileRetry</code> (default: 16).<br />
201 * Number of times to retry file delete and rename. in Windows, files can't
202 * be deleted if they are open. Waiting a bit can help (sometimes the
203 * Windows Explorer opens the files for a short time) may help. Sometimes,
204 * running garbage collection may close files if the user forgot to call
205 * Connection.close() or InputStream.close().
206 */
207 public static final int MAX_FILE_RETRY = Math.max(1, Utils.getProperty("h2.maxFileRetry", 16));
208
209 /**
210 * System property <code>h2.maxReconnect</code> (default: 3).<br />
211 * The maximum number of tries to reconnect in a row.
212 */
213 public static final int MAX_RECONNECT = Utils.getProperty("h2.maxReconnect", 3);
214
215 /**
216 * System property <code>h2.maxTraceDataLength</code> (default: 65535).<br />
217 * The maximum size of a LOB value that is written as data to the trace system.
218 */
219 public static final long MAX_TRACE_DATA_LENGTH = Utils.getProperty("h2.maxTraceDataLength", 65535);
220
221 /**
222 * System property <code>h2.modifyOnWrite</code> (default: false).<br />
223 * Only modify the database file when recovery is necessary, or when writing
224 * to the database. If disabled, opening the database always writes to the
225 * file (except if the database is read-only). When enabled, the serialized
226 * file lock is faster.
227 */
228 public static final boolean MODIFY_ON_WRITE = Utils.getProperty("h2.modifyOnWrite", false);
229
230 /**
231 * System property <code>h2.nioLoadMapped</code> (default: false).<br />
232 * If the mapped buffer should be loaded when the file is opened.
233 * This can improve performance.
234 */
235 public static final boolean NIO_LOAD_MAPPED = Utils.getProperty("h2.nioLoadMapped", false);
236
237 /**
238 * System property <code>h2.nioCleanerHack</code> (default: false).<br />
239 * If enabled, use the reflection hack to un-map the mapped file if
240 * possible. If disabled, System.gc() is called in a loop until the object
241 * is garbage collected. See also
242 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038
243 */
244 public static final boolean NIO_CLEANER_HACK = Utils.getProperty("h2.nioCleanerHack", false);
245
246 /**
247 * System property <code>h2.objectCache</code> (default: true).<br />
248 * Cache commonly used values (numbers, strings). There is a shared cache
249 * for all values.
250 */
251 public static final boolean OBJECT_CACHE = Utils.getProperty("h2.objectCache", true);
252
253 /**
254 * System property <code>h2.objectCacheMaxPerElementSize</code> (default:
255 * 4096).<br />
256 * The maximum size (precision) of an object in the cache.
257 */
258 public static final int OBJECT_CACHE_MAX_PER_ELEMENT_SIZE = Utils.getProperty("h2.objectCacheMaxPerElementSize", 4096);
259
260 /**
261 * System property <code>h2.objectCacheSize</code> (default: 1024).<br />
262 * The maximum number of objects in the cache.
263 * This value must be a power of 2.
264 */
265 public static final int OBJECT_CACHE_SIZE = MathUtils.nextPowerOf2(Utils.getProperty("h2.objectCacheSize", 1024));
266
267 /**
268 * System property <code>h2.pgClientEncoding</code> (default: UTF-8).<br />
269 * Default client encoding for PG server. It is used if the client does not
270 * sends his encoding.
271 */
272 public static final String PG_DEFAULT_CLIENT_ENCODING = Utils.getProperty("h2.pgClientEncoding", "UTF-8");
273
274 /**
275 * System property <code>h2.prefixTempFile</code> (default: h2.temp).<br />
276 * The prefix for temporary files in the temp directory.
277 */
278 public static final String PREFIX_TEMP_FILE = Utils.getProperty("h2.prefixTempFile", "h2.temp");
279
280 /**
281 * System property <code>h2.runFinalize</code> (default: true).<br />
282 * Run finalizers to detect unclosed connections.
283 */
284 public static boolean runFinalize = Utils.getProperty("h2.runFinalize", true);
285
286 /**
287 * System property <code>h2.serverCachedObjects</code> (default: 64).<br />
288 * TCP Server: number of cached objects per session.
289 */
290 public static final int SERVER_CACHED_OBJECTS = Utils.getProperty("h2.serverCachedObjects", 64);
291
292 /**
293 * System property <code>h2.serverResultSetFetchSize</code>
294 * (default: 100).<br />
295 * The default result set fetch size when using the server mode.
296 */
297 public static final int SERVER_RESULT_SET_FETCH_SIZE = Utils.getProperty("h2.serverResultSetFetchSize", 100);
298
299 /**
300 * System property <code>h2.socketConnectRetry</code> (default: 16).<br />
301 * The number of times to retry opening a socket. Windows sometimes fails
302 * to open a socket, see bug
303 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213296
304 */
305 public static final int SOCKET_CONNECT_RETRY = Utils.getProperty("h2.socketConnectRetry", 16);
306
307 /**
308 * System property <code>h2.socketConnectTimeout</code> (default: 2000).<br />
309 * The timeout in milliseconds to connect to a server.
310 */
311 public static final int SOCKET_CONNECT_TIMEOUT = Utils.getProperty("h2.socketConnectTimeout", 2000);
312
313 /**
314 * System property <code>h2.sortNullsHigh</code> (default: false).<br />
315 * Invert the default sorting behavior for NULL, such that NULL
316 * is at the end of a result set in an ascending sort and at
317 * the beginning of a result set in a descending sort.
318 */
319 public static final boolean SORT_NULLS_HIGH = Utils.getProperty("h2.sortNullsHigh", false);
320
321 /**
322 * System property <code>h2.splitFileSizeShift</code> (default: 30).<br />
323 * The maximum file size of a split file is 1L &lt;&lt; x.
324 */
325 public static final long SPLIT_FILE_SIZE_SHIFT = Utils.getProperty("h2.splitFileSizeShift", 30);
326
327 /**
328 * System property <code>h2.storeLocalTime</code> (default: false).<br />
329 * Store the local time. If disabled, the daylight saving offset is not
330 * taken into account.
331 */
332 public static final boolean STORE_LOCAL_TIME = Utils.getProperty("h2.storeLocalTime", false);
333
334 /**
335 * System property <code>h2.syncMethod</code> (default: sync).<br />
336 * What method to call when closing the database, on checkpoint, and on
337 * CHECKPOINT SYNC. The following options are supported:
338 * "sync" (default): RandomAccessFile.getFD().sync();
339 * "force": RandomAccessFile.getChannel().force(true);
340 * "forceFalse": RandomAccessFile.getChannel().force(false);
341 * "": do not call a method (fast but there is a risk of data loss
342 * on power failure).
343 */
344 public static final String SYNC_METHOD = Utils.getProperty("h2.syncMethod", "sync");
345
346 /**
347 * System property <code>h2.traceIO</code> (default: false).<br />
348 * Trace all I/O operations.
349 */
350 public static final boolean TRACE_IO = Utils.getProperty("h2.traceIO", false);
351
352 /**
353 * System property <code>h2.urlMap</code> (default: null).<br />
354 * A properties file that contains a mapping between database URLs. New
355 * connections are written into the file. An empty value in the map means no
356 * redirection is used for the given URL.
357 */
358 public static final String URL_MAP = Utils.getProperty("h2.urlMap", null);
359
360 /**
361 * System property <code>h2.useThreadContextClassLoader</code>
362 * (default: false).<br />
363 * Instead of using the default class loader when deserializing objects, the
364 * current thread-context class loader will be used.
365 */
366 public static final boolean USE_THREAD_CONTEXT_CLASS_LOADER =
367 Utils.getProperty("h2.useThreadContextClassLoader", false);
368
369 /**
370 * System property <code>h2.serializeJavaObject</code> (default: true).<br />
371 * <b>If true</b>, values of type OTHER will be stored in serialized form
372 * and have the semantics of binary data for all operations (such as sorting
373 * and conversion to string).
374 * <br />
375 * <b>If false</b>, the objects will be serialized only for I/O operations
376 * and a few other special cases (for example when someone tries to get the
377 * value in binary form or when comparing objects that are not comparable
378 * otherwise).
379 * <br />
380 * If the object implements the Comparable interface, the method compareTo
381 * will be used for sorting (but only if objects being compared have a
382 * common comparable super type). Otherwise the objects will be compared by
383 * type, and if they are the same by hashCode, and if the hash codes are
384 * equal, but objects are not, the serialized forms (the byte arrays) are
385 * compared.
386 * <br />
387 * The string representation of the values use the toString method of
388 * object.
389 * <br />
390 * In client-server mode, the server must have all required classes in the
391 * class path. On the client side, this setting is required to be disabled
392 * as well, to have correct string representation and display size.
393 * <br />
394 * In embedded mode, no data copying occurs, so the user has to make
395 * defensive copy himself before storing, or ensure that the value object is
396 * immutable.
397 */
398 public static boolean serializeJavaObject = Utils.getProperty("h2.serializeJavaObject", true);
399
400 /**
401 * System property <code>h2.javaObjectSerializer</code> (default: null).<br />
402 * The JavaObjectSerializer class name for java objects being stored in
403 * column of type OTHER. It must be the same on client and server to work
404 * correctly.
405 */
406 public static final String JAVA_OBJECT_SERIALIZER = Utils.getProperty("h2.javaObjectSerializer", null);
407
408 private static final String H2_BASE_DIR = "h2.baseDir";
409
410 private SysProperties() {
411 // utility class
412 }
413
414 /**
415 * INTERNAL
416 */
417 public static void setBaseDir(String dir) {
418 if (!dir.endsWith("/")) {
419 dir += "/";
420 }
421 System.setProperty(H2_BASE_DIR, dir);
422 }
423
424 /**
425 * INTERNAL
426 */
427 public static String getBaseDir() {
428 return Utils.getProperty(H2_BASE_DIR, null);
429 }
430
431 /**
432 * System property <code>h2.scriptDirectory</code> (default: empty
433 * string).<br />
434 * Relative or absolute directory where the script files are stored to or
435 * read from.
436 *
437 * @return the current value
438 */
439 public static String getScriptDirectory() {
440 return Utils.getProperty(H2_SCRIPT_DIRECTORY, "");
441 }
442
443 }
444