File: advancedtopics.xml

package info (click to toggle)
hsqldb 1.8.0.7-1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 11,824 kB
  • ctags: 11,226
  • sloc: java: 71,953; xml: 10,832; sql: 1,038; sh: 875; makefile: 58
file content (1306 lines) | stat: -rw-r--r-- 46,274 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: advancedtopics.xml,v 1.32 2005/06/30 22:38:54 fredt Exp $ -->
<chapter id="advanced-chapter">
  <title id="advanced-title">Advanced Topics</title>

  <chapterinfo>
    <authorgroup>
      <author>
        <firstname>Fred</firstname>

        <surname>Toussi</surname>

        <affiliation>
          <orgname>HSQLDB Development Group</orgname>
        </affiliation>

        <email>ft@cluedup.com</email>
      </author>
    </authorgroup>

    <edition>$Revision: 1.32 $</edition>

    <pubdate>$Date: 2005/06/30 22:38:54 $</pubdate>

    <keywordset>
      <keyword>Hsqldb</keyword>

      <keyword>Advanced</keyword>
    </keywordset>

    <legalnotice>
      <para>Copyright 2002-2005 Fred Toussi. Permission is granted to
      distribute this document without any alteration under the terms of the
      HSQLDB license. Additional permission is granted to the HSQLDB
      Development Group to distribute this document with or without
      alterations under the terms of the HSQLDB license.</para>
    </legalnotice>
  </chapterinfo>

  <section>
    <title>Purpose</title>

    <para>Many questions repeatedly asked in Forums and mailing lists are
    answered in this guide. If you want to use HSQLDB with your application,
    you should read this guide. This document covers system related issues.
    For issues related to SQL see the <link endterm="sql_issues-title"
    linkend="sql_issues-chapter" /> chapter.</para>
  </section>

  <section>
    <title>Connections</title>

    <para>The normal method of accessing an HSQLDB database is via the JDBC
    Connection interface. An introduction to different methods of providing
    database services and accessing them can be found in the <link
    endterm="sql_issues-title" linkend="sql_issues-chapter" /> chapter.
    Details and examples of how to connect via JDBC are provided in our <ulink
    url="../src/org/hsqldb/jdbc/jdbcConnection.html">JavaDoc for
    <literal>jdbcConnection</literal></ulink>.</para>

    <para>Version 1.7.2 introduced a uniform method of distinguishing between
    different types of connection, alongside new capabilities to provide
    access to multiple databases. The common driver identifier is
    <literal>jdbc:hsqldb:</literal> followed by a protocol identifier
    (<literal>mem: file: res: hsql: http: hsqls: https:</literal>) then
    followed by host and port identifiers in the case of servers, then
    followed by database identifier.</para>

    <table frame="all" pgwide="1" tocentry="1">
      <title>Hsqldb URL Components</title>

      <tgroup align="left" cols="3">
        <colspec colname="c1" />

        <colspec colname="c2" />

        <colspec colname="c3" />

        <thead>
          <row>
            <entry>Driver and Protocol</entry>

            <entry>Host and Port</entry>

            <entry>Database</entry>
          </row>
        </thead>

        <tbody valign="top">
          <row>
            <entry>
              <simplelist type="vert">
                <member>
                  <literal>jdbc:hsqldb:mem:</literal>
                </member>
              </simplelist>
            </entry>

            <entry>not available</entry>

            <entry>
              <simplelist type="vert">
                <member>
                  <literal>accounts</literal>
                </member>
              </simplelist>
            </entry>
          </row>

          <row>
            <entry nameend="c3" namest="c1">
              <para>Lowercase, single-word identifier creates the in-memory
              database when the first connection is made. Subsequent use of
              the same Connection URL connects to the existing DB.</para>

              <para>The old form for the URL, <literal>jdbc:hsqldb:.</literal>
              creates or connects to the same database as the new form for the
              URL, <literal>jdbc:hsqldb:mem:.</literal></para>
            </entry>
          </row>

          <row>
            <entry>
              <simplelist type="vert">
                <member>
                  <literal>jdbc:hsqldb:file:</literal>
                </member>
              </simplelist>
            </entry>

            <entry>not available</entry>

            <entry>
              <simplelist type="vert">
                <member>
                  <filename>mydb</filename>
                </member>

                <member>
                  <filename>/opt/db/accounts</filename>
                </member>

                <member>
                  <filename>C:/data/mydb</filename>
                </member>
              </simplelist>
            </entry>
          </row>

          <row>
            <entry nameend="c3" namest="c1">
              <para>The file path specifies the database file. In the above
              examples the first one refers to a set of mydb.* files in the
              directory where the <literal>java</literal>command for running
              the application was issued. The second and third examples refer
              to absolute paths on the host machine.</para>
            </entry>
          </row>

          <row>
            <entry>
              <simplelist type="vert">
                <member>
                  <literal>jdbc:hsqldb:res:</literal>
                </member>
              </simplelist>
            </entry>

            <entry>not available</entry>

            <entry>
              <simplelist type="vert">
                <member>
                  <filename>/adirectory/dbname</filename>
                </member>
              </simplelist>
            </entry>
          </row>

          <row>
            <entry nameend="c3" namest="c1">Database files can be loaded from
            one of the jars specified as part of the <literal>Java</literal>
            command the same way as resource files are accessed in Java
            programs. The <literal>/adirectory</literal> above stands for a
            directory in one of the jars.</entry>
          </row>

          <row>
            <entry>
              <simplelist type="vert">
                <member>
                  <literal>jdbc:hsqldb:hsql:</literal>
                </member>

                <member>
                  <literal>jdbc:hsqldb:hsqls:</literal>
                </member>

                <member>
                  <literal>jdbc:hsqldb:http:</literal>
                </member>

                <member>
                  <literal>jdbc:hsqldb:https:</literal>
                </member>
              </simplelist>
            </entry>

            <entry>
              <simplelist type="vert">
                <member>
                  <literal>//localhost</literal>
                </member>

                <member>
                  <literal>//192.0.0.10:9500</literal>
                </member>

                <member>
                  <literal>//dbserver.somedomain.com</literal>
                </member>
              </simplelist>
            </entry>

            <entry>
              <simplelist type="vert">
                <member>
                  <literal>/an_alias</literal>
                </member>

                <member>
                  <literal>/enrollments</literal>
                </member>

                <member>
                  <literal>/quickdb</literal>
                </member>
              </simplelist>
            </entry>
          </row>

          <row>
            <entry nameend="c3" namest="c1">
              <para>The host and port specify the IP address or host name of
              the server and an optional port number. The database to connect
              to is specified by an alias. This alias is a lowercase string
              defined in the <filename>server.properties</filename> file to
              refer to an actual database on the file system of the server or
              a transient, in-memory database on the server. The following
              example lines in <filename>server.properties </filename> or
              <filename>webserver.properties</filename> define the database
              aliases listed above and accessible to clients to refer to
              different file and in-memory databases.</para>

              <programlisting>
    database.0=file:/opt/db/accounts
    dbname.0=an_alias

    database.1=file:/opt/db/mydb
    dbname.1=enrollments

    database.2=mem:adatabase
    dbname.2=quickdb</programlisting>

              <para>The old form for the server URL, e.g.,
              <literal>jdbc:hsqldb:hsql//localhost</literal> connects to the
              same database as the new form for the URL,
              <literal>jdbc:hsqldb:hsql//localhost/</literal> where the alias
              is a zero length string. In the example below, the database
              files <literal>lists.*</literal> in the
              <literal>/home/dbmaster/</literal> directory are associated with
              the empty alias:</para>

              <programlisting>
    database.3=/home/dbmaster/lists
    dbname.3=</programlisting>
            </entry>
          </row>
        </tbody>
      </tgroup>
    </table>

    <section>
      <title>Connection properties</title>

      <para>Each new JDBC Connection to a database can specify connection
      properties. The properties <property>user</property> and
      <property>password</property> are always required. In 1.8.0 the
      following optional properties can also be used.</para>

      <para>Connection properties are specified either by establishing the
      connection via the:</para>

      <programlisting>
    DriverManager.getConnection (String url, Properties info);</programlisting>

      <para>method call, or the property can be appended to the full
      Connection URL.</para>

      <table frame="all" pgwide="1" tocentry="1">
        <title>Connection Properties</title>

        <tgroup align="left" cols="3">
          <colspec colname="c1" />

          <colspec colname="c2" />

          <colspec colname="c3" />

          <tbody valign="top">
            <row>
              <entry>
                <property>get_column_name</property>
              </entry>

              <entry>
                <literal>true</literal>
              </entry>

              <entry>column name in ResultSet</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>This property is used for compatibility with other JDBC
                driver implementations. When true (the default),
                <literal>ResultSet.getColumnName(int c)</literal> returns the
                underlying column name</para>

                <para>When false, the above method returns the same value as
                <literal>ResultSet.getColumnLabel(int column)</literal>
                Example below:</para>

                <programlisting>
    jdbc:hsqldb:hsql://localhost/enrollments;get_column_name=false
                    </programlisting>

                <para>When a ResultSet is used inside a user-defined stored
                procedure, the default, true, is always used for this
                property.</para>
              </entry>
            </row>

            <row>
              <entry>
                <property>ifexists</property>
              </entry>

              <entry>
                <literal>false</literal>
              </entry>

              <entry>connect only if database already exists</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>Has an effect only with <literal>mem:</literal> and
                <literal>file:</literal> database. When true, will not create
                a new database if one does not already exist for the
                URL.</para>

                <para>When false (the default), a new <literal>mem:</literal>
                or <literal>file:</literal> database will be created if it
                does not exist.</para>

                <para>Setting the property to true is useful when
                troubleshooting as no database is created if the URL is
                malformed. Example below:</para>

                <programlisting>
    jdbc:hsqldb:file:enrollments;ifexists=true</programlisting>
              </entry>
            </row>

            <row>
              <entry>
                <property>shutdown</property>
              </entry>

              <entry>
                <literal>false</literal>
              </entry>

              <entry>shut down the database when the last connection is
              closed</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>This mimics the behaviour of 1.7.1 and older versions.
                When the last connection to a database is closed, the database
                is automatically shut down. The property takes effect only
                when the first connection is made to the database. This means
                the connection that opens the database. It has no effect if
                used with subsequent, simultaneous connections.</para>

                <para>This command has two uses. One is for test suites, where
                connections to the database are made from one JVM context,
                immediately followed by another context. The other use is for
                applications where it is not easy to configure the environment
                to shutdown the database. Examples reported by users include
                web application servers, where the closing of the last
                connection conisides with the web app being shut down.</para>
              </entry>
            </row>
          </tbody>
        </tgroup>
      </table>

      <para>In addition, when a connection to an in-process database creates a
      new database, or opens an existing database (i.e. it is the first
      connection made to the database by the application), all the
      user-defined database properties can be specified as URL properties.
      This can be used to specify properties to enforce more strict SQL
      adherence, or to change cache_scale or similar properties before the
      database files are created. However, for new databases, it is
      recommended to use the SET PROPERTY command for such settings.</para>
    </section>
  </section>

  <section>
    <title>Properties Files</title>

    <para>HSQLDB relies on a set of properties files for different settings.
    Since 1.7.0 property naming has been streamlined and a number of new
    properties have been introduced.</para>

    <para>In all properties files, values are case-sensitive. All values apart
    from names of files or pages are required in lowercase (e.g.
    <property>server.silent</property>=<literal>FALSE</literal> will have no
    effect, but <property>server.silent</property>=<literal>false</literal>
    will work).</para>

    <para>The properties files and the settings stored in them are as
    follows:</para>

    <table frame="all" pgwide="1" tocentry="1">
      <title>Hsqldb Server Properties Files</title>

      <tgroup align="left" cols="3">
        <thead>
          <row>
            <entry>File Name</entry>

            <entry>Location</entry>

            <entry>Function</entry>
          </row>
        </thead>

        <tbody valign="top">
          <row>
            <entry>
              <filename>server.properties</filename>
            </entry>

            <entry>the directory where the command to run the
            <classname>Server</classname> class is issued</entry>

            <entry>settings for running HSQLDB as a database server
            communicating with the HSQL protocol</entry>
          </row>

          <row>
            <entry>
              <filename>webserver.properties</filename>
            </entry>

            <entry>the directory where the command to run the
            <classname>WebServer</classname> class is issued</entry>

            <entry>settings for running HSQLDB as a database server
            communicating with the HTTP protocol</entry>
          </row>

          <row>
            <entry>
              <filename>&lt;dbname&gt;.properties</filename>
            </entry>

            <entry>the directory where all the files for a database are
            located</entry>

            <entry>settings for each particular database</entry>
          </row>
        </tbody>
      </tgroup>
    </table>

    <para>Properties files for running the servers are not created
    automatically. You should create your own files that contain
    <property>server.property</property>=<literal>value</literal> pairs for
    each property.</para>

    <para>The properties file for each database is generated by the database
    engine. This file can be edited after closing the database. In 1.8.0, most
    of these properties can be changed via SQL commands.</para>

    <section>
      <title>Server and Web Server Properties</title>

      <para>In both <filename>server.properties</filename> and
      <filename>webserver.properties</filename> files, supported values and
      their defaults are as follows:</para>

      <table frame="all" pgwide="1" tocentry="1">
        <title>Property File Properties</title>

        <tgroup align="left" cols="3">
          <thead>
            <row>
              <entry>Value</entry>

              <entry>Default</entry>

              <entry>Description</entry>
            </row>
          </thead>

          <tbody valign="top">
            <row>
              <entry>
                <property>server.database.0</property>
              </entry>

              <entry>
                <literal>test</literal>
              </entry>

              <entry>the path and file name of the first database file to
              use</entry>
            </row>

            <row>
              <entry>
                <property>server.dbname.0</property>
              </entry>

              <entry>
                <literal>""</literal>
              </entry>

              <entry>lowercase server alias for the first database
              file</entry>
            </row>

            <row>
              <entry>
                <property>server.urlid.0</property>
              </entry>

              <entry>
                <literal>NONE</literal>
              </entry>

              <entry>SqlTool urlid used by UNIX init script. (This property is
              not used if your are running Server/Webserver on a platform
              other than UNIX, or of you are not using our UNIX init
              script).</entry>
            </row>

            <row>
              <entry>
                <property>server.silent</property>
              </entry>

              <entry>
                <literal>true</literal>
              </entry>

              <entry>no extensive messages displayed on console</entry>
            </row>

            <row>
              <entry>
                <property>server.trace</property>
              </entry>

              <entry>
                <literal>false</literal>
              </entry>

              <entry>JDBC trace messages displayed on console</entry>
            </row>
          </tbody>
        </tgroup>
      </table>

      <para>In 1.8.0, each server can serve up to 10 different databases
      simultaneously. The <property>server.database.0</property> property
      defines the filename / path whereas the
      <property>server.dbname.0</property> defines the lowercase alias used by
      clients to connect to that database. The digit 0 is incremented for the
      second database and so on. Values for the
      <property>server.database.{0-9}</property> property can use the
      <literal>mem:</literal>, <literal>file:</literal> or
      <literal>res:</literal> prefixes and properties as discussed above under
      CONNECTIONS. For example, <informalexample>
          <programlisting>
    database.0=mem:temp;sql.enforce_strict_size=true;</programlisting>
        </informalexample></para>

      <para>Values specific to <filename>server.properties</filename>
      are:</para>

      <table frame="all" pgwide="1" tocentry="1">
        <title>Server Property File Properties</title>

        <tgroup align="left" cols="3">
          <thead>
            <row>
              <entry>Value</entry>

              <entry>Default</entry>

              <entry>Description</entry>
            </row>
          </thead>

          <tbody valign="top">
            <row>
              <entry>
                <property>server.port</property>
              </entry>

              <entry>
                <literal>9001</literal>
              </entry>

              <entry>TCP/IP port used for talking to clients. All databases
              are served on the same port.</entry>
            </row>

            <row>
              <entry>
                <property>server.no_system_exit</property>
              </entry>

              <entry>
                <literal>true</literal>
              </entry>

              <entry>no <literal>System.exit()</literal> call when the
              database is closed</entry>
            </row>
          </tbody>
        </tgroup>
      </table>

      <para>Values specific to <filename>webserver.properties</filename>
      are:</para>

      <table frame="all" pgwide="1" tocentry="1">
        <title>WebServer Property File Properties</title>

        <tgroup align="left" cols="3">
          <thead>
            <row>
              <entry>Value</entry>

              <entry>Default</entry>

              <entry>Description</entry>
            </row>
          </thead>

          <tbody valign="top">
            <row>
              <entry>
                <property>server.port</property>
              </entry>

              <entry>
                <literal>80</literal>
              </entry>

              <entry>TCP/IP port used for talking to clients</entry>
            </row>

            <row>
              <entry>
                <property>server.default_page</property>
              </entry>

              <entry>
                <literal>index.html</literal>
              </entry>

              <entry>the default web page for server</entry>
            </row>

            <row>
              <entry>
                <property>server.root</property>
              </entry>

              <entry>
                <literal>./</literal>
              </entry>

              <entry>the location of served pages</entry>
            </row>

            <row>
              <entry>
                <property>.&lt;extension&gt;</property>
              </entry>

              <entry>
                <literal>?</literal>
              </entry>

              <entry>multiple entries such as
              <literal>.html=text/html</literal> define the mime types of the
              static files served by the web server. See the source for
              <filename>WebServer.java</filename> for a list.</entry>
            </row>
          </tbody>
        </tgroup>
      </table>

      <para>All the above values can be specified on the command line to start
      the server by omitting the <literal>server.</literal> prefix.</para>
    </section>

    <section>
      <title>Starting a Server from your application</title>

      <para>If you want to start the server from within your application, as
      opposed to the command line or batch files, you should create an
      instance of Server or Web Server, then assign the properties in the form
      of a String and start the Server. An example of this can be found in the
      <classname>org.hsqldb.test.TestBase</classname> source.</para>

      <note>
        <para>Upgrading: If you have existing custom properties files, change
        the values to the new naming convention. Note the use of digits at the
        end of <property>server.database.n</property> and
        <property>server.dbname.n</property> properties.</para>
      </note>
    </section>

    <section>
      <title>Individual Database Properties</title>

      <para>Each database has its own <filename>&lt;dbname&gt;.properties
      </filename> file as part of a small group of files which also includes
      <filename>&lt;dbname&gt;.script</filename> and
      <filename>&lt;dbname&gt;.data</filename>. The properties files contain
      key/value pairs for some important settings.</para>

      <para>In version 1.8.0 a new SQL command allows most database properties
      to be modified as follows:</para>

      <programlisting>
    SET PROPERTY "property_name" property_value</programlisting>

      <para>Properties that can be modified via <literal>SET
      PROPERTY</literal> are indicated in the table below. Other properties
      are indicated as <literal>PROPERTIES FILE ONLY</literal> and can be
      modified only by editing the .properties file after a shutdown and
      before a restart. Only the user-defined values listed below should ever
      be modified. Changing any other value could result in unexpected
      malfunction in database operations. Most of these values have been
      introduced for the new features since 1.7.0:</para>

      <table frame="all" pgwide="1" tocentry="1">
        <title>Database-specific Property File Properties</title>

        <tgroup align="left" cols="3">
          <colspec colname="c1" />

          <colspec colname="c2" />

          <colspec colname="c3" />

          <thead>
            <row>
              <entry>Value</entry>

              <entry>Default</entry>

              <entry>Description</entry>
            </row>
          </thead>

          <tbody valign="top">
            <row>
              <entry>
                <property>readonly</property>
              </entry>

              <entry>
                <literal>no</literal>
              </entry>

              <entry>whole database is read-only</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>When true, the database cannot be modified in use. This
                setting can be changed to <literal>yes</literal> if the
                database is to be opened from a CD. Prior to changing this
                setting, the database should be closed with the
                <literal>SHUTDOWN COMPACT</literal> command to ensure
                consistency and compactness of the data. <literal>(PROPERTIES
                FILE ONLY) but can be used as a connection property to open a
                normal database as readonly.</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>hsqldb.files_readonly</property>
              </entry>

              <entry>
                <literal>false</literal>
              </entry>

              <entry>database files will not be written to</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>When true, data in MEMORY tables can be modified and new
                MEMORY tables can be added. However, these changes are not
                saved when the database is shutdown. CACHED and TEXT tables
                are always readonly when this setting is true.
                <literal>(PROPERTIES FILE ONLY)</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>hsqldb.cache_file_scale</property>
              </entry>

              <entry>
                <literal>1</literal>
              </entry>

              <entry>Set larger data file limits. Once set, the limit will go
              up to 8GB.</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>This property can be set to 8 to increase the size limit
                of the .data file from 2GB to 8GB. To apply the change to an
                existing database, SHUTDOWN SCRIPT should be performed first,
                then the property=value line below should be added to the
                .properties file before reopening the database.
                <programlisting>hsqldb.cache_file_scale=8</programlisting></para>

                <para>The property can be set with the SQL command (as opposed
                to changing the value in the properties file) when the
                database has no CACHED tables (e.g. a new database).
                <literal>(SET PROPERTY)</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>sql.enforce_size</property>
              </entry>

              <entry>
                <literal>false</literal>
              </entry>

              <entry>trimming and padding string columns</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>This property is no longer supported. Use
                sql.enforce_sctrict_size</para>
              </entry>
            </row>

            <row>
              <entry>
                <property>sql.enforce_strict_size</property>
              </entry>

              <entry>
                <literal>false</literal>
              </entry>

              <entry>size enforcement and padding string columns</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>Conforms to SQL standards for size and precision of data
                types. When true, all CHARACTER, VARCHAR, NUMERIC and DECIMAL
                values that are in a row affected by an INSERT INTO or UPDATE
                statement are checked against the size specified in the SQL
                table definition. An exception is thrown if the value is too
                long. Also all CHARACTER values that are shorter than the
                specified size are padded with spaces. TIMESTAMP(0) and
                TIMESTAMP(6) are also allowed in order to specify the
                subsecond resolution of the values. When false (default),
                stores the exact string that is inserted. <literal> (SET
                PROPERTY)</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>sql.tx_no_multi_rewrite</property>
              </entry>

              <entry>
                <literal>false</literal>
              </entry>

              <entry>transaction management</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>In the default READ_UNCOMMITED mode, a transaction can
                write over rows inserted or updated by another uncommitted
                transaction.<literal> Setting this property to true will raise
                an exception when such a write is attempted (SET
                PROPERTY)</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>hsqldb.cache_scale</property>
              </entry>

              <entry>
                <literal>14</literal>
              </entry>

              <entry>memory cache exponent</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>Indicates the maximum number of rows of cached tables
                that are held in memory, calculated as 3 *(2**value) (three
                multiplied by (two to the power value)). The default results
                in up to 3*16384 rows from all cached tables being held in
                memory at any time.</para>

                <para>The value can range between 8-18. <literal>(SET
                PROPERTY)</literal>. If the value is set via SET PROPERTY then
                it becomes effective after the next database SHUTDOWN or
                CHECKPOINT. <literal>(SET PROPERTY)</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>hsqldb.cache_size_scale</property>
              </entry>

              <entry>
                <literal>10</literal>
              </entry>

              <entry>memory cache exponent</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>Indicates the average size of each row in the memory
                cache used with cached tables, calculated as 2**value (two to
                the power value). This result value is multiplied by the
                maximum number of rows defined by
                <property>hsqldb.cache_scale</property> to form the maximum
                number of bytes for all the rows in memory cache. The default
                results in 1024 bytes per row. This default, combined with the
                default number of rows, results in approximately 50MB of the
                .data file to be stored in the memory cache.</para>

                <para>The value can range between 6-20. <literal>(SET
                PROPERTY)</literal>. If the value is set via SET PROPERTY then
                it becomes effective after the next database SHUTDOWN or
                CHECKPOINT. <literal>(SET PROPERTY)</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>hsqldb.log_size</property>
              </entry>

              <entry>
                <literal>200</literal>
              </entry>

              <entry>size of log when checkpoint is performed</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>The value is the size in megabytes that the
                <literal>.log</literal> file can reach before an automatic
                checkpoint occurs. A checkpoint and rewrites the
                <literal>.script</literal> file and clears the
                <literal>.log</literal> file. The value can be changed via the
                <literal>SET LOGSIZE nnn</literal> SQL command.</para>
              </entry>
            </row>

            <row>
              <entry>
                <property>runtime.gc_interval</property>
              </entry>

              <entry>
                <literal>0</literal>
              </entry>

              <entry>forced garbage collection</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>This setting forces garbage collection each time a set
                number of result set row or cache row objects are created. The
                default, "0" means no garbage collection is forced by the
                program.</para>

                <para>This should not be set when the database engine is
                acting as a server inside an exclusive JVM. The setting can be
                useful when the database is used in-process with the
                application with some Java Runtime Environments (JRE's). Some
                JRE's increase the size of the memory heap before doing any
                automatic garbage collection. This setting would prevent any
                unnecessary enlargement of the heap. Typical values for this
                setting would probably be between 10,000 to 100,000.
                <literal>(PROPERTIES FILE ONLY)</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>hsqldb.nio_data_file</property>
              </entry>

              <entry>
                <literal>true</literal>
              </entry>

              <entry>use of nio access methods for the .data file</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>When HSQLDB is compiled and run in Java 1.4 or higher,
                setting this property to <literal>false</literal> will avoid
                the use of nio access methods, resulting in somewhat reduced
                speed. If the data file is larger than 256MB when it is first
                opened, nio access methods are not used. Also, if the file
                gets larger than the amount of available computer memory that
                needs to be allocated for nio access, non-nio access methods
                are used.</para>

                <para><literal>(SET PROPERTY)</literal>. If used before
                defining any CACHED table, it applies to the current session,
                otherwise it comes to effect after a SHUTDOWN and restart or
                CHECKPOINT.</para>
              </entry>
            </row>

            <row>
              <entry>
                <property>hsqldb.default_table_type</property>
              </entry>

              <entry>
                <literal>memory</literal>
              </entry>

              <entry>type of table created with unqualified CREATE
              TABLE</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>The CREATE TABLE command results in a MEMORY table by
                default. Setting the value "cached" for this property will
                result in a cached table by default. The qualified forms such
                as CREATE MEMORY TABLE or CREATE CACHED TABLE are not affected
                at all by this property. <literal>(SET
                PROPERTY)</literal></para>
              </entry>
            </row>

            <row>
              <entry>
                <property>hsqldb.applog</property>
              </entry>

              <entry>
                <literal>0</literal>
              </entry>

              <entry>application logging level</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>The default level 0 indicates no logging. Level 1
                results in events related to persistence to be logged,
                including any failures. The events are logged in a file ending
                with .app.log</para>
              </entry>
            </row>

            <row>
              <entry>
                <property>textdb.*</property>
              </entry>

              <entry>
                <literal>0</literal>
              </entry>

              <entry>default properties for new text tables</entry>
            </row>

            <row>
              <entry nameend="c3" namest="c1">
                <para>Properties that override the database engine defaults
                for newly created text tables. Settings in the text table
                <literal>SET &lt;tablename&gt; SOURCE &lt;source string&gt;
                </literal>command override both the engine defaults and the
                database properties defaults. Individual
                <property>textdb.*</property> properties are listed in the
                <link endterm="texttables-title"
                linkend="texttables-chapter" /> chapter. <literal>(SET
                PROPERTY)</literal></para>
              </entry>
            </row>
          </tbody>
        </tgroup>
      </table>

      <para>When connecting to an in-process database creates a new database,
      or opens an existing database (i.e. it is the first connection made to
      the database by the application), all the user-defined database
      properties listed in this section can be specified as URL
      properties.</para>

      <note>
        <para>Upgrading: From 1.7.0, the location of the database files can no
        longer be overridden by paths defined in the properties file. All
        files belonging to a database should reside in the same
        directory.</para>
      </note>

      <simpara>The property sql.compare_in_locale=true is no longer supported.
      If the line exists in a .properties file, it will switch the database to
      the collation for the current default. See the <link
      endterm="collation-title" linkend="collation-section" />
      command.</simpara>

      <simpara>When HSQLDB is used in OpenOffice.org, some property values
      will have a different default. The properties and values are:</simpara>

      <simpara>hsqldb.default_table_type=cached hsqldb.cache_scale=13
      hsqldb.log_size=10; hsqldb.nio_data_file=false
      sql.enforce_strict_size=true</simpara>
    </section>
  </section>

  <section>
    <title>SQL Commands for Database Properties</title>

    <para>There are some database properties that are set with dedicated SQL
    commands beginning with SET.</para>

    <table frame="all" pgwide="1" tocentry="1">
      <title>SQL command properties</title>

      <tgroup align="left" cols="1">
        <tbody valign="top">
          <row>
            <entry>
              <property>SET WRITE_DELAY {{TRUE | FALSE} | &lt;seconds&gt; |
              &lt;milliseconds&gt; MILLIS</property>
            </entry>
          </row>

          <row>
            <entry>
              <para>The default is TRUE and indicates that the changes to the
              database that have been logged are synched to the file system
              once every 20 seconds. FALSE indicates there is no delay and at
              each commit a file synch operation is performed. Numeric values
              from 0 can also be specified for the synch delay.</para>

              <para>The purpose of this command is to control the amount of
              data loss in case of a total system crash. A delay of 1 second
              means at most the data written to disk during the last second
              before the crash is lost. All data written prior to this has
              been synced and should be recoverable</para>

              <para>This setting should be specified on the basis of the
              reliability of the hardware used for running the database
              engine, the type of disk system used, the possibility of power
              failure etc. Also the nature of the data stored should be
              considered.</para>

              <para>In general, when the system is very reliable, the setting
              can be left to the default. If it is not very reliable, or the
              data is critical a setting of 1 or 2 seconds would suffice. Only
              in the worst case scenario or with the most critical data should
              a setting of 0 or FALSE be specified as this will slow the
              engine down to the speed at which the file synch operation can
              be performed by the disk subsystem.</para>

              <para>Values down to 10 millisconds can be specified by adding
              MILLIS to the command, but in practice a delay of 100
              milliseconds provides 99.99999% reliability with an average one
              system crash per 6 days.</para>
            </entry>
          </row>

          <row>
            <entry>
              <property>SET LOG_SIZE &lt;numeric value&gt;</property>
            </entry>
          </row>

          <row>
            <entry>
              <para>The engine writes out a log of all the changes to the
              database as they occur. This log is synched to the disk based on
              the WRITE_DELAY property above. The log is never reused unless
              there is an abnormal termination, i.e. the database process is
              terminated without SHUTDOWN, or it was terminated using SHUTDOWN
              IMMEDIATELY.</para>

              <para>The default maximum size of the .log file is 200 MB. When
              the maximum size is reached, a CHECKPOINT operation is
              performed. This operation will save the other database files in
              a consistent state and delete the old log. A value of 0
              indicates no limit for the .log file.</para>
            </entry>
          </row>

          <row>
            <entry>
              <property>SET CHECKPOINT DEFRAG &lt;numeric value&gt;</property>
            </entry>
          </row>

          <row>
            <entry>
              <para>When rows in CACHED tables are updated or deleted, the
              spaces are mostly reused. However, in time, some unused spaces
              are left in the .data file, especially when large tables are
              dropped or their structure is modified.</para>

              <para>A CHECKPOINT operation does not normally reclaim the empty
              spaces, whereas CHECKPOINT DEFRAG always does.</para>

              <para>This property determines when a normal CHECKPOINT, whether
              initiated by an administrator or when the size of the log
              exceeds its limit.</para>

              <para>The numeric value is the number of megabytes of recorded
              empty spaces in the .data file that would force a DEFRAG
              operation. Low values result in more frequent DEFRAG operations.
              A value of 0 indicates no automatic DEFRAG is performed. The
              default is 200 megabytes of lost space.</para>
            </entry>
          </row>

          <row>
            <entry>
              <property>SET REFERENTIAL INTEGRITY {TRUE | FALSE}</property>
            </entry>
          </row>

          <row>
            <entry>
              <para>This is TRUE by default. If bulk data needs to be loaded
              into the database, this property can be set FALSE for the
              duration of bulk load operation. This allows loading data for
              related tables in any order. The property should be set TRUE
              after bulk load. If the loaded data is not guaranteed to conform
              to the referential integrity constraints, SQL queries should be
              run after loading to identify and modify any non-conforming
              rows.</para>
            </entry>
          </row>
        </tbody>
      </tgroup>
    </table>
  </section>


</chapter>