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 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437
|
/*
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
// 05/24/2011-2.3 Guy Pelletier
// - 345962: Join fetch query when using tenant discriminator column fails.
package org.eclipse.persistence.expressions;
import java.util.*;
import java.io.*;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.queries.*;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.exceptions.*;
import org.eclipse.persistence.history.*;
import org.eclipse.persistence.internal.helper.*;
import org.eclipse.persistence.internal.expressions.*;
import org.eclipse.persistence.internal.localization.*;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;
/**
* <p>
* <b>Purpose</b>: Define an object-level representation of a database query where clause.</p>
* <p>
* <b>Description</b>: An expression is a tree-like structure that defines the selection
* criteria for a query against objects in the database. The expression has the advantage
* over SQL by being at the object-level, i.e. the object model attributes and relationships
* can be used to be query on instead of the database field names.
* Because it is an object, not a string the expression has the advantage that is can be
* easily manipulated through code to easily build complex selection criterias.</p>
* <p>
* <b>Responsibilities</b>:
* <ul>
* <li> Store the selection criteria in a tree-like structure.
* <li> Support public manipulation protocols for all comparison and function operators.
* <li> Use operator overloading to support all primitive types as well as objects.
* </ul>
*/
public abstract class Expression implements Serializable, Cloneable {
/** Required for serialization compatibility. */
static final long serialVersionUID = -5979150600092006081L;
/** Temporary values for table aliasing */
protected transient DatabaseTable lastTable;
protected transient DatabaseTable currentAlias;
protected boolean selectIfOrderedBy = true;
/** PERF: Cache the hashCode. */
protected int hashCode = 0;
/** Use the upper() function for case insensitive expression operations (default).
Seting this flag to false will use the lower() function instead. */
public static boolean shouldUseUpperCaseForIgnoreCase = true;
/**
* Base Expression Constructor. Not generally used by Developers
*/
public Expression() {
super();
}
/**
* PUBLIC:
* Function, return an expression that adds to a date based on
* the specified datePart. This is equivalent to the Sybase DATEADD function.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("date").addDate("year", 2)
* Java: NA
* SQL: DATEADD(date, 2, year)
* </pre></blockquote>
*/
public Expression addDate(String datePart, int numberToAdd) {
return addDate(datePart, Integer.valueOf(numberToAdd));
}
/**
* PUBLIC:
* Function, return an expression that adds to a date based on
* the specified datePart. This is equivalent to the Sybase DATEADD function.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("date").addDate("year", 2)
* Java: NA
* SQL: DATEADD(date, 2, year)
* </pre></blockquote>
*/
public Expression addDate(String datePart, Object numberToAdd) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.AddDate);
List args = new ArrayList(2);
args.add(Expression.fromLiteral(datePart, this));
args.add(numberToAdd);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Function, to add months to a date.
*/
public Expression addMonths(int months) {
return addMonths(Integer.valueOf(months));
}
/**
* PUBLIC:
* Function, to add months to a date.
*/
public Expression addMonths(Object months) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.AddMonths);
return anOperator.expressionFor(this, months);
}
/**
* INTERNAL:
* Find the alias for a given table
*/
public DatabaseTable aliasForTable(DatabaseTable table) {
return null;
}
/**
* PUBLIC: Returns an expression equivalent to all of <code>attributeName</code>
* holding true for <code>criteria</code>.
* <p>
* For every expression with an anyOf, its negation has either an allOf or a
* noneOf. The following two examples will illustrate as the second is the
* negation of the first:
* <p>
* AnyOf Example: Employees with a non '613' area code phone number.
* <blockquote><pre>
* ReadAllQuery query = new ReadAllQuery(Employee.class);
* ExpressionBuilder employee = new ExpressionBuilder();
* Expression exp = employee.anyOf("phoneNumbers").get("areaCode").notEqual("613");
* </pre></blockquote>
* <p>
* AllOf Example: Employees with all '613' area code phone numbers.
* <blockquote><pre>
* ExpressionBuilder employee = new ExpressionBuilder();
* ExpressionBuilder phones = new ExpressionBuilder();
* Expression exp = employee.allOf("phoneNumbers", phones.get("areaCode").equal("613"));
* SQL:
* SELECT ... EMPLOYEE t0 WHERE NOT EXISTS (SELECT ... PHONE t1 WHERE
* (t0.EMP_ID = t1.EMP_ID) AND NOT (t1.AREACODE = '613'))
* </pre></blockquote>
* <p>
* allOf is the universal counterpart to the existential anyOf. To have the
* condition evaluated for each instance it must be put inside of a subquery,
* which can be expressed as not exists (any of attributeName some condition).
* (All x such that y = !Exist x such that !y).
* <p>Likewise the syntax employee.allOf("phoneNumbers").get("areaCode").equal("613")
* is not supported for the <pre>equal</pre> must go inside a subQuery.
* <p>
* This method saves you from writing the sub query yourself. The above is
* equivalent to the following expression:
* <blockquote><pre>
* ExpressionBuilder employee = new ExpressionBuilder();
* ExpressionBuilder phone = new ExpressionBuilder();
* ReportQuery subQuery = new ReportQuery(Phone.class, phone);
* subQuery.retreivePrimaryKeys();
* subQuery.setSelectionCriteria(phone.equal(employee.anyOf("phoneNumbers").and(
* phone.get("areaCode").notEqual("613")));
* Expression exp = employee.notExists(subQuery);
* </pre></blockquote>
* <p>
* Note if employee has no phone numbers allOf ~ noneOf.
* @param criteria must have its own builder, as it will become the
* separate selection criteria of a subQuery.
* @return a notExists subQuery expression
*/
public Expression allOf(String attributeName, Expression criteria) {
ReportQuery subQuery = new ReportQuery();
subQuery.setShouldRetrieveFirstPrimaryKey(true);
Expression builder = criteria.getBuilder();
criteria = builder.equal(anyOf(attributeName)).and(criteria.not());
subQuery.setSelectionCriteria(criteria);
return notExists(subQuery);
}
/**
* PUBLIC:
* Return an expression that is the boolean logical combination of both expressions.
* This is equivalent to the SQL "AND" operator and the Java {@literal "&&"} operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").equal("Bob").and(employee.get("lastName").equal("Smith"))
* Java: (employee.getFirstName().equals("Bob")) {@literal &&} (employee.getLastName().equals("Smith"))
* SQL: F_NAME = 'Bob' AND L_NAME = 'Smith'
* </pre></blockquote>
*/
public Expression and(Expression theExpression) {
// Allow ands with null.
if (theExpression == null) {
return this;
}
ExpressionBuilder base = getBuilder();
Expression expressionToUse = theExpression;
// Ensure the same builder, unless a parralel query is used.
// For flashback added an extra condition: if left side is a 'NullExpression'
// then rebuild on it regardless.
if ((theExpression.getBuilder() != base) && ((base == this) || (theExpression.getBuilder().getQueryClass() == null))) {
expressionToUse = theExpression.rebuildOn(base);
}
if (base == this) {// Allow and to be sent to the builder.
return expressionToUse;
}
ExpressionOperator anOperator = getOperator(ExpressionOperator.And);
return anOperator.expressionFor(this, expressionToUse);
}
/**
* PUBLIC:
* Return an expression representing traversal of a 1:many or many:many relationship.
* This allows you to query whether any of the "many" side of the relationship satisfies the remaining criteria.
* <p>Example:
* </p>
* <table border=0 summary="This table compares an example EclipseLink anyOf Expression to Java and SQL">
* <tr>
* <th id="c1">Format</th>
* <th id="c2">Equivalent</th>
* </tr>
* <tr>
* <td headers="c1">EclipseLink</td>
* <td headers="c2">
* <pre>
* ReadAllQuery query = new ReadAllQuery(Employee.class);<br>
* ExpressionBuilder builder = new ExpressionBuilder();<br>
* Expression exp = builder.get("id").equal("14858");<br>
* exp = exp.or(builder.anyOf("managedEmployees").get("firstName").equal("Bob"));<br>
* </pre>
* </td>
* </tr>
* <tr>
* <td headers="c1">Java</td>
* <td headers="c2">No direct equivalent</td>
* </tr>
* <tr>
* <td headers="c1">SQL</td>
* <td headers="c2">SELECT DISTINCT ... WHERE (t2.MGR_ID (+) = t1.ID) AND (t2.F_NAME = 'Bob')</td>
* </tr>
* </table>
*/
public Expression anyOf(String attributeName) {
return anyOf(attributeName, true);
}
/**
* ADVANCED:
* Return an expression representing traversal of a 1:many or many:many relationship.
* This allows you to query whether any of the "many" side of the relationship satisfies the remaining criteria.
* <p>Example:
* </p>
* <table border=0 summary="This table compares an example EclipseLink anyOf Expression to Java and SQL">
* <tr>
* <th id="c3">Format</th>
* <th id="c4">Equivalent</th>
* </tr>
* <tr>
* <td headers="c3">EclipseLink</td>
* <td headers="c4">
* <pre>
* ReadAllQuery query = new ReadAllQuery(Employee.class);<br>
* ExpressionBuilder builder = new ExpressionBuilder();<br>
* Expression exp = builder.get("id").equal("14858");<br>
* exp = exp.or(builder.anyOf("managedEmployees").get("firstName").equal("Bob"));<br>
* </pre>
* </td>
* </tr>
* <tr>
* <td headers="c3">Java</td>
* <td headers="c4">No direct equivalent</td>
* </tr>
* <tr>
* <td headers="c3">SQL</td>
* <td headers="c4">SELECT DISTINCT ... WHERE (t2.MGR_ID (+) = t1.ID) AND (t2.F_NAME = 'Bob')</td>
* </tr>
* </table>
* @param shouldJoinBeIndependent indicates whether a new expression should be created.
*/
public Expression anyOf(String attributeName, boolean shouldJoinBeIndependent) {
throw new UnsupportedOperationException("anyOf");
}
/**
* ADVANCED:
* Return an expression representing traversal of a 1:many or many:many relationship.
* This allows you to query whether any of the "many" side of the relationship satisfies the remaining criteria.
* This version of the anyOf operation performs an outer join.
* Outer joins allow the join to performed even if the target of the relationship is empty.
* NOTE: outer joins are not supported on all database and have differing semantics.
* <p>Example:
* </p>
* <table border=0 summary="This table compares an example EclipseLink anyOfAllowingNone Expression to Java and SQL">
* <tr>
* <th id="c5">Format</th>
* <th id="c6">Equivalent</th>
* </tr>
* <tr>
* <td headers="c5">EclipseLink</td>
* <td headers="c6">
* <pre>
* ReadAllQuery query = new ReadAllQuery(Employee.class);<br>
* ExpressionBuilder builder = new ExpressionBuilder();<br>
* Expression exp = builder.get("id").equal("14858");<br>
* exp = exp.or(builder.anyOfAllowingNone("managedEmployees").get("firstName").equal("Bob"));<br>
* </pre>
* </td>
* </tr>
* <tr>
* <td headers="c5">Java</td>
* <td headers="c6">No direct equivalent</td>
* </tr>
* <tr>
* <td headers="c5">SQL</td>
* <td headers="c6">SELECT DISTINCT ... WHERE (t2.MGR_ID (+) = t1.ID) AND (t2.F_NAME = 'Bob')</td>
* </tr>
* </table>
*/
public Expression anyOfAllowingNone(String attributeName) {
return anyOfAllowingNone(attributeName, true);
}
/**
* ADVANCED:
* Return an expression representing traversal of a 1:many or many:many relationship.
* This allows you to query whether any of the "many" side of the relationship satisfies the remaining criteria.
* This version of the anyOf operation performs an outer join.
* Outer joins allow the join to performed even if the target of the relationship is empty.
* NOTE: outer joins are not supported on all database and have differing semantics.
* <p>Example:
* </p>
* <table border=0 summary="This table compares an example EclipseLink anyOfAllowingNone Expression to Java and SQL">
* <tr>
* <th id="c7">Format</th>
* <th id="c8">Equivalent</th>
* </tr>
* <tr>
* <td headers="c7">EclipseLink</td>
* <td headers="c8">
* <pre>
* ReadAllQuery query = new ReadAllQuery(Employee.class);<br>
* ExpressionBuilder builder = new ExpressionBuilder();<br>
* Expression exp = builder.get("id").equal("14858");<br>
* exp = exp.or(builder.anyOfAllowingNone("managedEmployees").get("firstName").equal("Bob"));<br>
* </pre>
* </td>
* </tr>
* <tr>
* <td headers="c7">Java</td>
* <td headers="c8">No direct equivalent</td>
* </tr>
* <tr>
* <td headers="c7">SQL</td>
* <td headers="c8">SELECT DISTINCT ... WHERE (t2.MGR_ID (+) = t1.ID) AND (t2.F_NAME = 'Bob')</td>
* </tr>
* </table>
* @param shouldJoinBeIndependent indicates whether a new expression should be created.
*/
public Expression anyOfAllowingNone(String attributeName, boolean shouldJoinBeIndependent) {
throw new UnsupportedOperationException("anyOfAllowingNone");
}
/**
* ADVANCED:
* Return an expression that allows you to treat its base as if it were a subclass of the class returned by the base.
* @deprecated replaced by {@link #treat(Class)}
*/
@Deprecated
public Expression as(Class castClass) {
return treat(castClass);
}
/**
* ADVANCED:
* Assign an alias to the expression in the select clause.
*/
public Expression as(String alias) {
ExpressionOperator operator = getOperator(ExpressionOperator.As);
return operator.expressionFor(this, literal(alias));
}
/**
* ADVANCED:
* Return an expression that allows you to treat its base as if it were a subclass of the class returned by the base
* This can only be called on an ExpressionBuilder, the result of expression.get(String), expression.getAllowingNull(String),
* the result of expression.anyOf("String") or the result of expression.anyOfAllowingNull("String")
*
* downcast uses Expression.type() internally to guarantee the results are of the specified class.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("project").treat(LargeProject.class).get("budget").equal(1000)
* Java: ((LargeProject)employee.getProjects().get(0)).getBudget() == 1000
* SQL: LPROJ.PROJ_ID (+)= PROJ.PROJ_ID AND L_PROJ.BUDGET = 1000 AND PROJ.TYPE = "L"
* </pre></blockquote>
*/
public Expression treat(Class castClass) {
return this;
}
/**
* PUBLIC:
* This can only be used within an ordering expression.
* It will order the result ascending.
* Example:
* <blockquote><pre>
* readAllQuery.addOrderBy(expBuilder.get("address").get("city").ascending())
* </pre></blockquote>
*/
public Expression ascending() {
return getFunction(ExpressionOperator.Ascending);
}
/**
* PUBLIC:
* This can only be used within an ordering expression.
* Null results will be ordered first.
* Example:
* <blockquote><pre>
* readAllQuery.addOrderBy(expBuilder.get("address").get("city").ascending().nullsFirst())
* </pre></blockquote>
*/
public Expression nullsFirst() {
return getFunction(ExpressionOperator.NullsFirst);
}
/**
* PUBLIC:
* This can only be used within an ordering expression.
* Null results will be ordered last.
* Example:
* <blockquote><pre>
* readAllQuery.addOrderBy(expBuilder.get("address").get("city").ascending().nullsLast())
* </pre></blockquote>
*/
public Expression nullsLast() {
return getFunction(ExpressionOperator.NullsLast);
}
/**
* PUBLIC:
* Function, returns the single character strings ascii value.
*/
public Expression asciiValue() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Ascii);
return anOperator.expressionFor(this);
}
/**
* Sets all tables represented by this expression to be queried as of a past
* time.
* <p>
* Example:
* </p>
* <pre>
* EclipseLink: employee.asOf(new AsOfClause(pastTime))
* Java: None
* SQL (Flashback): SELECT ... FROM EMPLOYEE AS OF TIMESTAMP (pastTime) t0 ...
* SQL (Generic): .. WHERE (t1.START {@literal <=} pastTime) AND ((t1.END IS NULL) OR t1.END {@literal >} pastTime)
* </pre>
* <p>
* Set an as of clause at the expression level to still query for current objects
* while expressing selection criteria like:
* <ul>
* <li>query objects as of one time that met some condition at another time.
* <li>query objects that changed a certain way over a certain interval (querying for change).
* </ul>
* <p>
* Simultaneously querying on two versions of the same object (one past
* one present) lets you express these advanced selection criteria.
* <p>
* Example: Querying on past attributes using parallel expressions.
* </p>
* <blockquote><pre>
* // Finds all employees who lived in Ottawa as of a past time.
* ExpressionBuilder employee = new ExpressionBuilder();
* ExpressionBuilder pastEmployee = new ExpressionBuilder(Employee.class);
* pastEmployee.asOf(pastTime);
* Expression pastAddress = pastEmployee.get("address"); // by default address will also be as of past time.
* Expression selectionCriteria = pastAddress.get("city").equal("Ottawa").and(
* employee.equal(pastEmployee));
* </pre></blockquote>
* <p>
* The advantage of the parallel expression is that you can still read current
* objects, the as of clause will affect only the where clause / selection criteria.
* <p>
* You may be tempted to rewrite the above as employee.get("address").asOf(pastTime).
* That is allowed but see below for the finer points involved in this.
* <p>
* Example: Querying on object changes using parallel expressions.
* </p>
* <blockquote><pre>
* // Finds all employees who recently received a raise. Note that current
* // objects are returned, so can be cached normally.
* ExpressionBuilder employee = new ExpressionBuilder();
* Expression pastEmployee = new ExpressionBuilder(Employee.class);
* pastEmployee.asOf(yesterday);
* Expression parallelJoin = employee.equal(pastEmployee);
* Expression selectionCriteria = parallelJoin.and(
* employee.get("salary").greaterThan(pastEmployee.get("salary")));
* </pre></blockquote>
* <p>
* Example: Querying on object changes using custom query keys
* </p><blockquote><pre>
* // First define the custom query key and add it to your descriptor.
* ExpressionBuilder builder = new ExpressionBuilder(Employee.class);
* Expression joinCriteria = builder.getField("EMPLOYEE.EMP_ID").equal(builder.getParameter("EMPLOYEE.EMP_ID"));
* OneToOneQueryKey selfReferential = new OneToOneQueryKey();
* selfReferential.setName("this");
* selfReferential.setJoinCriteria(joinCriteria);
* selfReferential.setReferenceClass(Employee.class);
* getSession().getDescriptor(Employee.class).addQueryKey(selfReferential);
*
* // Now build query as before.
* Expression employee = new ExpessionBuilder();
* Expression pastEmployee = employee.get("this").asOf(yesterday);
* Expression selectionCriteria = employee.get("salary").greaterThan(pastEmployee.get("salary"));
* </pre></blockquote>
* <p>
* Note in general that any parallel expression can be rewritten using a custom query key.
* EclipseLink will even automatically interpret x.get("this") for you so you do
* not need to define the above query key first.
* <p>
* <b>Full Reference:</b>
* <p>
* If an object is mapped to multiple tables, then each table will be as of
* the same time. Two objects mapped to the same table can not have different
* as of times. Conversely only expressions which have associated tables can have an as
* of clause.
* <p>
* If an as of clause is not explicitly set an expression will use the clause
* of its base expression, and so on recursively until one is found or an
* ExpressionBuilder is reached. Some usage scenarios follow:
* <ul>
* <li>employee.asOf(pastTime).anyOf("projects"): projects as of past time.
* <li>expressionBuilder.asOf(pastTime): entire expression as of past time.
* <li>employee.asOf(pastTime).anyOf("projects").asOf(null): projects as of current time.
* <li>employee.anyOf("projects").asOf(pastTime): projects only as of past time.
* </ul>
* <p>
* Watch out for x.asOf(oneTime).get("y").asOf(anotherTime).
* <ul>
* <li>emp.anyOf("phoneNumbers").asOf(yesterday) = emp.asOf(yesterday).anyOf("phoneNumbers") but:
* <li>emp.get("address").asOf(yesterday) != emp.asOf(yesterday).get("address").
* </ul>
* Whether the join is also as of yesterday depends on which table the foreign
* key field resides on. In an anyOf the foreign key is always on the right, but
* in a get (1-1) it could be on either side. For this
* reason employee.get("address").asOf(yesterday) is undefined as it can mean
* either 'my address as of yesterday', or 'my address, as of yesterday.'
* @param pastTime A read only data object used to represent a past time.
* @return <code>this</code>
* @since OracleAS EclipseLink 10<i>g</i> (10.0.3)
* @see org.eclipse.persistence.history.AsOfClause
* @see #hasAsOfClause
* @see org.eclipse.persistence.sessions.Session#acquireHistoricalSession(org.eclipse.persistence.history.AsOfClause)
* @see org.eclipse.persistence.queries.ObjectLevelReadQuery#setAsOfClause(org.eclipse.persistence.history.AsOfClause)
*/
public Expression asOf(AsOfClause pastTime) {
throw new UnsupportedOperationException("anyOfAllowingNone");
}
/**
* INTERNAL:
* Alias a particular table within this node
*/
protected void assignAlias(String name, DatabaseTable tableOrExpression) {
// By default, do nothing.
}
/**
* INTERNAL:
* Assign aliases to any tables which I own. Start with t(initialValue),
* and return the new value of the counter , i.e. if initialValue is one
* and I have tables ADDRESS and EMPLOYEE I will assign them t1 and t2 respectively, and return 3.
*/
public int assignTableAliasesStartingAt(int initialValue) {
if (hasBeenAliased()) {
return initialValue;
}
int counter = initialValue;
List<DatabaseTable> ownedTables = getOwnedTables();
if (ownedTables != null) {
for (DatabaseTable table : ownedTables) {
assignAlias("t" + counter, table);
counter++;
}
}
return counter;
}
/**
* PUBLIC:
* Function, This represents the aggregate function Average. Can be used only within Report Queries.
*/
public Expression average() {
return getFunction(ExpressionOperator.Average);
}
/**
* PUBLIC:
* Function, between two bytes
*/
public Expression between(byte leftValue, byte rightValue) {
return between(Byte.valueOf(leftValue), Byte.valueOf(rightValue));
}
/**
* PUBLIC:
* Function, between two chars
*/
public Expression between(char leftChar, char rightChar) {
return between(Character.valueOf(leftChar), Character.valueOf(rightChar));
}
/**
* PUBLIC:
* Function, between two doubles
*/
public Expression between(double leftValue, double rightValue) {
return between(Double.valueOf(leftValue), Double.valueOf(rightValue));
}
/**
* PUBLIC:
* Function, between two floats
*/
public Expression between(float leftValue, float rightValue) {
return between(Float.valueOf(leftValue), Float.valueOf(rightValue));
}
/**
* PUBLIC:
* Function, between two ints
*/
public Expression between(int leftValue, int rightValue) {
return between(Integer.valueOf(leftValue), Integer.valueOf(rightValue));
}
/**
* PUBLIC:
* Function, between two longs
*/
public Expression between(long leftValue, long rightValue) {
return between(Long.valueOf(leftValue), Long.valueOf(rightValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receiver's value is between two other values.
* This means the receiver's value is greater than or equal to the leftValue argument and less than or equal to the
* rightValue argument.
* <p>
* This is equivalent to the SQL "BETWEEN AND" operator and Java {@literal ">=", "<=;"} operators.
* <p>Example:
* <pre>
* EclipseLink: employee.get("age").between(19,50)
* Java: (employee.getAge() {@literal >=} 19) {@literal &&} (employee.getAge() {@literal <=} 50)
* SQL: AGE BETWEEN 19 AND 50
* </pre>
*/
public Expression between(Object leftValue, Object rightValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Between);
List args = new ArrayList(2);
args.add(leftValue);
args.add(rightValue);
return anOperator.expressionForArguments(this, args);
}
public Expression between(Expression leftExpression, Expression rightExpression) {
return between((Object)leftExpression, (Object)rightExpression);
}
/**
* PUBLIC:
* Function, between two shorts
*/
public Expression between(short leftValue, short rightValue) {
return between(Short.valueOf(leftValue), Short.valueOf(rightValue));
}
/**
* PUBLIC:
* Function Convert values returned by the query to values
* given in the caseItems Map. The equivalent of
* the Oracle CASE function
* <p>Example:
* <blockquote><pre>
* Map caseTable = new HashMap();
* caseTable.put("Robert", "Bob");
* caseTable.put("Susan", "Sue");
*
* EclipseLink: employee.get("name").caseStatement(caseTable, "No-Nickname")
* Java: NA
* SQL: CASE name WHEN "Robert" THEN "Bob"
* WHEN "Susan" THEN "Sue"
* ELSE "No-Nickname"
* </pre></blockquote>
* @param caseItems java.util.Map
* A Map containing the items to be processed.
* Keys represent the items to match coming from the query.
* Values represent what a key will be changed to.
* @param defaultItem java.lang.String the default value that will be used if none of the keys in the
* hashtable match
*/
public Expression caseStatement(Map caseItems, Object defaultItem) {
FunctionExpression expression = caseStatement();
expression.addChild(this);
Iterator iterator = caseItems.keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
expression.addChild(Expression.from(key, this));
expression.addChild(Expression.from(caseItems.get(key), this));
}
expression.addChild(Expression.from(defaultItem, this));
return expression;
}
/**
* INTERNAL:
* Creates an ArgumentListFunctionExpression that is capable of creating a case statement of the form:
* <blockquote><pre>
* SQL: CASE name WHEN "Robert" THEN "Bob"
* WHEN "Susan" THEN "Sue"
* ELSE "No-Nickname"
* </pre></blockquote>
*
* This expression must be manipulated to successfully build a case statement by adding appropriate
* children to it.
*
* A child must be added for the "case expression" (name above), a pair of children must be added for
* each "when then" expression and a child must be added for the else.
*
* @see ArgumentListFunctionExpression
*/
public ArgumentListFunctionExpression caseStatement() {
ExpressionOperator caseOperator = getOperator(ExpressionOperator.Case);
ExpressionOperator clonedCaseOperator = caseOperator.clone();
ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
expression.setBaseExpression(this);
expression.setOperator(clonedCaseOperator);
return expression;
}
/**
* PUBLIC:
* Function Convert values returned by the query to values
* given in the caseConditions Map. The equivalent of
* the SQL CASE function
* <p>Example:
* <blockquote><pre>
* Map caseTable = new HashMap();
* caseTable.put(employee.get("name").equals("Robert"), "Bob");
* caseTable.put(employee.get("name").equals("Susan"), "Sue");
*
* EclipseLink: expressionBuilder.caseConditionStatement(caseTable, "No-Nickname")
* Java: NA
* SQL: CASE WHEN name = "Robert" THEN "Bob"
* WHEN name = "Susan" THEN "Sue"
* ELSE "No-Nickname"
* </pre></blockquote>
* @param caseConditions java.util.Map
* A Map containing the items to be processed.
* Keys represent the items to match coming from the query.
* Values represent what a key will be changed to.
* @param defaultItem java.lang.Object the default value that will be used if none of the keys in the
* Map match
*/
public Expression caseConditionStatement(Map<Expression, Object> caseConditions, Object defaultItem) {
FunctionExpression expression = caseConditionStatement();
Iterator<Expression> iterator = caseConditions.keySet().iterator();
if (iterator.hasNext()){
Expression key = iterator.next();
expression.addChild(key);
expression.setBaseExpression(key);//base needs to be the same as the first child for reportQuery items.
expression.addChild(Expression.from(caseConditions.get(key), this));
while (iterator.hasNext()) {
key = iterator.next();
expression.addChild(key);
expression.addChild(Expression.from(caseConditions.get(key), this));
}
}
expression.addChild(Expression.from(defaultItem, this));
return expression;
}
/**
* INTERNAL:
* Creates an ArgumentListFunctionExpression that is capable of creating a case statement of the form:
* <blockquote><pre>
* SQL: CASE WHEN name = "Robert" THEN "Bob"
* WHEN name = "Susan" THEN "Sue"
* ELSE "No-Nickname"
* </pre></blockquote>
*
* This expression must be manipulated to successfully build a case statement by adding appropriate
* children to it.
*
* A pair of children must be added for each "when then" expression and a child must be added for the else.
*
* @see ArgumentListFunctionExpression
*/
public ArgumentListFunctionExpression caseConditionStatement() {
ExpressionOperator caseOperator = getOperator(ExpressionOperator.CaseCondition);
ExpressionOperator clonedCaseOperator = caseOperator.clone();
ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
expression.setBaseExpression(this);
expression.setOperator(clonedCaseOperator);
return expression;
}
/**
* PUBLIC:
* Function Test if arguments are equal, returning null if they are and the value of the
* first expression otherwise.
* <p>Example:
* <blockquote><pre>
* EclipseLink: builder.get("name").nullIf( "Bobby")
* Java: NA
* SQL: NULLIF(name, "Bobby")
* </pre></blockquote>
* @param object java.lang.Object the value/expression that will be compared to the base expression
*/
public Expression nullIf(Object object) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NullIf);
List args = new ArrayList(1);
args.add(Expression.from(object, this));
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Function Return null if all arguments are null and the first non-null argument otherwise
* The equivalent of the COALESCE SQL function
* <p>Example:
* <blockquote><pre>
* List list = new ArrayList(3);
* list.add(builder.get("firstName"));
* list.add(builder.get("lastName"));
* list.add(builder.get("nickname"));
*
* EclipseLink: expressionBuilder.coalesce(caseTable)
* Java: NA
* SQL: COALESCE(firstname, lastname, nickname)
* </pre></blockquote>
* @param expressions java.util.Collection
* A Collection containing the items to check if null
*/
public ArgumentListFunctionExpression coalesce(Collection expressions) {
ArgumentListFunctionExpression expression = coalesce();
Iterator iterator = expressions.iterator();
if (iterator.hasNext()){
Expression base = Expression.from(iterator.next(), this);
expression.addChild(base);
expression.setBaseExpression(base);//base needs to be the same as the first child for reportQuery items.
while (iterator.hasNext()) {
expression.addChild(Expression.from(iterator.next(), this));
}
}
return expression;
}
public ArgumentListFunctionExpression coalesce() {
ExpressionOperator coalesceOperator = getOperator(ExpressionOperator.Coalesce);
ExpressionOperator clonedCoalesceOperator = coalesceOperator.clone();
ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
expression.setBaseExpression(this);
expression.setOperator(clonedCoalesceOperator);
return expression;
}
/**
* INTERNAL:
* Clone the expression maintaining clone identity in the inter-connected expression graph.
*/
public Object clone() {
// 2612538 - the default size of Map (32) is appropriate
Map alreadyDone = new IdentityHashMap();
return copiedVersionFrom(alreadyDone);
}
/**
* INTERNAL:
* This expression is built on a different base than the one we want. Rebuild it and
* return the root of the new tree.
* This method will rebuildOn the receiver even it is a parallel select or a
* sub select: it will not replace every base with newBase.
* Also it will rebuild using anyOf as appropriate not get.
* @see org.eclipse.persistence.mappings.ForeignReferenceMapping#batchedValueFromRow
* @see #rebuildOn(Expression)
* @bug 2637484 INVALID QUERY KEY EXCEPTION THROWN USING BATCH READS AND PARALLEL EXPRESSIONS
* @bug 2612567 CR4298- NULLPOINTEREXCEPTION WHEN USING SUBQUERY AND BATCH READING IN 4.6
* @bug 2612140 CR2973- BATCHATTRIBUTE QUERIES WILL FAIL WHEN THE INITIAL QUERY HAS A SUBQUERY
* @bug 2720149 INVALID SQL WHEN USING BATCH READS AND MULTIPLE ANYOFS
*/
public Expression cloneUsing(Expression newBase) {
// 2612538 - the default size of Map (32) is appropriate
Map alreadyDone = new IdentityHashMap();
// cloneUsing is identical to cloning save that the primary builder
// will be replaced not with its clone but with newBase.
// ExpressionBuilder.registerIn() will check for this newBase with
// alreadyDone.get(alreadyDone);
// copiedVersionFrom() must be called on the primary builder before
// other builders.
alreadyDone.put(alreadyDone, newBase);
return copiedVersionFrom(alreadyDone);
}
/**
* PUBLIC:
* Function, returns the concatenation of the two string values.
*/
public Expression concat(Object left) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Concat);
return anOperator.expressionFor(this, left);
}
/**
* PUBLIC:
* Return an expression that performs a key word search.
* <p>Example:
* <blockquote><pre>
* EclipseLink: project.get("description").containsAllKeyWords("EclipseLink rdbms java")
* </pre></blockquote>
*/
public Expression containsAllKeyWords(String spaceSeparatedKeyWords) {
StringTokenizer tokenizer = new StringTokenizer(spaceSeparatedKeyWords);
Expression expression = null;
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (expression == null) {
expression = containsSubstringIgnoringCase(token);
} else {
expression = expression.and(containsSubstringIgnoringCase(token));
}
}
if (expression == null) {
return like("%");
} else {
return expression;
}
}
/**
* PUBLIC:
* Return an expression that performs a key word search.
* <p>Example:
* <blockquote><pre>
* EclipseLink: project.get("description").containsAllKeyWords("EclipseLink rdbms java")
* </pre></blockquote>
*/
public Expression containsAnyKeyWords(String spaceSeparatedKeyWords) {
StringTokenizer tokenizer = new StringTokenizer(spaceSeparatedKeyWords);
Expression expression = null;
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (expression == null) {
expression = containsSubstringIgnoringCase(token);
} else {
expression = expression.or(containsSubstringIgnoringCase(token));
}
}
if (expression == null) {
return like("%");
} else {
return expression;
}
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value contains the substring.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").containsSubstring("Bob")
* Java: employee.getFirstName().indexOf("Bob") != -1
* SQL: F_NAME LIKE '%BOB%'
* </pre></blockquote>
*/
public Expression containsSubstring(String theValue) {
return like("%" + theValue + "%");
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value contains the substring.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").containsSubstring("Bob")
* Java: employee.getFirstName().indexOf("Bob") != -1
* SQL: F_NAME LIKE '%BOB%'
* </pre></blockquote>
*/
public Expression containsSubstring(Expression expression) {
return like((value("%").concat(expression)).concat("%"));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value contains the substring, ignoring case.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").containsSubstringIgnoringCase("Bob")
* Java: employee.getFirstName().toUpperCase().indexOf("BOB") != -1
* SQL: UPPER(F_NAME) LIKE '%BOB%'
* </pre></blockquote>
*/
public Expression containsSubstringIgnoringCase(String theValue) {
if (shouldUseUpperCaseForIgnoreCase) {
return toUpperCase().containsSubstring(theValue.toUpperCase());
} else {
return toLowerCase().containsSubstring(theValue.toLowerCase());
}
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value contains the substring, ignoring case.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").containsSubstringIgnoringCase("Bob")
* Java: employee.getFirstName().toUpperCase().indexOf("BOB") != -1
* SQL: UPPER(F_NAME) LIKE '%BOB%'
* </pre></blockquote>
*/
public Expression containsSubstringIgnoringCase(Expression expression) {
if (shouldUseUpperCaseForIgnoreCase) {
return toUpperCase().containsSubstring(expression.toUpperCase());
} else {
return toLowerCase().containsSubstring(expression.toLowerCase());
}
}
/*
* Modify this individual expression node to use outer joins wherever there are
* equality operations between two field nodes.
*/
protected void convertNodeToUseOuterJoin() {
}
/**
* INTERNAL:
* Modify this expression to use outer joins wherever there are
* equality operations between two field nodes.
*/
public Expression convertToUseOuterJoin() {
ExpressionIterator iterator = new ExpressionIterator() {
public void iterate(Expression each) {
each.convertNodeToUseOuterJoin();
}
};
iterator.iterateOn(this);
return this;
}
/**
* INTERNAL:
*/
public Expression copiedVersionFrom(Map alreadyDone) {
if (alreadyDone == null) {
// For sub-selects no cloning is done.
return this;
}
Expression existing = (Expression)alreadyDone.get(this);
if (existing == null) {
return registerIn(alreadyDone);
} else {
return existing;
}
}
/**
* PUBLIC:
* This represents the aggregate function Average. Can be used only within Report Queries.
*/
public Expression count() {
return getFunction(ExpressionOperator.Count);
}
/**
* INTERNAL:
*/
public Expression create(Expression base, Object singleArgument, ExpressionOperator anOperator) {
// This is a replacement for real class methods in Java. Instead of returning a new instance we create it, then
// mutate it using this method.
return this;
}
/**
* INTERNAL:
*/
public Expression createWithBaseLast(Expression base, Object singleArgument, ExpressionOperator anOperator) {
// This is a replacement for real class methods in Java. Instead of returning a new instance we create it, then
// mutate it using this method.
return this;
}
/**
* INTERNAL:
*/
public Expression create(Expression base, List arguments, ExpressionOperator anOperator) {
// This is a replacement for real class methods in Java. Instead of returning a new instance we create it, then
// mutate it using this method.
return this;
}
/**
* PUBLIC:
* This gives access to the current timestamp on the database through expression.
* Please note, this method is added for consistency and returns the same
* result as currentDate.
*/
public Expression currentTimeStamp() {
return currentDate();
}
/**
* PUBLIC:
* This gives access to the current date on the database through expression.
*/
public Expression currentDate() {
return getFunction(ExpressionOperator.Today);
}
/**
* PUBLIC:
* This gives access to the current date only on the database through expression.
* Note the difference between currentDate() and this method. This method does
* not return the time portion of current date where as currentDate() does.
*/
public Expression currentDateDate() {
return getFunction(ExpressionOperator.CurrentDate);
}
/**
* PUBLIC:
* This gives access to the current time only on the database through expression.
* Note the difference between currentDate() and this method. This method does
* not return the date portion where as currentDate() does.
*/
public Expression currentTime() {
return getFunction(ExpressionOperator.CurrentTime);
}
/**
* PUBLIC:
* Function, Return the difference between the queried part of a date(i.e. years, days etc.)
* and same part of the given date. The equivalent of the Sybase function DateDiff
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("date").dateDifference("year", new Date(System.currentTimeMillis()))
* Java: NA
* SQL: DATEADD(date, 2, GETDATE)
* </pre></blockquote>
*/
public Expression dateDifference(String datePart, java.util.Date date) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.DateDifference);
FunctionExpression expression = new FunctionExpression();
expression.setBaseExpression(this);
expression.addChild(Expression.fromLiteral(datePart, this));
expression.addChild(Expression.from(date, this));
expression.addChild(this);
expression.setOperator(anOperator);
return expression;
}
/**
* PUBLIC:
* Function, Return the difference between the queried part of a date(i.e. years, days etc.)
* and same part of the given date. The equivalent of the Sybase function DateDiff
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("date").dateDifference("year", new Date(System.currentTimeMillis()))
* Java: NA
* SQL: DATEADD(date, 2, GETDATE)
* </pre></blockquote>
*/
public Expression dateDifference(String datePart, Expression comparisonExpression) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.DateDifference);
FunctionExpression expression = new FunctionExpression();
expression.setBaseExpression(this);
expression.addChild(Expression.fromLiteral(datePart, this));
expression.addChild(comparisonExpression);
expression.addChild(this);
expression.setOperator(anOperator);
return expression;
}
/**
* PUBLIC:
* return a string that represents the given part of a date. The equivalent
* of the Sybase DATENAME function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("date").dateName("year")
* Java: new String(date.getYear())
* SQL: DATENAME(date, year)
* </pre></blockquote>
*/
public Expression dateName(String datePart) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.DateName);
FunctionExpression expression = new FunctionExpression();
expression.setBaseExpression(this);
expression.addChild(Expression.fromLiteral(datePart, this));
expression.addChild(this);
expression.setOperator(anOperator);
return expression;
}
/**
* PUBLIC:
* Function return an integer which represents the requested
* part of the date. Equivalent of the Sybase function DATEPART
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("date").datePart("year")
* Java: date.getYear()
* SQL: DATEPART(date, year)
* </pre></blockquote>
*/
public Expression datePart(String datePart) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.DatePart);
FunctionExpression expression = new FunctionExpression();
expression.setBaseExpression(this);
expression.addChild(Expression.fromLiteral(datePart, this));
expression.addChild(this);
expression.setOperator(anOperator);
return expression;
}
/**
* PUBLIC:
* Function, returns the date converted to the string value in the default database format.
*/
public Expression dateToString() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.DateToString);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function Convert values returned by the query to values given in the decodeableItems Map.
* The equivalent of the Oracle DECODE function.
* Note: This will only work on databases that support Decode with the syntax below.
* <p>Example:
* <blockquote><pre>
* Map decodeTable = new HashMap();
* decodeTable.put("Robert", "Bob");
* decodeTable.put("Susan", "Sue");
*
* EclipseLink: employee.get("name").Decode(decodeTable, "No-Nickname")
* Java: NA
* SQL: DECODE(name, "Robert", "Bob", "Susan", "Sue", "No-Nickname")
* </pre></blockquote>
* @param decodeableItems java.util.Map
* a Map containing the items to be decoded. Keys represent
* the items to match coming from the query. Values represent what
* a key will be changed to.
* @param defaultItem
* the default value that will be used if none of the keys in the
* Map match
**/
public Expression decode(Map decodeableItems, String defaultItem) {
/**
* decode works differently than most of the functionality in the expression framework.
* It takes a variable number of arguments and as a result, the printed strings for
* a decode call have to be built when the number of arguments are known.
* As a result, we do not look up decode in the ExpressionOperator. Instead we build
* the whole operator here. The side effect of this is that decode will not thrown
* an invalid operator exception for any platform. (Even the ones that do not support
* decode)
*/
ExpressionOperator anOperator = new ExpressionOperator();
anOperator.setSelector(ExpressionOperator.Decode);
anOperator.setName("DECODE");
anOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
anOperator.setType(ExpressionOperator.FunctionOperator);
anOperator.bePrefix();
Vector v = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(decodeableItems.size() + 1);
v.add("DECODE(");
for (int i = 0; i < ((decodeableItems.size() * 2) + 1); i++) {
v.add(", ");
}
v.add(")");
anOperator.printsAs(v);
FunctionExpression expression = new FunctionExpression();
expression.setBaseExpression(this);
expression.addChild(this);
Iterator iterator = decodeableItems.keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
expression.addChild(Expression.from(key, this));
expression.addChild(Expression.from(decodeableItems.get(key), this));
}
expression.addChild(Expression.from(defaultItem, this));
expression.setOperator(anOperator);
return expression;
}
/**
* PUBLIC:
* This can only be used within an ordering expression.
* It will order the result descending.
* <p>Example:
* <blockquote><pre>
* readAllQuery.addOrderBy(expBuilder.get("address").get("city").descending())
* </pre></blockquote>
*/
public Expression descending() {
return getFunction(ExpressionOperator.Descending);
}
/**
* INTERNAL:
* Used in debug printing of this node.
*/
public String descriptionOfNodeType() {
return "Expression";
}
/**
* PUBLIC:
* Function return a value which indicates how much difference there is
* between two expressions. Equivalent of the Sybase DIFFERENCE function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("name").difference("Frank")
* SQL: DIFFERENCE(name, 'Frank')
* </pre></blockquote>
*/
public Expression difference(String expression) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Difference);
return anOperator.expressionFor(this, expression);
}
/**
* PUBLIC:
* Function, This represents the distinct option inside an aggregate function. Can be used only within Report Queries.
*/
public Expression distinct() {
return getFunction(ExpressionOperator.Distinct);
}
/**
* INTERNAL:
* Check if the object conforms to the expression in memory.
* This is used for in-memory querying.
* By default throw an exception as all valid root expressions must override.
* If the expression in not able to determine if the object conform throw a not supported exception.
*/
public boolean doesConform(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy) throws QueryException {
return doesConform(object, session, translationRow, valueHolderPolicy, false);
}
/**
* INTERNAL:
* New parameter added to doesConform for feature 2612601
* @param objectIsUnregistered true if object possibly not a clone, but is being
* conformed against the unit of work cache; if object is not in the UOW cache
* but some of its attributes are, use the registered versions of
* object's attributes for the purposes of this method.
*/
public boolean doesConform(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean objectIsUnregistered) throws QueryException {
throw QueryException.cannotConformExpression();
}
/**
* INTERNAL:
* Return if the expression is equal to the other.
* This is used to allow dynamic expression's SQL to be cached.
* Two expressions should be considered equal if they have the same "parameterized" SQL.
* This must be over written by each subclass.
*/
public boolean equals(Object expression) {
return (this == expression) || ((expression != null) && getClass().equals(expression.getClass()) && (hashCode() == expression.hashCode()));
}
/**
* INTERNAL:
* Return a consistent hash-code for the expression.
* This is used to allow dynamic expression's SQL to be cached.
* Two expressions should have the same hashCode if they have the same "parameterized" SQL.
* This should be over written by each subclass to provide a consistent value.
*/
public int hashCode() {
if (this.hashCode == 0) {
this.hashCode = computeHashCode();
}
return this.hashCode;
}
/**
* INTERNAL:
* Compute a consistent hash-code for the expression.
* This is used to allow dynamic expression's SQL to be cached.
* Two expressions should have the same hashCode if they have the same "parameterized" SQL.
* This should be over written by each subclass to provide a consistent value.
*/
public int computeHashCode() {
return 32;
}
public Expression equal(byte theValue) {
return equal(Byte.valueOf(theValue));
}
public Expression equal(char theChar) {
return equal(Character.valueOf(theChar));
}
public Expression equal(double theValue) {
return equal(Double.valueOf(theValue));
}
public Expression equal(float theValue) {
return equal(Float.valueOf(theValue));
}
public Expression equal(int theValue) {
return equal(Integer.valueOf(theValue));
}
public Expression equal(long theValue) {
return equal(Long.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receiver's value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").equal("Bob")
* Java: employee.getFirstName().equals("Bob")
* SQL: F_NAME = 'Bob'
* </pre></blockquote>
*/
public Expression equal(Object theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Equal);
return anOperator.expressionFor(this, theValue);
}
/**
* Returns an expression that compares if the receiver's value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
* <p>Since OracleAS EclipseLink 10<i>g</i> (9.0.4) if <code>this</code> is an <code>ExpressionBuilder</code> and <code>theValue</code>
* is not used elsewhere, both will be translated to the same table. This can
* generate SQL with one less join for most exists subqueries.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("manager").equal(employee)
* Java: employee.getManager().equals(employee)
* SQL (optimized): EMP_ID = MANAGER_ID
* SQL (unoptimized): t0.MANAGER_ID = t1.EMP_ID AND t0.EMP_ID = t1.EMP_ID
* </pre></blockquote>
* @see #equal(Object)
*/
public Expression equal(Expression theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Equal);
return anOperator.expressionFor(this, theValue);
}
public Expression equal(short theValue) {
return equal(Short.valueOf(theValue));
}
public Expression equal(boolean theBoolean) {
return equal(Boolean.valueOf(theBoolean));
}
/**
* INTERNAL:
* Return an expression representing an outer join comparison
*/
// cr3546
public Expression equalOuterJoin(Object theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.EqualOuterJoin);
return anOperator.expressionFor(this, theValue);
}
/**
* INTERNAL:
* Return an expression representing an outer join comparison
*/
public Expression equalOuterJoin(Expression theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.EqualOuterJoin);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receiver's value is equal to the other value, ignoring case.
* This is equivalent to the Java "equalsIgnoreCase" method.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").equalsIgnoreCase("Bob")
* Java: employee.getFirstName().equalsIgnoreCase("Bob")
* SQL: UPPER(F_NAME) = 'BOB'
* </pre></blockquote>
*/
public Expression equalsIgnoreCase(String theValue) {
if (shouldUseUpperCaseForIgnoreCase) {
return toUpperCase().equal(theValue.toUpperCase());
} else {
return toLowerCase().equal(theValue.toLowerCase());
}
}
/**
* PUBLIC:
* Return an expression that compares if the receiver's value is equal to the other value, ignoring case.
* This is equivalent to the Java "equalsIgnoreCase" method.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").equalsIgnoreCase("Bob")
* Java: employee.getFirstName().equalsIgnoreCase("Bob")
* SQL: UPPER(F_NAME) = 'BOB'
* </pre></blockquote>
*/
public Expression equalsIgnoreCase(Expression theValue) {
if (shouldUseUpperCaseForIgnoreCase) {
return toUpperCase().equal(theValue.toUpperCase());
} else {
return toLowerCase().equal(theValue.toLowerCase());
}
}
/**
* PUBLIC:
* Return a sub query expression.
* A sub query using a report query to define a subselect within another queries expression or select's where clause.
* The sub query (the report query) will use its own expression builder be can reference expressions from the base expression builder.
* <p>Example:
* <blockquote><pre>
* ExpressionBuilder builder = new ExpressionBuilder();
* ReportQuery subQuery = new ReportQuery(Employee.class, new ExpressionBuilder());
* subQuery.setSelectionCriteria(subQuery.getExpressionBuilder().get("name").equal(builder.get("name")));
* builder.exists(subQuery);
* </pre></blockquote>
*/
public Expression exists(ReportQuery subQuery) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Exists);
return anOperator.expressionFor(subQuery(subQuery));
}
/**
* INTERNAL:
* Extract the primary key from the expression into the row.
* Ensure that the query is querying the exact primary key.
* Return false if not on the primary key.
*/
public boolean extractPrimaryKeyValues(boolean requireExactMatch, ClassDescriptor descriptor, AbstractRecord primaryKeyRow, AbstractRecord translationRow) {
return extractValues(true, requireExactMatch, descriptor, primaryKeyRow, translationRow);
}
/**
* INTERNAL:
* Extract the primary key from the expression into the row.
* Ensure that the query is querying the exact primary key.
* Return false if not on the primary key.
*/
public boolean extractValues(boolean primaryKeyOnly, boolean requireExactMatch, ClassDescriptor descriptor, AbstractRecord primaryKeyRow, AbstractRecord translationRow) {
return false;
}
/**
* INTERNAL:
* Return if the expression is not a valid primary key expression and add all primary key fields to the set.
*/
public boolean extractFields(boolean requireExactMatch, boolean primaryKey, ClassDescriptor descriptor, List<DatabaseField> searchFields, Set<DatabaseField> foundFields) {
return false;
}
/**
* INTERNAL:
* Create an expression node.
*/
public static Expression from(Object value, Expression base) {
//CR#... null value used to return null, must build a null constant expression.
if (value instanceof Expression) {
Expression exp = (Expression)value;
if (exp.isValueExpression() || base.isExpressionBuilder()) {
exp.setLocalBase(base);
} else {
// We don't know which side of the relationship cares about the other one, so notify both
// However for 3107049 value.equal(value) would cause infinite loop if did that.
base.setLocalBase(exp);
}
return exp;
}
if (value instanceof ReportQuery) {
Expression exp = base.subQuery((ReportQuery)value);
exp.setLocalBase(base);// We don't know which side of the relationship cares about the other one, so notify both
base.setLocalBase(exp);
return exp;
}
return fromConstant(value, base);
}
/**
* INTERNAL:
* Create an expression node.
*/
public static Expression fromConstant(Object value, Expression base) {
return new ConstantExpression(value, base);
}
/**
* INTERNAL:
* Create an expression node.
*/
public static Expression fromLiteral(String value, Expression base) {
return new LiteralExpression(value, base);
}
/**
* PUBLIC:
* Return an expression that wraps the attribute or query key name.
* This method is used to construct user-defined queries containing joins.
* <p>Example:
* <blockquote><pre>
* builder.get("address").get("city").equal("Ottawa");
* </pre></blockquote>
*/
public Expression get(String attributeName) {
return get(attributeName, true);
}
/**
* PUBLIC:
* Return an expression that wraps the attribute or query key name.
* This method is used to construct user-defined queries containing joins.
* <p>Example:
* <blockquote><pre>
* builder.get("address", false).get("city").equal("Ottawa");
* </pre></blockquote>
* @param forceInnerJoin - allows the get to not force an inner-join (if getAllowingNull was used elsewhere).
*/
public Expression get(String attributeName, boolean forceInnerJoin) {
throw new UnsupportedOperationException("get");
}
/**
* ADVANCED:
* Return an expression that wraps the attribute or query key name.
* This is only applicable to 1:1 relationships, and allows the target of
* the relationship to be null if there is no corresponding relationship in the database.
* Implemented via an outer join in the database.
* <p>Example:
* <blockquote><pre>
* builder.getAllowingNull("address").get("city").equal("Ottawa");
* </pre></blockquote>
*/
public Expression getAllowingNull(String attributeName) {
throw new UnsupportedOperationException("getAllowingNull");
}
/**
* Answers the past time the expression is explicitly as of.
* @return An immutable object representation of the past time.
* <code>null</code> if no clause set, <code>AsOfClause.NO_CLAUSE</code> if
* clause explicitly set to <code>null</code>.
* @see #asOf(org.eclipse.persistence.history.AsOfClause)
* @see #hasAsOfClause()
*/
public AsOfClause getAsOfClause() {
return null;
}
/**
* INTERNAL:
* For Flashback: If this expression is not already as of some timestamp
* gets the clause from the base expression. Allows a clause to be set
* only on the builder and then propogated during normalize.
*/
public AsOfClause getAsOfClauseRecursively() {
return null;
}
/**
* INTERNAL:
* Return the expression builder which is the ultimate base of this expression, or
* null if there isn't one (shouldn't happen if we start from a root)
*/
public abstract ExpressionBuilder getBuilder();
/**
* INTERNAL:
* If there are any fields associated with this expression, return them
*/
public DatabaseField getClonedField() {
return null;
}
/**
* ADVANCED:
* Return an expression representing a field in a data-level query.
* This is used internally in EclipseLink, or to construct queries involving
* fields and/or tables that are not mapped.
* <p> Example:
* <blockquote><pre>
* builder.getField("ADDR_ID").greaterThan(100);
* builder.getTable("PROJ_EMP").getField("TYPE").equal("S");
* </pre></blockquote>
*/
public Expression getField(String fieldName) {
throw QueryException.illegalUseOfGetField(fieldName);
}
/**
* ADVANCED: Return an expression representing a field in a data-level query.
* This is used internally in EclipseLink, or to construct queries involving
* fields and/or tables that are not mapped.
* <p> Example:
* <blockquote><pre>
* builder.getField(aField).greaterThan(100);
* </pre></blockquote>
*/
public Expression getField(DatabaseField field) {
throw QueryException.illegalUseOfGetField(field);
}
/**
* INTERNAL:
*/
public Vector getFields() {
return org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(1);
}
/**
* INTERNAL:
*/
public List<DatabaseField> getSelectionFields() {
return getSelectionFields(null);
}
public List<DatabaseField> getSelectionFields(ReadQuery query) {
return getFields();
}
/**
* INTERNAL:
* Transform the object-level value into a database-level value
*/
public Object getFieldValue(Object objectValue, AbstractSession session) {
// Enums default to their ordinal
if (objectValue instanceof Enum){
return ((Enum)objectValue).ordinal();
}
return objectValue;
}
/**
* ADVANCED:
* Defines a join between the two objects based on the specified ON clause.
* This can be used to define a join condition on two unrelated objects,
* or to qualify a relationship join with additional criteria.
* <p> Example:
* <blockquote><pre>
* Expression address = employee.getAllowingNull("address");
* employee.join(address, address.get("city").equal("Ottawa"));
* query.addNonFetchJoin(address);
* </pre></blockquote>
*/
public Expression join(Expression target, Expression onClause) {
throw new UnsupportedOperationException("join");
}
/**
* ADVANCED:
* Defines an outer join between the two objects based on the specified ON clause.
* This can be used to define a join condition on two unrelated objects,
* or to qualify a relationship join with additional criteria.
* <p> Example:
* <blockquote><pre>
* Expression address = employee.getAllowingNull("address");
* employee.leftJoin(address, address.get("city").equal("Ottawa"));
* query.addNonFetchJoin(address);
* </pre></blockquote>
*/
public Expression leftJoin(Expression target, Expression onClause) {
throw new UnsupportedOperationException("leftJoin");
}
/**
* ADVANCED:
* This can be used for accessing user defined functions.
* The operator must be defined in ExpressionOperator to be able to reference it.
* @see ExpressionOperator
* <p> Example:
* <blockquote><pre>
* builder.get("name").getFunction(MyFunctions.FOO_BAR).greaterThan(100);
* </pre></blockquote>
*/
public Expression getFunction(int selector) {
ExpressionOperator anOperator = getOperator(selector);
return anOperator.expressionFor(this);
}
/**
* ADVANCED:
* This can be used for accessing user defined functions that have arguments.
* The operator must be defined in ExpressionOperator to be able to reference it.
* @see ExpressionOperator
* <p> Example:
* <blockquote><pre>
* List arguments = new ArrayList();
* arguments.add("blee");
* builder.get("name").getFunction(MyFunctions.FOO_BAR, arguments).greaterThan(100);
* </pre></blockquote>
*/
public Expression getFunction(int selector, List arguments) {
ExpressionOperator anOperator = getOperator(selector);
return anOperator.expressionForArguments(this, arguments);
}
/**
* ADVANCED:
* This can be used for accessing user defined operators that have arguments.
* The operator must be defined in ExpressionOperator to be able to reference it.
* @see ExpressionOperator
* <p> Example:
* <blockquote><pre>
* List arguments = new ArrayList();
* arguments.add("blee");
* builder.get("name").operator("FOO_BAR", arguments).greaterThan(100);
* </pre></blockquote>
*/
public Expression operator(String name, List arguments) {
Integer selector = ExpressionOperator.getPlatformOperatorSelectors().get(name);
if (selector == null) {
return getFunctionWithArguments(name, arguments);
}
return getFunction(selector, arguments);
}
/**
* ADVANCED:
* This can be used for accessing user defined functions that have arguments.
* The operator must be defined in ExpressionOperator to be able to reference it.
* @see ExpressionOperator
* <p> Example:
* <blockquote><pre>
* List arguments = new ArrayList();
* arguments.add("blee");
* builder.get("name").getFunction(MyFunctions.FOO_BAR, arguments).greaterThan(100);
* </pre></blockquote>
*/
@Deprecated
public Expression getFunction(int selector, Vector arguments) {
return getFunction(selector, (List)arguments);
}
/**
* ADVANCED:
* Return a user defined function accepting the argument.
* The function is assumed to be a normal prefix function and will print like, UPPER(base).
* <p> Example:
* <blockquote><pre>
* builder.get("firstName").getFunction("UPPER");
* </pre></blockquote>
*/
public Expression getFunction(String functionName) {
ExpressionOperator anOperator = ExpressionOperator.simpleFunction(0, functionName);
return anOperator.expressionFor(this);
}
/**
* ADVANCED:
* Return a user defined function accepting the argument.
* The function is assumed to be a normal prefix function and will print like, CONCAT(base, argument).
*/
public Expression getFunction(String functionName, Object argument) {
ExpressionOperator anOperator = ExpressionOperator.simpleTwoArgumentFunction(0, functionName);
return anOperator.expressionFor(this, argument);
}
/**
* ADVANCED:
* Return a user defined function accepting all of the arguments.
* The function is assumed to be a normal prefix function like, CONCAT(base, value1, value2, value3, ...).
*/
@Deprecated
public Expression getFunctionWithArguments(String functionName, Vector arguments) {
return getFunctionWithArguments(functionName, (List)arguments);
}
/**
* ADVANCED:
* Return a user defined function accepting all of the arguments.
* The function is assumed to be a normal prefix function like, CONCAT(base, value1, value2, value3, ...).
*/
public Expression getFunctionWithArguments(String functionName, List arguments) {
ExpressionOperator anOperator = new ExpressionOperator();
anOperator.setType(ExpressionOperator.FunctionOperator);
Vector v = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(arguments.size());
v.add(functionName + "(");
for (int index = 0; index < arguments.size(); index++) {
v.add(", ");
}
v.add(")");
anOperator.printsAs(v);
anOperator.bePrefix();
anOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
return anOperator.expressionForArguments(this, arguments);
}
/**
* ADVANCED:
* Parse the SQL for parameter and return a custom function expression
* using a custom operator that will print itself as the SQL.
* Arguments are passed using '?', and must match the number of arguments.
*/
public Expression sql(String sql, List arguments) {
ExpressionOperator anOperator = new ExpressionOperator();
anOperator.setType(ExpressionOperator.FunctionOperator);
Vector v = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(arguments.size());
int start = 0;
int index = sql.indexOf('?');
while (index != -1) {
v.add(sql.substring(start, index));
start = index + 1;
index = sql.indexOf('?', start);
}
if (start <= sql.length()) {
v.add(sql.substring(start, sql.length()));
}
anOperator.printsAs(v);
anOperator.bePrefix();
anOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
return anOperator.expressionForArguments(this, arguments);
}
/**
* PUBLIC:
* Return an expression that wraps the inheritance type field in an expression.
* <p>Example:
* <blockquote><pre>
* builder.getClassForInheritance().equal(SmallProject.class);
* builder.anyOf("projects").getClassForInheritance().equal(builder.getParameter("projectClass"));
* </pre></blockquote>
*/
public Expression type() {
//Only valid on an ObjectExpression
return null;
}
/**
* INTERNAL:
*/
public String getName() {
return "";
}
/**
* INTERNAL:
* Most expression have operators, so this is just a convenience method.
*/
public ExpressionOperator getOperator() {
return null;
}
/**
* INTERNAL:
* Create a new expression tree with the named operator. Part of the implementation of user-level "get"
*/
public static ExpressionOperator getOperator(int selector) {
/*
* Get an operator based on a user defined function, if it exists.
*/
ExpressionOperator result = ExpressionOperator.getOperator(Integer.valueOf(selector));
if (result != null) {
return result;
}
/*
* Create an operator based on known selectors.
* This is actually a temporary object which we expect Platforms to supply later.
* @see org.eclipse.persistence.internal.expressions.CompoundExpression#initializePlatformOperator(DatabasePlatform platform)
* @see org.eclipse.persistence.internal.expressions.FunctionExpression#initializePlatformOperator(DatabasePlatform platform)
*/
result = ExpressionOperator.getInternalOperator(Integer.valueOf(selector));
if (result != null) {
return result;
}
// Create a default Function ExpressionOperator
result = new ExpressionOperator();
result.setSelector(selector);
result.setNodeClass(ClassConstants.FunctionExpression_Class);
return result;
}
/**
* INTERNAL:
* Return the tables that this node owns for purposes of table aliasing.
*/
public List<DatabaseTable> getOwnedTables() {
return null;
}
/**
* INTERNAL:
* Return an expression representing a parameter with the given name and type
*/
public Expression getParameter(String parameterName, Object type) {
return new ParameterExpression(parameterName, getBuilder(), type);
}
/**
* ADVANCED:
* Return an expression representing a parameter with the given name.
*/
public Expression getParameter(String parameterName) {
return new ParameterExpression(parameterName, getBuilder(), null);
}
/**
* ADVANCED:
* Return an expression representing a parameter with the given name.
*/
public Expression getParameter(DatabaseField field) {
return new ParameterExpression(field, getBuilder());
}
/**
* ADVANCED:
* Return an expression representing a property with the given name.
*/
public Expression getProperty(DatabaseField field) {
ParameterExpression paramExpression = new ParameterExpression(field, this);
paramExpression.setIsProperty(true);
return paramExpression;
}
/**
* INTERNAL:
*/
public AbstractSession getSession() {
return getBuilder().getSession();
}
/**
* ADVANCED: Return an expression representing a table in a data-level query.
* This is used internally in EclipseLink, or to construct queries involving
* fields and/or tables that are not mapped.
* <p> Example:
* <blockquote><pre>
* builder.getTable("PROJ_EMP").getField("TYPE").equal("S");
* </pre></blockquote>
*/
public Expression getTable(String tableName) {
DatabaseTable table = new DatabaseTable(tableName);
return getTable(table);
}
/**
* ADVANCED: Return an expression representing a table in a data-level query.
* This is used internally in EclipseLink, or to construct queries involving
* fields and/or tables that are not mapped.
* <p> Example:
* <blockquote><pre>
* builder.getTable(linkTable).getField("TYPE").equal("S");
* </pre></blockquote>
*/
public Expression getTable(DatabaseTable table) {
throw QueryException.illegalUseOfGetTable(table);
}
/**
* ADVANCED: Return an expression representing a sub-select in the from clause.
* <p> Example:
* <blockquote><pre>
* builder.getAlias(builder.subQuery(reportQuery)).get("type").equal("S");
* </pre></blockquote>
*/
public Expression getAlias(Expression subSelect) {
throw QueryException.illegalUseOfGetTable(subSelect);
}
/**
* INTERNAL:
* Return the aliases used. By default, return null, since we don't have tables.
*/
public TableAliasLookup getTableAliases() {
return null;
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
*/
public Expression greaterThan(byte theValue) {
return greaterThan(Byte.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
*/
public Expression greaterThan(char theChar) {
return greaterThan(Character.valueOf(theChar));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
*/
public Expression greaterThan(double theValue) {
return greaterThan(Double.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
*/
public Expression greaterThan(float theValue) {
return greaterThan(Float.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
*/
public Expression greaterThan(int theValue) {
return greaterThan(Integer.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
*/
public Expression greaterThan(long theValue) {
return greaterThan(Long.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receiver's value is greater than the other value.
* This is equivalent to the SQL {@literal ">"} operator.
*/
public Expression greaterThan(Object theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.GreaterThan);
return anOperator.expressionFor(this, theValue);
}
public Expression greaterThan(Expression theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.GreaterThan);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
*/
public Expression greaterThan(short theValue) {
return greaterThan(Short.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is equal to the other value.
* This is equivalent to the SQL "=" operator and Java "equals" method.
*/
public Expression greaterThan(boolean theBoolean) {
return greaterThan(Boolean.valueOf(theBoolean));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(byte theValue) {
return greaterThanEqual(Byte.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(char theChar) {
return greaterThanEqual(Character.valueOf(theChar));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(double theValue) {
return greaterThanEqual(Double.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(float theValue) {
return greaterThanEqual(Float.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(int theValue) {
return greaterThanEqual(Integer.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(long theValue) {
return greaterThanEqual(Long.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(Object theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.GreaterThanEqual);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(Expression theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.GreaterThanEqual);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(short theValue) {
return greaterThanEqual(Short.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is greater and equal to the other value.
* This is equivalent to the SQL {@literal ">="} operator.
*/
public Expression greaterThanEqual(boolean theBoolean) {
return greaterThanEqual(Boolean.valueOf(theBoolean));
}
/**
* ADVANCED:
* Answers true if <code>this</code> is to be queried as of a past time.
* @return false from <code>asOf(null); hasAsOfClause()</code>.
* @see #getAsOfClause
*/
public boolean hasAsOfClause() {
return false;
}
/**
* INTERNAL:
* Answers if the database tables associated with this expression have been
* aliased. This insures the same tables are not aliased twice.
*/
public boolean hasBeenAliased() {
return false;
}
/**
* PUBLIC:
* Function, returns binary array value for the hex string.
*/
public Expression hexToRaw() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.HexToRaw);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function return a specific value if item returned from the
* query is null. Equivalent of the oracle NVL function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("name").ifNull("no-name")
* Java: NA
* SQL: NVL(name, 'no-name')
* </pre></blockquote>
*/
public Expression ifNull(Object nullValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Nvl);
return anOperator.expressionFor(this, nullValue);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(byte[] theBytes) {
List values = new ArrayList(theBytes.length);
for (int index = 0; index < theBytes.length; index++) {
values.add(Byte.valueOf(theBytes[index]));
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(char[] theChars) {
List values = new ArrayList(theChars.length);
for (int index = 0; index < theChars.length; index++) {
values.add(Character.valueOf(theChars[index]));
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(double[] theDoubles) {
List values = new ArrayList(theDoubles.length);
for (int index = 0; index < theDoubles.length; index++) {
values.add(Double.valueOf(theDoubles[index]));
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(float[] theFloats) {
List values = new ArrayList(theFloats.length);
for (int index = 0; index < theFloats.length; index++) {
values.add(Float.valueOf(theFloats[index]));
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(int[] theInts) {
List values = new ArrayList(theInts.length);
for (int index = 0; index < theInts.length; index++) {
values.add(Integer.valueOf(theInts[index]));
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(long[] theLongs) {
List values = new ArrayList(theLongs.length);
for (int index = 0; index < theLongs.length; index++) {
values.add(Long.valueOf(theLongs[index]));
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(Object[] theObjects) {
List values = new ArrayList(theObjects.length);
for (int index = 0; index < theObjects.length; index++) {
values.add(theObjects[index]);
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(short[] theShorts) {
List values = new ArrayList(theShorts.length);
for (int index = 0; index < theShorts.length; index++) {
values.add(Short.valueOf(theShorts[index]));
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression in(boolean[] theBooleans) {
List values = new ArrayList(theBooleans.length);
for (int index = 0; index < theBooleans.length; index++) {
values.add(Boolean.valueOf(theBooleans[index]));
}
return in(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").in(ages)
* Java: ages.contains(employee.getAge())
* SQL: AGE IN (55, 18, 30)
* </pre></blockquote>
*/
public Expression in(Collection theObjects) {
return in(new CollectionExpression(theObjects, this));
}
public Expression in(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.In);
return anOperator.expressionFor(this, arguments);
}
public Expression in(ReportQuery subQuery) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.InSubQuery);
return anOperator.expressionFor(this, subQuery);
}
/*
* PUBLIC:
* Index method could be applied to QueryKeyExpression corresponding to CollectionMapping
* that has non-null listOrderField (the field holding the index values).
* <p>Example:
* <blockquote><pre>
* ReportQuery query = new ReportQuery();
* query.setReferenceClass(Employee.class);
* ExpressionBuilder builder = query.getExpressionBuilder();
* Expression firstNameJohn = builder.get("firstName").equal("John");
* Expression anyOfProjects = builder.anyOf("projects");
* Expression exp = firstNameJohn.and(anyOfProjects.index().between(2, 4));
* query.setSelectionCriteria(exp);
* query.addAttribute("projects", anyOfProjects);
*
* SELECT DISTINCT t0.PROJ_ID, t0.PROJ_TYPE, t0.DESCRIP, t0.PROJ_NAME, t0.LEADER_ID, t0.VERSION, t1.PROJ_ID, t1.BUDGET, t1.MILESTONE
* FROM OL_PROJ_EMP t4, OL_SALARY t3, OL_EMPLOYEE t2, OL_LPROJECT t1, OL_PROJECT t0
* WHERE ((((t2.F_NAME = 'John') AND (t4.PROJ_ORDER BETWEEN 2 AND 4)) AND (t3.OWNER_EMP_ID = t2.EMP_ID)) AND
* (((t4.EMP_ID = t2.EMP_ID) AND (t0.PROJ_ID = t4.PROJ_ID)) AND (t1.PROJ_ID (+) = t0.PROJ_ID)))
* </pre></blockquote>
*/
public Expression index() {
throw QueryException.indexRequiresQueryKeyExpression(this);
}
/**
* PUBLIC:
* Function, returns the integer index of the substring within the source string.
*/
public Expression indexOf(Object substring) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Instring);
return anOperator.expressionFor(this, substring);
}
/**
* INTERNAL:
*/
public boolean isClassTypeExpression(){
return false;
}
/**
* INTERNAL:
*/
public boolean isCompoundExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isConstantExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isDataExpression() {
return false;
}
/**
* PUBLIC: A logical expression for the collection <code>attributeName</code>
* being empty.
* Equivalent to <code>size(attributeName).equal(0)</code>
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.isEmpty("phoneNumbers")
* Java: employee.getPhoneNumbers().size() == 0
* SQL: SELECT ... FROM EMP t0 WHERE (
* (SELECT COUNT(*) FROM PHONE t1 WHERE (t0.EMP_ID = t1.EMP_ID)) = 0)
* </pre></blockquote>
* This is a case where a fast operation in java does not translate to an
* equally fast operation in SQL, requiring a correlated subselect.
* @see #size(java.lang.String)
*/
public Expression isEmpty(String attributeName) {
return size(attributeName).equal(0);
}
/**
* INTERNAL:
*/
public boolean isExpressionBuilder() {
return false;
}
/**
* INTERNAL:
*/
public boolean isFieldExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isFunctionExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isLiteralExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isLogicalExpression() {
return false;
}
/**
* PUBLIC:
* Compare to null.
*/
public Expression isNull() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.IsNull);
return anOperator.expressionFor(this);
}
/**
* INTERNAL:
*/
public boolean isObjectExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isParameterExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isQueryKeyExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isRelationExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isSubSelectExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isTableExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isTreatExpression() {
return false;
}
/**
* INTERNAL:
*/
public boolean isMapEntryExpression(){
return false;
}
/**
* INTERNAL:
* Subclasses implement (isParameterExpression() || isConstantExpression())
*/
public boolean isValueExpression() {
return false;
}
/**
* INTERNAL:
* For iterating using an inner class
*/
public void iterateOn(ExpressionIterator iterator) {
iterator.iterate(this);
}
/**
* PUBLIC:
* Function, returns the date with the last date in the months of this source date.
*/
public Expression lastDay() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LastDay);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function, returns the string padded with the substring to the size.
*/
public Expression leftPad(int size, Object substring) {
return leftPad(Integer.valueOf(size), substring);
}
/**
* PUBLIC:
* Function, returns the string padded with the substring to the size.
*/
public Expression leftPad(Object size, Object substring) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LeftPad);
List args = new ArrayList(2);
args.add(size);
args.add(substring);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Function, returns the string left trimmed for white space.
*/
public Expression leftTrim() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LeftTrim);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function, returns the string with the substring trimed from the left.
*/
public Expression leftTrim(Object substring) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LeftTrim2);
return anOperator.expressionFor(this, substring);
}
/**
* PUBLIC:
* Function, returns the size of the string.
*/
public Expression length() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Length);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(byte theValue) {
return lessThan(Byte.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(char theChar) {
return lessThan(Character.valueOf(theChar));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(double theValue) {
return lessThan(Double.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(float theValue) {
return lessThan(Float.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(int theValue) {
return lessThan(Integer.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(long theValue) {
return lessThan(Long.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(Object theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LessThan);
return anOperator.expressionFor(this, theValue);
}
public Expression lessThan(Expression theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LessThan);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(short theValue) {
return lessThan(Short.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than the other value.
* This is equivalent to the SQL {@literal "<"} operator.
*/
public Expression lessThan(boolean theBoolean) {
return lessThan(Boolean.valueOf(theBoolean));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(byte theValue) {
return lessThanEqual(Byte.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(char theChar) {
return lessThanEqual(Character.valueOf(theChar));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(double theValue) {
return lessThanEqual(Double.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(float theValue) {
return lessThanEqual(Float.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(int theValue) {
return lessThanEqual(Integer.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(long theValue) {
return lessThanEqual(Long.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(Object theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LessThanEqual);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(Expression theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LessThanEqual);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(short theValue) {
return lessThanEqual(Short.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is less than and equal to the other value.
* This is equivalent to the SQL {@literal "<="} operator.
*/
public Expression lessThanEqual(boolean theBoolean) {
return lessThanEqual(Boolean.valueOf(theBoolean));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is like other value.
* This is equivalent to the SQL "LIKE" operator that except wildcards.
* The character "%" means any sequence of characters and the character "_" mean any character.
* i.e. "B%" == "Bob", "B_B" == "BOB"
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").like("B%")
* Java: NA
* SQL: F_NAME LIKE 'B%'
* </pre></blockquote>
*/
public Expression like(String value) {
return like(new ConstantExpression(value, this));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is like other value.
* This is equivalent to the SQL "LIKE ESCAPE" operator that except wildcards.
* The character "%" means any sequence of characters and the character "_" mean any character.
* i.e. "B%" == "Bob", "B_B" == "BOB"
* The escape sequence specifies a set of characters the may be used to indicate that
* an one of the wildcard characters should be interpreted literally.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").like("B\_SMITH", "\")
* Java: NA
* SQL: F_NAME LIKE 'B\_SMITH ESCAPE '\''
* </pre></blockquote>
*/
public Expression like(String value, String escapeSequence) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LikeEscape);
List args = new ArrayList(2);
args.add(value);
args.add(escapeSequence);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is like other value.
* This is equivalent to the SQL "LIKE" operator that except wildcards.
* The character "%" means any sequence of characters and the character "_" mean any character.
* i.e. "B%" == "Bob", "B_B" == "BOB"
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").like("B%")
* Java: NA
* SQL: F_NAME LIKE 'B%'
* </pre></blockquote>
*/
public Expression like(Expression argument) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Like);
return anOperator.expressionFor(this, argument);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value matches the regular expression.
* This uses the databases support for regular expression.
* Regular expressions are similar to LIKE except support a much larger scope of comparisons.
* i.e. "^B.*" == "Bob", "^B.B$" == "BOB"
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").regexp("^B.*")
* Java: Pattern.compile("^B.*").matcher(employee.getFirstName()).matches()
* SQL: F_NAME REGEXP '^B.*'
* </pre></blockquote>
*/
public Expression regexp(String regexp) {
return regexp(new ConstantExpression(regexp, this));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value matches the regular expression.
* This uses the databases support for regular expression.
* Regular expressions are similar to LIKE except support a much larger scope of comparisons.
* i.e. "^B.*" == "Bob", "^B.B$" == "BOB"
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").regexp("^B.*")
* Java: Pattern.compile("^B.*").matcher(employee.getFirstName()).matches()
* SQL: F_NAME REGEXP '^B.*'
* </pre></blockquote>
*/
public Expression regexp(Expression regexp) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Regexp);
return anOperator.expressionFor(this, regexp);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is like other value.
* This is equivalent to the SQL "LIKE ESCAPE" operator that except wildcards.
* The character "%" means any sequence of characters and the character "_" mean any character.
* i.e. "B%" == "Bob", "B_B" == "BOB"
* The escape sequence specifies a set of characters the may be used to indicate that
* an one of the wildcard characters should be interpreted literally.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").like("B\_SMITH", "\")
* Java: NA
* SQL: F_NAME LIKE 'B\_SMITH ESCAPE '\''
* </pre></blockquote>
*/
public Expression like(Expression value, Expression escapeSequence) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.LikeEscape);
List args = new ArrayList(2);
args.add(value);
args.add(escapeSequence);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is like the other value, ignoring case.
* This is a case in-sensitive like.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").likeIgnoreCase("%Bob%")
* Java: none
* SQL: UPPER(F_NAME) LIKE 'BOB'
* </pre></blockquote>
*/
public Expression likeIgnoreCase(String theValue) {
if (shouldUseUpperCaseForIgnoreCase) {
return toUpperCase().like(theValue.toUpperCase());
} else {
return toLowerCase().like(theValue.toLowerCase());
}
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is like the other value, ignoring case.
* This is a case in-sensitive like.
*/
public Expression likeIgnoreCase(Expression theValue) {
if (shouldUseUpperCaseForIgnoreCase) {
return toUpperCase().like(theValue.toUpperCase());
} else {
return toLowerCase().like(theValue.toLowerCase());
}
}
/**
* PUBLIC:
* Function, returns the position of <code>str</code> in <code>this</code>
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").locate("ob")
* Java: employee.getFirstName().indexOf("ob") + 1
* SQL: LOCATE('ob', t0.F_NAME)
* </pre></blockquote>
* <p>
* Note that while in String.locate(str) -1 is returned if not found, and the
* index starting at 0 if found, in SQL it is 0 if not found, and the index
* starting at 1 if found.
*/
public Expression locate(Object str) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Locate);
List args = new ArrayList(1);
args.add(str);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Function, returns the position of <code>str</code> in <code>this</code>,
* starting the search at <code>fromIndex</code>.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").locate("ob", 1)
* Java: employee.getFirstName().indexOf("ob", 1) + 1
* SQL: LOCATE('ob', t0.F_NAME, 1)
* </pre></blockquote>
* <p>
* Note that while in String.locate(str) -1 is returned if not found, and the
* index starting at 0 if found, in SQL it is 0 if not found, and the index
* starting at 1 if found.
*/
public Expression locate(String str, int fromIndex) {
return locate(str, Integer.valueOf(fromIndex));
}
/**
* PUBLIC:
* Function, returns the position of <code>str</code> in <code>this</code>,
* starting the search at <code>fromIndex</code>.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").locate("ob", 1)
* Java: employee.getFirstName().indexOf("ob", 1) + 1
* SQL: LOCATE('ob', t0.F_NAME, 1)
* </pre></blockquote>
* <p>
* Note that while in String.locate(str) -1 is returned if not found, and the
* index starting at 0 if found, in SQL it is 0 if not found, and the index
* starting at 1 if found.
*/
public Expression locate(Object str, Object fromIndex) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Locate2);
List args = new ArrayList(2);
args.add(str);
args.add(fromIndex);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* This represents the aggregate function Maximum. Can be used only within Report Queries.
*/
public Expression maximum() {
return getFunction(ExpressionOperator.Maximum);
}
/**
* PUBLIC:
* This represents the aggregate function Minimum. Can be used only within Report Queries.
*/
public Expression minimum() {
return getFunction(ExpressionOperator.Minimum);
}
/**
* PUBLIC:
* Function, returns the decimal number of months between the two dates.
*/
public Expression monthsBetween(Object otherDate) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.MonthsBetween);
return anOperator.expressionFor(this, otherDate);
}
/**
* PUBLIC:
* Return a Map.Entry containing the key and the value from a mapping that maps to a java.util.Map
* This expression can only be used as a return value in a ReportQuery and cannot be used as part of
* the WHERE clause in any query
*
* EclipseLink: eb.get("mapAttribute").mapEntry()
* @return
*/
public Expression mapEntry(){
MapEntryExpression expression = new MapEntryExpression(this);
expression.returnMapEntry();
return expression;
}
/**
* PUBLIC:
* Return the key from a mapping that maps to a java.util.Map
* This expression can be used either in as a return value in a ReportQuery or in the WHERE clause in a query
*
* EclipseLink: eb.get("mapAttribute").mapKey()
* @return
*/
public Expression mapKey(){
return new MapEntryExpression(this);
}
/**
* PUBLIC:
* funcation return a date converted to a new timezone. Equivalent of the Oracle NEW_TIME function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("date").newTime("EST", "PST")
* Java: NA
* SQL: NEW_TIME(date, 'EST', 'PST')
* </pre></blockquote>
*/
public Expression newTime(String timeZoneFrom, String timeZoneTo) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NewTime);
List args = new ArrayList(2);
args.add(timeZoneFrom);
args.add(timeZoneTo);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Function, returns the date with the next day from the source date as the day name given.
*/
public Expression nextDay(Object dayName) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NextDay);
return anOperator.expressionFor(this, dayName);
}
/**
* PUBLIC: Returns an expression equivalent to none of <code>attributeName</code>
* holding true for <code>criteria</code>.
* <p>
* For every expression with an anyOf, its negation has either an allOf or a
* noneOf. The following two examples will illustrate as the second is the
* negation of the first:
* <p>
* AnyOf Example: Employees with a '613' area code phone number.
* <blockquote><pre>
* ReadAllQuery query = new ReadAllQuery(Employee.class);
* ExpressionBuilder employee = new ExpressionBuilder();
* Expression exp = employee.anyOf("phoneNumbers").get("areaCode").equal("613");
* </pre></blockquote>
* <p>
* NoneOf Example: Employees with no '613' area code phone numbers.
* <blockquote><pre>
* ExpressionBuilder employee = new ExpressionBuilder();
* ExpressionBuilder phones = new ExpressionBuilder();
* Expression exp = employee.noneOf("phoneNumbers", phones.get("areaCode").equal("613"));
* SQL:
* SELECT ... EMPLOYEE t0 WHERE NOT EXISTS (SELECT ... PHONE t1 WHERE
* (t0.EMP_ID = t1.EMP_ID) AND (t1.AREACODE = '613'))
* </pre></blockquote>
* <p>
* noneOf is the universal counterpart to the existential anyOf. To have the
* condition evaluated for each instance it must be put inside of a subquery,
* which can be expressed as not exists (any of attributeName some condition).
* (All x such that !y = !Exist x such that y).
* <p>Likewise the syntax employee.noneOf("phoneNumbers").get("areaCode").equal("613")
* is not supported for the <code>equal</code> must go inside a subQuery.
* <p>
* This method saves you from writing the sub query yourself. The above is
* equivalent to the following expression:
* <blockquote><pre>
* ExpressionBuilder employee = new ExpressionBuilder();
* ExpressionBuilder phone = new ExpressionBuilder();
* ReportQuery subQuery = new ReportQuery(Phone.class, phone);
* subQuery.retreivePrimaryKeys();
* subQuery.setSelectionCriteria(phone.equal(employee.anyOf("phoneNumbers").and(
* phone.get("areaCode").equal("613")));
* Expression exp = employee.notExists(subQuery);
* </pre></blockquote>
* @param criteria must have its own builder, as it will become the
* separate selection criteria of a subQuery.
* @return a notExists subQuery expression
*/
public Expression noneOf(String attributeName, Expression criteria) {
ReportQuery subQuery = new ReportQuery();
subQuery.setShouldRetrieveFirstPrimaryKey(true);
Expression builder = criteria.getBuilder();
criteria = builder.equal(anyOf(attributeName)).and(criteria);
subQuery.setSelectionCriteria(criteria);
return notExists(subQuery);
}
/**
* INTERNAL:
* Normalize into a structure that is printable.
* Also compute printing information such as outer joins.
*/
public Expression normalize(ExpressionNormalizer normalizer) {
//This class has no validation but we should still make the method call for consistency
//bug # 2956674
//validation is moved into normalize to ensure that expressions are valid before we attempt to work with them
validateNode();
return this;
}
/**
* PUBLIC:
* Return an expression that is the boolean logical negation of the expression.
* This is equivalent to the SQL "NOT" operator and the Java "!" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").equal(24).not()
* Java: (! (employee.getAge() == 24))
* SQL: NOT (AGE = 24)
* </pre></blockquote>
*/
public Expression not() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Not);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(byte leftValue, byte rightValue) {
return notBetween(Byte.valueOf(leftValue), Byte.valueOf(rightValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(char leftChar, char rightChar) {
return notBetween(Character.valueOf(leftChar), Character.valueOf(rightChar));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(double leftValue, double rightValue) {
return notBetween(Double.valueOf(leftValue), Double.valueOf(rightValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(float leftValue, float rightValue) {
return notBetween(Float.valueOf(leftValue), Float.valueOf(rightValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(int leftValue, int rightValue) {
return notBetween(Integer.valueOf(leftValue), Integer.valueOf(rightValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(long leftValue, long rightValue) {
return notBetween(Long.valueOf(leftValue), Long.valueOf(rightValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(Object leftValue, Object rightValue) {
return between(leftValue, rightValue).not();
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(Expression leftExpression, Expression rightExpression) {
return between(leftExpression, rightExpression).not();
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not between two other values.
* Equivalent to between negated.
* @see #between(Object, Object)
*/
public Expression notBetween(short leftValue, short rightValue) {
return notBetween(Short.valueOf(leftValue), Short.valueOf(rightValue));
}
/**
* PUBLIC: A logical expression for the collection <code>attributeName</code>
* not being empty.
* Equivalent to <code>size(attributeName).greaterThan(0)</code>
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.notEmpty("phoneNumbers")
* Java: employee.getPhoneNumbers().size() {@literal >} 0
* SQL: SELECT ... FROM EMP t0 WHERE (
* (SELECT COUNT(*) FROM PHONE t1 WHERE (t0.EMP_ID = t1.EMP_ID)) {@literal >} 0)
* </pre></blockquote>
* This is a case where a fast operation in java does not translate to an
* equally fast operation in SQL, requiring a correlated subselect.
* @see #size(java.lang.String)
*/
public Expression notEmpty(String attributeName) {
return size(attributeName).greaterThan(0);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(byte theValue) {
return notEqual(Byte.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(char theChar) {
return notEqual(Character.valueOf(theChar));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(double theValue) {
return notEqual(Double.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(float theValue) {
return notEqual(Float.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(int theValue) {
return notEqual(Integer.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(long theValue) {
return notEqual(Long.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(Object theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotEqual);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(Expression theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotEqual);
return anOperator.expressionFor(this, theValue);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(short theValue) {
return notEqual(Short.valueOf(theValue));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not equal to the other value.
* This is equivalent to the SQL {@literal "<>"} operator
*
* @see #equal(Object)
*/
public Expression notEqual(boolean theBoolean) {
return notEqual(Boolean.valueOf(theBoolean));
}
/**
* PUBLIC:
* Return a sub query expression.
* A sub query using a report query to define a subselect within another queries expression or select's where clause.
* The sub query (the report query) will use its own expression builder be can reference expressions from the base expression builder.
* <p>Example:
* <blockquote><pre>
* ExpressionBuilder builder = new ExpressionBuilder();
* ReportQuery subQuery = new ReportQuery(Employee.class, new ExpressionBuilder());
* subQuery.setSelectionCriteria(subQuery.getExpressionBuilder().get("name").equal(builder.get("name")));
* builder.notExists(subQuery);
* </pre></blockquote>
*/
public Expression notExists(ReportQuery subQuery) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotExists);
return anOperator.expressionFor(subQuery(subQuery));
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(byte[] theBytes) {
List values = new ArrayList(theBytes.length);
for (int index = 0; index < theBytes.length; index++) {
values.add(Byte.valueOf(theBytes[index]));
}
return notIn(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(char[] theChars) {
List values = new ArrayList(theChars.length);
for (int index = 0; index < theChars.length; index++) {
values.add(Character.valueOf(theChars[index]));
}
return notIn(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(double[] theDoubles) {
List values = new ArrayList(theDoubles.length);
for (int index = 0; index < theDoubles.length; index++) {
values.add(Double.valueOf(theDoubles[index]));
}
return notIn(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(float[] theFloats) {
List values = new ArrayList(theFloats.length);
for (int index = 0; index < theFloats.length; index++) {
values.add(Float.valueOf(theFloats[index]));
}
return notIn(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(int[] theInts) {
List values = new ArrayList(theInts.length);
for (int index = 0; index < theInts.length; index++) {
values.add(Integer.valueOf(theInts[index]));
}
return notIn(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(long[] theLongs) {
List values = new ArrayList(theLongs.length);
for (int index = 0; index < theLongs.length; index++) {
values.add(Long.valueOf(theLongs[index]));
}
return notIn(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(Object[] theObjects) {
List values = new ArrayList(theObjects.length);
for (int index = 0; index < theObjects.length; index++) {
values.add(theObjects[index]);
}
return notIn(values);
}
public Expression notIn(ReportQuery subQuery) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotInSubQuery);
return anOperator.expressionFor(this, subQuery);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(short[] theShorts) {
List values = new ArrayList(theShorts.length);
for (int index = 0; index < theShorts.length; index++) {
values.add(Short.valueOf(theShorts[index]));
}
return notIn(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression notIn(boolean[] theBooleans) {
List values = new ArrayList(theBooleans.length);
for (int index = 0; index < theBooleans.length; index++) {
values.add(Boolean.valueOf(theBooleans[index]));
}
return notIn(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* The collection can be a collection of constants or expressions.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").in(ages)
* Java: ages.contains(employee.getAge())
* SQL: AGE IN (55, 18, 30)
* </pre></blockquote>
*/
public Expression notIn(Collection theObjects) {
return notIn(new CollectionExpression(theObjects, this));
}
public Expression notIn(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotIn);
return anOperator.expressionFor(this, arguments);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not like the other value.
* Equivalent to like negated.
* @see #like(String)
*/
public Expression notLike(String aString) {
return notLike(new ConstantExpression(aString, this));
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not like the other value.
* Equivalent to like negated.
* @see #like(String)
*/
public Expression notLike(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotLike);
return anOperator.expressionFor(this, arguments);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not like the other value.
* Equivalent to like negated.
* @param value string to compare
* @param escapeSequence the escape character to use
* @see #like(String)
*/
public Expression notLike(String value, String escapeSequence) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotLikeEscape);
List args = new ArrayList(2);
args.add(value);
args.add(escapeSequence);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Return an expression that compares if the receivers value is not like the other value.
* Equivalent to like negated.
* @param value string to compare
* @param escapeSequence the escape character to use
* @see #like(String)
*/
public Expression notLike(Expression value, Expression escapeSequence) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotLikeEscape);
List args = new ArrayList(2);
args.add(value);
args.add(escapeSequence);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Return an expression representing a comparison to null
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").notNull()
* Java: employee.getAge() != null
* SQL: AGE IS NOT NULL
* </pre></blockquote>
*/
public Expression notNull() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.NotNull);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Return an expression that is the boolean logical combination of both expressions.
* This is equivalent to the SQL "OR" operator and the Java "||" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").equal("Bob").OR(employee.get("lastName").equal("Smith"))
* Java: (employee.getFirstName().equals("Bob")) || (employee.getLastName().equals("Smith"))
* SQL: F_NAME = 'Bob' OR L_NAME = 'Smith'
* </pre></blockquote>
*/
public Expression or(Expression theExpression) {
// Allow ands with null.
if (theExpression == null) {
return this;
}
ExpressionBuilder base = getBuilder();
Expression expressionToUse = theExpression;
// Ensure the same builder, unless a parralel query is used.
if ((theExpression.getBuilder() != base) && (theExpression.getBuilder().getQueryClass() == null)) {
expressionToUse = theExpression.rebuildOn(base);
}
if (base == this) {// Allow and to be sent to the builder.
return expressionToUse;
}
ExpressionOperator anOperator = getOperator(ExpressionOperator.Or);
return anOperator.expressionFor(this, expressionToUse);
}
/**
* INTERNAL:
*/
public Expression performOperator(ExpressionOperator anOperator, List args) {
return anOperator.expressionForArguments(this, args);
}
protected void postCopyIn(Map alreadyDone) {
}
/**
* ADVANCED:
* Inserts the SQL as is directly into the expression.
* The sql will be printed immediately after (postfixed to) the sql for
* <b>this</b>.
* Warning: Allowing an unverified SQL string to be passed into this
* method makes your application vulnerable to SQL injection attacks.
*/
public Expression postfixSQL(String sqlString) {
ExpressionOperator anOperator = new ExpressionOperator();
anOperator.setType(ExpressionOperator.FunctionOperator);
Vector v = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(1);
v.add(sqlString);
anOperator.printsAs(v);
anOperator.bePostfix();
anOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
return anOperator.expressionFor(this);
}
/**
* ADVANCED:
* Insert the SQL as is directly into the expression.
* The sql will be printed immediately before (prefixed to) the sql for
* <b>this</b>.
* Warning: Allowing an unverified SQL string to be passed into this
* method makes your application vulnerable to SQL injection attacks.
*/
public Expression prefixSQL(String sqlString) {
ExpressionOperator anOperator = new ExpressionOperator();
anOperator.setType(ExpressionOperator.FunctionOperator);
Vector v = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(1);
v.add(sqlString);
anOperator.printsAs(v);
anOperator.bePrefix();
anOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
return anOperator.expressionFor(this);
}
/**
* INTERNAL:
* Print SQL
*/
public abstract void printSQL(ExpressionSQLPrinter printer);
/**
* INTERNAL:
* Print java for project class generation
*/
public void printJava(ExpressionJavaPrinter printer) {
//do nothing
}
/**
* INTERNAL:
* This expression is built on a different base than the one we want. Rebuild it and
* return the root of the new tree
* If receiver is a complex expression, use cloneUsing(newBase) instead.
* @see #cloneUsing(Expression newBase)
*/
public abstract Expression rebuildOn(Expression newBase);
/**
* INTERNAL:
* Search the tree for any expressions (like SubSelectExpressions) that have been
* built using a builder that is not attached to the query. This happens in case of an Exists
* call using a new ExpressionBuilder(). This builder needs to be replaced with one from the query.
*/
public abstract void resetPlaceHolderBuilder(ExpressionBuilder queryBuilder);
/**
* ADVANCED:
* For Object-relational support.
*/
public Expression ref() {
return getFunction(ExpressionOperator.Ref);
}
protected Expression registerIn(Map alreadyDone) {
Expression copy = shallowClone();
alreadyDone.put(this, copy);
copy.postCopyIn(alreadyDone);
return copy;
}
/**
* PUBLIC:
* Function, returns the string with occurances of the first substring replaced with the second substring.
*/
public Expression replace(Object stringToReplace, Object stringToReplaceWith) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Replace);
List args = new ArrayList(2);
args.add(stringToReplace);
args.add(stringToReplaceWith);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* return the result of this query repeated a given number of times.
* Equivalent of the Sybase REPLICATE function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("name").replicate(2)
* Java: NA
* SQL: REPLICATE(name, 2)
* </pre></blockquote>
*/
public Expression replicate(int constant) {
return replicate(Integer.valueOf(constant));
}
/**
* PUBLIC:
* return the result of this query repeated a given number of times.
* Equivalent of the Sybase REPLICATE function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("name").replicate(2)
* Java: NA
* SQL: REPLICATE(name, 2)
* </pre></blockquote>
*/
public Expression replicate(Object theValue) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Replicate);
return anOperator.expressionFor(this, theValue);
}
/**
* Reset cached information here so that we can be sure we're accurate.
*/
protected void resetCache() {
}
/**
* PUBLIC:
* Function return the reverse of the query result. Equivalent of the
* Sybase REVERSE function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("name").reverse()
* Java: NA
* SQL: REVERSE(name)
* </pre></blockquote>
*/
public Expression reverse() {
return getFunction(ExpressionOperator.Reverse);
}
/**
* PUBLIC:
* Function return a given number of characters starting at the
* right of a string. Equivalent to the Sybase RIGHT function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("name").right(2)
* Java: NA
* SQL: RIGHT(name, 2)
* </pre></blockquote>
*/
public Expression right(int characters) {
return right(Integer.valueOf(characters));
}
/**
* PUBLIC:
* Function return a given number of characters starting at the
* right of a string. Equivalent to the Sybase RIGHT function
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("name").right(2)
* Java: NA
* SQL: RIGHT(name, 2)
* </pre></blockquote>
*/
public Expression right(Object characters) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Right);
return anOperator.expressionFor(this, characters);
}
/**
* PUBLIC:
* Function, returns the string padded with the substring to the size.
*/
public Expression rightPad(int size, Object substring) {
return rightPad(Integer.valueOf(size), substring);
}
/**
* PUBLIC:
* Function, returns the string padded with the substring to the size.
*/
public Expression rightPad(Object size, Object substring) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.RightPad);
List args = new ArrayList(2);
args.add(size);
args.add(substring);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Function, returns the string right trimmed for white space.
*/
public Expression rightTrim() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.RightTrim);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function, returns the string with the substring trimed from the right.
*/
public Expression rightTrim(Object substring) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.RightTrim2);
return anOperator.expressionFor(this, substring);
}
/**
* PUBLIC:
* Function, returns the date rounded to the year, month or day.
*/
public Expression roundDate(Object yearOrMonthOrDayRoundToken) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.RoundDate);
return anOperator.expressionFor(this, yearOrMonthOrDayRoundToken);
}
/**
* PUBLIC:
* Return whether this expression should be included in the SELECT clause if it is used
* in an ORDER BY clause
*/
public boolean selectIfOrderedBy() {
return selectIfOrderedBy;
}
/**
* INTERNAL:
* Set the local base expression, ie the one on the other side of the operator
* Most types will ignore this, since they don't need it.
*/
public void setLocalBase(Expression exp) {
}
/**
* PUBLIC:
* Set whether this expression should be included in the SELECT clause of a query
* that uses it in the ORDER BY clause.
*
* @param selectIfOrderedBy
*/
public void setSelectIfOrderedBy(boolean selectIfOrderedBy) {
this.selectIfOrderedBy = selectIfOrderedBy;
}
/**
* INTERNAL:
*/
public Expression shallowClone() {
Expression result = null;
try {
result = (Expression)super.clone();
} catch (CloneNotSupportedException exception) {
throw new InternalError(exception.toString());
}
return result;
}
/**
* PUBLIC: A logical expression for the size of collection <code>attributeName</code>.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.size("phoneNumbers")
* Java: employee.getPhoneNumbers().size()
* SQL: SELECT ... FROM EMP t0 WHERE ...
* (SELECT COUNT(*) FROM PHONE t1 WHERE (t0.EMP_ID = t1.EMP_ID))
* </pre></blockquote>
* This is a case where a fast operation in java does not translate to an
* equally fast operation in SQL, requiring a correlated subselect.
*/
public Expression size(String attributeName) {
return SubSelectExpression.createSubSelectExpressionForCount(this, this, attributeName, null);
}
/**
* PUBLIC: A logical expression for the size of collection expression.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.size(Class returnType)
* Java: employee.getPhoneNumbers().size()
* SQL: SELECT ... FROM EMP t0 WHERE ...
* (SELECT COUNT(*) FROM PHONE t1 WHERE (t0.EMP_ID = t1.EMP_ID))
* </pre></blockquote>
* This is a case where a fast operation in java does not translate to an
* equally fast operation in SQL, requiring a correlated subselect.
*/
public Expression size(Class returnType) {
if (((BaseExpression)this).getBaseExpression() == null){
return SubSelectExpression.createSubSelectExpressionForCount(this, this, null, returnType);
}
return SubSelectExpression.createSubSelectExpressionForCount(((BaseExpression)this).getBaseExpression(), this, null, returnType);
}
/**
* PUBLIC:
* This represents the aggregate function StandardDeviation. Can be used only within Report Queries.
*/
public Expression standardDeviation() {
return getFunction(ExpressionOperator.StandardDeviation);
}
/**
* PUBLIC:
* Return a sub query expression.
* A sub query using a report query to define a subselect within another queries expression or select's where clause.
* The sub query (the report query) will use its own expression builder be can reference expressions from the base expression builder.
* <p>Example:
* <blockquote><pre>
* ExpressionBuilder builder = new ExpressionBuilder();
* ReportQuery subQuery = new ReportQuery(Employee.class, new ExpressionBuilder());
* subQuery.addMaximum("salary");
* builder.get("salary").equal(builder.subQuery(subQuery));
* </pre></blockquote>
*/
public Expression subQuery(ReportQuery subQuery) {
return new SubSelectExpression(subQuery, this);
}
/**
* PUBLIC:
* Function, returns the substring from the source string.
* EclipseLink: employee.get("firstName").substring(1, 2)
* Java: NA
* SQL: SUBSTR(FIRST_NAME, 1, 2)
*/
public Expression substring(int startPosition, int size) {
return substring(Integer.valueOf(startPosition), Integer.valueOf(size));
}
/**
* PUBLIC:
* Function, returns the substring from the source string.
* EclipseLink: employee.get("firstName").substring(1, 2)
* Java: NA
* SQL: SUBSTR(FIRST_NAME, 1, 2)
*/
public Expression substring(Object startPosition, Object size) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Substring);
List args = new ArrayList(2);
args.add(startPosition);
args.add(size);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Function, returns the substring from the source string.
* EclipseLink: employee.get("firstName").substring(1)
* Java: NA
* SQL: SUBSTR(FIRST_NAME, 1)
*/
public Expression substring(int startPosition) {
return substring(Integer.valueOf(startPosition));
}
/**
* PUBLIC:
* Function, returns the substring from the source string.
* EclipseLink: employee.get("firstName").substring(1)
* Java: NA
* SQL: SUBSTR(FIRST_NAME, 1)
*/
public Expression substring(Object startPosition) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.SubstringSingleArg);
List args = new ArrayList(1);
args.add(startPosition);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* This represents the aggregate function Sum. Can be used only within Report Queries.
*/
public Expression sum() {
return getFunction(ExpressionOperator.Sum);
}
/**
* PUBLIC:
* Function, returns the single character string with the ascii or character set value.
*/
public Expression toCharacter() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Chr);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function, returns date from the string using the default format.
*/
public Expression toDate() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ToDate);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Return an expression that represents the receiver value converted to a character string.
* This is equivalent to the SQL "TO_CHAR" operator and Java "toString" method.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("salary").toChar().equal("100000")
* Java: employee.getSalary().toString().equals("100000")
* SQL: TO_CHAR(SALARY) = '100000'
* </pre></blockquote>
*/
public Expression toChar() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ToChar);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Return an expression that represents the receiver value converted to a character string,
* with the database formating options (i.e. 'year', 'yyyy', 'day', etc.).
* This is equivalent to the SQL "TO_CHAR" operator and Java Date API.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("startDate").toChar("day").equal("monday")
* Java: employee.getStartDate().getDay().equals("monday")
* SQL: TO_CHAR(START_DATE, 'day') = 'monday'
* </pre></blockquote>
*/
public Expression toChar(String format) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ToCharWithFormat);
return anOperator.expressionFor(this, format);
}
/**
* PUBLIC:
* Return an expression that represents the receiver value converted to lower case.
* This is equivalent to the SQL "LOWER" operator and Java "toLowerCase" method.
* This is only allowed for String attribute values.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").toLowerCase().equal("bob")
* Java: employee.getFirstName().toLowerCase().equals("bob")
* SQL: LOWER(F_NAME) = 'bob'
* </pre></blockquote>
*/
public Expression toLowerCase() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ToLowerCase);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function, returns the number converted from the string.
*/
public Expression toNumber() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ToNumber);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Print a debug form of the expression tree.
*/
public String toString() {
try {
StringWriter innerWriter = new StringWriter();
BufferedWriter outerWriter = new BufferedWriter(innerWriter);
toString(outerWriter, 0);
outerWriter.flush();
return innerWriter.toString();
} catch (IOException e) {
return ToStringLocalization.buildMessage("error_printing_expression", (Object[])null);
}
}
/**
* INTERNAL:
* Print a debug form of the expression tree.
*/
public void toString(BufferedWriter writer, int indent) throws IOException {
writer.newLine();
for (int i = 0; i < indent; i++) {
writer.write(" ");
}
writer.write(descriptionOfNodeType());
writer.write(" ");
writeDescriptionOn(writer);
writeSubexpressionsTo(writer, indent + 1);
}
/**
* PUBLIC:
* Return an expression that represents the receiver value converted to upper case.
* This is equivalent to the SQL "UPPER" operator and Java "toUpperCase" method.
* This is only allowed for String attribute values.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("firstName").toUpperCase().equal("BOB")
* Java: employee.getFirstName().toUpperCase().equals("BOB")
* SQL: UPPER(F_NAME) = 'BOB'
* </pre></blockquote>
*/
public Expression toUpperCase() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ToUpperCase);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function, returns the string with the first letter of each word capitalized.
*/
public Expression toUppercaseCasedWords() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Initcap);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function, returns the string with each char from the from string converted to the char in the to string.
*/
public Expression translate(Object fromString, Object toString) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Translate);
List args = new ArrayList(2);
args.add(fromString);
args.add(toString);
return anOperator.expressionForArguments(this, args);
}
/**
* PUBLIC:
* Function, returns the string trimmed for white space.
*/
public Expression trim() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Trim);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Function, returns the string right and left trimmed for the substring.
*/
public Expression trim(Object substring) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Trim2);
return anOperator.expressionFor(this, substring);
}
/**
* PUBLIC:
* XMLType Function, extracts a secton of XML from a larget XML document
* @param xpath XPath expression representing the node to be returned
*/
public Expression extractXml(String xpath) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ExtractXml);
return anOperator.expressionFor(this, xpath);
}
/**
* PUBLIC:
* Extract the date part from the date/time value.
* EXTRACT is part of the SQL standard, so should be supported by most databases.
* @param part is the date part to extract, "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", "SECOND", "TIMEZONE_HOUR", "TIMEZONE_MINUTE".
*/
public Expression extract(String part) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Extract);
return anOperator.expressionFor(this, literal(part));
}
/**
* PUBLIC:
* Cast the value to the database type.
* CAST is part of the SQL standard, so should be supported by most databases.
* @param type is the database type name, this is database specific but should include, "CHAR", "VARCHAR", "NUMERIC", "INTEGER", "DATE", "TIME", "TIMESTAMP",
* the type may include a size and scale.
*/
public Expression cast(String type) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Cast);
return anOperator.expressionFor(this, literal(type));
}
/**
* PUBLIC:
* XMLType Function, extracts a value from an XMLType field
* @param xpath XPath expression
*/
public Expression extractValue(String xpath) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ExtractValue);
return anOperator.expressionFor(this, xpath);
}
/**
* PUBLIC:
* XMLType Function, gets the number of nodes returned by the given xpath expression
* returns 0 if there are none
* @param xpath Xpath expression
*/
public Expression existsNode(String xpath) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ExistsNode);
return anOperator.expressionFor(this, xpath);
}
/**
* PUBLIC:
* XMLType Function - evaluates to 0 if the xml is a well formed document and 1 if the document
* is a fragment
*/
public Expression isFragment() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.IsFragment);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* XMLType Function - gets a string value from an XMLType
*/
public Expression getStringVal() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.GetStringVal);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* XMLType Function - gets a number value from an XMLType
*/
public Expression getNumberVal() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.GetNumberVal);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* return the date truncated to the indicated datePart. Equivalent
* to the Sybase TRUNC function for dates
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("date").truncDate(year)
* Java: NA
* SQL: TRUNC(date, year)
* </pre></blockquote>
*/
public Expression truncateDate(String datePart) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.TruncateDate);
return anOperator.expressionFor(this, datePart);
}
/**
* INTERNAL:
* We are given an expression that comes from a different context than the one in which this was built,
* e.g. it is the selection criteria of a mapping, or the criteria on which multiple tables are joined in a descriptor.
* We need to transform it so it refers to the objects we are dealing with, and AND it into the rest of our expression.
*
* We want to replace the original base expression with (newBase), and any parameters will be given values based
* on the context which (this) provides.
*
* For example, suppose that the main expression is
* emp.address.streetName = 'something'
* and we are trying to twist the selection criteria for the mapping 'address' in Employee. Because that mapping
* selects addresses, we will use the 'address' node as the base. Values for any parameters will come from the 'emp' node,
* which was the base of the original expression. Note that the values need not be constants, they can be fields.
*
* We do this by taking the tree we're trying to merge and traverse it more or less re-executing it
* it with the appropriate initial receiver and context.
* Return the root of the new expression tree. This will probably need to be AND'ed with the root of the old tree.
*/
public Expression twist(Expression expression, Expression newBase) {
if (expression == null) {
return null;
}
return expression.twistedForBaseAndContext(newBase, this, null);
}
/**
* INTERNAL:
* Rebuild myself against the base, with the values of parameters supplied by the context
* expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping)
* into part of some larger expression. You normally would not call this directly, instead calling twist
* See the comment there for more details"
*/
public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase) {
// Will be overridden by subclasses
return this;
}
/**
* INTERNAL:
* Do any required validation for this node. Throw an exception for any incorrect constructs.
*/
public void validateNode() {
}
/**
* PUBLIC:
* Function, this represents the value function, used in nestedtable
*/
public Expression value() {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Value);
return anOperator.expressionFor(this);
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(byte constant) {
return value(Byte.valueOf(constant));
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(char constant) {
return value(Character.valueOf(constant));
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(double constant) {
return value(Double.valueOf(constant));
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(float constant) {
return value(Float.valueOf(constant));
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(int constant) {
return value(Integer.valueOf(constant));
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(long constant) {
return value(Long.valueOf(constant));
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(Object constant) {
return new ConstantExpression(constant, this);
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(short constant) {
return value(Short.valueOf(constant));
}
/**
* PUBLIC:
* Return an expression on the constant.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("a constant", builder.value("a constant"));
* </pre></blockquote>
*/
public Expression value(boolean constant) {
return value(Boolean.valueOf(constant));
}
/**
* ADVANCED:
* Return an expression on the literal.
* A literal is a specific SQL syntax string that will be printed as is without quotes in the SQL.
* It can be useful for printing database key words or global variables.
* <p>Example:
* <blockquote><pre>
* reportQuery.addItem("currentTime", builder.literal("SYSDATE"));
* </pre></blockquote>
*/
public Expression literal(String literal) {
return new LiteralExpression(literal, this);
}
/**
* ADVANCED:
* Return an expression for the alias.
* This allows an alias used in the select clause to be used in other clauses.
*/
public Expression alias(String alias) {
return literal(alias);
}
/**
* INTERNAL:
* Return the value for in memory comparison.
* This is only valid for valueable expressions.
* New parameter added for feature 2612601
* @param isObjectUnregistered true if object possibly not a clone, but is being
* conformed against the unit of work cache.
*/
public Object valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered) {
throw QueryException.cannotConformExpression();
}
/**
* INTERNAL:
* Return the value for in memory comparison.
* This is only valid for valueable expressions.
*/
public Object valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy) {
return valueFromObject(object, session, translationRow, valueHolderPolicy, false);
}
/**
* PUBLIC:
* Function, this represents the aggregate function Variance. Can be used only within Report Queries.
*/
public Expression variance() {
return getFunction(ExpressionOperator.Variance);
}
/**
* INTERNAL:
* Used to print a debug form of the expression tree.
*/
public void writeDescriptionOn(BufferedWriter writer) throws IOException {
writer.write("some expression");
}
/**
* INTERNAL:
* Append the field name to the writer. Should be overridden for special operators such as functions.
*/
protected void writeField(ExpressionSQLPrinter printer, DatabaseField field, SQLSelectStatement statement) {
//print ", " before each selected field except the first one
if (printer.isFirstElementPrinted()) {
printer.printString(", ");
} else {
printer.setIsFirstElementPrinted(true);
}
if (statement.requiresAliases()) {
if (field.getTable() != lastTable) {
lastTable = field.getTable();
currentAlias = aliasForTable(lastTable);
}
printer.printString(currentAlias.getQualifiedNameDelimited(printer.getPlatform()));
printer.printString(".");
}
printer.printString(field.getNameDelimited(printer.getPlatform()));
//bug6070214: unique field aliases need to be generated when required.
if (statement.getUseUniqueFieldAliases()){
printer.printString(" AS " + statement.generatedAlias(field.getNameDelimited(printer.getPlatform())));
}
}
/**
* INTERNAL:
* Append the field's alias to the writer.
* This is used for pessimistic locking.
*/
protected void writeAlias(ExpressionSQLPrinter printer, DatabaseField field, SQLSelectStatement statement) {
//print ", " before each selected field except the first one
if (printer.isFirstElementPrinted()) {
printer.printString(", ");
} else {
printer.setIsFirstElementPrinted(true);
}
if (statement.requiresAliases()) {
if (field.getTable() != this.lastTable) {
this.lastTable = field.getTable();
this.currentAlias = aliasForTable(this.lastTable);
}
printer.printString(this.currentAlias.getQualifiedNameDelimited(printer.getPlatform()));
} else {
printer.printString(field.getTable().getQualifiedNameDelimited(printer.getPlatform()));
}
}
/**
* INTERNAL:
* called from SQLSelectStatement.writeFieldsFromExpression(...)
*/
public void writeFields(ExpressionSQLPrinter printer, Vector newFields, SQLSelectStatement statement) {
for (DatabaseField field : getSelectionFields(statement.getQuery())) {
newFields.add(field);
writeField(printer, field, statement);
}
}
/**
* INTERNAL:
* Used in SQL printing.
*/
public void writeSubexpressionsTo(BufferedWriter writer, int indent) throws IOException {
// In general, there are no sub-expressions
}
/**
*
* PUBLIC:
* Return an expression that is used with a comparison expression.
* The ANY keyword denotes that the search condition is TRUE if the comparison is TRUE
* for at least one of the values that is returned. If the subquery returns no value,
* the search condition is FALSE
*/
public Expression any(byte[] theBytes) {
List values = new ArrayList(theBytes.length);
for (int index = 0; index < theBytes.length; index++) {
values.add(Byte.valueOf(theBytes[index]));
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression any(char[] theChars) {
List values = new ArrayList(theChars.length);
for (int index = 0; index < theChars.length; index++) {
values.add(Character.valueOf(theChars[index]));
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression any(double[] theDoubles) {
List values = new ArrayList(theDoubles.length);
for (int index = 0; index < theDoubles.length; index++) {
values.add(Double.valueOf(theDoubles[index]));
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression any(float[] theFloats) {
List values = new ArrayList(theFloats.length);
for (int index = 0; index < theFloats.length; index++) {
values.add(Float.valueOf(theFloats[index]));
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression any(int[] theInts) {
List values = new ArrayList(theInts.length);
for (int index = 0; index < theInts.length; index++) {
values.add(Integer.valueOf(theInts[index]));
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression any(long[] theLongs) {
List values = new ArrayList(theLongs.length);
for (int index = 0; index < theLongs.length; index++) {
values.add(Long.valueOf(theLongs[index]));
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression any(Object[] theObjects) {
List values = new ArrayList(theObjects.length);
for (int index = 0; index < theObjects.length; index++) {
values.add(theObjects[index]);
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression any(short[] theShorts) {
List values = new ArrayList(theShorts.length);
for (int index = 0; index < theShorts.length; index++) {
values.add(Short.valueOf(theShorts[index]));
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression any(boolean[] theBooleans) {
List values = new ArrayList(theBooleans.length);
for (int index = 0; index < theBooleans.length; index++) {
values.add(Boolean.valueOf(theBooleans[index]));
}
return any(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").in(ages)
* Java: ages.contains(employee.getAge())
* SQL: AGE IN (55, 18, 30)
* </pre></blockquote>
* @deprecated since 2.4 replaced by any(List)
* @see #any(List)
*/
@Deprecated
public Expression any(Vector theObjects) {
return any((List)theObjects);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").in(ages)
* Java: ages.contains(employee.getAge())
* SQL: AGE IN (55, 18, 30)
* </pre></blockquote>
*/
public Expression any(List theObjects) {
return any(new ConstantExpression(theObjects, this));
}
public Expression any(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Any);
return anOperator.expressionFor(this, arguments);
}
/**
* PUBLIC:
* Return a union expression with the subquery.
*/
public Expression union(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Union);
return anOperator.expressionFor(this, arguments);
}
/**
* PUBLIC:
* Return a intersect expression with the subquery.
*/
public Expression intersect(ReportQuery query) {
return intersect(subQuery(query));
}
/**
* PUBLIC:
* Return a intersect all expression with the subquery.
*/
public Expression intersectAll(ReportQuery query) {
return intersectAll(subQuery(query));
}
/**
* PUBLIC:
* Return a intersect expression with the subquery.
*/
public Expression intersect(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Intersect);
return anOperator.expressionFor(this, arguments);
}
/**
* PUBLIC:
* Return a except expression with the subquery.
*/
public Expression except(ReportQuery query) {
return except(subQuery(query));
}
/**
* PUBLIC:
* Return a except all expression with the subquery.
*/
public Expression exceptAll(ReportQuery query) {
return exceptAll(subQuery(query));
}
/**
* PUBLIC:
* Return a except expression with the subquery.
*/
public Expression except(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Except);
return anOperator.expressionFor(this, arguments);
}
/**
* PUBLIC:
* Return a union expression with the subquery.
*/
public Expression union(ReportQuery query) {
return union(subQuery(query));
}
/**
* PUBLIC:
* Return a union all expression with the subquery.
*/
public Expression unionAll(ReportQuery query) {
return unionAll(subQuery(query));
}
/**
* PUBLIC:
* Return a union all expression with the subquery.
*/
public Expression unionAll(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.UnionAll);
return anOperator.expressionFor(this, arguments);
}
/**
* PUBLIC:
* Return a intersect all expression with the subquery.
*/
public Expression intersectAll(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.IntersectAll);
return anOperator.expressionFor(this, arguments);
}
/**
* PUBLIC:
* Return a except all expression with the subquery.
*/
public Expression exceptAll(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.ExceptAll);
return anOperator.expressionFor(this, arguments);
}
public Expression any(ReportQuery subQuery) {
return any(subQuery(subQuery));
}
/**
* PUBLIC:
* Return an expression that is used with a comparison expression.
* The SOME keyword denotes that the search condition is TRUE if the comparison is TRUE
* for at least one of the values that is returned. If the subquery returns no value,
* the search condition is FALSE
*/
public Expression some(byte[] theBytes) {
List values = new ArrayList(theBytes.length);
for (int index = 0; index < theBytes.length; index++) {
values.add(Byte.valueOf(theBytes[index]));
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression some(char[] theChars) {
List values = new ArrayList(theChars.length);
for (int index = 0; index < theChars.length; index++) {
values.add(Character.valueOf(theChars[index]));
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression some(double[] theDoubles) {
List values = new ArrayList(theDoubles.length);
for (int index = 0; index < theDoubles.length; index++) {
values.add(Double.valueOf(theDoubles[index]));
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression some(float[] theFloats) {
List values = new ArrayList(theFloats.length);
for (int index = 0; index < theFloats.length; index++) {
values.add(Float.valueOf(theFloats[index]));
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression some(int[] theInts) {
List values = new ArrayList(theInts.length);
for (int index = 0; index < theInts.length; index++) {
values.add(Integer.valueOf(theInts[index]));
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression some(long[] theLongs) {
List values = new ArrayList(theLongs.length);
for (int index = 0; index < theLongs.length; index++) {
values.add(Long.valueOf(theLongs[index]));
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression some(Object[] theObjects) {
List values = new ArrayList(theObjects.length);
for (int index = 0; index < theObjects.length; index++) {
values.add(theObjects[index]);
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression some(short[] theShorts) {
List values = new ArrayList(theShorts.length);
for (int index = 0; index < theShorts.length; index++) {
values.add(Short.valueOf(theShorts[index]));
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression some(boolean[] theBooleans) {
List values = new ArrayList(theBooleans.length);
for (int index = 0; index < theBooleans.length; index++) {
values.add(Boolean.valueOf(theBooleans[index]));
}
return some(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").in(ages)
* Java: ages.contains(employee.getAge())
* SQL: AGE IN (55, 18, 30)
* </pre></blockquote>
* @deprecated since 2.4 replaced by some(List)
* @see #some(List)
*/
@Deprecated
public Expression some(Vector theObjects) {
return some(new ConstantExpression(theObjects, this));
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").in(ages)
* Java: ages.contains(employee.getAge())
* SQL: AGE IN (55, 18, 30)
* </pre></blockquote>
*/
public Expression some(List theObjects) {
return some(new ConstantExpression(theObjects, this));
}
public Expression some(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Some);
return anOperator.expressionFor(this, arguments);
}
public Expression some(ReportQuery subQuery) {
return some(subQuery(subQuery));
}
/**
*
* PUBLIC:
* Return an expression that is used with a comparison expression.
* The SOME keyword denotes that the search condition is TRUE if the comparison is TRUE
* for at least one of the values that is returned. If the subquery returns no value,
* the search condition is FALSE
*/
public Expression all(byte[] theBytes) {
List values = new ArrayList(theBytes.length);
for (int index = 0; index < theBytes.length; index++) {
values.add(Byte.valueOf(theBytes[index]));
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression all(char[] theChars) {
List values = new ArrayList(theChars.length);
for (int index = 0; index < theChars.length; index++) {
values.add(Character.valueOf(theChars[index]));
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression all(double[] theDoubles) {
List values = new ArrayList(theDoubles.length);
for (int index = 0; index < theDoubles.length; index++) {
values.add(Double.valueOf(theDoubles[index]));
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression all(float[] theFloats) {
List values = new ArrayList(theFloats.length);
for (int index = 0; index < theFloats.length; index++) {
values.add(Float.valueOf(theFloats[index]));
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression all(int[] theInts) {
List values = new ArrayList(theInts.length);
for (int index = 0; index < theInts.length; index++) {
values.add(Integer.valueOf(theInts[index]));
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression all(long[] theLongs) {
List values = new ArrayList(theLongs.length);
for (int index = 0; index < theLongs.length; index++) {
values.add(Long.valueOf(theLongs[index]));
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression all(Object[] theObjects) {
List values = new ArrayList(theObjects.length);
for (int index = 0; index < theObjects.length; index++) {
values.add(theObjects[index]);
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression all(short[] theShorts) {
List values = new ArrayList(theShorts.length);
for (int index = 0; index < theShorts.length; index++) {
values.add(Short.valueOf(theShorts[index]));
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
*/
public Expression all(boolean[] theBooleans) {
List values = new ArrayList(theBooleans.length);
for (int index = 0; index < theBooleans.length; index++) {
values.add(Boolean.valueOf(theBooleans[index]));
}
return all(values);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").in(ages)
* Java: ages.contains(employee.getAge())
* SQL: AGE IN (55, 18, 30)
* </pre></blockquote>
* @deprecated since 2.4 replaced by all(List)
* @see #all(List)
*/
@Deprecated
public Expression all(Vector theObjects) {
return all((List)theObjects);
}
/**
* PUBLIC:
* Return an expression that checks if the receivers value is contained in the collection.
* This is equivalent to the SQL "IN" operator and Java "contains" operator.
* <p>Example:
* <blockquote><pre>
* EclipseLink: employee.get("age").in(ages)
* Java: ages.contains(employee.getAge())
* SQL: AGE IN (55, 18, 30)
* </pre></blockquote>
*/
public Expression all(List theObjects) {
return all(new ConstantExpression(theObjects, this));
}
public Expression all(Expression arguments) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.All);
return anOperator.expressionFor(this, arguments);
}
public Expression all(ReportQuery subQuery) {
return all(subQuery(subQuery));
}
/**
* INTERNAL:
* Lookup the descriptor for this item by traversing its expression recursively.
*/
public ClassDescriptor getLeafDescriptor(DatabaseQuery query, ClassDescriptor rootDescriptor, AbstractSession session) {
return null;
}
/**
* INTERNAL:
* Lookup the mapping for this item by traversing its expression recursively.
* If an aggregate of foreign mapping is found it is traversed.
*/
public DatabaseMapping getLeafMapping(DatabaseQuery query, ClassDescriptor rootDescriptor, AbstractSession session) {
return null;
}
}
|