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 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567
|
/*
========== licence begin GPL
Copyright (C) 2002-2003 SAP AG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
========== licence end
*/
package com.sap.dbtech.jdbc;
import java.sql.SQLException;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Ref;
import java.sql.ResultSetMetaData;
import java.sql.Types;
import java.sql.ResultSet;
import java.util.*;
import java.math.BigDecimal;
import java.net.URL;
import java.io.InputStream;
import java.io.Reader;
import com.sap.dbtech.jdbc.exceptions.*;
import com.sap.dbtech.jdbc.packet.*;
import com.sap.dbtech.jdbc.translators.*;
import com.sap.dbtech.jdbc.translators.AbstractProcedurePutval;
import com.sap.dbtech.util.*;
import com.sap.dbtech.vsp00.*;
import com.sap.dbtech.vsp001.*;
/**
*
*/
public class CallableStatementSapDB
extends StatementSapDB
implements java.sql.CallableStatement, SQLParamController
{
private Vector inputOMSStreams;
private Vector outputOMSStreams;
private Vector inputProcedureLongs;
final static int maxParseAgainCnt = 10;
Parseinfo parseinfo;
boolean lastWasNull;
StructuredMem replyMem;
protected Object [] inputArgs;
Vector inputLongs;
java.util.Vector batchRows;
short [] outPutTypes;
byte [] outPutScale;
FetchInfo fetchInfo;
java.util.AbstractMap columnMap; /*points to colmapping of Parseinfo for faster access*/
private final String initialParamValue = "initParam";
/**
*
* @param connection com.sap.dbtech.jdbc.ConnectionSapDBTech
* @param sql java.lang.String
* @exception java.sql.SQLException The exception description.
*/
CallableStatementSapDB(
ConnectionSapDB connection,
String sql)
throws SQLException
{
super(connection,
ResultSet.TYPE_FORWARD_ONLY,
defaultConcurrency_C,
connection.getHoldability());
this.constructor(sql);
}
/**
*
* @param connection com.sap.dbtech.jdbc.ConnectionSapDBTech
* @param sql java.lang.String
* @exception java.sql.SQLException The exception description.
*/
CallableStatementSapDB(
ConnectionSapDB connection,
String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException
{
super (connection, resultSetType, resultSetConcurrency,resultSetHoldability);
this.constructor(sql);
}
/**
* JDBC 2.0
*
* Adds a set of parameters to the batch.
*
* @exception SQLException if a database access error occurs
* @see Statement#addBatch
*/
public void addBatch()
throws SQLException
{
if (this.batchItems == null) {
this.batchItems = new java.util.Vector ();
}
this.batchItems.addElement(this.inputArgs);
Object [] nextRow = new Object [this.parseinfo.paramInfos.length];
DBTechTranslator paraminfos[] = this.parseinfo.paramInfos;
int paraminfos_length = paraminfos.length;
for (int i = 0; i < paraminfos_length; ++i) {
nextRow [i] = paraminfos[i].cloneObjectForBatch(this.inputArgs[i]);
}
this.inputArgs = nextRow;
}
/**
* JDBC 2.0
*
* Adds a SQL command to the current batch of commmands for the statement.
* This method is optional.
*
* @throws SQLException always (not allowed for PreparedStatement).
*
*/
public void addBatch(String sql)
throws SQLException
{
throw new JDBCDriverException (MessageTranslator.translate
(MessageKey.ERROR_PREPAREDSTATEMENT_ADDBATCH),
this);
}
/**
*
* @return int
*/
private int calculateInputRecord ()
{
int result = 0;
DBTechTranslator currentInfo;
int currentFieldLen;
for (int i = 0; i < this.parseinfo.paramInfos.length; ++i) {
currentInfo = this.parseinfo.paramInfos[i];
if (currentInfo.isInput()) {
currentFieldLen = currentInfo.getPhysicalLength();
if (this.parseinfo.varDataInput) {
if (currentFieldLen < 250) {
result += 1;
} else {
result += 3;
}
} else {
result += 1;
}
result += currentFieldLen;
}
}
return result;
}
/**
*
*/
public void clearParameters ()
throws SQLException
{
for (int i = 0; i < this.inputArgs.length; ++i) {
this.inputArgs [i] = initialParamValue;
}
}
/**
*
* @param sql java.lang.String
* @exception java.sql.SQLException The exception description.
*/
private void constructor (
String sql)
throws SQLException
{
this.parseinfo = this.doParse (sql, false);
}
/**
* Parses the SQL command, or looks the parsed command up in the
* cache.
* @param sql The SQL to parse.
* @param parseAgain if <code>true</code>, the data of the
* existing <code>Parseinfo</code> structure shall be overwritten.
* @return the <code>Parseinfo</code> produced.
* @exception java.sql.SQLException The exception description.
*/
private Parseinfo doParse (String sql,
boolean parseAgain)
throws SQLException
{
if (sql == null) {
throw new SQLExceptionSapDB(MessageTranslator.translate
(MessageKey.ERROR_SQLSTATEMENT_NULL),
"42000");
}
ReplyPacket replyPacket;
PartEnumeration enume;
Parseinfo result = null;
ParseinfoCache cache = this.connection.parseCache;
String[] columnNames = null;
if (sql == null)
throw new SQLExceptionSapDB("SQL statement is null","42000");
this.fetchInfo = null;
if (parseAgain) {
result = this.parseinfo;
result.setMassParseid(null);
}
else if (cache != null) {
result = cache.findParseinfo (sql);
}
if ((result == null) || parseAgain) {
/*
* exceute SQL
*/
// boolean backupWithInfo=setWithInfo;
// !!! withinfo flag is not set as it may cause a crash !!!
try {
setWithInfo=true;
replyPacket = this.sendSQL (sql, this.resultSetType, this.resultSetConcurrency, parseAgain);
} catch(com.sap.dbtech.jdbc.exceptions.TimeoutException exc){
if (this.statementType == Statement_UpdatableResultSet){
this.connection.close();
throw exc;
}
replyPacket = this.sendSQL (sql, this.resultSetType, this.resultSetConcurrency, parseAgain);
}
// finally {
// setWithInfo=backupWithInfo;
// }
/*
* parse result
*/
if (!parseAgain) {
result = new Parseinfo (this.connection, sql, replyPacket.functionCode ());
}
enume = replyPacket.partEnumeration ();
DBTechTranslator shortInfos[] = null;
while (enume.hasMoreElements ()) {
enume.nextElement ();
switch (enume.partKind ()) {
case PartKind.Parsid_C:
int parseidPos = replyPacket.getPartDataPos ();
result.setParseIdAndSession(replyPacket.getBytes (parseidPos, 12),
replyPacket.getInt4 (parseidPos));
break;
case PartKind.Shortinfo_C:
shortInfos=replyPacket.parseShortFields(this.connection.isSpaceoptionSet,
result.isDBProc,
result.procParamInfos, false);
break;
case PartKind.Vardata_Shortinfo_C:
result.varDataInput = true;
shortInfos=replyPacket.parseShortFields(this.connection.isSpaceoptionSet,
result.isDBProc,
result.procParamInfos, true);
break;
case PartKind.Resulttablename_C:
result.setSelect(true);
int cursorLength = replyPacket.partLength ();
if (cursorLength > 0) {
this.cursorName = replyPacket.getString (replyPacket.getPartDataPos (), cursorLength);
}
break;
case PartKind.Tablename_C:
result.setUpdateTableName(replyPacket.getString (replyPacket.getPartDataPos (), replyPacket.partLength ()));
break;
case PartKind.Columnnames_C:
columnNames = replyPacket.parseColumnNames ();
break;
default:
// this.addWarning(new SQLWarning
// (MessageTranslator.translate
// (MessageKey.WARNING_PART_NOTHANDLED,
// PartKind.names[enume.partKind()]))
// );
break;
}
}
result.setShortInfosAndColumnNames(shortInfos, columnNames);
if ((cache != null) && !parseAgain) {
cache.addParseinfo (result);
}
}
this.inputArgs = new Object [result.paramInfos.length];
this.clearParameters();
return result;
}
/**
* execute method comment.
*/
public boolean execute()
throws java.sql.SQLException
{
this.assertOpen ();
return this.execute (maxParseAgainCnt);
}
/**
*
*/
private void
reparse ()
throws java.sql.SQLException
{
Object [] tmpArgs = this.inputArgs;
this.doParse (this.parseinfo.sqlCmd, true);
this.inputArgs = tmpArgs;
}
/**
*
*/
protected String getUpdTablename(String sqlCmd) {
return this.parseinfo.updTableName;
}
/**
* execute method comment.
*/
public boolean execute(int afterParseAgain)
throws SQLException
{
if (this.connection == null) {
throw new InternalJDBCError(MessageTranslator.translate(MessageKey.ERROR_INTERNAL_CONNECTIONNULL));
}
RequestPacket requestPacket;
ReplyPacket replyPacket;
boolean isQuery;
DataPart dataPart;
// if this is one of the statements that is executed
// during parse instead of execution, execute it
// by doing a reparse
if(this.parseinfo.isAlreadyExecuted()) {
this.replyMem = null;
this.closeResultSet (true);
if (this.connection == null) {
throw new NullPointerException ();
}
this.reparse();
this.rowsAffected=0;
return false;
}
if (! this.parseinfo.isValid ()) {
this.reparse ();
}
try {
this.canceled = false;
this.closeResultSet(true);
// check if a reparse is needed.
if (!this.parseinfo.isValid ()) {
this.reparse ();
}
this.replyMem = null;
this.outputOMSStreams = null;
requestPacket = this.connection.getRequestPacket (this.packetEncodingUnicode);
requestPacket.initExecute (this.parseinfo.getParseId(),
this.connection.autocommit,
this.resultSetType);
if (this.parseinfo.isSelect) {
requestPacket.addCursorPart (this.cursorName);
}
// We must add a data part if we have input parameters or even if
// we have output streams.
if (this.parseinfo.inputCount > 0 || this.parseinfo.hasStreams) {
dataPart = requestPacket.newDataPart(this.parseinfo.varDataInput);
if (this.parseinfo.inputCount > 0) {
dataPart.addRow(this.parseinfo.inputCount);
for (int i = 0; i < this.parseinfo.paramInfos.length; ++i) {
if (this.parseinfo.paramInfos[i].isInput()
&& initialParamValue == this.inputArgs[i]) {
if (this.parseinfo.paramInfos[i].isStreamKind()
&& this.outPutTypes != null
&& this.outPutTypes[i + 1] != 0) {
if (this.outputOMSStreams == null) {
this.outputOMSStreams = new Vector();
}
ABAPStreamTranslator t = (ABAPStreamTranslator) this.parseinfo.paramInfos[i];
AbstractABAPStreamGetval getval = t
.createGetval();
outputOMSStreams.add(getval);
t.put(dataPart, getval);
} else {
throw new SQLException(MessageTranslator
.translate(
MessageKey.ERROR_MISSINGINOUT,
Integer.toString(i + 1)),
"02000");
}
} else {
this.parseinfo.paramInfos[i].put(dataPart,
this.inputArgs[i]);
}
}
this.inputProcedureLongs = null;
if (this.parseinfo.hasLongs) {
if (this.parseinfo.isDBProc) {
this.handleProcedureStreamsForExecute(dataPart,
this.inputArgs);
} else {
this.handleStreamsForExecute(dataPart,
this.inputArgs);
}
}
if (this.parseinfo.hasStreams) {
this.handleOMSStreamsForExecute(dataPart);
}
} else {
// we have only streams
this.handleOMSStreamsForExecute(dataPart);
}
dataPart.close();
}
/*add a decribe order if command rturns a resultset*/
if ( this.parseinfo.isSelect
&&this.parseinfo.columnInfos == null
&&this.parseinfo.functionCode != FunctionCode.DBProcWithResultSetExecute_FC ){
requestPacket.initDbsCommand("DESCRIBE ",false, false, ResultSet.TYPE_FORWARD_ONLY);
requestPacket.addParseidPart(this.parseinfo.getParseId());
}
try {
replyPacket = this.connection.execute (requestPacket, this,
(!this.parseinfo.hasStreams && this.inputProcedureLongs==null)?ConnectionSapDB.GC_ALLOWED:ConnectionSapDB.GC_NONE);
// Recycling of parse infos and cursor names is not allowed
// if streams are in the command. Even sending it just behind
// as next packet is harmful. Same with INPUT LONG parameters of
// DB Procedures.
}
catch (SQLException dbExc) {
if ((dbExc.getErrorCode() == -8) && afterParseAgain > 0) {
this.resetPutvals (this.inputLongs);
this.reparse ();
this.connection.freeRequestPacket(requestPacket);
afterParseAgain--;
return this.execute (afterParseAgain);
}
else {
// The request packet has already been recycled in
// Connection.execute()
throw dbExc;
}
}
// --- now it becomes difficult ...
if (this.parseinfo.isSelect) {
isQuery = this.parseResult(replyPacket, null, this.parseinfo
.getColumnInfos(), this.parseinfo.columnNames);
} else {
if(inputProcedureLongs != null) {
replyPacket = this.processProcedureStreams(replyPacket);
} else if (this.parseinfo.hasStreams) {
replyPacket = this.processOMSStreams(replyPacket);
}
isQuery = this.parseResult(replyPacket, null, this.parseinfo
.getColumnInfos(), this.parseinfo.columnNames);
int returnCode = replyPacket.returnCode();
if (replyPacket.existsPart(PartKind.Data_C)) {
this.replyMem = replyPacket.getPointer(replyPacket
.getPartDataPos());
}
if ((this.parseinfo.hasLongs && !this.parseinfo.isDBProc) && (returnCode == 0)) {
this.handleStreamsForPutval(replyPacket);
}
}
return isQuery;
}
catch (TimeoutException timeout) {
if (this.connection.isInTransaction()
|| this.statementType == Statement_UpdatableResultSet ) {
throw timeout;
} else {
this.closeResultSet(true);
this.resetPutvals (this.inputLongs);
this.reparse ();
return this.execute (maxParseAgainCnt);
}
} finally{
this.canceled = false;
}
}
/**
* This method is inherited from <code>java.sql.Statement</code>. <b>This method
* executes the current statement, which is in contrast to the standard. According to
* the standard, it has
* always to throw an <code>java.sql.SQLException</code> (JDBC, sec. 13.2.4).</b>
* @param statement The statement (ignored).
* @exception java.sql.SQLException if a database error occurs during execution
* of the parsed statement.
*/
public boolean execute (
String sql)
throws SQLException
{
/*
* special hack for requisit
*/
return this.execute ();
/* boolean result; */
/* Statement stmt = this.connection.createStatement (); */
/* */
/* result = stmt.execute (sql); */
/* if (result) { */
/* this.currentResultSet = (ResultSetSapDB) stmt.getResultSet (); */
/* this.rowsAffected = stmt.getUpdateCount (); */
/* } */
/* return result; */
}
/**
*
*/
/**
* JDBC 2.0
*
* Submits a batch of commands to the database for execution.
* This method is optional.
*
* @return an array of update counts containing one element for each
* command in the batch. The array is ordered according
* to the order in which commands were inserted into the batch.
* @throws SQLException if a database access error occurs or the
* driver does not support batch statements
*/
public int[] executeBatch ()
throws SQLException
{
this.assertOpen ();
if (this.parseinfo != null
&& this.parseinfo.isSelect)
throw new BatchUpdateExceptionSapDB
(MessageTranslator.translate(MessageKey.ERROR_BATCHRESULTSET),
new int[0]);
if (this.parseinfo != null
&& (this.parseinfo.functionCode == FunctionCode.DBProcExecute_FC
|| this.parseinfo.functionCode == FunctionCode.DBProcWithResultSetExecute_FC)){
for (int i = 0; i < this.parseinfo.paramInfos.length; i++) {
if (this.parseinfo.paramInfos[i].isOutput())
throw new BatchUpdateExceptionSapDB
(MessageTranslator.translate(MessageKey.ERROR_BATCHPROCOUT),
new int[0]);
}
}
if (this.batchItems == null) {
return new int [0];
}
Vector streamVec = null;
boolean inTrans = this.connection.isInTransaction ();
java.util.Vector localBatchItems = this.batchItems;
this.batchItems = null;
try {
this.canceled = false;
int count = localBatchItems.size ();
RequestPacket requestPacket;
ReplyPacket replyPacket = null;
int inputCursor = 0;
boolean noError = true;
int recordSize = 0;
int insertCountPartSize = RequestPacket.resultCountPartSize ();
int executeCount = -1;
int [] result = new int[count];
this.rowsAffected = -1;
/*initialize update counts*/
for (int i = 0; i < result.length; i++) {
result[i]=StatementSapDB.BATCH_SUCCESS_NO_INFO_C;
}
if (this.parseinfo.getMassParseid() == null) {
this.parseMassCmd(false);
}
if (this.parseinfo.paramInfos.length > 0) {
recordSize = this.calculateInputRecord ();
}
while ((inputCursor < count) && noError) {
streamVec = null;
int firstRecordNo = inputCursor;
requestPacket = this.connection.getRequestPacket(this.packetEncodingUnicode);
requestPacket.initExecute (this.parseinfo.getMassParseid(),
this.connection.autocommit,
this.resultSetType);
if (executeCount == -1) {
requestPacket.addUndefResultCount ();
}
else {
requestPacket.addResultCount(executeCount);
}
requestPacket.addCursorPart (this.cursorName);
DataPart dataPart;
if (this.parseinfo.paramInfos.length > 0) {
dataPart = requestPacket.newDataPart (this.parseinfo.varDataInput);
if (executeCount == -1) {
dataPart.setFirstPart ();
}
do {
Object [] row = (Object []) localBatchItems.elementAt(inputCursor);
dataPart.addRow(this.parseinfo.inputCount);
for (int i = 0; i < this.parseinfo.paramInfos.length; ++i) {
/*check whether the parameter was set by application or throw an exception*/
if (this.parseinfo.paramInfos[i].isInput()
&& initialParamValue == row [i])
throw new BatchUpdateExceptionSapDB (MessageTranslator.translate(MessageKey.ERROR_BATCHMISSINGIN,
Integer.toString(inputCursor+1),
Integer.toString(i+1)),
"0200", makeBatchCountArray(result));
this.parseinfo.paramInfos [i].put (dataPart, row [i]);
}
if (this.parseinfo.hasLongs) {
this.handleStreamsForExecute (dataPart, row);
if (streamVec == null)
streamVec = new Vector(this.inputLongs.size());
streamVec.addAll(this.inputLongs);
}
dataPart.moveRecordBase ();
++inputCursor;
} while ((inputCursor < count)
&& dataPart.hasRoomFor (recordSize, insertCountPartSize)
&& this.parseinfo.isMassCmd());
if (inputCursor == count) {
dataPart.setLastPart ();
}
dataPart.closeArrayPart (inputCursor - firstRecordNo);
}
else{
++inputCursor; //commands without parameters
}
try {
replyPacket = this.connection.execute (requestPacket, this, ConnectionSapDB.GC_DELAYED);
}
catch (SQLException dbExc) {
if (dbExc.getErrorCode() == -8) {
this.resetPutvals (streamVec);
this.parseMassCmd(true);
inputCursor = firstRecordNo;
continue; // redo this packet
}
else {
SQLExceptionSapDB specific = (SQLExceptionSapDB) dbExc;
// An autocommit session does roll back automatically all what was
// in this package. Thus, in case of an error we must not
// add the current count from the packet.
if(!this.connection.getAutoCommit()) {
if(this.rowsAffected >0) {
this.rowsAffected += specific.getErrorPos () - 1;
} else {
this.rowsAffected = specific.getErrorPos () - 1;
}
}
throw new BatchUpdateExceptionSapDB (dbExc,
new Integer(inputCursor + 1),
makeBatchCountArray(result));
}
}
executeCount = replyPacket.resultCount (false);
if (this.parseinfo.hasLongs) {
this.handleStreamsForPutval (replyPacket);
}
if (! this.parseinfo.isMassCmd()
&& executeCount != -1){
result[inputCursor-1] = executeCount;
if(this.rowsAffected >0) {
this.rowsAffected += executeCount;
} else {
this.rowsAffected = executeCount;
}
}else {
this.rowsAffected = executeCount;
}
}
return result;
}
catch (TimeoutException timeout) {
if (inTrans
|| this.statementType == Statement_UpdatableResultSet) {
throw timeout;
}
else {
this.batchItems = localBatchItems;
this.resetPutvals (streamVec);
return this.executeBatch ();
}
} finally{
this.canceled = false;
}
}
private int[] makeBatchCountArray(int [] resultArr)
{
int [] erg;
if (this.rowsAffected > 0) {
erg = new int [this.rowsAffected];
System.arraycopy(resultArr,0,erg,0,erg.length);
}
else {
erg = new int [0];
}
return erg;
}
/**
* executeQuery method comment.
*/
public java.sql.ResultSet executeQuery()
throws java.sql.SQLException
{
if (this.parseinfo != null
&& ! this.parseinfo.isSelect) {
throw new SQLExceptionSapDB(MessageTranslator.translate(MessageKey.ERROR_SQLSTATEMENT_ROWCOUNT));
} else {
this.execute ();
return this.currentResultSet;
}
}
/**
* This method is inherited from <code>java.sql.Statement</code>. It has
* always to throw an <code>java.sql.SQLException</code> (JDBC, sec. 13.2.4).
* @param statement The statement (ignored).
* @exception java.sql.SQLException always
*/
public java.sql.ResultSet executeQuery(String statement)
throws java.sql.SQLException
{
throw new SQLExceptionSapDB(MessageTranslator.translate
(MessageKey.ERROR_EXECUTEQUERY_PREPAREDSTATEMENT));
}
/**
* executeQuery method comment.
*/
public ResultSetSapDB executeQuerySap ()
throws java.sql.SQLException
{
if (this.parseinfo != null
&& ! this.parseinfo.isSelect) {
throw new SQLExceptionSapDB(MessageTranslator.translate(MessageKey.ERROR_SQLSTATEMENT_ROWCOUNT));
}
return(ResultSetSapDB) this.currentResultSet;
}
/**
*
*/
public int executeUpdate()
throws java.sql.SQLException
{
if (this.parseinfo != null
&& this.parseinfo.isSelect) {
throw new SQLExceptionSapDB(MessageTranslator.translate(MessageKey.ERROR_SQLSTATEMENT_RESULTSET));
} else {
this.execute ();
if(this.hasRowCount) {
return this.rowsAffected;
} else {
return 0;
}
}
}
/**
* This method is inherited from <code>java.sql.Statement</code>. It has
* always to throw an <code>java.sql.SQLException</code> (JDBC, sec. 13.2.4).
* @param statement The statement (ignored).
* @exception java.sql.SQLException always
*/
public int executeUpdate(String statement)
throws java.sql.SQLException
{
throw new SQLExceptionSapDB(MessageTranslator.translate
(MessageKey.ERROR_EXECUTEUPDATE_PREPAREDSTATEMENT));
}
/**
* findColumn method comment.
*/
private DBTechTranslator findColInfo (
int colIndex)
throws SQLException
{
DBTechTranslator info;
try {
info = this.parseinfo.paramInfos [colIndex - 1];
}
catch (ArrayIndexOutOfBoundsException exc) {
throw new JDBCDriverException
(MessageTranslator.translate(MessageKey.ERROR_COLINDEX_NOTFOUND,
Integer.toString(colIndex)),
this);
}
return info;
}
private DBTechTranslator findParamInfo (String paramName)
throws SQLException
{
if (!this.parseinfo.isDBProc) {
throw new SQLExceptionSapDB
(MessageTranslator.translate(MessageKey.ERROR_SQLSTATEMENT_NOPROCEDURE));
}
if (this.columnMap == null) {
this.columnMap = this.parseinfo.getColumnMap ();
}
DBTechTranslator info = (DBTechTranslator) this.columnMap.get (paramName);
if (info == null) {
info = (DBTechTranslator)
this.columnMap.get (paramName.toUpperCase ());
if (info != null) {
// cache different case for faster lookup next time
this.columnMap.put (paramName, info);
}
}
if (info == null) {
/*maybe the parameter couldn't retrieved because of kernel bug*/
throw new InvalidColumnException (paramName, this);
}
return info;
}
/**
* JDBC 2.0
*
* Gets the value of a JDBC <code>ARRAY</code> parameter as an
* {@link Array} object in the Java programming language.
* @param i the first parameter is 1, the second is 2, and
* so on
* @return the parameter value as an <code>Array</code> object in
* the Java programming language. If the value was SQL NULL, the
* value <code>null</code> is returned.
* @exception SQLException if a database access error occurs
*/
public Array getArray (int i)
throws SQLException
{
throwNotSupported(MessageTranslator.translate(MessageKey.ERROR_ARRAY_UNSUPPORTED));
return null;
}
//--------------------------JDBC 2.0-----------------------------
/**
* JDBC 2.0
*
* Gets the value of a JDBC <code>NUMERIC</code> parameter as a
* <code>java.math.BigDecimal</code> object with as many digits to the
* right of the decimal point as the value contains.
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value in full precision. If the value is
* SQL NULL, the result is <code>null</code>.
* @exception SQLException if a database access error occurs
*/
public java.math.BigDecimal getBigDecimal(
int parameterIndex)
throws SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getBigDecimal (this, this.getReplyData());
}
/**
* getBigDecimal method comment.
*/
public java.math.BigDecimal getBigDecimal(
int parameterIndex,
int scale)
throws java.sql.SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getBigDecimal (scale, this, this.getReplyData());
}
/**
* JDBC 2.0
*
* Gets the value of a JDBC <code>BLOB</code> parameter as a
* {@link Blob} object in the Java programming language.
* @param i the first parameter is 1, the second is 2, and so on
* @return the parameter value as a <code>Blob</code> object in the
* Java programming language. If the value was SQL NULL, the value
* <code>null</code> is returned.
* @exception SQLException if a database access error occurs
*/
public Blob getBlob (
int i)
throws SQLException
{
assertOpen();
return this.findColInfo (i).getBlob (this, this.getReplyData(), this.getReplyData());
}
/**
* getBoolean method comment.
*/
public boolean getBoolean(
int parameterIndex)
throws java.sql.SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getBoolean (this, this.getReplyData());
}
/**
* getByte method comment.
*/
public byte getByte(
int parameterIndex)
throws java.sql.SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getByte (this, this.getReplyData());
}
/**
* getBytes method comment.
*/
public byte[] getBytes(int parameterIndex)
throws java.sql.SQLException {
assertOpen();
return this.findColInfo (parameterIndex).getBytes (this, this.getReplyData());
}
/**
* JDBC 2.0
*
* Gets the value of a JDBC <code>CLOB</code> parameter as a
* <code>Clob</code> object in the Java programming language.
* @param i the first parameter is 1, the second is 2, and
* so on
* @return the parameter value as a <code>Clob</code> object in the
* Java programming language. If the value was SQL NULL, the
* value <code>null</code> is returned.
* @exception SQLException if a database access error occurs
*/
public Clob getClob (
int i)
throws SQLException
{
assertOpen();
return this.findColInfo (i).getClob (this, this.getReplyData(), this.getReplyData());
}
/**
* getDate method comment.
*/
public java.sql.Date getDate(
int parameterIndex)
throws java.sql.SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getDate (this, this.getReplyData(),null);
}
/**
* Gets the value of a JDBC <code>DATE</code> parameter as a
* <code>java.sql.Date</code> object, using
* the given <code>Calendar</code> object
* to construct the date.
* With a <code>Calendar</code> object, the driver
* can calculate the date taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param cal the <code>Calendar</code> object the driver will use
* to construct the date
* @return the parameter value. If the value is SQL NULL, the result is
* <code>null</code>.
* @exception SQLException if a database access error occurs
*/
public java.sql.Date getDate(int parameterIndex,
Calendar cal)
throws SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getDate (this, this.getReplyData(),cal);
}
/**
* getDouble method comment.
*/
public double getDouble(
int parameterIndex)
throws java.sql.SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getDouble (this, this.getReplyData());
}
/**
* getFloat method comment.
*/
public float getFloat(
int parameterIndex)
throws java.sql.SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getFloat (this, this.getReplyData());
}
/**
*
* @return java.lang.Object
* @param index int
*/
Object getInputParameter (
int parameterIndex)
{
return this.inputArgs [parameterIndex - 1];
}
/**
* getInt method comment.
*/
public int getInt(
int parameterIndex)
throws java.sql.SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getInt (this, this.getReplyData());
}
/**
* getLong method comment.
*/
public long getLong(
int parameterIndex)
throws java.sql.SQLException
{
assertOpen();
return this.findColInfo (parameterIndex).getLong (this, this.getReplyData());
}
/**
* JDBC 2.0
*
* Gets the number, types and properties of a ResultSet's columns.
*
*
* @return the description of a ResultSet's columns
* @exception SQLException if a database access error occurs
*/
public ResultSetMetaData getMetaData()
throws SQLException
{
if(this.fetchInfo==null) {
if(this.parseinfo==null) {
return null;
} else {
if( (! this.parseinfo.isSelect)
&& (this.parseinfo.functionCode != FunctionCode.Select_FC)
&& (this.parseinfo.functionCode != FunctionCode.DBProcWithResultSetExecute_FC)) {
// leave as is if this is not a simple select
return null;
}
DBTechTranslator[] colinfos=this.parseinfo.getColumnInfos();
if(colinfos!=null) {
return new ResultSetMetaDataSapDB(colinfos);
} else {
// send describe parseid
try {
this.parseinfo.doDescribeParseId();
}
catch (Exception ex) {
return null;
}
return new ResultSetMetaDataSapDB (
this.getFetchInfo(this.cursorName,
this.parseinfo.getColumnInfos(),
this.parseinfo.columnNames).getColInfo());
}
}
} else {
return new ResultSetMetaDataSapDB (this.fetchInfo.getColInfo());
}
}
/**
* getObject method comment.
*/
public Object getObject(
int parameterIndex)
throws java.sql.SQLException
{
assertOpen();
Object result=null;
int typeCode;
int scale;
DBTechTranslator translator = this.findColInfo (parameterIndex);
StructuredMem replymem = this.getReplyData();
if (this.outPutTypes == null) {
typeCode = 0;
}
else {
typeCode = this.outPutTypes [parameterIndex];
}
switch (typeCode) {
case Types.BIT:
if(!translator.isNull(this, replymem))
result = new Boolean (translator.getBoolean(this, replymem));
break;
case Types.TINYINT:
if(!translator.isNull(this, replymem))
result = new Byte (translator.getByte (this, replymem));
break;
case Types.SMALLINT:
if(!translator.isNull(this, replymem))
result = new Short (translator.getShort (this, replymem));
break;
case Types.INTEGER:
if(!translator.isNull(this, replymem))
result = new Integer (translator.getInt (this, replymem));
break;
case Types.BIGINT:
if(!translator.isNull(this, replymem))
result = new Long (translator.getLong (this, replymem));
break;
case Types.REAL:
if(!translator.isNull(this, replymem))
result = new Float (translator.getFloat (this, replymem));
break;
case Types.FLOAT:
if(!translator.isNull(this, replymem))
result = new Float (translator.getFloat (this, replymem));
break;
case Types.DOUBLE:
if(!translator.isNull(this, replymem))
result = new Double (translator.getDouble (this, replymem));
break;
case Types.NUMERIC:
case Types.DECIMAL:
scale = this.outPutScale [parameterIndex];
if (scale == -1) {
result = translator.getBigDecimal(this, replymem);
}
else {
result = translator.getBigDecimal(scale, this, replymem);
}
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
result = translator.getString (this, replymem);
break;
case Types.DATE:
result = translator.getDate (this, replymem, null);
break;
case Types.TIME:
result = translator.getTime (this, replymem, null);
break;
case Types.TIMESTAMP:
result = translator.getTimestamp(this, replymem, null);
break;
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
result = translator.getBytes (this, replymem);
break;
case java.sql.Types.BLOB:
result = translator.getBlob (this, replymem, replymem);
break;
case java.sql.Types.CLOB:
result = translator.getClob (this, replymem, replymem);
break;
default:
result = translator.getObject (this, replymem);
}
return result;
}
/**
* JDBC 2.0
*
* Returns an object representing the value of OUT parameter
* <code>i</code> and uses <code>map</code> for the custom
* mapping of the parameter value.
* <p>
* This method returns a Java object whose type corresponds to the
* JDBC type that was registered for this parameter using the method
* <code>registerOutParameter</code>. By registering the target
* JDBC type as <code>java.sql.Types.OTHER</code>, this method can
* be used to read database-specific abstract data types.
* @param i the first parameter is 1, the second is 2, and so on
* @param map the mapping from SQL type names to Java classes
* @return a java.lang.Object holding the OUT parameter value.
* @exception SQLException if a database access error occurs
*/
public Object getObject (int i,
Map map)
throws SQLException
{
throw new NotImplemented (MessageTranslator.translate(MessageKey.ERROR_GETOBJECT_NOTIMPLEMENTED));
}
/**
* JDBC 2.0
*
* Gets the value of a JDBC <code>REF(<structured-type>)</code>
* parameter as a {@link Ref} object in the Java programming language.
* @param i the first parameter is 1, the second is 2,
* and so on
* @return the parameter value as a <code>Ref</code> object in the
* Java programming language. If the value was SQL NULL, the value
* <code>null</code> is returned.
* @exception SQLException if a database access error occurs
*/
public Ref getRef (int i)
throws SQLException
{
throwNotSupported(MessageTranslator.translate(MessageKey.ERROR_REF_UNSUPPORTED));
return null;
}
/**
*
* @return com.sap.dbtech.util.StructuredMem
*/
public StructuredMem getReplyData ()
throws SQLException
{
if(this.replyMem==null &&
((this.outputOMSStreams==null)
||(this.outputOMSStreams!=null && this.outputOMSStreams.size()==0))) {
throw new SQLExceptionSapDB(MessageTranslator.translate
(MessageKey.ERROR_NOOUTPARAMDATA));
}
return this.replyMem;
}
/**
* getShort method comment.
*/
public short getShort(
int parameterIndex)
throws java.sql.SQLException
{
return this.findColInfo (parameterIndex).getShort (this, this.getReplyData());
}
/**
* getString method comment.
*/
public String getString(
int parameterIndex)
throws java.sql.SQLException
{
return this.findColInfo (parameterIndex).getString (this, this.getReplyData());
}
/**
* getTime method comment.
*/
public java.sql.Time getTime(
int parameterIndex)
throws java.sql.SQLException
{
return this.findColInfo (parameterIndex).getTime (this, this.getReplyData(),null);
}
/**
* Gets the value of a JDBC <code>TIME</code> parameter as a
* <code>java.sql.Time</code> object, using
* the given <code>Calendar</code> object
* to construct the time.
* With a <code>Calendar</code> object, the driver
* can calculate the time taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param cal the <code>Calendar</code> object the driver will use
* to construct the time
* @return the parameter value; if the value is SQL NULL, the result is
* <code>null</code>.
* @exception SQLException if a database access error occurs
*/
public java.sql.Time getTime(
int parameterIndex,
Calendar cal)
throws SQLException
{
return this.findColInfo (parameterIndex).getTime (this, this.getReplyData(),cal);
}
/**
* getTimestamp method comment.
*/
public java.sql.Timestamp getTimestamp(int parameterIndex) throws java.sql.SQLException {
return this.findColInfo (parameterIndex).getTimestamp (this, this.getReplyData(),null);
}
/**
* Gets the value of a JDBC <code>TIMESTAMP</code> parameter as a
* <code>java.sql.Timestamp</code> object, using
* the given <code>Calendar</code> object to construct
* the <code>Timestamp</code> object.
* With a <code>Calendar</code> object, the driver
* can calculate the timestamp taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param cal the <code>Calendar</code> object the driver will use
* to construct the timestamp
* @return the parameter value. If the value is SQL NULL, the result is
* <code>null</code>.
* @exception SQLException if a database access error occurs
*/
public java.sql.Timestamp getTimestamp(int parameterIndex,
Calendar cal)
throws SQLException
{
return this.findColInfo (parameterIndex).getTimestamp (this, this.getReplyData(),cal);
}
private static class PutvalComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
Putval p1 = (Putval) o1;
Putval p2 = (Putval) o2;
int p1_bufpos = p1.getBufpos();
int p2_bufpos = p2.getBufpos();
return p1_bufpos - p2_bufpos;
}
public boolean equals(Object o)
{
return o==this;
}
}
private static final PutvalComparator putvalComparator = new PutvalComparator();
/**
*
* @exception java.sql.SQLException The exception description.
*/
private void handleStreamsForExecute (DataPart dataPart,
Object [] arguments)
throws SQLException
{
Putval putval;
Enumeration putvals;
int i;
/*
* get all putval objects
*/
this.inputLongs = new Vector ();
for (i = 0; i < this.parseinfo.paramInfos.length; ++i) {
Object inarg = arguments [i];
if (inarg == null) {
continue;
}
try {
putval = (Putval) inarg;
this.inputLongs.addElement (putval);
}
catch (ClassCastException exc) {
// not a long for input, ignore
}
}
if(this.inputLongs.size()>1) {
Collections.sort(this.inputLongs, putvalComparator);
}
/*
* write data (and patch descriptor)
*/
putvals = this.inputLongs.elements ();
for (i = 0; putvals.hasMoreElements (); ++i) {
putval = (Putval) putvals.nextElement ();
if (putval.atEnd()){
throw new SQLExceptionSapDB(MessageTranslator.translate(MessageKey.ERROR_STREAM_ISATEND));
}
putval.transferStream (dataPart, i);
}
}
private void handleProcedureStreamsForExecute(DataPart dataPart, Object[] objects)throws SQLExceptionSapDB
{
this.inputProcedureLongs = new Vector();
for(int i=0; i<this.parseinfo.paramInfos.length; ++i) {
Object arg = this.inputArgs[i];
if(arg == null) {
continue;
} else {
try {
AbstractProcedurePutval pv = (AbstractProcedurePutval) arg;
inputProcedureLongs.addElement(pv);
pv.updateIndex(inputProcedureLongs.size() - 1);
} catch(ClassCastException ignored) {
continue;
}
}
}
}
/**
*
* @param dataPart
* @param objects
*/
private void handleOMSStreamsForExecute(DataPart dataPart)
{
//
this.inputOMSStreams = new Vector();
for (int i = 0; i < this.parseinfo.paramInfos.length; ++i) {
Object inarg = this.inputArgs[i];
if (inarg == null) {
continue;
}
try {
this.inputOMSStreams
.addElement((AbstractABAPStreamPutval) inputArgs[i]);
} catch (ClassCastException exc) {
// not a stream
}
}
int inputoms_size = inputOMSStreams.size();
for (int k = 0; k < inputoms_size; ++k) {
ABAPStreamDescriptor t = (ABAPStreamDescriptor) inputOMSStreams
.elementAt(k);
t.updateIndex(k);
}
if (this.outputOMSStreams != null) {
// update the index for the output streams
for (int k = 0; k < outputOMSStreams.size(); ++k) {
ABAPStreamDescriptor t = (ABAPStreamDescriptor) outputOMSStreams
.elementAt(k);
t.updateIndex(k);
}
}
}
private ReplyPacket processProcedureStreams(ReplyPacket packet)
throws SQLException
{
ReplyPacket erg = null;
do {
try {
if (packet.existsPart(PartKind.AbapIStream_C)) {
StreamInfo[] streaminfos = packet.parseStreamInfos();
StreamInfo info = streaminfos[0];
int tabid = info.getTabId();
if (tabid < 0 || tabid > inputProcedureLongs.size()) {
throw new SQLExceptionSapDB(MessageTranslator
.translate(MessageKey.ERROR_UNKNOWN_PROCEDURELONG, Integer
.toString(tabid)));
}
AbstractProcedurePutval pv = (AbstractProcedurePutval) inputProcedureLongs.elementAt(tabid);
RequestPacket requestPacket = connection.getRequestPacket(this.packetEncodingUnicode);
DataPart dataPart = requestPacket.initStreamCommand(connection.autocommit);
pv.transferStream(dataPart, info.getRowCount());
dataPart.close();
packet = connection.execute(requestPacket, this, ConnectionSapDB.GC_NONE);
} else {
erg = packet;
break;
}
} catch(SQLException sqlEx) {
ReplyPacket tmppacket = connection.sendStreamErrorPacket(sqlEx);
if(tmppacket == null) {
throw sqlEx;
}
erg = tmppacket;
break;
}
} while (true);
for (int k = 0; k < inputProcedureLongs.size(); ++k) {
AbstractProcedurePutval pv = (AbstractProcedurePutval) inputProcedureLongs.elementAt(k);
pv.closeStream();
}
return erg;
}
private ReplyPacket processOMSStreams(ReplyPacket replyPacket)
throws SQLException
{
do {
if (replyPacket.existsPart(PartKind.AbapIStream_C)) {
int tabid = replyPacket.parseABAPTabIDForInput();
AbstractABAPStreamPutval pv = (AbstractABAPStreamPutval) this.inputOMSStreams
.elementAt(tabid);
if (pv.atEnd()) {
throw new SQLExceptionSapDB(MessageTranslator.translate(
MessageKey.ERROR_STREAM_EOF, Integer
.toString(tabid)));
}
RequestPacket requestPacket = this.connection
.getRequestPacket(this.packetEncodingUnicode);
DataPart dataPart = requestPacket
.initStreamCommand(this.connection.autocommit);
pv.transferStream(dataPart);
dataPart.close();
replyPacket = connection.execute(requestPacket, this,
ConnectionSapDB.GC_NONE);
} else if (replyPacket.existsPart(PartKind.AbapOStream_C)) {
int tabid = replyPacket.parseABAPTabIDForOutput();
AbstractABAPStreamGetval gv = (AbstractABAPStreamGetval) this.outputOMSStreams
.elementAt(tabid);
boolean eos = gv.addReplyData(replyPacket);
RequestPacket requestPacket = this.connection
.getRequestPacket(this.packetEncodingUnicode);
DataPart datapart = requestPacket
.initStreamCommand(this.connection.autocommit);
if (eos) {
datapart.fillWithOMSReturnCode(100);
} else {
datapart.fillWithOMSReturnCode(0);
}
datapart.close();
replyPacket = connection.execute(requestPacket, this,
ConnectionSapDB.GC_NONE);
} else {
if (this.outputOMSStreams != null) {
for (int i = 0; i < this.outputOMSStreams.size(); ++i) {
AbstractABAPStreamGetval gv = (AbstractABAPStreamGetval) this.outputOMSStreams
.elementAt(i);
if (gv != null) {
gv.coalesceReply();
}
}
}
return replyPacket;
}
} while (true);
}
/**
*
*/
private void getChangedPutvalDescriptors (
ReplyPacket replyPacket)
{
byte [][] descriptorArray = replyPacket.parseLongDescriptors ();
byte [] descriptor;
com.sap.dbtech.util.StructuredBytes descriptorPointer;
Putval putval;
int valIndex;
if (! replyPacket.existsPart (PartKind.Longdata_C)) {
return;
}
for (int i = 0; i < descriptorArray.length; ++i) {
descriptor = descriptorArray [i];
descriptorPointer = new com.sap.dbtech.util.StructuredBytes (descriptor);
valIndex = descriptorPointer.getInt2 (LongDesc.Valind_O);
putval = (Putval) this.inputLongs.elementAt (valIndex);
putval.setDescriptor (descriptor);
}
}
/**
*
* @exception java.sql.SQLException The exception description.
*/
private void handleStreamsForPutval(ReplyPacket replyPacket)
throws SQLException {
if (this.inputLongs.size() == 0) {
return;
}
Putval lastStream = (Putval) this.inputLongs.lastElement();
RequestPacket requestPacket;
DataPart dataPart;
int descriptorPos;
Putval putval;
int firstOpenStream = 0;
int count = this.inputLongs.size();
boolean requiresTrailingPacket = false;
while (!lastStream.atEnd()) {
this.getChangedPutvalDescriptors(replyPacket);
requestPacket = this.connection.getRequestPacket(this.packetEncodingUnicode);
dataPart = requestPacket.initPutval(this.connection.autocommit);
/*
* get all descriptors and putvals
*/
for (int i = firstOpenStream; (i < count)
&& dataPart.hasRoomFor(LongDesc.Size_C + 1); ++i) {
putval = (Putval) this.inputLongs.elementAt(i);
if (putval.atEnd()) {
++firstOpenStream;
} else {
descriptorPos = dataPart.getExtent();
putval.putDescriptor(dataPart, descriptorPos);
dataPart.addArg(descriptorPos, LongDesc.Size_C + 1);
if (this.canceled) {
putval.markErrorStream();
++firstOpenStream;
} else {
putval.transferStream(dataPart, i);
if (putval.atEnd()) {
++firstOpenStream;
}
}
}
}
if (lastStream.atEnd() && !this.canceled) {
try {
lastStream.markAsLast(dataPart);
} catch (ArrayIndexOutOfBoundsException exc) {
// no place for end of LONGs marker
requiresTrailingPacket = true;
}
}
// at end: patch last descriptor
dataPart.close();
/*
* execute and get descriptors
*/
replyPacket = this.connection.execute(requestPacket, this,
ConnectionSapDB.GC_DELAYED);
/*
* write trailing end of LONGs marker
*/
if (requiresTrailingPacket && !this.canceled) {
requestPacket = this.connection.getRequestPacket(false);
dataPart = requestPacket.initPutval(this.connection.autocommit);
lastStream.markAsLast(dataPart);
dataPart.close();
// temporary fix for problem with kernel and LONG values in
// autocommit mode (again disabled).
if(false) {
try {
this.connection.execute(requestPacket, this,
ConnectionSapDB.GC_DELAYED);
} catch(SQLException sqlEx) {
if(this.connection.getAutoCommit() && sqlEx.getErrorCode() == -7065) {
// nothing
} else {
throw sqlEx;
}
}
} else {
this.connection.execute(requestPacket, this,
ConnectionSapDB.GC_DELAYED);
}
}
}
if (this.canceled) {
throw new SQLExceptionSapDB(MessageTranslator
.translate(MessageKey.ERROR_STATEMENT_CANCELLED), "42000",
-102);
}
}
/**
*
* @exception java.sql.SQLException
* The exception description.
*/
private void parseMassCmd (boolean parsegain)
throws SQLException
{
RequestPacket requestPacket;
ReplyPacket replyPacket;
requestPacket = this.connection.getRequestPacket (false);
try{
requestPacket.initParseCommand (this.parseinfo.sqlCmd, true, parsegain);
this.packetEncodingUnicode = false;
} catch (ConversionExceptionSapDB e) {
this.connection.freeRequestPacket(requestPacket);
requestPacket = this.connection.getRequestPacket (true);
this.packetEncodingUnicode = true;
requestPacket.initParseCommand (this.parseinfo.sqlCmd, true, parsegain);
}
requestPacket.setMassCommand ();
//requestPacket.addCursorPart (this.cursorName);
replyPacket = this.connection.execute (requestPacket, this, ConnectionSapDB.GC_ALLOWED);
if (replyPacket.existsPart (PartKind.Parsid_C)) {
this.parseinfo.setMassParseid(replyPacket.getBytes (replyPacket.getPartDataPos (), 12));
}
}
/**
* registerOutParameter method comment.
*/
public void registerOutParameter(
int parameterIndex,
int sqlType)
throws java.sql.SQLException
{
this.registerOutParameter (parameterIndex, sqlType, -1);
}
/**
* registerOutParameter method comment.
*/
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws java.sql.SQLException {
if (this.outPutTypes == null) {
this.outPutTypes = new short [this.parseinfo.paramInfos.length + 1];
this.outPutScale = new byte [this.parseinfo.paramInfos.length + 1];
}
this.outPutTypes [parameterIndex] = (short) sqlType;
this.outPutScale [parameterIndex] = (byte) scale;
}
/**
* JDBC 2.0
*
* Registers the designated output parameter. This version of
* the method <code>registerOutParameter</code>
* should be used for a user-named or REF output parameter. Examples
* of user-named types include: STRUCT, DISTINCT, JAVA_OBJECT, and
* named array types.
*
* Before executing a stored procedure call, you must explicitly
* call <code>registerOutParameter</code> to register the type from
* <code>java.sql.Types</code> for each
* OUT parameter. For a user-named parameter the fully-qualified SQL
* type name of the parameter should also be given, while a REF
* parameter requires that the fully-qualified type name of the
* referenced type be given. A JDBC driver that does not need the
* type code and type name information may ignore it. To be portable,
* however, applications should always provide these values for
* user-named and REF parameters.
*
* Although it is intended for user-named and REF parameters,
* this method may be used to register a parameter of any JDBC type.
* If the parameter does not have a user-named or REF type, the
* typeName parameter is ignored.
*
* <P><B>Note:</B> When reading the value of an out parameter, you
* must use the <code>getYYY</code> method whose Java type YYY corresponds to the
* parameter's registered SQL type.
*
* @param parameterIndex the first parameter is 1, the second is 2,...
* @param sqlType a value from java.sql.Types
* @param typeName the fully-qualified name of an SQL structured type
* @exception SQLException if a database-access error occurs
*/
public void registerOutParameter (
int paramIndex,
int sqlType,
String typeName)
throws SQLException
{
this.registerOutParameter (paramIndex, sqlType, -1);
}
/**
* Overwrites the inherited method. Instead of executing the command,
* this does a parse only!
* @param requestPacket the request packet.
* @param sqlCmd the SQL command to parse.
* @exception java.sql.SQLException if a database error occurs.
*/
ReplyPacket sendCommand (
RequestPacket requestPacket,
String sqlCmd,
int gcFlags,
boolean parseAgain)
throws SQLException
{
ReplyPacket replyPacket;
requestPacket.initParseCommand (sqlCmd, true, parseAgain);
if(setWithInfo)
requestPacket.setWithInfo();
replyPacket = this.connection.execute (requestPacket, false, true, this,
gcFlags);
return replyPacket;
}
/**
* JDBC 2.0
*
* Sets an Array parameter.
*
* @param i the first parameter is 1, the second is 2, ...
* @param x an object representing an SQL array
* @exception SQLException if a database access error occurs
*/
public void setArray (int i,
Array x)
throws SQLException
{
throwNotSupported(MessageTranslator.translate(MessageKey.ERROR_ARRAY_UNSUPPORTED));
}
/**
* setAsciiStream method comment.
*/
public void setAsciiStream(
int parameterIndex,
java.io.InputStream x,
int length)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transAsciiStreamForInput (x,length);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setBigDecimal method comment.
*/
public void setBigDecimal(
int parameterIndex,
java.math.BigDecimal x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transBigDecimalForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setBinaryStream method comment.
*/
public void setBinaryStream(
int parameterIndex,
java.io.InputStream x,
int length)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transBinaryStreamForInput (x,length);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* JDBC 2.0
*
* Sets a BLOB parameter.
*
* @param i the first parameter is 1, the second is 2, ...
* @param x an object representing a BLOB
* @exception SQLException if a database access error occurs
*/
public void setBlob (
int i,
Blob x)
throws SQLException
{
Object arg = this.findColInfo (i).transBlobForInput (x);
this.inputArgs [i - 1] = arg;
}
/**
* setBoolean method comment.
*/
public void setBoolean(
int parameterIndex,
boolean x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transBooleanForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setByte method comment.
*/
public void setByte(
int parameterIndex,
byte x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transByteForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setBytes method comment.
*/
public void setBytes(
int parameterIndex,
byte[] x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transBytesForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* JDBC 2.0
*
* Sets the designated parameter to the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a LONGVARCHAR
* parameter, it may be more practical to send it via a
* java.io.Reader. JDBC will read the data from the stream
* as needed, until it reaches end-of-file. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the java reader which contains the UNICODE data
* @param length the number of characters in the stream
* @exception SQLException if a database access error occurs
*/
public void setCharacterStream(
int parameterIndex,
java.io.Reader reader,
int length)
throws SQLException
{
Object arg = this.findColInfo (parameterIndex).transCharacterStreamForInput (reader, length);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* JDBC 2.0
*
* Sets a CLOB parameter.
*
* @param i the first parameter is 1, the second is 2, ...
* @param x an object representing a CLOB
* @exception SQLException if a database access error occurs
*/
public void setClob (
int i,
Clob x)
throws SQLException
{
Object arg = this.findColInfo (i).transClobForInput (x);
this.inputArgs [i - 1] = arg;
}
/**
* setDate method comment.
*/
public void setDate(
int parameterIndex,
java.sql.Date x)
throws java.sql.SQLException
{
this.setDate(parameterIndex,x,null);
}
/**
* JDBC 2.0
*
* Sets the designated parameter to a java.sql.Date value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL DATE,
* which the driver then sends to the database. With a
* a <code>Calendar</code> object, the driver can calculate the date
* taking into account a custom timezone and locale. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone and locale.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the date
* @exception SQLException if a database access error occurs
*/
public void setDate(
int parameterIndex,
java.sql.Date x,
Calendar cal)
throws SQLException
{
if(cal==null) {
cal=Calendar.getInstance();
}
Object arg = this.findColInfo (parameterIndex).transDateForInput (x,cal);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setDouble method comment.
*/
public void setDouble(
int parameterIndex,
double x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transDoubleForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setFloat method comment.
*/
public void setFloat(
int parameterIndex,
float x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transFloatForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setInt method comment.
*/
public void setInt(int parameterIndex,
int x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transIntForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
*
* @param wasNull boolean
*/
public void setLastWasNull (
boolean wasNull)
{
this.lastWasNull = wasNull;
}
/**
* setLong method comment.
*/
public void setLong(
int parameterIndex,
long x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transLongForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setNull method comment.
*/
public void setNull(
int parameterIndex,
int sqlType)
throws java.sql.SQLException
{
this.inputArgs [parameterIndex - 1] = null;
}
public void setDefault(
int parameterIndex)
throws java.sql.SQLException
{
this.inputArgs [parameterIndex - 1] = DBTechTranslator.DefaultValue;
}
/**
* JDBC 2.0
*
* Sets the designated parameter to SQL NULL. This version of setNull should
* be used for user-named types and REF type parameters. Examples
* of user-named types include: STRUCT, DISTINCT, JAVA_OBJECT, and
* named array types.
*
* <P><B>Note:</B> To be portable, applications must give the
* SQL type code and the fully-qualified SQL type name when specifying
* a NULL user-defined or REF parameter. In the case of a user-named type
* the name is the type name of the parameter itself. For a REF
* parameter the name is the type name of the referenced type. If
* a JDBC driver does not need the type code or type name information,
* it may ignore it.
*
* Although it is intended for user-named and Ref parameters,
* this method may be used to set a null parameter of any JDBC type.
* If the parameter does not have a user-named or REF type, the given
* typeName is ignored.
*
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param sqlType a value from java.sql.Types
* @param typeName the fully-qualified name of an SQL user-named type,
* ignored if the parameter is not a user-named type or REF
* @exception SQLException if a database access error occurs
*/
public void setNull (
int paramIndex,
int sqlType,
String typeName)
throws java.sql.SQLException
{
this.setNull (paramIndex, sqlType);
}
/**
* setObject method comment.
*/
public void setObject(
int parameterIndex,
Object x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transObjectForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setObject method comment.
*/
public void setObject(
int parameterIndex,
Object x,
int targetSqlType)
throws java.sql.SQLException
{
// specials for JDBC Compliance
switch(targetSqlType) {
case Types.INTEGER:
if(x instanceof Number) {
Number n=(Number)x;
this.setInt(parameterIndex, n.intValue());
return;
}
case Types.BIGINT:
if(x instanceof Number) {
Number n=(Number)x;
this.setLong(parameterIndex, n.longValue());
return;
}
}
this.setObject (parameterIndex, x);
}
/**
* setObject method comment.
*/
public void setObject(
int parameterIndex,
Object x,
int targetSqlType,
int scale)
throws java.sql.SQLException
{
// ignore targetSqlType
this.setObject (parameterIndex, x, scale);
}
/**
* JDBC 2.0
*
* Sets a REF(<structured-type>) parameter.
*
* @param i the first parameter is 1, the second is 2, ...
* @param x an object representing data of an SQL REF Type
* @exception SQLException if a database access error occurs
*/
public void setRef (int i,
Ref x)
throws SQLException
{
throwNotSupported(MessageTranslator.translate(MessageKey.ERROR_REF_UNSUPPORTED));
}
/**
* setShort method comment.
*/
public void setShort(
int parameterIndex,
short x)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transShortForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setString method comment.
*/
public void setString(
int parameterIndex,
String x)
throws java.sql.SQLException
{
this.assertOpen();
if ( x != null
&& this.connection.isSQLModeOracle
&& x.equalsIgnoreCase("") ) {
/* in oracle mode a null values will be inserted
if the string value is equal to "" */
this.inputArgs [parameterIndex - 1] = null;
}
else {
Object arg = this.findColInfo (parameterIndex).transStringForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
}
/**
* setTime method comment.
*/
public void setTime(
int parameterIndex,
java.sql.Time x)
throws java.sql.SQLException
{
this.setTime(parameterIndex,x, null);
}
/**
* JDBC 2.0
*
* Sets the designated parameter to a java.sql.Time value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL TIME,
* which the driver then sends to the database. With a
* a <code>Calendar</code> object, the driver can calculate the time
* taking into account a custom timezone and locale. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone and locale.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the time
* @exception SQLException if a database access error occurs
*/
public void setTime(int parameterIndex,
java.sql.Time x,
Calendar cal)
throws SQLException
{
if(cal==null) {
cal=Calendar.getInstance();
}
Object arg = this.findColInfo (parameterIndex).transTimeForInput (x, cal);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setTimestamp method comment.
*/
public void setTimestamp(
int parameterIndex,
java.sql.Timestamp x)
throws java.sql.SQLException
{
this.setTimestamp(parameterIndex,x,null);
}
/**
* JDBC 2.0
*
* Sets the designated parameter to a java.sql.Timestamp value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL TIMESTAMP,
* which the driver then sends to the database. With a
* a <code>Calendar</code> object, the driver can calculate the timestamp
* taking into account a custom timezone and locale. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone and locale.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the timestamp
* @exception SQLException if a database access error occurs
*/
public void setTimestamp(int parameterIndex,
java.sql.Timestamp x,
Calendar cal)
throws SQLException
{
if(cal==null) {
cal=Calendar.getInstance();
}
Object arg = this.findColInfo (parameterIndex).transTimestampForInput (x, cal);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* setUnicodeStream method comment.
*/
public void setUnicodeStream(
int parameterIndex,
java.io.InputStream x,
int length)
throws java.sql.SQLException
{
Object arg = this.findColInfo (parameterIndex).transUnicodeStreamForInput (x);
this.inputArgs [parameterIndex - 1] = arg;
}
/**
* wasNull method comment.
*/
public boolean wasNull()
throws java.sql.SQLException
{
return this.lastWasNull;
}
/**
*
*/
protected FetchInfo
getFetchInfo (
String cursorName,
DBTechTranslator [] infos,
String [] columnNames)
throws SQLException
{
if (this.fetchInfo == null) {
this.fetchInfo = new FetchInfo (this.connection,
cursorName, infos, columnNames, this.packetEncodingUnicode);
}
else {
if (!this.fetchInfo.getCursorName ().equals (cursorName)) {
this.fetchInfo = new FetchInfo (this.connection,
cursorName, infos, columnNames, this.packetEncodingUnicode);
}
}
return this.fetchInfo;
}
protected void updateFetchInfo(DBTechTranslator [] infos, String[] columnNames) throws SQLException {
this.parseinfo.setMetaData(infos, columnNames);
}
/**
*
*/
public void
close ()
throws SQLException
{
this.replyMem=null;
if (this.connection != null
&& this.parseinfo != null
&& !this.parseinfo.cached) {
this.connection.dropParseid (this.parseinfo.getParseId());
this.parseinfo.setParseIdAndSession(null, -1);
this.connection.dropParseid (this.parseinfo.getMassParseid());
this.parseinfo.setMassParseid(null);
}
super.close ();
}
/**
*
*/
protected void
resetPutvals (Vector inpLongs)
{
if (inpLongs != null) {
Enumeration putvals = inpLongs.elements ();
while (putvals.hasMoreElements ()) {
Putval putval = (Putval) putvals.nextElement ();
putval.reset ();
}
}
}
public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
this.registerOutParameter (parameterName, sqlType, -1);
}
public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
this.registerOutParameter((this.findParamInfo(parameterName).getColIndex())+1, sqlType, scale);
}
public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
this.registerOutParameter (parameterName, sqlType, -1);
}
public URL getURL(int parm1) throws java.sql.SQLException {
this.throwNotSupported("Type URL");
return null;
}
public void setURL(String parm1, URL parm2) throws java.sql.SQLException {
this.throwNotSupported("Type URL");
}
public void setNull(String parameterName, int sqlType) throws SQLException {
this.setNull((this.findParamInfo(parameterName).getColIndex())+1,sqlType);
}
public void setDefault(String parameterName) throws SQLException {
this.setDefault((this.findParamInfo(parameterName).getColIndex())+1);
}
public void setBoolean(String parameterName, boolean x) throws SQLException {
this.setBoolean((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setByte(String parameterName, byte x) throws SQLException {
this.setByte((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setShort(String parameterName, short x) throws SQLException {
this.setShort((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setInt(String parameterName, int x) throws SQLException {
this.setInt((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setLong(String parameterName, long x) throws SQLException {
this.setLong((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setFloat(String parameterName, float x) throws SQLException {
this.setFloat((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setDouble(String parameterName, double x) throws SQLException {
this.setDouble((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
this.setBigDecimal((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setString(String parameterName, String x) throws SQLException {
this.setString((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setBytes(String parameterName, byte[] x) throws SQLException {
this.setBytes((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setDate(String parameterName, java.sql.Date x) throws SQLException {
this.setDate((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setTime(String parameterName, java.sql.Time x) throws SQLException {
this.setTime((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setTimestamp(String parameterName, java.sql.Timestamp x) throws SQLException {
this.setTimestamp((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
this.setAsciiStream((this.findParamInfo(parameterName).getColIndex())+1,x,length);
}
public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
this.setBinaryStream((this.findParamInfo(parameterName).getColIndex())+1,x,length);
}
public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
this.setObject((this.findParamInfo(parameterName).getColIndex())+1,x,targetSqlType,scale);
}
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
this.setObject((this.findParamInfo(parameterName).getColIndex())+1,x,targetSqlType);
}
public void setObject(String parameterName, Object x) throws SQLException {
this.setObject((this.findParamInfo(parameterName).getColIndex())+1,x);
}
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
this.setCharacterStream((this.findParamInfo(parameterName).getColIndex())+1,reader,length);
}
public void setDate(String parameterName, java.sql.Date x, Calendar cal) throws SQLException {
this.setDate((this.findParamInfo(parameterName).getColIndex())+1,x,cal);
}
public void setTime(String parameterName, java.sql.Time x, Calendar cal) throws SQLException {
this.setTime((this.findParamInfo(parameterName).getColIndex())+1,x,cal);
}
public void setTimestamp(String parameterName, java.sql.Timestamp x, Calendar cal) throws SQLException {
this.setTimestamp((this.findParamInfo(parameterName).getColIndex())+1,x,cal);
}
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
this.setNull((this.findParamInfo(parameterName).getColIndex())+1,sqlType,typeName);
}
public String getString(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getString (this, this.getReplyData());
}
public boolean getBoolean(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getBoolean (this, this.getReplyData());
}
public byte getByte(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getByte (this, this.getReplyData());
}
public short getShort(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getShort (this, this.getReplyData());
}
public int getInt(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getInt (this, this.getReplyData());
}
public long getLong(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getLong (this, this.getReplyData());
}
public float getFloat(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getFloat (this, this.getReplyData());
}
public double getDouble(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getDouble (this, this.getReplyData());
}
public byte[] getBytes(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getBytes (this, this.getReplyData());
}
public java.sql.Date getDate(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getDate (this, this.getReplyData(),null);
}
public java.sql.Time getTime(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getTime (this, this.getReplyData(),null);
}
public java.sql.Timestamp getTimestamp(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getTimestamp (this, this.getReplyData(),null);
}
public Object getObject(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getObject (this, this.getReplyData());
}
public BigDecimal getBigDecimal(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getBigDecimal (this, this.getReplyData());
}
public Object getObject(String parameterName, Map map) throws SQLException {
throw new NotImplemented ();
}
public Ref getRef(String parameterName) throws SQLException {
throwNotSupported(MessageTranslator.translate(MessageKey.ERROR_REF_UNSUPPORTED));
return null;
}
public Blob getBlob(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getBlob (this, this.getReplyData(), this.getReplyData());
}
public Clob getClob(String parameterName) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getClob (this, this.getReplyData(), this.getReplyData());
}
public Array getArray(String parameterName) throws SQLException {
throwNotSupported(MessageTranslator.translate(MessageKey.ERROR_ARRAY_UNSUPPORTED));
return null;
}
public java.sql.Date getDate(String parameterName, Calendar cal) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getDate (this, this.getReplyData(),cal);
}
public java.sql.Time getTime(String parameterName, Calendar cal) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getTime (this, this.getReplyData(),cal);
}
public java.sql.Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
assertOpen();
return this.findParamInfo (parameterName).getTimestamp (this, this.getReplyData(),cal);
}
public URL getURL(String parm1) throws java.sql.SQLException {
throwNotSupported(MessageTranslator.translate(MessageKey.ERROR_URL_UNSUPPORTED));
return null;
}
public void setURL(int parm1, URL parm2) throws java.sql.SQLException {
throwNotSupported(MessageTranslator.translate(MessageKey.ERROR_URL_UNSUPPORTED));
}
public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException {
return ParameterMetaDataSapDB.createParameterMetaDataSapDB(this.parseinfo.getParamInfo());
}
public AbstractABAPStreamGetval getOMSGetval(int index)
throws SQLException {
if(this.outputOMSStreams == null) {
return null;
}
for(int i=0; i<this.outputOMSStreams.size(); ++i) {
AbstractABAPStreamGetval t = (AbstractABAPStreamGetval) this.outputOMSStreams.elementAt(i);
if(t != null) {
if(index == t.getColIndex()) {
return t;
}
}
}
throw new SQLExceptionSapDB(MessageTranslator.translate(MessageKey.ERROR_COLINDEX_NOTFOUND, Integer.toString(index)));
}
boolean isParameterSet(int parameterIndex){
return ! (initialParamValue == this.inputArgs[parameterIndex-1]);
}
void unsetParameter(int parameterIndex){
this.inputArgs[parameterIndex-1] = initialParamValue;
}
Object[] getInputArgs() {
return inputArgs;
}
}
|