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 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302
|
/*-
* Public Domain 2014-2019 MongoDB, Inc.
* Public Domain 2008-2014 WiredTiger, Inc.
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* wiredtiger.i
* The SWIG interface file defining the wiredtiger Java API.
*/
%module wiredtiger
%include "enums.swg"
%include "typemaps.i"
%include "stdint.i"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("wiredtiger_java");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}
%{
#include "wiredtiger.h"
#include "src/include/wt_internal.h"
/*
* Closed handle checking:
*
* The typedef WT_CURSOR_NULLABLE used in wiredtiger.h is only made
* visible to the SWIG parser and is used to identify arguments of
* Cursor type that are permitted to be null. Likewise, typedefs
* WT_{CURSOR,SESSION,CONNECTION}_CLOSED identify 'close' calls that
* need explicit nulling of the swigCPtr. These typedefs permit
* special casing in typemaps for input args.
*
* We want SWIG to see these 'fake' typenames, but not the compiler.
*/
#define WT_CURSOR_NULLABLE WT_CURSOR
#define WT_CURSOR_CLOSED WT_CURSOR
#define WT_SESSION_CLOSED WT_SESSION
#define WT_CONNECTION_CLOSED WT_CONNECTION
/*
* For Connections, Sessions and Cursors created in Java, each of
* WT_CONNECTION_IMPL, WT_SESSION_IMPL and WT_CURSOR have a
* lang_private field that store a pointer to a JAVA_CALLBACK, alloced
* during the various open calls. {conn,session,cursor}CloseHandler()
* functions reach into the associated java object, set the swigCPtr
* to 0, and free the JAVA_CALLBACK. Typemaps matching Connection,
* Session, Cursor args use the NULL_CHECK macro, which checks if
* swigCPtr is 0.
*/
typedef struct {
JavaVM *javavm; /* Used in async threads to craft a jnienv */
JNIEnv *jnienv; /* jni env that created the Session/Cursor */
WT_SESSION_IMPL *session; /* session used for alloc/free */
bool cursor_raw; /* is the cursor opened raw? */
jobject jobj; /* the java Session/Cursor/AsyncOp object */
jobject jcallback; /* callback object for async ops */
jfieldID cptr_fid; /* cached Cursor.swigCPtr field id in session */
jfieldID asynccptr_fid; /* cached AsyncOp.swigCptr fid in conn */
jfieldID kunp_fid; /* cached AsyncOp.keyUnpacker fid in conn */
jfieldID vunp_fid; /* cached AsyncOp.valueUnpacker fid in conn */
jmethodID notify_mid; /* cached AsyncCallback.notify mid in conn */
} JAVA_CALLBACK;
static void throwWiredTigerException(JNIEnv *jenv, int err) {
const char *clname;
jclass excep;
clname = NULL;
excep = NULL;
if (err == WT_PANIC)
clname = "com/wiredtiger/db/WiredTigerPanicException";
else if (err == WT_ROLLBACK)
clname = "com/wiredtiger/db/WiredTigerRollbackException";
else
clname = "com/wiredtiger/db/WiredTigerException";
if (clname)
excep = (*jenv)->FindClass(jenv, clname);
if (excep)
(*jenv)->ThrowNew(jenv, excep, wiredtiger_strerror(err));
}
struct __wt_java_modify_impl;
struct __wt_java_modify_list;
typedef struct __wt_java_modify_impl WT_MODIFY_IMPL;
typedef struct __wt_java_modify_list WT_MODIFY_LIST;
static void modify_impl_release(WT_MODIFY_IMPL *impl);
static void modify_list_release(WT_MODIFY_LIST *impl);
/*
* An extension to the WT_MODIFY struct, so we can associate some Java-specific
* information with it.
*/
typedef struct __wt_java_modify_impl {
WT_MODIFY modify;
JNIEnv *jnienv;
jobject ref;
} WT_MODIFY_IMPL;
%}
/* No finalizers */
%typemap(javafinalize) SWIGTYPE ""
/* Event handlers are not supported in Java. */
%typemap(in, numinputs=0) WT_EVENT_HANDLER * %{ $1 = NULL; %}
/* Allow silently passing the Java object and JNIEnv into our code. */
%typemap(in, numinputs=0) jobject *jthis %{ $1 = jarg1_; %}
%typemap(in, numinputs=0) JNIEnv * %{ $1 = jenv; %}
/* 64 bit typemaps. */
%typemap(jni) uint64_t "jlong"
%typemap(jtype) uint64_t "long"
%typemap(jstype) uint64_t "long"
%typemap(javain) uint64_t "$javainput"
%typemap(javaout) uint64_t {
return ($jnicall);
}
/* Return byte[] from cursor.get_value */
%typemap(jni) WT_ITEM, WT_ITEM * "jbyteArray"
%typemap(jtype) WT_ITEM, WT_ITEM * "byte[]"
%typemap(jstype) WT_ITEM, WT_ITEM * "byte[]"
%typemap(javain) WT_ITEM, WT_ITEM * "$javainput"
%typemap(javaout) WT_ITEM, WT_ITEM * {
return ($jnicall);
}
%typemap(in) WT_ITEM * (WT_ITEM item) %{
$1 = &item;
$1->data = (*jenv)->GetByteArrayElements(jenv, $input, 0);
$1->size = (size_t)(*jenv)->GetArrayLength(jenv, $input);
%}
%typemap(argout) WT_ITEM * %{
(*jenv)->ReleaseByteArrayElements(jenv, $input, (void *)$1->data, 0);
%}
%typemap(out) WT_ITEM %{
if ($1.data == NULL)
$result = NULL;
else if (($result = (*jenv)->NewByteArray(jenv, (jsize)$1.size)) != NULL) {
(*jenv)->SetByteArrayRegion(jenv,
$result, 0, (jsize)$1.size, $1.data);
}
%}
/*
* In some cases, for an internal interface, we need something like a WT_ITEM,
* but we need to hold onto the memory past the method call, and release it
* later. A WT_ITEM_HOLD serves the purpose, it retains the java object
* for the byte array that we make into a global reference.
*/
%typemap(jni) WT_ITEM_HOLD, WT_ITEM_HOLD * "jbyteArray"
%typemap(jtype) WT_ITEM_HOLD, WT_ITEM_HOLD * "byte[]"
%typemap(jstype) WT_ITEM_HOLD, WT_ITEM_HOLD * "byte[]"
%typemap(javain) WT_ITEM_HOLD, WT_ITEM_HOLD * "$javainput"
%typemap(javaout) WT_ITEM_HOLD, WT_ITEM_HOLD * {
return ($jnicall);
}
%typemap(in) WT_ITEM_HOLD * (WT_ITEM_HOLD item) %{
$1 = &item;
$1->data = (*jenv)->GetByteArrayElements(jenv, $input, 0);
$1->size = (size_t)(*jenv)->GetArrayLength(jenv, $input);
$1->jnienv = jenv;
$1->ref = (*jenv)->NewGlobalRef(jenv, $input);
%}
%typemap(argout) WT_ITEM_HOLD * %{
/* Explicitly don't release the byte array elements here. */
%}
/* Don't require empty config strings. */
%typemap(default) const char *config %{ $1 = NULL; %}
%typemap(out) int %{
if ($1 != 0 && $1 != WT_NOTFOUND) {
throwWiredTigerException(jenv, $1);
return ($null);
}
$result = $1;
%}
%define NULL_CHECK(val, name)
if (!val) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException,
#name " is null");
return ($null);
}
%enddef
/*
* 'Declare' a WiredTiger class. This sets up boilerplate typemaps.
*/
%define WT_CLASS(type, class, name)
/*
* Extra 'self' elimination.
* The methods we're wrapping look like this:
* struct __wt_xxx {
* int method(WT_XXX *, ...otherargs...);
* };
* To SWIG, that is equivalent to:
* int method(struct __wt_xxx *self, WT_XXX *, ...otherargs...);
* and we use consecutive argument matching of typemaps to convert two args to
* one.
*/
%typemap(in, numinputs=0) type *name {
$1 = *(type **)&jarg1;
NULL_CHECK($1, $1_name)
}
%typemap(in) class ## _NULLABLE * {
$1 = *(type **)&$input;
}
%typemap(in) type * {
$1 = *(type **)&$input;
NULL_CHECK($1, $1_name)
}
%typemap(javaimports) type "
/**
* @copydoc class
* @ingroup wt_java
*/"
%enddef
/*
* Declare a WT_CLASS so that close methods call a specified closeHandler,
* after the WT core close function has completed. Arguments to the
* closeHandler are saved in advance since, as macro args, they may refer to
* values that are freed/zeroed by the close.
*/
%define WT_CLASS_WITH_CLOSE_HANDLER(type, class, name, closeHandler,
sess, priv)
WT_CLASS(type, class, name)
/*
* This typemap recognizes a close function via a special declaration on its
* first argument. See WT_HANDLE_CLOSED in wiredtiger.h . Like
* WT_CURSOR_NULLABLE, the WT_{CURSOR,SESSION,CONNECTION}_CLOSED typedefs
* are only visible to the SWIG parser.
*/
%typemap(in, numinputs=0) class ## _CLOSED *name (
WT_SESSION *savesess, JAVA_CALLBACK *jcb) {
$1 = *(type **)&jarg1;
NULL_CHECK($1, $1_name)
savesess = sess;
jcb = (JAVA_CALLBACK *)(priv);
}
%typemap(freearg, numinputs=0) class ## _CLOSED *name {
closeHandler(jenv, savesess2, jcb2);
}
%enddef
%pragma(java) moduleimports=%{
/**
* @defgroup wt_java WiredTiger Java API
*
* Java wrappers around the WiredTiger C API.
*/
/**
* @ingroup wt_java
*/
%}
WT_CLASS_WITH_CLOSE_HANDLER(struct __wt_connection, WT_CONNECTION, connection,
closeHandler, NULL, ((WT_CONNECTION_IMPL *)$1)->lang_private)
WT_CLASS_WITH_CLOSE_HANDLER(struct __wt_session, WT_SESSION, session,
closeHandler, $1, ((WT_SESSION_IMPL *)$1)->lang_private)
WT_CLASS_WITH_CLOSE_HANDLER(struct __wt_cursor, WT_CURSOR, cursor,
cursorCloseHandler, $1->session, ((WT_CURSOR *)$1)->lang_private)
WT_CLASS(struct __wt_async_op, WT_ASYNC_OP, op)
%define COPYDOC(SIGNATURE_CLASS, CLASS, METHOD)
%javamethodmodifiers SIGNATURE_CLASS::METHOD "
/**
* @copydoc CLASS::METHOD
*/
public ";
%enddef
%include "java_doc.i"
/* WT_ASYNC_OP customization. */
/* First, replace the varargs get / set methods with Java equivalents. */
%ignore __wt_async_op::get_key;
%ignore __wt_async_op::get_value;
%ignore __wt_async_op::set_key;
%ignore __wt_async_op::set_value;
%ignore __wt_async_op::insert;
%ignore __wt_async_op::remove;
%ignore __wt_async_op::search;
%ignore __wt_async_op::update;
%immutable __wt_async_op::connection;
%immutable __wt_async_op::key_format;
%immutable __wt_async_op::value_format;
%javamethodmodifiers __wt_async_op::key_format "protected";
%javamethodmodifiers __wt_async_op::value_format "protected";
/* WT_CURSOR customization. */
/* First, replace the varargs get / set methods with Java equivalents. */
%ignore __wt_cursor::get_key;
%ignore __wt_cursor::get_value;
%ignore __wt_cursor::set_key;
%ignore __wt_cursor::set_value;
%ignore __wt_cursor::insert;
%ignore __wt_cursor::remove;
%ignore __wt_cursor::reset;
%ignore __wt_cursor::search;
%ignore __wt_cursor::search_near;
%ignore __wt_cursor::update;
%javamethodmodifiers __wt_cursor::next "protected";
%rename (next_wrap) __wt_cursor::next;
%javamethodmodifiers __wt_cursor::prev "protected";
%rename (prev_wrap) __wt_cursor::prev;
%javamethodmodifiers __wt_cursor::key_format "protected";
%javamethodmodifiers __wt_cursor::value_format "protected";
%ignore __wt_modify::data;
%ignore __wt_modify::position;
%ignore __wt_modify::size;
%ignore __wt_cursor::modify;
%ignore wiredtiger_calc_modify;
%ignore __wt_cursor::compare(WT_CURSOR *, WT_CURSOR *, int *);
%rename (compare_wrap) __wt_cursor::compare;
%ignore __wt_cursor::equals(WT_CURSOR *, WT_CURSOR *, int *);
%rename (equals_wrap) __wt_cursor::equals;
%rename (AsyncOpType) WT_ASYNC_OPTYPE;
%rename (getKeyFormat) __wt_async_op::getKey_format;
%rename (getValueFormat) __wt_async_op::getValue_format;
%rename (getType) __wt_async_op::get_type;
/*
* Special cases: override the out typemap, return checking is done in the
* wrapper.
*/
%typemap(out) int __wt_cursor::compare_wrap,
int __wt_cursor::equals_wrap %{
$result = $1;
%}
/* SWIG magic to turn Java byte strings into data / size. */
%apply (char *STRING, int LENGTH) { (char *data, int size) };
/* Status from search_near */
%javaconst(1);
%inline %{
enum SearchStatus { FOUND, NOTFOUND, SMALLER, LARGER };
%}
%wrapper %{
/* Zero out SWIG's pointer to the C object,
* equivalent to 'jobj.swigCPtr = 0;' in java.
* We expect that either env in non-null (if called
* via an explicit session/cursor close() call), or
* that session is non-null (if called implicitly
* as part of connection/session close).
*/
static int
javaClose(JNIEnv *env, WT_SESSION *session, JAVA_CALLBACK *jcb, jfieldID *pfid)
{
jclass cls;
jfieldID fid;
WT_CONNECTION_IMPL *conn;
/* If we were not called via an implicit close call,
* we won't have a JNIEnv yet. Get one from the connection,
* since the thread that started the session may have
* terminated.
*/
if (env == NULL) {
conn = (WT_CONNECTION_IMPL *)session->connection;
env = ((JAVA_CALLBACK *)conn->lang_private)->jnienv;
}
if (pfid == NULL || *pfid == NULL) {
cls = (*env)->GetObjectClass(env, jcb->jobj);
fid = (*env)->GetFieldID(env, cls, "swigCPtr", "J");
if (pfid != NULL)
*pfid = fid;
} else
fid = *pfid;
(*env)->SetLongField(env, jcb->jobj, fid, 0L);
(*env)->DeleteGlobalRef(env, jcb->jobj);
__wt_free(jcb->session, jcb);
return (0);
}
/* Connection and Session close handler. */
static int
closeHandler(JNIEnv *env, WT_SESSION *session, JAVA_CALLBACK *jcb)
{
return (javaClose(env, session, jcb, NULL));
}
/* Cursor specific close handler. */
static int
cursorCloseHandler(JNIEnv *env, WT_SESSION *wt_session, JAVA_CALLBACK *jcb)
{
int ret;
JAVA_CALLBACK *sess_jcb;
WT_SESSION_IMPL *session;
session = (WT_SESSION_IMPL *)wt_session;
sess_jcb = (JAVA_CALLBACK *)session->lang_private;
ret = javaClose(env, wt_session, jcb,
sess_jcb ? &sess_jcb->cptr_fid : NULL);
return (ret);
}
/* Add event handler support. */
static int
javaCloseHandler(WT_EVENT_HANDLER *handler, WT_SESSION *session,
WT_CURSOR *cursor)
{
int ret;
JAVA_CALLBACK *jcb;
WT_UNUSED(handler);
ret = 0;
if (cursor != NULL) {
if ((jcb = (JAVA_CALLBACK *)cursor->lang_private) != NULL) {
ret = cursorCloseHandler(NULL, session, jcb);
cursor->lang_private = NULL;
}
} else if ((jcb = ((WT_SESSION_IMPL *)session)->lang_private) != NULL) {
ret = closeHandler(NULL, session, jcb);
((WT_SESSION_IMPL *)session)->lang_private = NULL;
}
return (ret);
}
WT_EVENT_HANDLER javaApiEventHandler = {NULL, NULL, NULL, javaCloseHandler};
static int
javaAsyncHandler(WT_ASYNC_CALLBACK *cb, WT_ASYNC_OP *asyncop, int opret,
uint32_t flags)
{
int ret, envret;
JAVA_CALLBACK *jcb, *conn_jcb;
JavaVM *javavm;
jclass cls;
jfieldID fid;
jmethodID mid;
jobject jcallback;
JNIEnv *jenv;
WT_ASYNC_OP_IMPL *op;
WT_SESSION_IMPL *session;
WT_UNUSED(cb);
WT_UNUSED(flags);
op = (WT_ASYNC_OP_IMPL *)asyncop;
session = O2S(op);
jcb = (JAVA_CALLBACK *)asyncop->c.lang_private;
conn_jcb = (JAVA_CALLBACK *)S2C(session)->lang_private;
asyncop->c.lang_private = NULL;
jcallback = jcb->jcallback;
/*
* We rely on the fact that the async machinery uses a pool of
* threads. Here we attach the current native (POSIX)
* thread to a Java thread and never detach it. If the native
* thread was previously seen by this callback, it will be
* attached to the same Java thread as before without
* incurring the cost of the thread initialization.
* Marking the Java thread as a daemon means its existence
* won't keep an application from exiting.
*/
javavm = jcb->javavm;
envret = (*javavm)->GetEnv(javavm, (void **)&jenv, JNI_VERSION_1_6);
if (envret == JNI_EDETACHED) {
if ((*javavm)->AttachCurrentThreadAsDaemon(javavm,
(void **)&jenv, NULL) != 0) {
ret = EBUSY;
goto err;
}
} else if (envret != JNI_OK) {
ret = EBUSY;
goto err;
}
/*
* Look up any needed field and method ids, and cache them
* in the connection's lang_private. fid and mids are
* stable.
*/
if (conn_jcb->notify_mid == NULL) {
/* Any JNI error until the actual callback is unexpected. */
ret = EINVAL;
cls = (*jenv)->GetObjectClass(jenv, jcb->jobj);
if (cls == NULL)
goto err;
fid = (*jenv)->GetFieldID(jenv, cls,
"keyUnpacker", "Lcom/wiredtiger/db/PackInputStream;");
if (fid == NULL)
goto err;
conn_jcb->kunp_fid = fid;
fid = (*jenv)->GetFieldID(jenv, cls,
"valueUnpacker", "Lcom/wiredtiger/db/PackInputStream;");
if (fid == NULL)
goto err;
conn_jcb->vunp_fid = fid;
cls = (*jenv)->GetObjectClass(jenv, jcallback);
if (cls == NULL)
goto err;
mid = (*jenv)->GetMethodID(jenv, cls, "notify",
"(Lcom/wiredtiger/db/AsyncOp;II)I");
if (mid == NULL)
goto err;
conn_jcb->notify_mid = mid;
}
/*
* Invalidate the unpackers so any calls to op.getKey()
* and op.getValue get fresh results.
*/
(*jenv)->SetObjectField(jenv, jcb->jobj, conn_jcb->kunp_fid, NULL);
(*jenv)->SetObjectField(jenv, jcb->jobj, conn_jcb->vunp_fid, NULL);
/* Call the registered callback. */
ret = (*jenv)->CallIntMethod(jenv, jcallback, conn_jcb->notify_mid,
jcb->jobj, opret, flags);
if ((*jenv)->ExceptionOccurred(jenv)) {
(*jenv)->ExceptionDescribe(jenv);
(*jenv)->ExceptionClear(jenv);
}
if (0) {
err: __wt_err(session, ret, "Java async callback error");
}
/* Invalidate the AsyncOp, further use throws NullPointerException. */
ret = javaClose(jenv, NULL, jcb, &conn_jcb->asynccptr_fid);
(*jenv)->DeleteGlobalRef(jenv, jcallback);
if (ret == 0 && (opret == 0 || opret == WT_NOTFOUND))
return (0);
else
return (1);
}
WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler};
%}
%extend __wt_async_op {
%javamethodmodifiers get_key_wrap "protected";
WT_ITEM get_key_wrap(JNIEnv *jenv) {
WT_ITEM k;
int ret;
k.data = NULL;
if ((ret = $self->get_key($self, &k)) != 0)
throwWiredTigerException(jenv, ret);
return (k);
}
%javamethodmodifiers get_value_wrap "protected";
WT_ITEM get_value_wrap(JNIEnv *jenv) {
WT_ITEM v;
int ret;
v.data = NULL;
if ((ret = $self->get_value($self, &v)) != 0)
throwWiredTigerException(jenv, ret);
return (v);
}
%javamethodmodifiers insert_wrap "protected";
int insert_wrap(WT_ITEM *k, WT_ITEM *v) {
$self->set_key($self, k);
$self->set_value($self, v);
return ($self->insert($self));
}
%javamethodmodifiers remove_wrap "protected";
int remove_wrap(WT_ITEM *k) {
$self->set_key($self, k);
return ($self->remove($self));
}
%javamethodmodifiers search_wrap "protected";
int search_wrap(WT_ITEM *k) {
$self->set_key($self, k);
return ($self->search($self));
}
%javamethodmodifiers update_wrap "protected";
int update_wrap(WT_ITEM *k, WT_ITEM *v) {
$self->set_key($self, k);
$self->set_value($self, v);
return ($self->update($self));
}
%javamethodmodifiers _java_raw "protected";
bool _java_raw(JNIEnv *jenv) {
(void)jenv;
JAVA_CALLBACK *jcb = (JAVA_CALLBACK *)$self->c.lang_private;
return (jcb->cursor_raw);
}
%javamethodmodifiers _java_init "protected";
int _java_init(jobject jasyncop) {
JAVA_CALLBACK *jcb =
(JAVA_CALLBACK *)$self->c.lang_private;
jcb->jobj = JCALL1(NewGlobalRef, jcb->jnienv, jasyncop);
JCALL1(DeleteLocalRef, jcb->jnienv, jasyncop);
return (0);
}
}
/* Cache key/value formats in Async_op */
%typemap(javabody) struct __wt_async_op %{
private long swigCPtr;
protected boolean swigCMemOwn;
protected boolean javaRaw;
protected String keyFormat;
protected String valueFormat;
protected PackOutputStream keyPacker;
protected PackOutputStream valuePacker;
protected PackInputStream keyUnpacker;
protected PackInputStream valueUnpacker;
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
keyFormat = getKey_format();
valueFormat = getValue_format();
javaRaw = _java_raw();
keyPacker = new PackOutputStream(keyFormat, javaRaw);
valuePacker = new PackOutputStream(valueFormat, javaRaw);
wiredtigerJNI.AsyncOp__java_init(swigCPtr, this, this);
}
protected static long getCPtr($javaclassname obj) {
return ((obj == null) ? 0 : obj.swigCPtr);
}
%}
%typemap(javacode) struct __wt_async_op %{
/**
* Retrieve the format string for this async_op's key.
*/
public String getKeyFormat() {
return keyFormat;
}
/**
* Retrieve the format string for this async_op's value.
*/
public String getValueFormat() {
return valueFormat;
}
/**
* Append a byte to the async_op's key.
*
* \param value The value to append.
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putKeyByte(byte value)
throws WiredTigerPackingException {
keyUnpacker = null;
keyPacker.addByte(value);
return this;
}
/**
* Append a byte array to the async_op's key.
*
* \param value The value to append.
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putKeyByteArray(byte[] value)
throws WiredTigerPackingException {
this.putKeyByteArray(value, 0, value.length);
return this;
}
/**
* Append a byte array to the async_op's key.
*
* \param value The value to append.
* \param off The offset into value at which to start.
* \param len The length of the byte array.
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putKeyByteArray(byte[] value, int off, int len)
throws WiredTigerPackingException {
keyUnpacker = null;
keyPacker.addByteArray(value, off, len);
return this;
}
/**
* Append an integer to the async_op's key.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putKeyInt(int value)
throws WiredTigerPackingException {
keyUnpacker = null;
keyPacker.addInt(value);
return this;
}
/**
* Append a long to the async_op's key.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putKeyLong(long value)
throws WiredTigerPackingException {
keyUnpacker = null;
keyPacker.addLong(value);
return this;
}
/**
* Append a record number to the async_op's key.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putKeyRecord(long value)
throws WiredTigerPackingException {
keyUnpacker = null;
keyPacker.addRecord(value);
return this;
}
/**
* Append a short integer to the async_op's key.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putKeyShort(short value)
throws WiredTigerPackingException {
keyUnpacker = null;
keyPacker.addShort(value);
return this;
}
/**
* Append a string to the async_op's key.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putKeyString(String value)
throws WiredTigerPackingException {
keyUnpacker = null;
keyPacker.addString(value);
return this;
}
/**
* Append a byte to the async_op's value.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putValueByte(byte value)
throws WiredTigerPackingException {
valueUnpacker = null;
valuePacker.addByte(value);
return this;
}
/**
* Append a byte array to the async_op's value.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putValueByteArray(byte[] value)
throws WiredTigerPackingException {
this.putValueByteArray(value, 0, value.length);
return this;
}
/**
* Append a byte array to the async_op's value.
*
* \param value The value to append
* \param off The offset into value at which to start.
* \param len The length of the byte array.
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putValueByteArray(byte[] value, int off, int len)
throws WiredTigerPackingException {
valueUnpacker = null;
valuePacker.addByteArray(value, off, len);
return this;
}
/**
* Append an integer to the async_op's value.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putValueInt(int value)
throws WiredTigerPackingException {
valueUnpacker = null;
valuePacker.addInt(value);
return this;
}
/**
* Append a long to the async_op's value.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putValueLong(long value)
throws WiredTigerPackingException {
valueUnpacker = null;
valuePacker.addLong(value);
return this;
}
/**
* Append a record number to the async_op's value.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putValueRecord(long value)
throws WiredTigerPackingException {
valueUnpacker = null;
valuePacker.addRecord(value);
return this;
}
/**
* Append a short integer to the async_op's value.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putValueShort(short value)
throws WiredTigerPackingException {
valueUnpacker = null;
valuePacker.addShort(value);
return this;
}
/**
* Append a string to the async_op's value.
*
* \param value The value to append
* \return This async_op object, so put calls can be chained.
*/
public AsyncOp putValueString(String value)
throws WiredTigerPackingException {
valueUnpacker = null;
valuePacker.addString(value);
return this;
}
/**
* Retrieve a byte from the async_op's key.
*
* \return The requested value.
*/
public byte getKeyByte()
throws WiredTigerPackingException {
return getKeyUnpacker().getByte();
}
/**
* Retrieve a byte array from the async_op's key.
*
* \param output The byte array where the returned value will be stored.
* The array should be large enough to store the entire
* data item, if not a truncated value will be returned.
*/
public void getKeyByteArray(byte[] output)
throws WiredTigerPackingException {
this.getKeyByteArray(output, 0, output.length);
}
/**
* Retrieve a byte array from the async_op's key.
*
* \param output The byte array where the returned value will be stored.
* \param off Offset into the destination buffer to start copying into.
* \param len The length should be large enough to store the entire
* data item, if not a truncated value will be returned.
*/
public void getKeyByteArray(byte[] output, int off, int len)
throws WiredTigerPackingException {
getKeyUnpacker().getByteArray(output, off, len);
}
/**
* Retrieve a byte array from the async_op's key.
*
* \return The requested value.
*/
public byte[] getKeyByteArray()
throws WiredTigerPackingException {
return getKeyUnpacker().getByteArray();
}
/**
* Retrieve an integer from the async_op's key.
*
* \return The requested value.
*/
public int getKeyInt()
throws WiredTigerPackingException {
return getKeyUnpacker().getInt();
}
/**
* Retrieve a long from the async_op's key.
*
* \return The requested value.
*/
public long getKeyLong()
throws WiredTigerPackingException {
return getKeyUnpacker().getLong();
}
/**
* Retrieve a record number from the async_op's key.
*
* \return The requested value.
*/
public long getKeyRecord()
throws WiredTigerPackingException {
return getKeyUnpacker().getRecord();
}
/**
* Retrieve a short integer from the async_op's key.
*
* \return The requested value.
*/
public short getKeyShort()
throws WiredTigerPackingException {
return getKeyUnpacker().getShort();
}
/**
* Retrieve a string from the async_op's key.
*
* \return The requested value.
*/
public String getKeyString()
throws WiredTigerPackingException {
return getKeyUnpacker().getString();
}
/**
* Retrieve a byte from the async_op's value.
*
* \return The requested value.
*/
public byte getValueByte()
throws WiredTigerPackingException {
return getValueUnpacker().getByte();
}
/**
* Retrieve a byte array from the async_op's value.
*
* \param output The byte array where the returned value will be stored.
* The array should be large enough to store the entire
* data item, if not a truncated value will be returned.
*/
public void getValueByteArray(byte[] output)
throws WiredTigerPackingException {
this.getValueByteArray(output, 0, output.length);
}
/**
* Retrieve a byte array from the async_op's value.
*
* \param output The byte array where the returned value will be stored.
* \param off Offset into the destination buffer to start copying into.
* \param len The length should be large enough to store the entire
* data item, if not a truncated value will be returned.
*/
public void getValueByteArray(byte[] output, int off, int len)
throws WiredTigerPackingException {
getValueUnpacker().getByteArray(output, off, len);
}
/**
* Retrieve a byte array from the async_op's value.
*
* \return The requested value.
*/
public byte[] getValueByteArray()
throws WiredTigerPackingException {
return getValueUnpacker().getByteArray();
}
/**
* Retrieve an integer from the async_op's value.
*
* \return The requested value.
*/
public int getValueInt()
throws WiredTigerPackingException {
return getValueUnpacker().getInt();
}
/**
* Retrieve a long from the async_op's value.
*
* \return The requested value.
*/
public long getValueLong()
throws WiredTigerPackingException {
return getValueUnpacker().getLong();
}
/**
* Retrieve a record number from the async_op's value.
*
* \return The requested value.
*/
public long getValueRecord()
throws WiredTigerPackingException {
return getValueUnpacker().getRecord();
}
/**
* Retrieve a short integer from the async_op's value.
*
* \return The requested value.
*/
public short getValueShort()
throws WiredTigerPackingException {
return getValueUnpacker().getShort();
}
/**
* Retrieve a string from the async_op's value.
*
* \return The requested value.
*/
public String getValueString()
throws WiredTigerPackingException {
return getValueUnpacker().getString();
}
/**
* Insert the async_op's current key/value into the table.
*
* \return The status of the operation.
*/
public int insert()
throws WiredTigerException {
byte[] key = keyPacker.getValue();
byte[] value = valuePacker.getValue();
keyPacker.reset();
valuePacker.reset();
return insert_wrap(key, value);
}
/**
* Update the async_op's current key/value into the table.
*
* \return The status of the operation.
*/
public int update()
throws WiredTigerException {
byte[] key = keyPacker.getValue();
byte[] value = valuePacker.getValue();
keyPacker.reset();
valuePacker.reset();
return update_wrap(key, value);
}
/**
* Remove the async_op's current key/value into the table.
*
* \return The status of the operation.
*/
public int remove()
throws WiredTigerException {
byte[] key = keyPacker.getValue();
keyPacker.reset();
return remove_wrap(key);
}
/**
* Search for an item in the table.
*
* \return The result of the comparison.
*/
public int search()
throws WiredTigerException {
int ret = search_wrap(keyPacker.getValue());
keyPacker.reset();
valuePacker.reset();
return ret;
}
/**
* Set up the key unpacker or return previously cached value.
*
* \return The key unpacker.
*/
private PackInputStream getKeyUnpacker()
throws WiredTigerPackingException {
if (keyUnpacker == null)
keyUnpacker =
new PackInputStream(keyFormat, get_key_wrap(),
javaRaw);
return keyUnpacker;
}
/**
* Set up the value unpacker or return previously cached value.
*
* \return The value unpacker.
*/
private PackInputStream getValueUnpacker()
throws WiredTigerPackingException {
if (valueUnpacker == null)
valueUnpacker =
new PackInputStream(valueFormat, get_value_wrap(),
javaRaw);
return valueUnpacker;
}
%}
%extend __wt_cursor {
%javamethodmodifiers get_key_wrap "protected";
WT_ITEM get_key_wrap(JNIEnv *jenv) {
WT_ITEM k;
int ret;
k.data = NULL;
if ((ret = $self->get_key($self, &k)) != 0)
throwWiredTigerException(jenv, ret);
return (k);
}
%javamethodmodifiers get_value_wrap "protected";
WT_ITEM get_value_wrap(JNIEnv *jenv) {
WT_ITEM v;
int ret;
v.data = NULL;
if ((ret = $self->get_value($self, &v)) != 0)
throwWiredTigerException(jenv, ret);
return (v);
}
%javamethodmodifiers insert_wrap "protected";
int insert_wrap(WT_ITEM *k, WT_ITEM *v) {
$self->set_key($self, k);
$self->set_value($self, v);
return ($self->insert($self));
}
%javamethodmodifiers remove_wrap "protected";
int remove_wrap(WT_ITEM *k) {
$self->set_key($self, k);
return ($self->remove($self));
}
%javamethodmodifiers reset_wrap "protected";
int reset_wrap() {
return $self->reset($self);
}
%javamethodmodifiers search_wrap "protected";
int search_wrap(WT_ITEM *k) {
$self->set_key($self, k);
return ($self->search($self));
}
%javamethodmodifiers search_near_wrap "protected";
enum SearchStatus search_near_wrap(JNIEnv *jenv, WT_ITEM *k) {
int cmp, ret;
$self->set_key($self, k);
ret = $self->search_near(self, &cmp);
if (ret != 0 && ret != WT_NOTFOUND)
throwWiredTigerException(jenv, ret);
if (ret == 0)
return (cmp == 0 ? FOUND : cmp < 0 ? SMALLER : LARGER);
return (NOTFOUND);
}
%javamethodmodifiers update_wrap "protected";
int update_wrap(WT_ITEM *k, WT_ITEM *v) {
$self->set_key($self, k);
$self->set_value($self, v);
return ($self->update($self));
}
%javamethodmodifiers compare_wrap "protected";
int compare_wrap(JNIEnv *jenv, WT_CURSOR *other) {
int cmp, ret = $self->compare($self, other, &cmp);
if (ret != 0)
throwWiredTigerException(jenv, ret);
return (cmp);
}
%javamethodmodifiers equals_wrap "protected";
int equals_wrap(JNIEnv *jenv, WT_CURSOR *other) {
int cmp, ret = $self->equals($self, other, &cmp);
if (ret != 0)
throwWiredTigerException(jenv, ret);
return (cmp);
}
%javamethodmodifiers _java_raw "protected";
bool _java_raw(JNIEnv *jenv) {
(void)jenv;
JAVA_CALLBACK *jcb = (JAVA_CALLBACK *)$self->lang_private;
return (jcb->cursor_raw);
}
%javamethodmodifiers _java_init "protected";
int _java_init(jobject jcursor) {
JAVA_CALLBACK *jcb = (JAVA_CALLBACK *)$self->lang_private;
jcb->jobj = JCALL1(NewGlobalRef, jcb->jnienv, jcursor);
JCALL1(DeleteLocalRef, jcb->jnienv, jcursor);
return (0);
}
int modify_wrap(WT_MODIFY_LIST *list, WT_ITEM *k) {
int ret;
$self->set_key($self, k);
ret = $self->modify(self, list->mod_array, list->count);
modify_list_release(list);
return (ret);
}
/*
* Called internally after a new call. The artificial constructor for
* WT_MODIFY_LIST has no opportunity to throw an exception on a memory
* allocation failure, so the the null check must be made within a
* method on WT_CURSOR.
*/
bool _new_check_modify_list(WT_MODIFY_LIST *list) {
JAVA_CALLBACK *jcb;
if (list == NULL) {
jcb = (JAVA_CALLBACK *)$self->lang_private;
throwWiredTigerException(jcb->jnienv, ENOMEM);
return (false);
}
return (true);
}
/*
* Called internally after a new call. The artificial constructor for
* WT_MODIFY has no opportunity to throw an exception on a memory
* allocation failure, so the the null check must be made within a
* method on WT_CURSOR.
*/
bool _new_check_modify(WT_MODIFY *mod) {
JAVA_CALLBACK *jcb;
if (mod == NULL) {
jcb = (JAVA_CALLBACK *)$self->lang_private;
throwWiredTigerException(jcb->jnienv, ENOMEM);
return (false);
}
return (true);
}
}
/* Cache key/value formats in Cursor */
%typemap(javabody) struct __wt_cursor %{
private long swigCPtr;
protected boolean swigCMemOwn;
protected String keyFormat;
protected String valueFormat;
protected PackOutputStream keyPacker;
protected PackOutputStream valuePacker;
protected PackInputStream keyUnpacker;
protected PackInputStream valueUnpacker;
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
keyFormat = getKey_format();
valueFormat = getValue_format();
keyPacker = new PackOutputStream(keyFormat, _java_raw());
valuePacker = new PackOutputStream(valueFormat, _java_raw());
wiredtigerJNI.Cursor__java_init(swigCPtr, this, this);
}
protected static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%typemap(javacode) struct __wt_cursor %{
/**
* Retrieve the format string for this cursor's key.
*/
public String getKeyFormat() {
return keyFormat;
}
/**
* Retrieve the format string for this cursor's value.
*/
public String getValueFormat() {
return valueFormat;
}
/**
* Append a byte to the cursor's key.
*
* \param value The value to append.
* \return This cursor object, so put calls can be chained.
*/
public Cursor putKeyByte(byte value)
throws WiredTigerPackingException {
keyPacker.addByte(value);
return this;
}
/**
* Append a byte array to the cursor's key.
*
* \param value The value to append.
* \return This cursor object, so put calls can be chained.
*/
public Cursor putKeyByteArray(byte[] value)
throws WiredTigerPackingException {
this.putKeyByteArray(value, 0, value.length);
return this;
}
/**
* Append a byte array to the cursor's key.
*
* \param value The value to append.
* \param off The offset into value at which to start.
* \param len The length of the byte array.
* \return This cursor object, so put calls can be chained.
*/
public Cursor putKeyByteArray(byte[] value, int off, int len)
throws WiredTigerPackingException {
keyPacker.addByteArray(value, off, len);
return this;
}
/**
* Append an integer to the cursor's key.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putKeyInt(int value)
throws WiredTigerPackingException {
keyPacker.addInt(value);
return this;
}
/**
* Append a long to the cursor's key.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putKeyLong(long value)
throws WiredTigerPackingException {
keyPacker.addLong(value);
return this;
}
/**
* Append a record number to the cursor's key.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putKeyRecord(long value)
throws WiredTigerPackingException {
keyPacker.addRecord(value);
return this;
}
/**
* Append a short integer to the cursor's key.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putKeyShort(short value)
throws WiredTigerPackingException {
keyPacker.addShort(value);
return this;
}
/**
* Append a string to the cursor's key.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putKeyString(String value)
throws WiredTigerPackingException {
keyPacker.addString(value);
return this;
}
/**
* Append a byte to the cursor's value.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putValueByte(byte value)
throws WiredTigerPackingException {
valuePacker.addByte(value);
return this;
}
/**
* Append a byte array to the cursor's value.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putValueByteArray(byte[] value)
throws WiredTigerPackingException {
this.putValueByteArray(value, 0, value.length);
return this;
}
/**
* Append a byte array to the cursor's value.
*
* \param value The value to append
* \param off The offset into value at which to start.
* \param len The length of the byte array.
* \return This cursor object, so put calls can be chained.
*/
public Cursor putValueByteArray(byte[] value, int off, int len)
throws WiredTigerPackingException {
valuePacker.addByteArray(value, off, len);
return this;
}
/**
* Append an integer to the cursor's value.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putValueInt(int value)
throws WiredTigerPackingException {
valuePacker.addInt(value);
return this;
}
/**
* Append a long to the cursor's value.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putValueLong(long value)
throws WiredTigerPackingException {
valuePacker.addLong(value);
return this;
}
/**
* Append a record number to the cursor's value.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putValueRecord(long value)
throws WiredTigerPackingException {
valuePacker.addRecord(value);
return this;
}
/**
* Append a short integer to the cursor's value.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putValueShort(short value)
throws WiredTigerPackingException {
valuePacker.addShort(value);
return this;
}
/**
* Append a string to the cursor's value.
*
* \param value The value to append
* \return This cursor object, so put calls can be chained.
*/
public Cursor putValueString(String value)
throws WiredTigerPackingException {
valuePacker.addString(value);
return this;
}
/**
* Retrieve a byte from the cursor's key.
*
* \return The requested value.
*/
public byte getKeyByte()
throws WiredTigerPackingException {
return keyUnpacker.getByte();
}
/**
* Retrieve a byte array from the cursor's key.
*
* \param output The byte array where the returned value will be stored.
* The array should be large enough to store the entire
* data item, if not a truncated value will be returned.
*/
public void getKeyByteArray(byte[] output)
throws WiredTigerPackingException {
this.getKeyByteArray(output, 0, output.length);
}
/**
* Retrieve a byte array from the cursor's key.
*
* \param output The byte array where the returned value will be stored.
* \param off Offset into the destination buffer to start copying into.
* \param len The length should be large enough to store the entire
* data item, if not a truncated value will be returned.
*/
public void getKeyByteArray(byte[] output, int off, int len)
throws WiredTigerPackingException {
keyUnpacker.getByteArray(output, off, len);
}
/**
* Retrieve a byte array from the cursor's key.
*
* \return The requested value.
*/
public byte[] getKeyByteArray()
throws WiredTigerPackingException {
return keyUnpacker.getByteArray();
}
/**
* Retrieve an integer from the cursor's key.
*
* \return The requested value.
*/
public int getKeyInt()
throws WiredTigerPackingException {
return keyUnpacker.getInt();
}
/**
* Retrieve a long from the cursor's key.
*
* \return The requested value.
*/
public long getKeyLong()
throws WiredTigerPackingException {
return keyUnpacker.getLong();
}
/**
* Retrieve a record number from the cursor's key.
*
* \return The requested value.
*/
public long getKeyRecord()
throws WiredTigerPackingException {
return keyUnpacker.getRecord();
}
/**
* Retrieve a short integer from the cursor's key.
*
* \return The requested value.
*/
public short getKeyShort()
throws WiredTigerPackingException {
return keyUnpacker.getShort();
}
/**
* Retrieve a string from the cursor's key.
*
* \return The requested value.
*/
public String getKeyString()
throws WiredTigerPackingException {
return keyUnpacker.getString();
}
/**
* Retrieve a byte from the cursor's value.
*
* \return The requested value.
*/
public byte getValueByte()
throws WiredTigerPackingException {
return valueUnpacker.getByte();
}
/**
* Retrieve a byte array from the cursor's value.
*
* \param output The byte array where the returned value will be stored.
* The array should be large enough to store the entire
* data item, if not a truncated value will be returned.
*/
public void getValueByteArray(byte[] output)
throws WiredTigerPackingException {
this.getValueByteArray(output, 0, output.length);
}
/**
* Retrieve a byte array from the cursor's value.
*
* \param output The byte array where the returned value will be stored.
* \param off Offset into the destination buffer to start copying into.
* \param len The length should be large enough to store the entire
* data item, if not a truncated value will be returned.
*/
public void getValueByteArray(byte[] output, int off, int len)
throws WiredTigerPackingException {
valueUnpacker.getByteArray(output, off, len);
}
/**
* Retrieve a byte array from the cursor's value.
*
* \return The requested value.
*/
public byte[] getValueByteArray()
throws WiredTigerPackingException {
return valueUnpacker.getByteArray();
}
/**
* Retrieve an integer from the cursor's value.
*
* \return The requested value.
*/
public int getValueInt()
throws WiredTigerPackingException {
return valueUnpacker.getInt();
}
/**
* Retrieve a long from the cursor's value.
*
* \return The requested value.
*/
public long getValueLong()
throws WiredTigerPackingException {
return valueUnpacker.getLong();
}
/**
* Retrieve a record number from the cursor's value.
*
* \return The requested value.
*/
public long getValueRecord()
throws WiredTigerPackingException {
return valueUnpacker.getRecord();
}
/**
* Retrieve a short integer from the cursor's value.
*
* \return The requested value.
*/
public short getValueShort()
throws WiredTigerPackingException {
return valueUnpacker.getShort();
}
/**
* Retrieve a string from the cursor's value.
*
* \return The requested value.
*/
public String getValueString()
throws WiredTigerPackingException {
return valueUnpacker.getString();
}
/**
* Insert the cursor's current key/value into the table.
*
* \return The status of the operation.
*/
public int insert()
throws WiredTigerException {
byte[] key = keyPacker.getValue();
byte[] value = valuePacker.getValue();
keyPacker.reset();
valuePacker.reset();
return insert_wrap(key, value);
}
/**
* Update the cursor's current key/value into the table.
*
* \return The status of the operation.
*/
public int update()
throws WiredTigerException {
byte[] key = keyPacker.getValue();
byte[] value = valuePacker.getValue();
keyPacker.reset();
valuePacker.reset();
return update_wrap(key, value);
}
/**
* Remove the cursor's current key/value into the table.
*
* \return The status of the operation.
*/
public int remove()
throws WiredTigerException {
byte[] key = keyPacker.getValue();
keyPacker.reset();
return remove_wrap(key);
}
/**
* Compare this cursor's position to another Cursor.
*
* \return The result of the comparison.
*/
public int compare(Cursor other)
throws WiredTigerException {
return compare_wrap(other);
}
/**
* Compare this cursor's position to another Cursor.
*
* \return The result of the comparison.
*/
public int equals(Cursor other)
throws WiredTigerException {
return equals_wrap(other);
}
/**
* Retrieve the next item in the table.
*
* \return The result of the comparison.
*/
public int next()
throws WiredTigerException {
int ret = next_wrap();
keyPacker.reset();
valuePacker.reset();
keyUnpacker = initKeyUnpacker(ret == 0);
valueUnpacker = initValueUnpacker(ret == 0);
return ret;
}
/**
* Retrieve the previous item in the table.
*
* \return The result of the comparison.
*/
public int prev()
throws WiredTigerException {
int ret = prev_wrap();
keyPacker.reset();
valuePacker.reset();
keyUnpacker = initKeyUnpacker(ret == 0);
valueUnpacker = initValueUnpacker(ret == 0);
return ret;
}
/**
* Reset a cursor.
*
* \return The status of the operation.
*/
public int reset()
throws WiredTigerException {
int ret = reset_wrap();
keyPacker.reset();
valuePacker.reset();
keyUnpacker = null;
valueUnpacker = null;
return ret;
}
/**
* Search for an item in the table.
*
* \return The result of the comparison.
*/
public int search()
throws WiredTigerException {
int ret = search_wrap(keyPacker.getValue());
keyPacker.reset();
valuePacker.reset();
keyUnpacker = initKeyUnpacker(ret == 0);
valueUnpacker = initValueUnpacker(ret == 0);
return ret;
}
/**
* Search for an item in the table.
*
* \return The result of the comparison.
*/
public SearchStatus search_near()
throws WiredTigerException {
SearchStatus ret = search_near_wrap(keyPacker.getValue());
keyPacker.reset();
valuePacker.reset();
keyUnpacker = initKeyUnpacker(ret != SearchStatus.NOTFOUND);
valueUnpacker = initValueUnpacker(ret != SearchStatus.NOTFOUND);
return ret;
}
/**
* Initialize a key unpacker after an operation that changes
* the cursor position.
*
* \param success Whether the associated operation succeeded.
* \return The key unpacker.
*/
private PackInputStream initKeyUnpacker(boolean success)
throws WiredTigerException {
if (!success || keyFormat.equals(""))
return null;
else
return new PackInputStream(keyFormat,
get_key_wrap(), _java_raw());
}
/**
* Initialize a value unpacker after an operation that changes
* the cursor position.
*
* \param success Whether the associated operation succeeded.
* \return The value unpacker.
*/
private PackInputStream initValueUnpacker(boolean success)
throws WiredTigerException {
if (!success || valueFormat.equals(""))
return null;
else
return new PackInputStream(valueFormat,
get_value_wrap(), _java_raw());
}
/**
* Modify an existing record.
*
* The cursor must already be positioned, and the key's value will be
* updated.
*
* \param mods an array of modifications.
* \return 0 on success, errno on error.
*/
public int modify(Modify mods[])
throws WiredTigerException {
byte[] key = keyPacker.getValue();
keyPacker.reset();
WT_MODIFY_LIST l = new WT_MODIFY_LIST(mods.length);
if (!_new_check_modify_list(l))
return (0); // exception is already thrown
int pos = 0;
for (Modify m : mods) {
if (!_new_check_modify(m))
return (0); // exception is already thrown
l.set(pos, m);
pos++;
}
return modify_wrap(l, key);
}
%}
/*
* Support for WT_CURSOR.modify.
*/
%inline %{
typedef struct __wt_java_item_hold {
#ifndef SWIG
void *data;
size_t size;
JNIEnv *jnienv;
jobject ref;
#endif
} WT_ITEM_HOLD;
/*
* An internal Java class encapsulates a list of Modify objects (stored as a
* WT_MODIFY array in C).
*/
typedef struct __wt_java_modify_list {
#ifndef SWIG
WT_MODIFY *mod_array;
jobject *ref_array;
JNIEnv *jnienv;
int count;
#endif
} WT_MODIFY_LIST;
%}
%extend __wt_java_modify_list {
__wt_java_modify_list(int count) {
WT_MODIFY_LIST *self;
if (__wt_calloc_def(NULL, 1, &self) != 0)
return (NULL);
if (__wt_calloc_def(NULL, (size_t)count,
&self->mod_array) != 0) {
__wt_free(NULL, self);
return (NULL);
}
if (__wt_calloc_def(NULL, (size_t)count,
&self->ref_array) != 0) {
__wt_free(NULL, self->mod_array);
__wt_free(NULL, self);
return (NULL);
}
self->count = count;
return (self);
}
~__wt_java_modify_list() {
modify_list_release(self);
__wt_free(NULL, self);
}
void set(int i, WT_MODIFY *m) {
WT_MODIFY_IMPL *impl = (WT_MODIFY_IMPL *)m;
self->mod_array[i] = *m;
self->ref_array[i] = impl->ref;
impl->ref = (jobject)0;
self->jnienv = impl->jnienv;
}
};
%extend __wt_modify {
__wt_modify() {
WT_MODIFY_IMPL *self;
if (__wt_calloc_def(NULL, 1, &self) != 0)
return (NULL);
self->modify.data.data = NULL;
self->modify.data.size = 0;
self->modify.offset = 0;
self->modify.size = 0;
return (&self->modify);
}
__wt_modify(WT_ITEM_HOLD *itemdata,
size_t offset, size_t size) {
WT_MODIFY_IMPL *self;
if (__wt_calloc_def(NULL, 1, &self) != 0)
return (NULL);
self->modify.data.data = itemdata->data;
self->modify.data.size = itemdata->size;
self->modify.offset = offset;
self->modify.size = size;
self->ref = itemdata->ref;
self->jnienv = itemdata->jnienv;
return (&self->modify);
}
~__wt_modify() {
modify_impl_release((WT_MODIFY_IMPL *)self);
__wt_free(NULL, self);
}
};
%{
static void modify_list_release(WT_MODIFY_LIST *list) {
for (int i = 0; i < list->count; i++)
if (list->ref_array[i] != (jobject)0) {
(*list->jnienv)->ReleaseByteArrayElements(
list->jnienv, list->ref_array[i],
(jbyte *)list->mod_array[i].data.data, 0);
(*list->jnienv)->DeleteGlobalRef(
list->jnienv, list->ref_array[i]);
}
__wt_free(NULL, list->ref_array);
__wt_free(NULL, list->mod_array);
list->count = 0;
}
static void modify_impl_release(WT_MODIFY_IMPL *impl) {
if (impl->ref != (jobject)0) {
(*impl->jnienv)->ReleaseByteArrayElements(
impl->jnienv, impl->ref,
(jbyte *)impl->modify.data.data, 0);
(*impl->jnienv)->DeleteGlobalRef(impl->jnienv, impl->ref);
impl->ref = (jobject)0;
}
}
%}
/* Put a WiredTigerException on all wrapped methods. We'd like this
* to only apply to methods returning int. SWIG doesn't have a way
* to do this, so we remove the exception for simple getters and such.
*/
%javaexception("com.wiredtiger.db.WiredTigerException") { $action; }
%javaexception("") wiredtiger_strerror { $action; }
%javaexception("") __wt_async_op::_java_raw { $action; }
%javaexception("") __wt_async_op::connection { $action; }
%javaexception("") __wt_async_op::get_type { $action; }
%javaexception("") __wt_async_op::get_id { $action; }
%javaexception("") __wt_async_op::key_format { $action; }
%javaexception("") __wt_async_op::value_format { $action; }
%javaexception("") __wt_connection::_java_init { $action; }
%javaexception("") __wt_connection::get_home { $action; }
%javaexception("") __wt_connection::is_new { $action; }
%javaexception("") __wt_cursor::_java_raw { $action; }
%javaexception("") __wt_cursor::key_format { $action; }
%javaexception("") __wt_cursor::session { $action; }
%javaexception("") __wt_cursor::uri { $action; }
%javaexception("") __wt_cursor::value_format { $action; }
%javaexception("") __wt_session::_java_init { $action; }
%javaexception("") __wt_session::connection { $action; }
/* Remove / rename parts of the C API that we don't want in Java. */
%immutable __wt_cursor::session;
%immutable __wt_cursor::uri;
%immutable __wt_cursor::key_format;
%immutable __wt_cursor::value_format;
%immutable __wt_session::connection;
%ignore __wt_collator;
%ignore __wt_connection::add_collator;
%ignore __wt_compressor;
%ignore __wt_connection::add_compressor;
%ignore __wt_data_source;
%ignore __wt_connection::add_data_source;
%ignore __wt_encryptor;
%ignore __wt_connection::add_encryptor;
%ignore __wt_event_handler;
%ignore __wt_extractor;
%ignore __wt_connection::add_extractor;
%ignore __wt_file_system;
%ignore __wt_file_handle;
%ignore __wt_connection::set_file_system;
%ignore __wt_item;
%ignore __wt_lsn;
%ignore __wt_session::msg_printf;
%ignore wiredtiger_struct_pack;
%ignore wiredtiger_struct_size;
%ignore wiredtiger_struct_unpack;
%ignore wiredtiger_version;
%ignore __wt_connection::get_extension_api;
%ignore wiredtiger_extension_init;
%ignore wiredtiger_extension_terminate;
%define REQUIRE_WRAP(typedefname, name, javaname)
%ignore name;
%javamethodmodifiers name##_wrap "
/**
* @copydoc typedefname
*/
public ";
%rename(javaname) name##_wrap;
%enddef
REQUIRE_WRAP(::wiredtiger_open, wiredtiger_open, open)
REQUIRE_WRAP(WT_CONNECTION::async_new_op,
__wt_connection::async_new_op, async_new_op)
REQUIRE_WRAP(WT_CONNECTION::open_session,
__wt_connection::open_session, open_session)
REQUIRE_WRAP(WT_SESSION::transaction_pinned_range,
__wt_session::transaction_pinned_range, transaction_pinned_range)
REQUIRE_WRAP(WT_SESSION::open_cursor, __wt_session::open_cursor, open_cursor)
REQUIRE_WRAP(WT_ASYNC_OP::get_id, __wt_async_op::get_id,getId)
%rename(AsyncOp) __wt_async_op;
%rename(Cursor) __wt_cursor;
%rename(Modify) __wt_modify;
%rename(Session) __wt_session;
%rename(Connection) __wt_connection;
%define TRACKED_CLASS(jclassname, ctypename, java_init_fcn, implclass)
%ignore jclassname::jclassname();
%typemap(javabody) struct ctypename %{
private long swigCPtr;
protected boolean swigCMemOwn;
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
java_init_fcn(swigCPtr, this, this);
}
protected static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%extend ctypename {
%javamethodmodifiers _java_init "protected";
int _java_init(jobject jsess) {
implclass *session = (implclass *)$self;
JAVA_CALLBACK *jcb = (JAVA_CALLBACK *)session->lang_private;
jcb->jobj = JCALL1(NewGlobalRef, jcb->jnienv, jsess);
JCALL1(DeleteLocalRef, jcb->jnienv, jsess);
return (0);
}
}
%enddef
TRACKED_CLASS(Session, __wt_session, wiredtigerJNI.Session__java_init, WT_SESSION_IMPL)
TRACKED_CLASS(Connection, __wt_connection, wiredtigerJNI.Connection__java_init, WT_CONNECTION_IMPL)
/* Note: Cursor incorporates the elements of TRACKED_CLASS into its
* custom constructor and %extend clause.
*/
%include "wiredtiger.h"
/* Return new connections, sessions and cursors. */
%inline {
WT_CONNECTION *wiredtiger_open_wrap(JNIEnv *jenv, const char *home, const char *config) {
extern WT_EVENT_HANDLER javaApiEventHandler;
WT_CONNECTION *conn = NULL;
WT_CONNECTION_IMPL *connimpl;
JAVA_CALLBACK *jcb;
int ret;
if ((ret = wiredtiger_open(home, &javaApiEventHandler, config, &conn)) != 0)
goto err;
connimpl = (WT_CONNECTION_IMPL *)conn;
if ((ret = __wt_calloc_def(connimpl->default_session, 1, &jcb)) != 0)
goto err;
jcb->jnienv = jenv;
connimpl->lang_private = jcb;
err: if (ret != 0)
throwWiredTigerException(jenv, ret);
return (conn);
}
}
%extend __wt_connection {
WT_ASYNC_OP *async_new_op_wrap(JNIEnv *jenv, const char *uri,
const char *config, jobject callbackObject) {
extern WT_ASYNC_CALLBACK javaApiAsyncHandler;
WT_ASYNC_OP *asyncop = NULL;
WT_CONNECTION_IMPL *connimpl;
JAVA_CALLBACK *jcb;
int ret;
if ((ret = $self->async_new_op($self, uri, config, &javaApiAsyncHandler, &asyncop)) != 0)
goto err;
connimpl = (WT_CONNECTION_IMPL *)$self;
if ((ret = __wt_calloc_def(connimpl->default_session, 1, &jcb)) != 0)
goto err;
jcb->jnienv = jenv;
jcb->session = connimpl->default_session;
(*jenv)->GetJavaVM(jenv, &jcb->javavm);
jcb->jcallback = JCALL1(NewGlobalRef, jenv, callbackObject);
JCALL1(DeleteLocalRef, jenv, callbackObject);
asyncop->c.lang_private = jcb;
asyncop->c.flags |= WT_CURSTD_RAW;
err: if (ret != 0)
throwWiredTigerException(jenv, ret);
return (asyncop);
}
}
%extend __wt_connection {
WT_SESSION *open_session_wrap(JNIEnv *jenv, const char *config) {
extern WT_EVENT_HANDLER javaApiEventHandler;
WT_SESSION *session = NULL;
WT_SESSION_IMPL *sessionimpl;
JAVA_CALLBACK *jcb;
int ret;
if ((ret = $self->open_session($self, &javaApiEventHandler, config, &session)) != 0)
goto err;
sessionimpl = (WT_SESSION_IMPL *)session;
if ((ret = __wt_calloc_def(sessionimpl, 1, &jcb)) != 0)
goto err;
jcb->jnienv = jenv;
sessionimpl->lang_private = jcb;
err: if (ret != 0)
throwWiredTigerException(jenv, ret);
return (session);
}
}
%extend __wt_session {
WT_CURSOR *open_cursor_wrap(JNIEnv *jenv, const char *uri, WT_CURSOR_NULLABLE *to_dup, const char *config) {
WT_CURSOR *cursor = NULL;
JAVA_CALLBACK *jcb;
int ret;
if ((ret = $self->open_cursor($self, uri, to_dup, config, &cursor)) != 0)
goto err;
if ((ret = __wt_calloc_def((WT_SESSION_IMPL *)cursor->session,
1, &jcb)) != 0)
goto err;
if ((cursor->flags & WT_CURSTD_RAW) != 0)
jcb->cursor_raw = true;
if ((cursor->flags & WT_CURSTD_DUMP_JSON) == 0)
cursor->flags |= WT_CURSTD_RAW;
jcb->jnienv = jenv;
jcb->session = (WT_SESSION_IMPL *)cursor->session;
cursor->lang_private = jcb;
err: if (ret != 0)
throwWiredTigerException(jenv, ret);
return (cursor);
}
}
%extend __wt_async_op {
long get_id_wrap(JNIEnv *jenv) {
WT_UNUSED(jenv);
return ((long)self->get_id(self));
}
}
%extend __wt_session {
long transaction_pinned_range_wrap(JNIEnv *jenv) {
int ret;
uint64_t range = 0;
ret = self->transaction_pinned_range(self, &range);
if (ret != 0)
throwWiredTigerException(jenv, ret);
return ((long)range);
}
}
|