Source

Bituf-Handbook / src / docbkx / bituf-handbook.xml

Full commit
   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
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<book>
  <bookinfo>
    <title>The Bitumen Framework Handbook</title>

    <author>
      <firstname>Shantanu</firstname>

      <surname>Kumar</surname>
    </author>

    <copyright>
      <year>2011</year>
      <holder>Shantanu Kumar</holder>
    </copyright>

    <legalnotice>
      <para>
        <mediaobject>
          <imageobject>
            <imagedata fileref="88x31.png" />
          </imageobject>
        </mediaobject>
      </para>
      <blockquote>
        <para>The Bitumen Framework Handbook by Shantanu Kumar is licensed under
          a Creative Commons Attribution-NoDerivs 3.0 Unported License<footnote><para>
          URL:
          <link linkend="http://creativecommons.org/licenses/by-nd/3.0/">
            http://creativecommons.org/licenses/by-nd/3.0/
          </link></para></footnote>
        </para>
      </blockquote>
    </legalnotice>

    <pubdate>28 Feb 2011</pubdate>
  </bookinfo>

  <chapter>
    <title>Introduction</title>

    <section>
      <title>Premise</title>

      <para><emphasis>The Bitumen Framework Handbook</emphasis> serves as a
        developer's guide to using Bitumen Framework for developing applications
        in the Clojure programming language, giving you the knowhow to use it in
        various situations.
      </para>

      <section>
        <title>What is it?</title>

        <para>Bitumen Framework<footnote><para>URL:
          <link linkend="http://code.google.com/p/bitumenframework/">
          http://code.google.com/p/bitumenframework/
          </link></para></footnote> is a collection of libraries for developing
          Clojure<footnote><para><link linkend="http://clojure.org">
          http://clojure.org</link></para></footnote> applications on the
          <trademark>Java</trademark> Virtual Machine. This handbook describes
          how to use those libraries for various use-cases.
        </para>

        <para>Clojure is a functional Lisp with strong focus on immutability
        and concurrency. Clojure also has excellent Java interoperability,
        something that Bitumen Framework libraries use heavily.</para>

      </section>

      <section>
        <title>Intended Audience</title>

        <para>An ideal reader would know enough Clojure to be able to write
        short programs on her own and try out things on the REPL. She would
        know general programming and logic concepts. Prior experience in
        application programming using another language and knowing about
        Java/JVM to some extent may be helpful.</para>
      </section>
    </section>

    <section>
      <title>Bitumen Framework Libraries</title>

      <para>This handbook contains several chapters, each dedicated to one
        specific library from the Bitumen Framework. They broadly cover the
        following libraries:
        <itemizedlist>
          <listitem><para>Clj-MiscUtil</para></listitem>
          <listitem><para>Clj-DBSpec</para></listitem>
          <listitem><para>OSS-JDBC</para></listitem>
          <listitem><para>Clj-DBCP</para></listitem>
          <listitem><para>Clj-Liquibase</para></listitem>
          <listitem><para>Lein-LB</para></listitem>
          <listitem><para>Fountain-JDBC</para></listitem>
          <listitem><para>SQLRat</para></listitem>
          <listitem><para>Clj-StringTemplate</para></listitem>
        </itemizedlist>
      </para>

      <section>
        <title>Description of Libraries</title>

        <para>The libraries listed above serve different purposes toward
          developing applications. Their description is below.
        </para>
        <section>
          <title>Clj-MiscUtil</title>
          <para><emphasis>Description:</emphasis> Clj-MiscUtil is an assortment of
            Clojure functions/macros to carry out miscellaneous common activities
            (see <emphasis>Table of Contents, Chapter 2</emphasis>.)
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/clj-miscutil/src">
              https://bitbucket.org/kumarshantanu/clj-miscutil/src
            </link>
          </para>
        </section>
        <section>
          <title>Clj-DBSpec</title>
          <para><emphasis>Description:</emphasis> Clj-DBSpec is a common
            configuration spec for dealing with relational databases e.g. data
            source, connection, conversion of schema/tables/columns/indices names
            between the database and Clojure.
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/clj-dbspec/src">
              https://bitbucket.org/kumarshantanu/clj-dbspec/src
            </link>
          </para>
        </section>
        <section>
          <title>OSS-JDBC</title>
          <para><emphasis>Description:</emphasis> OSS-JDBC is a regularly
            updated collection of Open Source JDBC drivers for various
            databases. The OSS-JDBC Maven artefact pulls in all JDBC drivers
            for supported databases.
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/oss-jdbc/src">
              https://bitbucket.org/kumarshantanu/oss-jdbc/src
            </link>
          </para>
        </section>
        <section>
          <title>Clj-DBCP</title>
          <para><emphasis>Description:</emphasis> Clj-DBCP is a simple
          Java-6/Clojure wrapper around the Apache DBCP library for creating
          database connection pools and for embedding databases in applications.
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/clj-dbcp/src">
              https://bitbucket.org/kumarshantanu/clj-dbcp/src
            </link>
          </para>
        </section>
        <section>
          <title>Clj-Liquibase</title>
          <para><emphasis>Description:</emphasis> Clj-Liquibase is a simple
          Clojure DSL/wrapper around the Liquibase library
          <link linkend="http://www.liquibase.org/">http://www.liquibase.org/</link>
          for carrying out relational database change management and migrations.
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/clj-liquibase/src">
              https://bitbucket.org/kumarshantanu/clj-liquibase/src
            </link>
          </para>
        </section>
        <section>
          <title>Lein-LB</title>
          <para><emphasis>Description:</emphasis> Leiningen plugin for
            Liquibase,<footnote><para>URL:
              <link linkend="http://www.liquibase.org/">
                http://www.liquibase.org/
              </link></para></footnote> a database change management software.
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/lein-lb/src">
              https://bitbucket.org/kumarshantanu/lein-lb/src
            </link>
          </para>
        </section>
        <section>
          <title>Fountain-JDBC</title>
          <para><emphasis>Description:</emphasis> Fountain-JDBC is a Clojure
            wrapper for Spring-JDBC<footnote><para>URL:
            <link linkend="http://www.springsource.org/about">
              http://www.springsource.org/about
            </link></para></footnote>.
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/fountain-jdbc/src">
              https://bitbucket.org/kumarshantanu/fountain-jdbc/src
            </link>
          </para>
        </section>
        <section>
          <title>SQLRat</title>
          <para><emphasis>Description:</emphasis> SQLRat is a Clojure (v1.2 or
            later) library to access relational databases using entity objects
            and to navigate entity relations in a stateless manner. Easy to use
            and flexible - you can also pass in native SQL for accessing the
            database.
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/sqlrat/src">
              https://bitbucket.org/kumarshantanu/sqlrat/src
            </link>
          </para>
        </section>
        <section>
          <title>Clj-StringTemplate</title>
          <para><emphasis>Description:</emphasis> Clj-StringTemplate is a simple
            Clojure wrapper around the StringTemplate library.
          </para>
          <para><emphasis>Project URL:</emphasis>
            <link linkend="https://bitbucket.org/kumarshantanu/clj-stringtemplate/src">
              https://bitbucket.org/kumarshantanu/clj-stringtemplate/src
            </link>
          </para>
        </section>
      </section>

      <section>
        <title>Version matrix</title>

        <para>The libraries described above have the following inter-dependncies:
          <informaltable>
            <tgroup cols="4">
              <thead>
                <row>
                  <entry>Library==&gt;</entry>
                  <entry>Version</entry>
                  <entry>Depends on==&gt;</entry>
                  <entry>Version</entry>
                </row>
              </thead>
              <tbody>
                <row>
                  <entry>Clj-MiscUtil</entry>
                  <entry>0.2</entry>
                  <entry>-</entry>
                  <entry>-</entry>
                </row>
                <row>
                  <entry>Clj-DBSpec</entry>
                  <entry>0.1</entry>
                  <entry>-</entry>
                  <entry>-</entry>
                </row>
                <row>
                  <entry>OSS-JDBC</entry>
                  <entry>0.4</entry>
                  <entry>-</entry>
                  <entry>-</entry>
                </row>
                <row>
                  <entry>Clj-DBCP</entry>
                  <entry>0.4</entry>
                  <entry>-</entry>
                  <entry>-</entry>
                </row>
                <row>
                  <entry>Clj-Liquibase</entry>
                  <entry>0.1</entry>
                  <entry>Clj-DBSpec</entry>
                  <entry>0.1</entry>
                </row>
                <row>
                  <entry>Lein-LB</entry>
                  <entry>0.1</entry>
                  <entry>- (will use Clj-Liquibase in 0.2)</entry>
                  <entry>-</entry>
                </row>
                <row>
                  <entry></entry>
                  <entry></entry>
                  <entry>Clj-MiscUtil</entry>
                  <entry>0.2</entry>
                </row>
                <row>
                  <entry>Fountain-JDBC</entry>
                  <entry>0.1</entry>
                  <entry>Clj-DBSpec</entry>
                  <entry>0.1</entry>
                </row>
                <row>
                  <entry></entry>
                  <entry></entry>
                  <entry>Clj-MiscUtil</entry>
                  <entry>0.2</entry>
                </row>
                <row>
                  <entry>SQLRat</entry>
                  <entry>0.2</entry>
                  <entry>Clj-ArgUtil (deprecated)</entry>
                  <entry>0.1</entry>
                </row>
                <row>
                  <entry>Clj-StringTemplate</entry>
                  <entry>0.2</entry>
                  <entry>-</entry>
                  <entry>-</entry>
                </row>
              </tbody>
            </tgroup>
          </informaltable>
        </para>
      </section>
    </section>

    <section>
      <title>Resources</title>

      <para>Resources information related to the project are below.</para>
      
      <section>
        <title>Project location</title>
        <para>URL:
          <link linkend="http://code.google.com/p/bitumenframework/">
            http://code.google.com/p/bitumenframework/
          </link>
        </para>
      </section>
      <section>
        <title>Documentation</title>
        <para>You can access the source of this handbook:
          <link linkend="https://bitbucket.org/kumarshantanu/bituf-handbook/src">
            https://bitbucket.org/kumarshantanu/bituf-handbook/src
          </link>. Apart from this handbook every project may have its own
          tutorial/documentation that you can access at the respective project
          page.
        </para>
      </section>
      <section>
        <title>License</title>
        <para>Unless mentioned otherwise all libraries in Bitumen Framework are
          released under Apache License 2.0<footnote><para>URL:
            <link linkend="http://www.apache.org/licenses/LICENSE-2.0">
              http://www.apache.org/licenses/LICENSE-2.0
            </link>
          </para></footnote> However, please note each library may have its own
          respective license (owing to the dependencies).</para>
      </section>
      <section>
        <title>Project Blog</title>
        <para>On BlogSpot:
          <link linkend="http://bitumenframework.blogspot.com/">
            http://bitumenframework.blogspot.com/
          </link>
        </para>
      </section>
      <section>
        <title>Twitter</title>
        <para>Author:
          <link linkend="http://twitter.com/kumarshantanu">
            http://twitter.com/kumarshantanu
          </link>
        </para>
        <para>Project:
          <link linkend="http://twitter.com/bituf">
            http://twitter.com/bituf
          </link>
        </para>
      </section>
      <section>
        <title>Reporting Bugs</title>
        <para>You can report bugs for every library to its respective project
          issue tracker on BitBucket.<footnote><para>URL:
          <link linkend="https://bitbucket.org/kumarshantanu/">
            https://bitbucket.org/kumarshantanu/
          </link></para></footnote>
        </para>
      </section>
      <section>
        <title>Discussion Group</title>
        <para>On Google groups:
          <link linkend="http://groups.google.com/group/bitumenframework">
            http://groups.google.com/group/bitumenframework
          </link>
        </para>
      </section>
      <section>
        <title>Contributing</title>
        <para>You are encouraged to participate in the development of Bitumen
          Framework. There is plenty of work ahead to be accomplished and your
          contribution in terms of code, ideas, bug reports, feedback, graphic
          art or whichever way you can, are most welcome.
        </para>
      </section>
      <section>
        <title>Contact</title>
        <para>Feel free to get in touch with the project author and members
          on the project discussion group. You can also contact by writing an
          email to kumar(dot)shantanu(at)gmail(dot)com or via Twitter.
        </para>
      </section>
    </section>
  </chapter>

  <chapter>
    <title>Miscellaneous Activities</title>

    <para>This chapter describes the usage of
    <firstterm>Clj-MiscUtil</firstterm> library for miscellaneous tasks. The
    tasks are categorized below into sub-sections. Clj-MiscUtil is under the
    namespace <literal> org.bituf.clj-miscutil</literal> that you can include
    as follows:</para>

    <programlisting>(use 'org.bituf.clj-miscutil)</programlisting>

    <para>or</para>

    <programlisting>(ns example.app
  (:require
    [org.bituf.clj-miscutil :as mu]))</programlisting>

    <para>The examples below assume the first statement.</para>

    <sect1>
      <title>Random values</title>

      <para>Random numeric and string values may be required for various
      purposes while programming. The <literal> random-number</literal> and
      <literal>random-string</literal> functions cater for these.</para>

      <sect2>
        <title>Generating a random number</title>

        <para>To generate a random number (long), you can use the
        <literal>random-number</literal> function.</para>

        <programlisting>(random-number)</programlisting>

        <para>Random numbers may be useful to create unique filenames or
        database table names with a common prefix.</para>

        <para><programlisting>(str "invoices-2011-02-20-" (random-number))</programlisting></para>

        <para>To obtain a random number (double precision) from a certain
        min/max range, you can specify the range:</para>

        <programlisting>;; return a random number between 10 (included) and 20 (excluded)
(random-number 10 20)</programlisting>

        <para>For an example, to randomly pick a value from a vector, you
        would use something like this:</para>

        <programlisting>(let [v [1 2 3 4 5 6 7 8 9]]
  (v (int (random-number 0 (count v)))))</programlisting>
      </sect2>

      <sect2>
        <title>Generating a random string</title>

        <para>Random alphanumeric string can be generated using the
        <literal>random-string</literal> function that returns string of
        length 11-13 characters by default. You can optionally specify a
        length of the random string.</para>

        <programlisting>(random-string)     ; string of random 11-13 characters

(random-string 20)  ; string of 20 random characters</programlisting>

        <para>Another way of generating alphanumeric random characters is to
        use the <literal>random-charseq</literal> function. By default this
        function returns a lazy-sequence of infinite alphanumeric characters
        but you can optionally specify a length.</para>

        <programlisting>(random-charseq)     ; lazy seq of infinite random characters

(random-charseq 10)  ; lazy seq of 10 random characters</programlisting>
      </sect2>
    </sect1>

    <sect1>
      <title>Type checking</title>

      <para>Clojure core has some built in functions to determine the types of
      values, such as <literal>number?</literal>, <literal> string?</literal>,
      <literal>map?</literal> etc. Additional such functions not available in
      Clojure core are below:</para>

      <programlisting>(boolean? false)       ; returns true
(boolean? "hello")     ; returns false

(not-boolean? "hello") ; returns true
(not-boolean? true)    ; returns false

(date? (java.util.Date.))      ; returns true
(date? "hello")                ; returns false

(not-date? (java.util.Date.))  ; returns false
(not-date? "hello")            ; returns true</programlisting>
    </sect1>

    <sect1>
      <title>Pretty printing</title>

      <para>These are some pretty printing functions that you can use:</para>
      <para><emphasis role="bold"><literal><function>with-stringwriter</function></literal></emphasis></para>
      <para>This macro is used to assign a StringWriter to specified symbol in a
      let binding and execute body of code in that context. Returns the string
      from StringWriter . Example:</para>
      <programlisting>(with-stringwriter s
  (.append s "Hello")
  (.append s "World"))  ; returns "HelloWorld"</programlisting>
      
      <para><emphasis role="bold"><literal><function>with-err-str</function></literal></emphasis></para>
      <para>This macro is like <literal><function>with-out-str</function></literal>
      but for <literal><function>*err*</function></literal> instead of
      <literal><function>*out*</function></literal>.</para>
      
      <para><emphasis role="bold"><literal><function>pprint-str</function></literal></emphasis></para>
      
      <para>This function (accepts one argument) prints anything that you pass
      to it using <literal><function>clojure.pprint/pprint</function></literal>
      and returns the result as string.</para>
      
      <para><emphasis role="bold"><literal><function>comma-sep-str</function></literal></emphasis></para>
      
      <para>This function accepts a collection as argument and returns a comma
      separated string representation.</para>
      
      <para><emphasis role="bold"><literal><function>echo</function></literal></emphasis></para>
      
      <para>This function is a simple diagnostic tool that pretty-prints
      anything (single argument) you pass to it and returns the same argument.</para>
      
    </sect1>

    <sect1>
      <title>Number sign detection</title>

      <para>Detecting sign of numbers may be tricky. <literal>(pos?
      34)</literal> returns <literal>true</literal> as expected, but
      <literal>(pos? "Hello")</literal> throws <literal>
      ClassCastException</literal>. The alternatives below return false in
      event of exceptions.</para>

      <programlisting>(zeronum? 0)        ; return true
(zeronum? 36)       ; return false
(zeronum? "hello")  ; returns false

(posnum? 378)       ; returns true
(posnum? -32)       ; returns false
(posnum? :pqrs)     ; returns false

(negnum? 378)       ; returns false
(negnum? -32)       ; returns true
(negnum? :pqrs)     ; returns false</programlisting>
    </sect1>

    <sect1>
      <title>Print tables</title>

      <para>Printing tables of data is useful for many scenarios. The data to
      be printed as a table is generally a collection of rows, optionally with
      a header row. You can use the <literal> print-table</literal> function
      to print a table of data to <literal>*out*</literal>.</para>

      <programlisting>(print-table [{:a 10 :b 20 :c 30}
              {:a 40 :b 50 :c 60}
              {:a 70 :b 80 :c 90}])  ; with titles "a", "b" and "c"

(print-table [[10 20 30]
              [40 50 60]
              [70 80 90]])           ; without any titles

(print-table  [:a :b :c]
             [[10 20 30]
              [40 50 60]
              [70 80 90]])           ; with titles "a", "b" and "c"</programlisting>

      <para>The examples above use the defaults to print the tables. You can
      override the defaults to alter the way tables are printed. For example,
      every column width is computed by default, if you want to specify width
      of columns you can use something like this:</para>

      <programlisting>(binding [*pt-cols-width* [5 -1 7]]
  (print-table [{:id 1001 :name "Harry"    :gender :male}
                {:id 2997 :name "Samantha" :gender :female}
                {:id 8328 :name "Christie" :gender :female}]))</programlisting>

      <para>Other options you can override are as follows:</para>

      <programlisting linenumbering="numbered">*pt-column-delim*   -- column delimiter string
*pt-min-cols-width* -- collection of minimum width for each column
*pt-max-cols-width* -- collection of maximum width for each column
*pt-cols-width*     -- collection of numeric width for each column</programlisting>

      <para><emphasis role="bold">Note:</emphasis> One notable feature of
      <literal>*pt-cols-width*</literal> is that a non-positive number implies
      that the width would be automatically computed.</para>
    </sect1>

    <sect1>
      <title>Var metadata</title>

      <para>Details about vars can be very useful during debugging,
      diagnostics or error reporting. You can find out the name (string) of a
      var using the macro <literal>var-name</literal>, fn-body of the var
      using <literal>var-body</literal> function and type/value of a value
      using the <literal>val-dump</literal> function.</para>

      <programlisting>(var-name map?)  ; returns "map?"

(var-body map?)  ; returns source code for map? function

(val-dump #"[a-z0-9]")  ; returns type and value as string</programlisting>
    </sect1>

    <sect1>
      <title>Throwing exceptions</title>

      <para>Throwing exceptions with sufficient diagnostic context in them is
      very important for meaningful error reporting. The functions shown below
      let you throw exceptions with relevant context:</para>

      <informaltable>
        <tgroup cols="3">
          <thead>
            <row>
              <entry>Function</entry>

              <entry>Which exception</entry>

              <entry>When to use</entry>
            </row>
          </thead>

          <tbody>
            <row>
              <entry><literal>illegal-arg</literal></entry>

              <entry>IllegalArgumentException</entry>

              <entry>You want to specify the reason as one or more string
              values</entry>
            </row>

            <row>
              <entry><literal>illegal-arg-wrap</literal></entry>

              <entry>IllegalArgumentException</entry>

              <entry>You want to wrap another exception</entry>
            </row>

            <row>
              <entry><literal>illegal-argval</literal></entry>

              <entry>IllegalArgumentException</entry>

              <entry>Actual argument is different from expected input</entry>
            </row>

            <row>
              <entry><literal>illegal-state</literal></entry>

              <entry>IllegalStateException</entry>

              <entry>You want to specify the reason as one or more string
              values</entry>
            </row>

            <row>
              <entry><literal>illegal-state-wrap</literal></entry>

              <entry>IllegalStateException</entry>

              <entry>You want to wrap another exception</entry>
            </row>

            <row>
              <entry><literal>unsupported-op</literal></entry>

              <entry>UnsupportedOperationException</entry>

              <entry>You want to specify the reason as one or more string
              values</entry>
            </row>

            <row>
              <entry><literal>unsupported-op-wrap</literal></entry>

              <entry>UnsupportedOperationException</entry>

              <entry>You want to wrap another exception</entry>
            </row>
          </tbody>
        </tgroup>
      </informaltable>

      <para>Examples of these functions are as follows:</para>

      <programlisting>(illegal-arg "name should not have more than 3 vowels")

(try (get-fname empname)
  (catch Exception e
    (illegal-arg-wrap e (str "bad empname: " empname))))

(illegal-argval "empname" "string having 3 vowels or less" empname)

(illegal-state "Value of x cannot be &gt; " max-x)

;; assuming e is an exception
(illegal-state-wrap e "Fahrenheit cannot be more than 98.4 degrees")

(unsupported-op "Not yet implemented")

;; assuming e is an exception
(unsupported-op e "Attempt to carry out activity failed")</programlisting>
    </sect1>

    <sect1>
      <title>Non-breaking error handling</title>

      <blockquote><para>This has been discussed
        <footnote><para>Part 1: <link
          linkend="http://bitumenframework.blogspot.com/2010/11/non-breaking-error-handling-in-clojure.html"
          >http://bitumenframework.blogspot.com/2010/11/non-breaking-error-handling-in-clojure.html</link></para>
        </footnote>
        <footnote><para>Part 2: <link
          linkend="http://bitumenframework.blogspot.com/2011/01/non-breaking-error-handling-in-clojure.html"
          >http://bitumenframework.blogspot.com/2011/01/non-breaking-error-handling-in-clojure.html</link></para>
        </footnote>
        on the Bitumen Framework blog.</para>
      </blockquote>
      
      <para>When executing code that might throw an exception we generally
      wrap it in a try/catch block as we want to deal with the breakage in
      execution flow. Dealing with execution breakage in-place makes the code
      imperative and often brittle.</para>

      <sect2>
        <title>The <literal>maybe</literal> macro family</title>

        <para>The <literal>maybe</literal> macro executes body of code and
        returns a vector of two elements - the first element being the return
        value, and the second being the exception.</para>

        <programlisting>(maybe (pos? 648)) ; returns [true nil]
(maybe (pos? nil)) ; returns [nil &lt;NullPointerException instance&gt;]</programlisting>

        <para>Since <literal>maybe</literal> is a macro you can pass arbitrary
        body of well-formed code to it and it will consistently return a
        2-element vector every time. An example usage of
        <literal>maybe</literal> is as follows:</para>

        <programlisting>(doseq [[ret ex] (map #(maybe (process-order %)) orders)]
  (or ret (log/success ret))
  (or ex  (do (log/error ex)
            (trigger-alert ex))))</programlisting>

        <para>There are two close cousins of the <literal> maybe</literal>
        macro, called <literal>maybe-ret</literal> (gets the return value, or
        <literal>nil</literal> when an exception is thrown) and
        <literal>maybe-ex</literal> (gets the exception, or
        <literal>nil</literal> when no exception is thrown).</para>

        <programlisting>(maybe-ret (Integer/parseInt "45"))    ; returns 45
(maybe-ret (Integer/parseInt "hello")) ; returns nil

(maybe-ex (Integer/parseInt "45"))     ; returns nil
(maybe-ex (Integer/parseInt "hello"))  ; returns NumberFormatException</programlisting>
      </sect2>

      <sect2>
        <title>Selectively uphold or ignore exceptions</title>

        <para>At times we may need to ignore or uphold exceptions based on the
        context. The macros <literal>filter-exception</literal> (takes a
        predicate function) and <literal> with-exceptions</literal> (takes
        list of exceptions to uphold and ignore) let us do exactly that. Both
        macros return <literal> nil</literal> when an exception is
        ignored.</para>

        <para>When you need arbitrary control over how/when to filter an
        exception you can use <literal> filter-exception</literal>.</para>

        <programlisting>(filter-exception #(instance? ClassCastException %)
  (pos? "hello"))  ; returns nil</programlisting>

        <para>Another situation is when you know beforehand which exceptions
        to uphold and which ones to ignore.</para>

        <programlisting>;; throws exception
(with-exceptions [IllegalArgumentException IllegalStateException]
                 [RuntimeException]
  "foo" ; non-effective return value
  (throw (IllegalArgumentException. "dummy")))

;; swallows exception
(with-exceptions [IllegalArgumentException IllegalStateException]
                 [RuntimeException]
  "foo" ; non-effective return value
  (throw (NullPointerException. "dummy")))</programlisting>

      </sect2>
    </sect1>

    <sect1>
      <title>Type conversion</title>

      <para>Type conversion is one of the most frequent needs during data
      processing. The table below describes which function converts to which
      type. All functions in this section accept input in various formats and
      try to coerce the input into desired type.</para>

      <informaltable>
        <tgroup cols="4">
          <colspec colname="c1" />

          <colspec colname="c2" />

          <colspec colname="c3" />

          <colspec colname="c4" />

          <thead>
            <row>
              <entry align="center">Function</entry>

              <entry align="center">Converts to</entry>

              <entry align="center" nameend="c4" namest="c3">Remarks</entry>
            </row>
          </thead>

          <tbody>
            <row>
              <entry><literal>as-string</literal></entry>

              <entry>string</entry>

              <entry nameend="c4" namest="c3">converts anything to string
              (i.e. <literal>:key</literal> becomes <literal>
              "key"</literal>)</entry>
            </row>

            <row>
              <entry><literal>java-filename</literal></entry>

              <entry>string</entry>

              <entry nameend="c4" namest="c3">Replaces path separators in
              supplied filename with Java-compatible platform independent
              separator</entry>
            </row>

            <row>
              <entry><literal>as-vstr</literal></entry>

              <entry>string</entry>

              <entry nameend="c4" namest="c3">Verbose string (i.e.
              <literal>nil</literal> becomes <literal>
              "&lt;nil&gt;"</literal>)</entry>
            </row>

            <row>
              <entry><literal>as-keys</literal></entry>

              <entry>collection</entry>

              <entry nameend="c4" namest="c3">Gets keys of a map, or the
              entire collection if not a map</entry>
            </row>

            <row>
              <entry><literal>as-vals</literal></entry>

              <entry>collection</entry>

              <entry nameend="c4" namest="c3">Gets vals of map, or the entire
              collection of not a map</entry>
            </row>

            <row>
              <entry><literal>as-vector</literal></entry>

              <entry>vector</entry>

              <entry nameend="c4" namest="c3">Turns anything into a
              vector</entry>
            </row>

            <row>
              <entry><literal>as-set</literal></entry>

              <entry>set</entry>

              <entry nameend="c4" namest="c3">Turns anything into a
              set</entry>
            </row>

            <row>
              <entry><literal>as-map</literal></entry>

              <entry>map</entry>

              <entry nameend="c4" namest="c3">Turns anything into a
              map</entry>
            </row>

            <row>
              <entry><literal>coerce</literal></entry>

              <entry>depends on the predicate function</entry>

              <entry nameend="c4" namest="c3">Coerces value using a predicate
              function</entry>
            </row>

            <row>
              <entry><literal>as-boolean</literal></entry>

              <entry>boolean</entry>

              <entry nameend="c4" namest="c3">Parses anything as
              boolean</entry>
            </row>

            <row>
              <entry><literal>as-short</literal></entry>

              <entry>short integer</entry>

              <entry nameend="c4" namest="c3">Parses anything as short</entry>
            </row>

            <row>
              <entry><literal>as-integer</literal></entry>

              <entry>integer</entry>

              <entry nameend="c4" namest="c3">Parses anything as
              integer</entry>
            </row>

            <row>
              <entry><literal>as-long</literal></entry>

              <entry>long integer</entry>

              <entry nameend="c4" namest="c3">Parses anything as long</entry>
            </row>

            <row>
              <entry><literal>as-float</literal></entry>

              <entry>float</entry>

              <entry nameend="c4" namest="c3">Parses anything as float</entry>
            </row>

            <row>
              <entry><literal>as-double</literal></entry>

              <entry>double</entry>

              <entry nameend="c4" namest="c3">Parses anything as
              double</entry>
            </row>
          </tbody>
        </tgroup>
      </informaltable>
    </sect1>

    <sect1>
      <title>`<literal>not-</literal>` associated functions</title>

      <para>Quite often we use a <literal>(not ..)</literal> version of a
      boolean function, e.g. <literal>(not (map? foo))</literal> while
      checking for conditions. The functions listed below are shorthand of
      using with <literal>not</literal>:</para>

      <informaltable>
        <tgroup cols="4">
          <thead>
            <row>
              <entry align="center">Function==&gt;</entry>

              <entry align="center">Counterpart in clojure.core</entry>

              <entry align="center">Function==&gt;</entry>

              <entry align="center">Counterpart in clojure.core</entry>
            </row>
          </thead>

          <tbody>
            <row>
              <entry><literal>any?</literal></entry>

              <entry><literal>not-any?</literal></entry>

              <entry><literal>not-associative?</literal></entry>

              <entry><literal>associative?</literal></entry>
            </row>

            <row>
              <entry><literal>not-bound?</literal></entry>

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

              <entry><literal>not-char?</literal></entry>

              <entry><literal>char?</literal></entry>
            </row>

            <row>
              <entry><literal>not-chunked-seq?</literal></entry>

              <entry><literal>chunked-seq?</literal></entry>

              <entry><literal>not-class?</literal></entry>

              <entry><literal>class?</literal></entry>
            </row>

            <row>
              <entry><literal>not-coll?</literal></entry>

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

              <entry><literal>not-contains?</literal></entry>

              <entry><literal>contains?</literal></entry>
            </row>

            <row>
              <entry><literal>not-counted?</literal></entry>

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

              <entry><literal>not-decimal?</literal></entry>

              <entry><literal>decimal?</literal></entry>
            </row>

            <row>
              <entry><literal>not-delay?</literal></entry>

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

              <entry><literal>not-distinct?</literal></entry>

              <entry><literal>distinct?</literal></entry>
            </row>

            <row>
              <entry><literal>not-empty?</literal></entry>

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

              <entry><literal>not-even?</literal></entry>

              <entry><literal>even?</literal></entry>
            </row>

            <row>
              <entry><literal>not-extends?</literal></entry>

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

              <entry><literal>not-false?</literal></entry>

              <entry><literal>false?</literal></entry>
            </row>

            <row>
              <entry><literal>not-float?</literal></entry>

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

              <entry><literal>not-fn?</literal></entry>

              <entry><literal>fn?</literal></entry>
            </row>

            <row>
              <entry><literal>not-future-cancelled?</literal></entry>

              <entry><literal>future-cancelled?</literal></entry>

              <entry><literal>not-future-done?</literal></entry>

              <entry><literal>future-done?</literal></entry>
            </row>

            <row>
              <entry><literal>not-future?</literal></entry>

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

              <entry><literal>not-identical?</literal></entry>

              <entry><literal>identical?</literal></entry>
            </row>

            <row>
              <entry><literal>not-ifn?</literal></entry>

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

              <entry><literal>not-instance?</literal></entry>

              <entry><literal>instance?</literal></entry>
            </row>

            <row>
              <entry><literal>not-integer?</literal></entry>

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

              <entry><literal>not-isa?</literal></entry>

              <entry><literal>isa?</literal></entry>
            </row>

            <row>
              <entry><literal>not-keyword?</literal></entry>

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

              <entry><literal>not-list?</literal></entry>

              <entry><literal>list?</literal></entry>
            </row>

            <row>
              <entry><literal>not-map?</literal></entry>

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

              <entry><literal>not-neg?</literal></entry>

              <entry><literal>neg?</literal></entry>
            </row>

            <row>
              <entry><literal>not-nil?</literal></entry>

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

              <entry><literal>not-number?</literal></entry>

              <entry><literal>number?</literal></entry>
            </row>

            <row>
              <entry><literal>not-odd?</literal></entry>

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

              <entry><literal>not-pos?</literal></entry>

              <entry><literal>pos?</literal></entry>
            </row>

            <row>
              <entry><literal>not-ratio?</literal></entry>

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

              <entry><literal>not-rational?</literal></entry>

              <entry><literal>rational?</literal></entry>
            </row>

            <row>
              <entry><literal>not-reversible?</literal></entry>

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

              <entry><literal>not-satisfies?</literal></entry>

              <entry><literal>satisfies?</literal></entry>
            </row>

            <row>
              <entry><literal>not-seq?</literal></entry>

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

              <entry><literal>not-sequential?</literal></entry>

              <entry><literal>sequential?</literal></entry>
            </row>

            <row>
              <entry><literal>not-set?</literal></entry>

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

              <entry><literal>not-sorted?</literal></entry>

              <entry><literal>sorted?</literal></entry>
            </row>

            <row>
              <entry><literal>not-special-symbol?</literal></entry>

              <entry><literal>special-symbol?</literal></entry>

              <entry><literal>not-string?</literal></entry>

              <entry><literal>string?</literal></entry>
            </row>

            <row>
              <entry><literal>not-symbol?</literal></entry>

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

              <entry><literal>not-thread-bound?</literal></entry>

              <entry><literal>thread-bound?</literal></entry>
            </row>

            <row>
              <entry><literal>not-true?</literal></entry>

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

              <entry><literal>not-var?</literal></entry>

              <entry><literal>var?</literal></entry>
            </row>

            <row>
              <entry><literal>not-vector?</literal></entry>

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

              <entry><literal>not-zero?</literal></entry>

              <entry><literal>zero?</literal></entry>
            </row>
          </tbody>
        </tgroup>
      </informaltable>
    </sect1>

    <sect1>
      <title>Map transformation</title>

      <para>Transforming collections can be easily done using <literal>
      map</literal> or <literal>for</literal>. However, transforming maps
      always involves destructuring the key and value and then apply any
      transformation. The functions <literal> map-keys</literal> and
      <literal>map-vals</literal> let you simply transform either the keys or
      the values of a map. When using <literal>map-keys</literal> you must
      ensure that the transformed set of keys are unique.</para>

      <programlisting>(map-keys inc (array-map 1 2 3 4 5 6)) ; returns {2 2 4 4 6 6}

(map-vals dec (array-map 1 2 3 4 5 6)) ; returns {1 1 3 3 5 5}</programlisting>
    </sect1>

    <sect1>
      <title>Array types</title>

      <para>Dealing with arrays may become unavoidable when working with Java
      libraries. The following functions may help:</para>

      <para><emphasis role="bold">array-type</emphasis></para>

      <para><literal><function>array-type</function></literal> returns the
      common type (class) of elements that can be contained in the
      array.</para>

      <para><emphasis
      role="bold"><literal><function>array?</function></literal></emphasis></para>

      <para><literal><function>array?</function></literal> returns true if the
      argument is an array, false otherwise.</para>

      <para><emphasis
      role="bold"><literal><function>not-array?</function></literal></emphasis></para>

      <para><literal><function>not-array?</function></literal> is same as
      <literal><function>(not (array? foo))</function></literal>.</para>
    </sect1>

    <sect1>
      <title>`<literal>contains-val?</literal>` : `<literal>contains?</literal>` for value</title>

      <para>The <literal>contains?</literal> function in clojure.core looks
      for a key in a collection. For a vector the keys are the indices, for
      sets they are the elements and for maps they are keys. The
      <literal>contains-val?</literal> function looks for values instead of
      keys.</para>

      <programlisting>(contains?     [:a :b :c] :b) ; returns false
(contains-val? [:a :b :c] :b) ; returns true

(contains?     {:a 10 :b 20} 20) ; returns false
(contains-val? {:a 10 :b 20} 20) ; returns true</programlisting>
    </sect1>

    <sect1>
      <title>Stack trace and Exceptions</title>

      <blockquote><para>This concept has been discussed<footnote>
        <para>URL:<link
          linkend="http://bitumenframework.blogspot.com/2010/10/stack-traces-for-clojure-app.html"
          >http://bitumenframework.blogspot.com/2010/10/stack-traces-for-clojure-app.html</link>
        </para></footnote>
        on the Bitumen Framework Blog.</para>
      </blockquote>
      
      <para>Exception stack trace for Clojure code usually includes quite some
      unwanted entries, which are not very useful while debugging and rather
      clutter the view. The function
      <literal><function>print-exception-stacktrace</function></literal>
      can be used to print an exception stack trace with reduced clutter. It
      falls back to the following as stack trace elements (in that order):
      <simplelist>
        <member>1. Application code and Dependencies (without Clojure core/contrib or Java code)</member>
        <member>2. Clojure core/contrib and application code (without Java code)</member>
        <member>3. All Java and Clojure code (everything)</member>
      </simplelist></para>
      <para>When trying this on the REPL with Clojure core/contrib libraries,
      you may not encounter #1 in the stack trace.</para>
      <para>There are two convenience macros - <literal>!</literal> and
      <literal>!!</literal> that accept a body of code and print friendly stack
      trace if there is any exception. The difference between the two is that
      <literal>!</literal> prints only required columns of the stack trace and
      <literal>!!</literal> prints an additional IDE Reference column to
      generate filenames clickable within the IDE (tested on Eclipse and IDEA).
      Example is below:</para>
      <programlisting>(! (foo arg))   ; prints normal stack-trace columns

(!! (foo arg))  ; prints extra IDE reference column</programlisting>
    </sect1>

    <sect1>
      <title>Assertion helpers</title>

      <para><emphasis role="bold"><literal><function>verify-arg</function></literal></emphasis></para>
      <para>Throws IllegalArgumentException if body of code does not return true.</para>
      <programlisting>(verify-arg (map? arg)) ; verifies arg is a map</programlisting>
      
      <para><emphasis role="bold"><literal><function>verify-type</function></literal></emphasis></para>
      <para>Throws IllegalArgumentException if argument does not match expected type.</para>
      <programlisting>(verify-type java.util.Date join-date)</programlisting>
      
      <para><emphasis role="bold"><literal><function>verify-cond</function></literal></emphasis></para>
      <para>This macro is same as <literal><function>verify-arg</function></literal>
      but throws IllegalStateException instead of IllegalArgumentException.</para>
      
      <para><emphasis role="bold"><literal><function>verify-opt</function></literal></emphasis></para>
      <para>This function ensures that only permitted optional arguments are passed
      as optional arguments to a function or macro.</para>
      <programlisting>(defn foo
  [arg &amp; {:keys [a b] :as opt}] {:pre [(verify-opt [:a :b] opt)]}
  ...)</programlisting>
      
    </sect1>

    <sect1>
      <title>Type annotation</title>

      <blockquote><para>This topic has been discussed<footnote><para>URL:<link
        linkend="http://bitumenframework.blogspot.com/2010/10/typed-abstractions-in-clojure.html"
        >http://bitumenframework.blogspot.com/2010/10/typed-abstractions-in-clojure.html</link>
        </para></footnote> on the Bitumen Framework blog.</para>
      </blockquote>
      
      <para>Type annotation is a way to inject type metadata into regular objects
        without altering their content. The type metadata can be read back later
        to act upon them in different ways.
      </para>
      <sect2>
        <title>Annotating with types</title>
        <para>The following functions help you annotate objects with type metadata:</para>
        <para><emphasis role="bold">typed</emphasis></para>
        <para>This function annotates an object with specified type(s), e.g.</para>
        <para><programlisting>(typed [:argentina :spain]
  :speaks-spanish)                 ; tag the object with one type

(typed {:name "Henry"
        :age   23
        :place "Connecticut"}
  :person-data :has-age :has-name) ; tag object with multiple types

(typed 65 :average-weight)         ; throws exception - 65 is not object</programlisting></para>
        <para><emphasis role="bold">ftyped</emphasis></para>
        <para>For non-objects such as numbers, string, date etc. we need to use
          <literal>ftyped</literal> so that they can be coerced as objects before
          they are type-annotated, e.g.
          <programlisting>(ftyped 65 :average-weight)        ; this works fine</programlisting>
          <emphasis>Note:</emphasis>Objects created using <literal>ftyped</literal>
          are no-arg functions that must be executed to return the wrapped value, e.g.
          <programlisting>(let [d (ftyped 60 :retirement-age)] (d))</programlisting>
        </para>
        <para><emphasis role="bold">obj?</emphasis></para>
        <para><emphasis role="bold">not-obj?</emphasis></para>
        <para>These functions tell whether a value is an object (i.e. whether it
          implements the IObject protocol) or not. Only such objects can be
          annotated with type metadata.
        </para>
      </sect2>
      
      <sect2>
        <title>Reading the types back</title>
        <para><emphasis role="bold">type-meta</emphasis></para>
        <para>This function returns the type metadata of an object
          <programlisting>(type-meta (typed {:order-id 34}
             :pending))              ; returns :pending

(type-meta (typed [:france :germany]
             :european :countries))  ; returns [:european :countries]

(type-meta (typed (typed [10 20]
                    :numbers)
             :sample))               ; returns [:numbers :sample]</programlisting>
        </para>
      </sect2>
      <sect2>
        <title>Type hierarchies and implied types</title>
        <blockquote>
          <para><emphasis>Note:</emphasis> The type and hierarchy system
            described here works in conjunction with <literal>type</literal> and
            <literal>isa?</literal> functions and integrates with Clojure multi-methods
            <footnote><para>URL:<link
              linkend="http://clojure.org/multimethods"
              >http://clojure.org/multimethods</link></para>
            </footnote>
            <footnote><para>URL:<link
              linkend="http://dosync.posterous.com/beyond-javascript-prototype-chains"
              >http://dosync.posterous.com/beyond-javascript-prototype-chains</link></para>
            </footnote>.
          </para>
        </blockquote>
        <para>Clojure has a built-in feature of type annotation and hierarchy
          independent of the objects themselves. It means objects are not
          hard-bound to the types (as in classes, e.g. Java) and type hierarchies
          can be applied at runtime. This feature enables multiple-inheritance of
          types in Clojure. See this example:
          <programlisting>(derive ::employee ::salaried) ; employee is salaried
(derive ::salaried ::person)   ; salaried is a person

;; returns true because ::employee is both ::salaried and ::person
(every? #(typed? (typed {:id 3964 :name "Joe"}
                   ::employee) %)
  [::salaried ::person])

;; returns true because ::employee is at least ::person
(some   #(typed? (typed {:id 9604 :name "Cher"}
                   ::employee) %)
  [::freelancer ::person])</programlisting>
        </para>
        <para><emphasis role="bold">typed?</emphasis></para>
        <para>You would notice that the code snippet makes use of the function
          <literal>typed?</literal>, which returns true if the object is of
          specified type. It internally makes use of the <literal>isa?</literal>
          function that knows about the specified and global hierarchies.
        </para>
      </sect2>
    </sect1>

    <sect1>
      <title>Keyword/String conversion</title>

      <para>The keyword/string conversion functions would be best shown with
        examples:
        <programlisting>(k-to-camelstr :to-do) ; returns "toDo"
(camelstr-to-k "toDo") ; returns :to-do

(k-to-methodname :to-do ["add"]) ; returns "addToDo" (now see k-to-camelstr)
(k-to-setter :price)       ; returns "setPrice"
(k-to-setter :set-price)   ; returns "setPrice" (detects "set", no repeat)
(k-to-getter :price)       ; returns "getPrice"
(k-to-getter :get-price)   ; returns "getPrice"  (detects "get", no repeat)
(k-to-getter :is-in-stock) ; returns "isInStock" (detects "is" too)

(coll-as-string [:a :b :c])    ; returns ["a" "b" "c"]
(coll-as-keys   ["a" "b" "c"]) ; returns [:a :b :c]
(keys-to-str {:a 10 :b 20})    ; returns {"a" 10 "b" 20}
(str-to-keys {"a" 10 "b" 20})  ; returns {:a 10 :b 20}</programlisting>
      </para>
    </sect1>

    <sect1>
      <title>Reflection (not for performance-critical code)</title>

      <para>The examples below show how to use the API:
        <programlisting></programlisting>
      </para>
      
      <sect2>
        <title>Call Java methods</title>
        <programlisting>(method "Hello" :char-at 0) ; .charAt(0) - returns \H

(method (call-specs "Hello"
          [:char-at 0]     ; .charAt(0)       - returns \H
          [:substring 3 4] ; .substring(3, 4) - returns "l"
          [:to-string]     ; .toString()      - returns "Hello"
          ))

(map #((apply pojo-fn "Hello" %))
  [[:char-at 0]     ; returns primitive char
   [:substring 3 4] ; returns string
   [:to-string]     ; no-arg method
   ]) ; returns lazy (\H "l" "Hello")</programlisting>
      </sect2>
      
      <sect2>
        <title>Call Java setter methods</title>
        <programlisting>(setter (StringBuilder.)
  :length 0) ; .setLength(0) - returns void, 'setter' returns nil

(setter (call-specs sb
          [:length 4]     ; .setLength(4)      - returns void
          [:char-at 0 \C] ; .setCharAt(0, 'C') - returns void
          )) ; 'setter' returns [nil nil]

(map #((apply setter-fn sb %))
  [[:length 4]     ; .setLength(4)      - returns void
   [:char-at 0 \C] ; .setCharAt(0, 'C') - returns void
   ]) ; returns lazy (nil nil)</programlisting>
      </sect2>
      
      <sect2>
        <title>Call Java getter methods</title>
        <programlisting>(let [lst (java.util.LinkedList.)
      _   (.add lst 1)
      _   (.add lst 2)]
  (getter lst :first) ; .getFirst() - returns 1
  (getter (call-specs lst :first ; .getFirst() - returns 1
                          :last  ; .getLast()  - returns 2
                          )) ; returns [1 2]
  (map (getter-fn lst) [:first ; .getFirst() - returns 1
                        :last  ; .getLast()  - returns 2
                        ])) ; returns lazy (1 2)</programlisting>
      </sect2>
    </sect1>

    <sect1>
      <title>java.util.Properties handling</title>

      <para>Assuming that the file sample.properties has the following content:
        <programlisting>a=10
b=20
c=true</programlisting>
        Properties can be transformed into maps:
        <programlisting>(let [ps (read-properties "src/test/conf/sample.properties")]
  (property-map ps)     ; returns {"a" "10" "b" "20" "c" "true"}
  (strkey-to-keyword
    (property-map ps))) ; returns {:a "10" :b "20" :c "true"}

(is-true? "true") ; returns true (useful to test bool values in properties)</programlisting>
      </para>
    </sect1>

    <sect1>
      <title>JNDI functions</title>

      <para>
        These JNDI tree-printing functions can be used to debug the JNDI
        configuration:
        <programlisting>(print-jndi-tree) ; print the JNDI tree referring initial context

(find-jndi-subcontext (javax.naming.InitialContext.)
         "java:comp") ; returns javax.naming.Context (if configured)

(jndi-lookup
  "java:comp/env/myDataSource") ; returns javax.sql.DataSource (if configured)</programlisting>
      </para>
    </sect1>
  </chapter>

  <chapter>
    <title>RDBMS Essentials (TODO)</title>

    <para>TODO</para>

    <section>
      <title>Configuration</title>

      <para></para>
    </section>

    <section>
      <title>Obtaining JDBC Drivers</title>

      <para></para>
    </section>

    <section>
      <title>Connection Pooling</title>

      <para></para>
    </section>

    <section>
      <title>Simple SQL</title>

      <para></para>
    </section>

    <section>
      <title>Parameterized SQL</title>

      <para></para>
    </section>

    <section>
      <title>CRUD - Create, Retrieve, Update, Delete</title>

      <para></para>
    </section>

    <section>
      <title>Batch Operations</title>

      <para></para>
    </section>

    <section>
      <title>Stored Procedures/Functions</title>

      <para></para>

      <section>
        <title>Parameters to Stored Procedures</title>

        <para></para>
      </section>
    </section>

    <section>
      <title>Error handling and Recovery</title>

      <para></para>

      <section>
        <title>Exceptions</title>

        <para></para>
      </section>

      <section>
        <title>Vendor specific Error Codes</title>

        <para></para>
      </section>
    </section>
  </chapter>

  <chapter>
    <title>RDBMS Transactions (TODO)</title>

    <section>
      <title>Programmatic Transactions</title>

      <para></para>
    </section>

    <section>
      <title>Isolation Levels</title>

      <para></para>
    </section>

    <section>
      <title>Declarative Transactions</title>

      <para></para>
    </section>
  </chapter>

  <chapter>
    <title>Managing RDBMS Changes</title>

    <para>Databases often undergo changes due to application upgrades and
      changes in requirements during development. We need to apply changes to
      databases to propogate sets of changes to various environments (Dev, QA,
      Staging, Production etc.) To consistently manage such changes we need a
      canonical format to express the database changes that can be also used to
      track the database state and apply changes.
    </para>

    <para><emphasis>Clj-Liquibase</emphasis> wraps over <emphasis>Liquibase</emphasis>
      to provide database change management functionality. While Liquibase lets
      you define the changes in an XML format, the Liquibase extensions integrate
      at API and invocation level to provide a seamless experience. When using
      Clj-Liquibase you define the database changes in pure Clojure code and
      invoke the changes using Clojure API.
    </para>
    
    <section>
      <title>Quickstart</title>
      <para>To use Clj-Liquibase you need to include the required namespace in
        your application and define a changelog.
        <programlisting>;; filename: fooapp/src/fooapp/dbchange.clj
(ns fooapp.dbchange
  (:require
    [org.bituf.clj-liquibase        :as lb]
    [org.bituf.clj-liquibase.change :as ch]))

(def ct-change1 (ch/create-table :sample-table1
                  [[:id     :int          :null false :pk true :autoinc true]
                   [:name   [:varchar 40] :null false]
                   [:gender [:char 1]     :null false]]))

(def changeset-1 ["id=1" "author=shantanu" [ct-change1]])

(lb/defchangelog changelog [changeset-1])</programlisting></para>
      
      <para>After defining the changelog, you need to apply the changes
        <emphasis role="bold">(see below)</emphasis>.
        <programlisting>;; filename: fooapp/src/fooapp/dbmigrate.clj
(ns fooapp.dbmigrate.clj
  (:require [fooapp.dbchange         :as dbch]
            [org.bituf.clj-dbcp      :as dbcp]
            [org.bituf.clj-dbspec    :as spec]
            [org.bituf.clj-liquibase :as lb]))

;; define datasource for supported database using Clj-DBCP
(def ds (dbcp/mysql-datasource "localhost" "dbname" "user" "pass"))

(defn do-lb-action "Wrap f using DBSpec middleware and execute it"
  [f]
  (let [g (spec/wrap-dbspec (spec/make-dbspec ds)
            (lb/wrap-lb-init f))]
    (g)))

(defn do-update "Invoke this function to update the database"
  []
  (do-lb-action #(lb/update dbch/changelog-1)))</programlisting>
      </para>
    </section>
    
    <section>
      <title>How it works</title>
      <para></para>
    </section>
    
    <section>
      <title>Changes</title>
      <para></para>
    </section>
    
    <section>
      <title>Actions</title>
      <para></para>
    </section>
    
    <section>
      <title>Leiningen Integration</title>
      <para></para>
    </section>
    
  </chapter>

  <chapter>
    <title>Using RDBMS - Entities (TODO)</title>

    <para></para>
  </chapter>

  <chapter>
    <title>Text Templates (TODO)</title>

    <para></para>
  </chapter>
</book>