001package springdao.support; 002 003import org.apache.logging.log4j.LogManager; 004import org.apache.logging.log4j.Logger; 005 006/** 007 * 008 * @author Kent Yeh 009 */ 010public class JpqlHelper { 011 012 private static final Logger logger = LogManager.getLogger(JpqlHelper.class); 013 private final StringBuilder sb = new StringBuilder(); 014 015 /** 016 * Factory method to get a instance of JpqlHelper.<br/> 017 * 取得一個新建的instance 018 * 019 * @return {@link JpqlHelper this} 020 */ 021 public static JpqlHelper get() { 022 return new JpqlHelper(); 023 } 024 025 /** 026 * Quote string within two single quote 'string'.<br/> 027 * 字串前後加單引號 028 * 029 * @param s 030 * @return 's' 031 */ 032 public static String $q(String s) { 033 return "'" + s + "'"; 034 } 035 036 public JpqlHelper() { 037 } 038 039 /** 040 * add String.<br/> 041 * 加入字串 042 * 043 * @param s 字串 044 * @return {@link JpqlHelper this} 045 */ 046 public JpqlHelper $(String s) { 047 sb.append(" ").append(s).append(" "); 048 return this; 049 } 050 051 /** 052 * append a comma ",".<br/> 053 * 加入一個逗點(,) 054 * 055 * @return {@link JpqlHelper this} 056 */ 057 public JpqlHelper c$() { 058 sb.append(" ,"); 059 return this; 060 } 061 062 /** 063 * append string prefix a comma ",".<br/> 064 * 加入一個逗點後再加字串 065 * 066 * @param s 067 * @return {@link JpqlHelper this} 068 */ 069 public JpqlHelper c$(String s) { 070 sb.append(",").append(s).append(" "); 071 return this; 072 } 073 074 /** 075 * Quote string within two single quote 'string'.<br/> 076 * 用兩個單引號夾住字串 077 * 078 * @param s 079 * @return {@link JpqlHelper this} 080 */ 081 public JpqlHelper q$(String s) { 082 sb.append(" '").append(s).append("' "); 083 return this; 084 } 085 086 /** 087 * add "(..string..)".<br/> 088 * 將字串置於括號內 "(..string..)" 089 * 090 * @param s 091 * @return {@link JpqlHelper this} 092 */ 093 public JpqlHelper ps$(String s) { 094 while (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') { 095 sb.delete(sb.length() - 1, sb.length()); 096 } 097 sb.append("(").append(s).append(") "); 098 return this; 099 } 100 101 /** 102 * add left parentheses " (;.<br/> 103 * 加入左括號 "(" 104 * 105 * @return {@link JpqlHelper this} 106 */ 107 public JpqlHelper lp$() { 108 while (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') { 109 sb.delete(sb.length() - 1, sb.length()); 110 } 111 sb.append("("); 112 return this; 113 } 114 115 /** 116 * add right parentheses ")".<br/> 117 * 加入右括號 ")" 118 * 119 * @return {@link JpqlHelper this} 120 */ 121 public JpqlHelper rp$() { 122 while (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') { 123 sb.delete(sb.length() - 1, sb.length()); 124 } 125 sb.append(")"); 126 return this; 127 } 128 129 /** 130 * add 131 * "<span style="background-color:yellow"> </span>(..string..)" 132 * 133 * @param s 134 * @return {@link JpqlHelper this} 135 */ 136 public JpqlHelper sps$(String s) { 137 sb.append(" (").append(s).append(") "); 138 return this; 139 } 140 141 /** 142 * append a string <span style="color:blue">SELECT</span>.<br/> 143 * 加入一個<span style="color:blue">SELECT</span>字串 144 * 145 * @return {@link JpqlHelper this} 146 */ 147 public JpqlHelper select() { 148 return $("SELECT"); 149 } 150 151 /** 152 * append a string 153 * <span style="color:blue">SELECT</span> <span style="color:#FF8000">fields</span>.<br/> 154 * 加入一個<span style="color:blue">SELECT</span> <span style="color:#FF8000">fields</span>字串 155 * 156 * @param fields 157 * @return {@link JpqlHelper this} 158 */ 159 public JpqlHelper select(String fields) { 160 return $("SELECT " + fields); 161 } 162 163 /** 164 * append a string <span style="color:blue">SELECT DISTINCT</span>.<br/> 165 * 加入一個<span style="color:blue">SELECT DISTINCT</span>字串 166 * 167 * @return {@link JpqlHelper this} 168 */ 169 public JpqlHelper selectDistinct() { 170 return $("SELECT DISTINCT"); 171 } 172 173 /** 174 * append a string <span style="color:blue">SELECT 175 * DISTINCT</span> <span style="color:#FF8000">fields</span>.<br/> 176 * 加入一個<span style="color:blue">SELECT 177 * DISTINCT</span> <span style="color:#FF8000">fields</span>字串 178 * 179 * @param fields 180 * @return {@link JpqlHelper this} 181 */ 182 public JpqlHelper selectDistinct(String fields) { 183 return $("SELECT DISTINCT " + fields); 184 } 185 186 /** 187 * append a string <span style="color:blue">FROM</span>.<br/> 188 * 加入一個<span style="color:blue">FROM</span>字串 189 * 190 * @return {@link JpqlHelper this} 191 */ 192 public JpqlHelper from() { 193 return $("FROM"); 194 } 195 196 /** 197 * append a string 198 * <span style="color:blue">FROM</span> <span style="color:#FF8000">entity</span>.<br/> 199 * 加入一個<span style="color:blue">FROM</span> <span style="color:#FF8000">entity</span>字串 200 * 201 * @param entity 202 * @return {@link JpqlHelper this} 203 */ 204 public JpqlHelper from(String entity) { 205 return $("FROM " + entity); 206 } 207 208 /** 209 * append a string <span style="color:blue">WHERE</span>.<br/> 210 * 加入一個<span style="color:blue">WHERE</span>字串 211 * 212 * @return {@link JpqlHelper this} 213 */ 214 public JpqlHelper where() { 215 return $("WHERE"); 216 } 217 218 /** 219 * append a string 220 * <span style="color:blue">WHERE</span> <span style="color:#FF8000">qlCriteria</span>.<br/> 221 * 加入一個<span style="color:blue">WHERE</span> <span style="color:#FF8000">qlCriteria</span>字串 222 * 223 * @param qlCriteria 224 * @return {@link JpqlHelper this} 225 */ 226 public JpqlHelper where(String qlCriteria) { 227 return $("WHERE " + qlCriteria); 228 } 229 230 /** 231 * append a string 232 * <span style="color:blue">CASE</span>.<br/> 233 * 加入一個<span style="color:blue">CASE</span>字串 234 * 235 * @return {@link JpqlHelper this} 236 */ 237 public JpqlHelper Case() { 238 return $("CASE"); 239 } 240 241 /** 242 * append a string 243 * <span style="color:blue">,CASE</span>.<br/> 244 * 加入一個<span style="color:blue">,CASE</span>字串 245 * 246 * @return {@link JpqlHelper this} 247 */ 248 public JpqlHelper cCase() { 249 return $(",CASE"); 250 } 251 252 /** 253 * append a string 254 * <span style="color:blue">CASE</span> <span style="color:#FF8000">field</span>.<br/> 255 * 加入一個<span style="color:blue">CASE</span> <span style="color:#FF8000">field</span>字串 256 * 257 * @param field 258 * @return {@link JpqlHelper this} 259 */ 260 public JpqlHelper Case(String field) { 261 return $("CASE " + field); 262 } 263 264 /** 265 * append a string 266 * <span style="color:blue">,CASE</span> <span style="color:#FF8000">field</span>.<br/> 267 * 加入一個<span style="color:blue">,CASE</span> <span style="color:#FF8000">field</span>字串 268 * 269 * @param field 270 * @return {@link JpqlHelper this} 271 */ 272 public JpqlHelper cCase(String field) { 273 return $(",CASE " + field); 274 } 275 276 /** 277 * append a string 278 * <span style="color:blue">WHEN</span>.<br/> 279 * 加入一個<span style="color:blue">WHEN</span>字串 280 * 281 * @return {@link JpqlHelper this} 282 */ 283 public JpqlHelper when() { 284 return $("WHEN"); 285 } 286 287 /** 288 * append a string 289 * <span style="color:blue">THEN</span>.<br/> 290 * 加入一個<span style="color:blue">THEN</span>字串 291 * 292 * @return {@link JpqlHelper this} 293 */ 294 public JpqlHelper then() { 295 return $("THEN"); 296 } 297 298 /** 299 * append a string 300 * <span style="color:blue">WHEN</span> <span style="color:#FF8000">condition</span> THEN <span style="color:#FF8000">result</span>.<br/> 301 * 加入一個<span style="color:blue">WHEN</span> <span style="color:#FF8000">condition</span> THEN <span style="color:#FF8000">result</span>字串 302 * 303 * @param condition 304 * @param result 305 * @return {@link JpqlHelper this} 306 */ 307 public JpqlHelper whenThen(String condition, String result) { 308 return $("WHEN " + condition + " THEN " + result); 309 } 310 311 /** 312 * append a string 313 * <span style="color:blue">ELSE</span> <span style="color:#FF8000">result</span>.<br/> 314 * 加入一個<span style="color:blue">ELSE</span> <<span style="color:#FF8000">result</span>字串 315 * 316 * @param result 317 * @return {@link JpqlHelper this} 318 */ 319 public JpqlHelper Else(String result) { 320 return $("ELSE " + result); 321 } 322 323 /** 324 * append a string 325 * <span style="color:blue">ELSE</span> <span style="color:#FF8000">result</span> <span style="color:blue">END</span>.<br/> 326 * 加入一個<span style="color:blue">ELSE</span> <<span style="color:#FF8000">result</span> <span style="color:blue">END</span>字串 327 * 328 * @param result 329 * @return {@link JpqlHelper this} 330 */ 331 public JpqlHelper elseEnd(String result) { 332 return $("ELSE " + result + " END"); 333 } 334 335 /** 336 * append a string 337 * <span style="color:blue">END</span>.<br/> 338 * 加入一個<span style="color:blue">END</span>字串 339 * 340 * @return {@link JpqlHelper this} 341 */ 342 public JpqlHelper end() { 343 return $("END"); 344 } 345 346 /** 347 * append a string <span style="color:blue">UPDATE</span>.<br/> 348 * 加入一個<span style="color:blue">UPDATE</span>字串 349 * 350 * @return {@link JpqlHelper this} 351 */ 352 public JpqlHelper update() { 353 return $("UPDATE"); 354 } 355 356 /** 357 * append a string 358 * <span style="color:blue">UPDATE</span> <span style="color:#FF8000">entity</span>.<br/> 359 * 加入一個<span style="color:blue">UPDATE</span> <span style="color:#FF8000">entity</span>字串 360 * 361 * @param entity 362 * @return {@link JpqlHelper this} 363 */ 364 public JpqlHelper update(String entity) { 365 return $("UPDATE " + entity); 366 } 367 368 /** 369 * append a string <span style="color:blue">DELETE</span>.<br/> 370 * 加入一個<span style="color:blue">DELETE FROM</span>字串 371 * 372 * @return {@link JpqlHelper this} 373 */ 374 public JpqlHelper delete() { 375 return $("DELETE FROM"); 376 } 377 378 /** 379 * append a string 380 * <span style="color:blue">DELETE</span> <span style="color:#FF8000">entity</span>.<br/> 381 * 加入一個<span style="color:blue">DELETE FROM</span> <span style="color:#FF8000">entity</span>字串 382 * 383 * @param entity 384 * @return {@link JpqlHelper this} 385 */ 386 public JpqlHelper delete(String entity) { 387 return $("DELETE FROM " + entity); 388 } 389 390 /** 391 * append a string <span style="color:blue">JOIN</span>.<br/> 392 * 加入一個<span style="color:blue">JOIN</span>字串 393 * 394 * @return {@link JpqlHelper this} 395 */ 396 public JpqlHelper join() { 397 return $("JOIN"); 398 } 399 400 /** 401 * append a string 402 * <span style="color:blue">JOIN</span> <span style="color:#FF8000">other</span>.<br/> 403 * 加入一個<span style="color:blue">JOIN</span> <span style="color:#FF8000">other</span>字串 404 * 405 * @param other 406 * @return {@link JpqlHelper this} 407 */ 408 public JpqlHelper join(String other) { 409 return $("JOIN " + other); 410 } 411 412 /** 413 * append a string <span style="color:blue">INNER JOIN</span>.<br/> 414 * 加入一個<span style="color:blue">INNER JOIN</span>字串 415 * 416 * @return {@link JpqlHelper this} 417 */ 418 public JpqlHelper innerJoin() { 419 return $("INNER JOIN"); 420 } 421 422 /** 423 * append a string <span style="color:blue">INNER 424 * JOIN</span> <span style="color:#FF8000">other</span>.<br/> 425 * 加入一個<span style="color:blue">INNER 426 * JOIN</span> <span style="color:#FF8000">other</span>字串 427 * 428 * @param other 429 * @return {@link JpqlHelper this} 430 */ 431 public JpqlHelper innerJoin(String other) { 432 return $("INNER JOIN " + other); 433 } 434 435 /** 436 * append a string <span style="color:blue">LEFT OUTER JOIN</span>.<br/> 437 * 加入一個<span style="color:blue">LEFT OUTER JOIN</span>字串 438 * 439 * @return {@link JpqlHelper this} 440 */ 441 public JpqlHelper leftJoin() { 442 return $("LEFT OUTER JOIN"); 443 } 444 445 /** 446 * append a string <span style="color:blue">LEFT OUTER 447 * JOIN</span> <span style="color:#FF8000">other</span>.<br/> 448 * 加入一個<span style="color:blue">LEFT OUTER 449 * JOIN</span> <span style="color:#FF8000">other</span>字串 450 * 451 * @param other 452 * @return {@link JpqlHelper this} 453 */ 454 public JpqlHelper leftJoin(String other) { 455 return $("LEFT OUTER JOIN " + other); 456 } 457 458 /** 459 * append a string <span style="color:blue">ON</span>.<br/> 460 * 加入一個<span style="color:blue">ON</span>字串 461 * 462 * @return {@link JpqlHelper this} 463 */ 464 public JpqlHelper on() { 465 return $("ON"); 466 } 467 468 /** 469 * append a string <span style="color:blue">UNION</span>.<br/> 470 * 加入一個<span style="color:blue">UNION</span>字串 471 * 472 * @return {@link JpqlHelper this} 473 */ 474 public JpqlHelper union() { 475 return $("UNION"); 476 } 477 478 /** 479 * append a string <span style="color:blue">INTERSECT</span>.<br/> 480 * 加入一個<span style="color:blue">INTERSECT</span>字串 481 * 482 * @return {@link JpqlHelper this} 483 */ 484 public JpqlHelper intersect() { 485 return $("INTERSECT"); 486 } 487 488 /** 489 * append a string <span style="color:blue">EXCEPT</span>.<br/> 490 * 加入一個<span style="color:blue">EXCEPT</span>字串 491 * 492 * @return {@link JpqlHelper this} 493 */ 494 public JpqlHelper except() { 495 return $("EXCEPT"); 496 } 497 498 /** 499 * append a string <span style="color:blue">GROUP BY</span>.<br/> 500 * 加入一個<span style="color:blue">GROUP BY</span>字串 501 * 502 * @return {@link JpqlHelper this} 503 */ 504 public JpqlHelper groupBy() { 505 return $("GROUP BY"); 506 } 507 508 /** 509 * append a string <span style="color:blue">GROUP 510 * BY</span> <span style="color:#FF8000">fields</span>.<br/> 511 * 加入一個<span style="color:blue">GROUP 512 * BY</span> <span style="color:#FF8000">fields</span>字串 513 * 514 * @param fields 515 * @return {@link JpqlHelper this} 516 */ 517 public JpqlHelper groupBy(String fields) { 518 return $("GROUP BY " + fields); 519 } 520 521 /** 522 * append a string <span style="color:blue">HAVING</span>.<br/> 523 * 加入一個<span style="color:blue">HAVING</span>字串 524 * 525 * @return {@link JpqlHelper this} 526 */ 527 public JpqlHelper having() { 528 return $("HAVING"); 529 } 530 531 /** 532 * append a string 533 * <span style="color:blue">HAVING</span> <span style="color:#FF8000">criteria</span>.<br/> 534 * 加入一個<span style="color:blue">HAVING</span> <span style="color:#FF8000">criteria</span>字串 535 * 536 * @param criteria 537 * @return {@link JpqlHelper this} 538 */ 539 public JpqlHelper having(String criteria) { 540 return $("HAVING " + criteria); 541 } 542 543 /** 544 * append a string <span style="color:blue">FETCH</span>.<br/> 545 * 加入一個<span style="color:blue">FETCH</span>字串 546 * 547 * @return {@link JpqlHelper this} 548 */ 549 public JpqlHelper fetch() { 550 return $("FETCH"); 551 } 552 553 /** 554 * append a string 555 * <span style="color:blue">FETCH</span> <span style="color:#FF8000">field</span>.<br/> 556 * 加入一個<span style="color:blue">FETCH</span> <span style="color:#FF8000">field</span>字串 557 * 558 * @param field 559 * @return {@link JpqlHelper this} 560 */ 561 public JpqlHelper fetch(String field) { 562 return $("FETCH " + field); 563 } 564 565 /** 566 * append a string <span style="color:blue">DISTINCT</span>.<br/> 567 * 加入一個<span style="color:blue">DISTINCT</span>字串 568 * 569 * @return {@link JpqlHelper this} 570 */ 571 public JpqlHelper distinct() { 572 return $("DISTINCT"); 573 } 574 575 /** 576 * append a string 577 * <span style="color:blue">DISTINCT</span> <span style="color:#FF8000">fields</span>.<br/> 578 * 加入一個<span style="color:blue">DISTINCT</span> <span style="color:#FF8000">fields</span>字串 579 * 580 * @param fields 581 * @return {@link JpqlHelper this} 582 */ 583 public JpqlHelper distinct(String fields) { 584 return $("DISTINCT " + fields); 585 } 586 587 /** 588 * append a string <span style="color:blue">IS NULL</span>.<br/> 589 * 加入一個<span style="color:blue">IS NULL</span>字串 590 * 591 * @return {@link JpqlHelper this} 592 */ 593 public JpqlHelper isNull() { 594 return $("IS NULL"); 595 } 596 597 /** 598 * append a string 599 * <span style="color:blue">IS NOT NULL</span>.<br/> 600 * 加入一個<span style="color:blue">IS NOT NULL</span>字串 601 * 602 * @return {@link JpqlHelper this} 603 */ 604 public JpqlHelper isNotNull() { 605 return $("IS NOT NULL"); 606 } 607 608 /** 609 * append a string <span style="color:blue">TRUE</span>.<br/> 610 * 加入一個<span style="color:blue">TRUE</span>字串 611 * 612 * @return {@link JpqlHelper this} 613 */ 614 public JpqlHelper True() { 615 return $("True"); 616 } 617 618 /** 619 * append a string <span style="color:blue">FALSE</span>.<br/> 620 * 加入一個<span style="color:blue">FALSE</span>字串 621 * 622 * @return {@link JpqlHelper this} 623 */ 624 public JpqlHelper False() { 625 return $("False"); 626 } 627 628 /** 629 * append a string <span style="color:blue">NOT</span>.<br/> 630 * 加入一個<span style="color:blue">NOT</span>字串 631 * 632 * @return {@link JpqlHelper this} 633 */ 634 public JpqlHelper not() { 635 return $("NOT"); 636 } 637 638 /** 639 * append a string <span style="color:blue">AND</span>.<br/> 640 * 加入一個<span style="color:blue">AND</span>字串 641 * 642 * @return {@link JpqlHelper this} 643 */ 644 public JpqlHelper and() { 645 return $("AND"); 646 } 647 648 /** 649 * append a string <span style="color:blue">OR</span>.<br/> 650 * 加入一個<span style="color:blue">OR</span>字串 651 * 652 * @return {@link JpqlHelper this} 653 */ 654 public JpqlHelper or() { 655 return $("OR"); 656 } 657 658 /** 659 * append a string <span style="color:blue">BETWEEN</span>.<br/> 660 * 加入一個<span style="color:blue">BETWEEN</span>字串 661 * 662 * @return {@link JpqlHelper this} 663 */ 664 public JpqlHelper between() { 665 return $("BETWEEN"); 666 } 667 668 /** 669 * append a string 670 * <span style="color:blue">BETWEEN</span> <span style="color:#FF8000">from</span> <span style="color:blue">AND</span> <span style="color:#FF8000">to</span>.<br/> 671 * 加入一個<span style="color:blue">BETWEEN</span> <span style="color:#FF8000">from</span> <span style="color:blue">AND</span> <span style="color:#FF8000">to</span>字串 672 * 673 * @param from 674 * @param to 675 * @return {@link JpqlHelper this} 676 */ 677 public JpqlHelper between(String from, String to) { 678 return $("BETWEEN " + from + " AND " + to); 679 } 680 681 /** 682 * append a string <span style="color:blue">LIKE</span>.<br/> 683 * 加入一個<span style="color:blue">LIKE</span>字串 684 * 685 * @return {@link JpqlHelper this} 686 */ 687 public JpqlHelper like() { 688 return $("LIKE"); 689 } 690 691 /** 692 * append a string 693 * <span style="color:#FF8000">left</span> <span style="color:blue">LIKE</span> <span style="color:#FF8000">right</span>.<br/> 694 * 加入一個<span style="color:#FF8000">left</span> <span style="color:blue">LIKE</span> <span style="color:#FF8000">right</span>字串 695 * 696 * @param left 697 * @param right 698 * @return {@link JpqlHelper this} 699 */ 700 public JpqlHelper like(String left, String right) { 701 return $(left + " LIKE " + right); 702 } 703 704 /** 705 * append a string <span style="color:blue">IN</span>.<br/> 706 * 加入一個<span style="color:blue">IN</span>字串 707 * 708 * @return {@link JpqlHelper this} 709 */ 710 public JpqlHelper in() { 711 return $("IN"); 712 } 713 714 /** 715 * append a string 716 * <span style="color:blue">IN</span> (<span style="color:#FF8000">fields</span>).<br/> 717 * 加入一個<span style="color:blue">IN (<span style="color:#FF8000">fields</span>)</span>字串 718 * 719 * @param fields 720 * @return {@link JpqlHelper this} 721 */ 722 public JpqlHelper in(String fields) { 723 return $("IN (" + fields + ")"); 724 } 725 726 /** 727 * append a string 728 * <span style="color:blue">AS</span> <span style="color:#FF8000">field</span>.<br/> 729 * 加入一個<span style="color:blue">AS</span> <span style="color:#FF8000">fields</span>字串 730 * 731 * @param field 732 * @return {@link JpqlHelper this} 733 */ 734 public JpqlHelper as(String field) { 735 return $("AS " + field); 736 } 737 738 /** 739 * append a string <span style="color:blue">IS EMPTY</span>.<br/> 740 * 加入一個<span style="color:blue">IS EMPTY</span>字串 741 * 742 * @return {@link JpqlHelper this} 743 */ 744 public JpqlHelper isEmpty() { 745 return $("IS EMPTY"); 746 } 747 748 /** 749 * append a string 750 * <span style="color:blue">IS NOT EMPTY</span>.<br/> 751 * 加入一個<span style="color:blue">IS NOT EMPTY</span>字串 752 * 753 * @return {@link JpqlHelper this} 754 */ 755 public JpqlHelper isNotEmpty() { 756 return $("IS NOT EMPTY"); 757 } 758 759 /** 760 * append a string <span style="color:blue">MEMBER OF</span>.<br/> 761 * 加入一個<span style="color:blue">MEMBER OF</span>字串 762 * 763 * @return {@link JpqlHelper this} 764 */ 765 public JpqlHelper memberOf() { 766 return $("MEMBER OF"); 767 } 768 769 /** 770 * append a string 771 * <span style="color:#FF8000">left</span> <span style="color:blue">MEMBER OF</span> <span style="color:#FF8000">right</span>.<br/> 772 * 加入一個<span style="color:#FF8000">left</span> <span style="color:blue">MEMBER OF</span> <span style="color:#FF8000">right</span>字串 773 * 774 * @param left 775 * @param right 776 * @return {@link JpqlHelper this} 777 */ 778 public JpqlHelper memberOf(String left, String right) { 779 return $(left + " MEMBER OF " + right); 780 } 781 782 /** 783 * append a string 784 * <span style="color:blue">ABS</span>.<br/> 785 * 加入一個<span style="color:blue">ABS</span>字串 786 * 787 * @return {@link JpqlHelper this} 788 */ 789 public JpqlHelper abs() { 790 return $("ABS"); 791 } 792 793 /** 794 * append a string 795 * <span style="color:blue">,ABS</span>.<br/> 796 * 加入一個<span style="color:blue">,ABS</span>字串 797 * 798 * @return {@link JpqlHelper this} 799 */ 800 public JpqlHelper cAbs() { 801 return $(",ABS"); 802 } 803 804 /** 805 * append a string 806 * <span style="color:blue">ABS</span>(<span style="color:#FF8000">field</span>).<br/> 807 * 加入一個<span style="color:blue">ABS</span>(<span style="color:#FF8000">field</span>)字串 808 * 809 * @param field 810 * @return {@link JpqlHelper this} 811 */ 812 public JpqlHelper abs(String field) { 813 return $("ABS(" + field + ")"); 814 } 815 816 /** 817 * append a string 818 * <span style="color:blue">,ABS</span>(<span style="color:#FF8000">field</span>).<br/> 819 * 加入一個<span style="color:blue">,ABS</span>(<span style="color:#FF8000">field</span>)字串 820 * 821 * @param field 822 * @return {@link JpqlHelper this} 823 */ 824 public JpqlHelper cAbs(String field) { 825 return $(",ABS(" + field + ")"); 826 } 827 828 /** 829 * append a string <span style="color:blue">AVG</span>.<br/> 830 * 加入一個<span style="color:blue">AVG</span>字串 831 * 832 * @return {@link JpqlHelper this} 833 */ 834 public JpqlHelper avg() { 835 return $("AVG"); 836 } 837 838 /** 839 * append a string <span style="color:blue">,AVG</span>.<br/> 840 * 加入一個<span style="color:blue">,AVG</span>字串 841 * 842 * @return {@link JpqlHelper this} 843 */ 844 public JpqlHelper cAvg() { 845 return $(",AVG"); 846 } 847 848 /** 849 * append a string 850 * <span style="color:blue">AVG</span>(<span style="color:#FF8000">field</span>).<br/> 851 * 加入一個<span style="color:blue">AVG</span>(<span style="color:#FF8000">field</span>)字串 852 * 853 * @param field 854 * @return {@link JpqlHelper this} 855 */ 856 public JpqlHelper avg(String field) { 857 return $("AVG(" + field + ")"); 858 } 859 860 /** 861 * append a string 862 * <span style="color:blue">,AVG</span>(<span style="color:#FF8000">field</span>).<br/> 863 * 加入一個<span style="color:blue">,AVG</span>(<span style="color:#FF8000">field</span>)字串 864 * 865 * @param field 866 * @return {@link JpqlHelper this} 867 */ 868 public JpqlHelper cAvg(String field) { 869 return $(",AVG(" + field + ")"); 870 } 871 872 /** 873 * append a string <span style="color:blue">SQRT</span>.<br/> 874 * 加入一個<span style="color:blue">SQRT</span>字串 875 * 876 * @return {@link JpqlHelper this} 877 */ 878 public JpqlHelper sqrt() { 879 return $("SQRT"); 880 } 881 882 /** 883 * append a string <span style="color:blue">,SQRT</span>.<br/> 884 * 加入一個<span style="color:blue">,SQRT</span>字串 885 * 886 * @return {@link JpqlHelper this} 887 */ 888 public JpqlHelper cSqrt() { 889 return $(",SQRT"); 890 } 891 892 /** 893 * append a string 894 * <span style="color:blue">SQRT</span>(<span style="color:#FF8000">field</span>).<br/> 895 * 加入一個<span style="color:blue">SQRT</span>(<span style="color:#FF8000">field</span>)字串 896 * 897 * @param field 898 * @return {@link JpqlHelper this} 899 */ 900 public JpqlHelper sqrt(String field) { 901 return $("SQRT(" + field + ")"); 902 } 903 904 /** 905 * append a string 906 * <span style="color:blue">,SQRT</span>(<span style="color:#FF8000">field</span>).<br/> 907 * 加入一個<span style="color:blue">,SQRT</span>(<span style="color:#FF8000">field</span>)字串 908 * 909 * @param field 910 * @return {@link JpqlHelper this} 911 */ 912 public JpqlHelper cSqrt(String field) { 913 return $(",SQRT(" + field + ")"); 914 } 915 916 /** 917 * append a string 918 * <span style="color:blue">COALESCE</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">defaultValue</span>).<br/> 919 * 加入一個<span style="color:blue">COALESCE</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">defaultValue</span>)字串 920 * 921 * @param field 922 * @param defaultValue 923 * @return {@link JpqlHelper this} 924 */ 925 public JpqlHelper coalesce(String field, String defaultValue) { 926 return $("COALESCE(" + field + "," + defaultValue + ")"); 927 } 928 929 /** 930 * append a string 931 * <span style="color:blue">,COALESCE</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">defaultValue</span>).<br/> 932 * 加入一個<span style="color:blue">,COALESCE</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">defaultValue</span>)字串 933 * 934 * @param field 935 * @param defaultValue 936 * @return {@link JpqlHelper this} 937 */ 938 public JpqlHelper cCoalesce(String field, String defaultValue) { 939 return $(",COALESCE(" + field + "," + defaultValue + ")"); 940 } 941 942 /** 943 * append a string 944 * <span style="color:blue">NULLIF</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">defaultValue</span>).<br/> 945 * 加入一個<span style="color:blue">NULLIF</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">defaultValue</span>)字串 946 * 947 * @param field 948 * @param defaultValue 949 * @return {@link JpqlHelper this} 950 */ 951 public JpqlHelper nullif(String field, String defaultValue) { 952 return $("NULLIF(" + field + "," + defaultValue + ")"); 953 } 954 955 /** 956 * append a string 957 * <span style="color:blue">,NULLIF</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">defaultValue</span>).<br/> 958 * 加入一個<span style="color:blue">,NULLIF</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">defaultValue</span>)字串 959 * 960 * @param field 961 * @param defaultValue 962 * @return {@link JpqlHelper this} 963 */ 964 public JpqlHelper cNullif(String field, String defaultValue) { 965 return $(",NULLIF(" + field + "," + defaultValue + ")"); 966 } 967 968 /** 969 * append a string <span style="color:blue">MAX</span>.<br/> 970 * 加入一個<span style="color:blue">MAX</span>字串 971 * 972 * @return {@link JpqlHelper this} 973 */ 974 public JpqlHelper max() { 975 return $("MAX"); 976 } 977 978 /** 979 * append a string <span style="color:blue">,MAX</span>.<br/> 980 * 加入一個<span style="color:blue">,MAX</span>字串 981 * 982 * @return {@link JpqlHelper this} 983 */ 984 public JpqlHelper cMax() { 985 return $(",MAX"); 986 } 987 988 /** 989 * append a string 990 * <span style="color:blue">MAX</span>(<span style="color:#FF8000">field</span>).<br/> 991 * 加入一個<span style="color:blue">MAX</span>(<span style="color:#FF8000">field</span>)字串 992 * 993 * @param field 994 * @return {@link JpqlHelper this} 995 */ 996 public JpqlHelper max(String field) { 997 return $("MAX(" + field + ")"); 998 } 999 1000 /** 1001 * append a string 1002 * <span style="color:blue">,MAX</span>(<span style="color:#FF8000">field</span>).<br/> 1003 * 加入一個<span style="color:blue">,MAX</span>(<span style="color:#FF8000">field</span>)字串 1004 * 1005 * @param field 1006 * @return {@link JpqlHelper this} 1007 */ 1008 public JpqlHelper cMax(String field) { 1009 return $(",MAX(" + field + ")"); 1010 } 1011 1012 /** 1013 * append a string <span style="color:blue">MIN</span>.<br/> 1014 * 加入一個<span style="color:blue">MIN</span>字串 1015 * 1016 * @return {@link JpqlHelper this} 1017 */ 1018 public JpqlHelper min() { 1019 return $("MIN"); 1020 } 1021 1022 /** 1023 * append a string <span style="color:blue">,MIN</span>.<br/> 1024 * 加入一個<span style="color:blue">,MIN</span>字串 1025 * 1026 * @return {@link JpqlHelper this} 1027 */ 1028 public JpqlHelper cMin() { 1029 return $(",MIN"); 1030 } 1031 1032 /** 1033 * append a string 1034 * <span style="color:blue">MIN</span>(<span style="color:#FF8000">field</span>).<br/> 1035 * 加入一個<span style="color:blue">MIN</span>(<span style="color:#FF8000">field</span>)字串 1036 * 1037 * @param field 1038 * @return {@link JpqlHelper this} 1039 */ 1040 public JpqlHelper min(String field) { 1041 return $("MIN(" + field + ")"); 1042 } 1043 1044 /** 1045 * append a string 1046 * <span style="color:blue">,MIN</span>(<span style="color:#FF8000">field</span>).<br/> 1047 * 加入一個<span style="color:blue">,MIN</span>(<span style="color:#FF8000">field</span>)字串 1048 * 1049 * @param field 1050 * @return {@link JpqlHelper this} 1051 */ 1052 public JpqlHelper cMin(String field) { 1053 return $(",MIN(" + field + ")"); 1054 } 1055 1056 /** 1057 * append a string <span style="color:blue">SUM</span>.<br/> 1058 * 加入一個<span style="color:blue">SUM</span>字串 1059 * 1060 * @return {@link JpqlHelper this} 1061 */ 1062 public JpqlHelper sum() { 1063 return $("SUM"); 1064 } 1065 1066 /** 1067 * append a string <span style="color:blue">,SUM</span>.<br/> 1068 * 加入一個<span style="color:blue">,SUM</span>字串 1069 * 1070 * @return {@link JpqlHelper this} 1071 */ 1072 public JpqlHelper cSum() { 1073 return $(",SUM"); 1074 } 1075 1076 /** 1077 * append a string 1078 * <span style="color:blue">SUM</span>(<span style="color:#FF8000">field</span>).<br/> 1079 * 加入一個<span style="color:blue">SUM</span>(<span style="color:#FF8000">field</span>)字串 1080 * 1081 * @param field 1082 * @return {@link JpqlHelper this} 1083 */ 1084 public JpqlHelper sum(String field) { 1085 return $("SUM(" + field + ")"); 1086 } 1087 1088 /** 1089 * append a string 1090 * <span style="color:blue">,SUM</span>(<span style="color:#FF8000">field</span>).<br/> 1091 * 加入一個<span style="color:blue">,SUM</span>(<span style="color:#FF8000">field</span>)字串 1092 * 1093 * @param field 1094 * @return {@link JpqlHelper this} 1095 */ 1096 public JpqlHelper cSum(String field) { 1097 return $(",SUM(" + field + ")"); 1098 } 1099 1100 /** 1101 * append a string 1102 * <span style="color:blue">COUNT</span>.<br/> 1103 * 加入一個<span style="color:blue">COUNT</span>字串 1104 * 1105 * @return {@link JpqlHelper this} 1106 */ 1107 public JpqlHelper count() { 1108 sb.append(" COUNT"); 1109 return this; 1110 } 1111 1112 /** 1113 * append a string 1114 * <span style="color:blue">,COUNT</span>.<br/> 1115 * 加入一個<span style="color:blue">,COUNT</span>字串 1116 * 1117 * @return {@link JpqlHelper this} 1118 */ 1119 public JpqlHelper cCount() { 1120 sb.append(" ,COUNT"); 1121 return this; 1122 } 1123 1124 /** 1125 * append a string 1126 * <span style="color:blue">COUNT</span>(<span style="color:#FF8000">field</span>).<br/> 1127 * 加入一個<span style="color:blue">COUNT</span>(<span style="color:#FF8000">field</span>)字串 1128 * 1129 * @param field 1130 * @return {@link JpqlHelper this} 1131 */ 1132 public JpqlHelper count(String field) { 1133 return $("COUNT(" + field + ")"); 1134 } 1135 1136 /** 1137 * append a string 1138 * <span style="color:blue">,COUNT</span>(<span style="color:#FF8000">field</span>).<br/> 1139 * 加入一個<span style="color:blue">,COUNT</span>(<span style="color:#FF8000">field</span>)字串 1140 * 1141 * @param field 1142 * @return {@link JpqlHelper this} 1143 */ 1144 public JpqlHelper cCount(String field) { 1145 return $(",COUNT(" + field + ")"); 1146 } 1147 1148 /** 1149 * append a string 1150 * <span style="color:blue">COUNT</span>(DISTINCT <span style="color:#FF8000">field</span>).<br/> 1151 * 加入一個<span style="color:blue">COUNT</span>(DISTINCT <span style="color:#FF8000">field</span>)字串 1152 * 1153 * @param field 1154 * @return {@link JpqlHelper this} 1155 */ 1156 public JpqlHelper countDistinct(String field) { 1157 return $("COUNT(DISTINCT " + field + ")"); 1158 } 1159 1160 /** 1161 * append a string 1162 * <span style="color:blue">,COUNT</span>(DISTINCT <span style="color:#FF8000">field</span>).<br/> 1163 * 加入一個<span style="color:blue">,COUNT</span>(DISTINCT <span style="color:#FF8000">field</span>)字串 1164 * 1165 * @param field 1166 * @return {@link JpqlHelper this} 1167 */ 1168 public JpqlHelper cCountDistinct(String field) { 1169 return $(",COUNT(DISTINCT " + field + ")"); 1170 } 1171 1172 /** 1173 * append a string 1174 * <span style="color:blue">ORDER BY</span>.<br/> 1175 * 加入一個<span style="color:blue">ORDER BY</span>字串 1176 * 1177 * @return {@link JpqlHelper this} 1178 */ 1179 public JpqlHelper orderBy() { 1180 return $("ORDER BY"); 1181 } 1182 1183 /** 1184 * append a string 1185 * <span style="color:blue">NULLS FIRST</span>.<br/> 1186 * 加入一個<span style="color:blue">NULLS FIRST</span>字串 1187 * 1188 * @return {@link JpqlHelper this} 1189 */ 1190 public JpqlHelper nullsFirst() { 1191 return $("NULLS FIRST"); 1192 } 1193 1194 /** 1195 * append a string 1196 * <span style="color:blue">ORDER BY <span style="color:#FF8000">fields</span></span>.<br/> 1197 * 加入一個<span style="color:blue">ORDER BY <span style="color:#FF8000">fields</span></span>字串 1198 * 1199 * @param fields 1200 * @return {@link JpqlHelper this} 1201 */ 1202 public JpqlHelper orderBy(String fields) { 1203 return $("ORDER BY " + fields); 1204 } 1205 1206 /** 1207 * append a string 1208 * <span style="color:blue">ASC</span>.<br/> 1209 * 加入一個<span style="color:blue">ASC</span>字串 1210 * 1211 * @return {@link JpqlHelper this} 1212 */ 1213 public JpqlHelper asc() { 1214 return $("ASC"); 1215 } 1216 1217 /** 1218 * append a string 1219 * <span style="color:blue">DESC</span>.<br/> 1220 * 加入一個<span style="color:blue">DESC</span>字串 1221 * 1222 * @return {@link JpqlHelper this} 1223 */ 1224 public JpqlHelper desc() { 1225 return $("DESC"); 1226 } 1227 1228 /** 1229 * append a string 1230 * <span style="color:blue">MOD</span>(<span style="color:#FF8000">number</span>,<span style="color:#FF8000">divisor</span>).<br/> 1231 * 加入一個<span style="color:blue">MOD</span>(<span style="color:#FF8000">number</span>,<span style="color:#FF8000">divisor</span>)字串 1232 * 1233 * @param number 1234 * @param divisor 1235 * @return {@link JpqlHelper this} 1236 */ 1237 public JpqlHelper mod(String number, String divisor) { 1238 return $("MOD(" + number + ", " + divisor + ")"); 1239 } 1240 1241 /** 1242 * append a string 1243 * <span style="color:blue">,MOD</span>(<span style="color:#FF8000">number</span>,<span style="color:#FF8000">divisor</span>).<br/> 1244 * 加入一個<span style="color:blue">mMOD</span>(<span style="color:#FF8000">number</span>,<span style="color:#FF8000">divisor</span>)字串 1245 * 1246 * @param number 1247 * @param divisor 1248 * @return {@link JpqlHelper this} 1249 */ 1250 public JpqlHelper cMod(String number, String divisor) { 1251 return $(",MOD(" + number + ", " + divisor + ")"); 1252 } 1253 1254 /** 1255 * append a string 1256 * <span style="color:blue">UPPER</span>.<br/> 1257 * 加入一個<span style="color:blue">UPPER</span>字串 1258 * 1259 * @return {@link JpqlHelper this} 1260 */ 1261 public JpqlHelper upper() { 1262 return $("UPPER"); 1263 } 1264 1265 /** 1266 * append a string 1267 * <span style="color:blue">,UPPER</span>.<br/> 1268 * 加入一個<span style="color:blue">,UPPER</span>字串 1269 * 1270 * @return {@link JpqlHelper this} 1271 */ 1272 public JpqlHelper cUpper() { 1273 return $(",UPPER"); 1274 } 1275 1276 /** 1277 * append a string 1278 * <span style="color:blue">UPPER</span>(<span style="color:#FF8000">field</span>).<br/> 1279 * 加入一個<span style="color:blue">UPPER</span>(<span style="color:#FF8000">field</span>)字串 1280 * 1281 * @param field 1282 * @return {@link JpqlHelper this} 1283 */ 1284 public JpqlHelper upper(String field) { 1285 return $("UPPER(" + field + ")"); 1286 } 1287 1288 /** 1289 * append a string 1290 * <span style="color:blue">,UPPER</span>(<span style="color:#FF8000">field</span>).<br/> 1291 * 加入一個<span style="color:blue">,UPPER</span>(<span style="color:#FF8000">field</span>)字串 1292 * 1293 * @param field 1294 * @return {@link JpqlHelper this} 1295 */ 1296 public JpqlHelper cUpper(String field) { 1297 return $(",UPPER(" + field + ")"); 1298 } 1299 1300 /** 1301 * append a string 1302 * <span style="color:blue">LOWER</span>.<br/> 1303 * 加入一個<span style="color:blue">LOWER</span>字串 1304 * 1305 * @return {@link JpqlHelper this} 1306 */ 1307 public JpqlHelper lower() { 1308 return $("LOWER"); 1309 } 1310 1311 /** 1312 * append a string 1313 * <span style="color:blue">,LOWER</span>.<br/> 1314 * 加入一個<span style="color:blue">,LOWER</span>字串 1315 * 1316 * @return {@link JpqlHelper this} 1317 */ 1318 public JpqlHelper cLower() { 1319 return $(",LOWER"); 1320 } 1321 1322 /** 1323 * append a string 1324 * <span style="color:blue">LOWER</span>(<span style="color:#FF8000">field</span>).<br/> 1325 * 加入一個<span style="color:blue">LOWER</span>(<span style="color:#FF8000">field</span>)字串 1326 * 1327 * @param field 1328 * @return {@link JpqlHelper this} 1329 */ 1330 public JpqlHelper lower(String field) { 1331 return $("LOWER(" + field + ")"); 1332 } 1333 1334 /** 1335 * append a string 1336 * <span style="color:blue">,LOWER</span>(<span style="color:#FF8000">field</span>).<br/> 1337 * 加入一個<span style="color:blue">,LOWER</span>(<span style="color:#FF8000">field</span>)字串 1338 * 1339 * @param field 1340 * @return {@link JpqlHelper this} 1341 */ 1342 public JpqlHelper cLower(String field) { 1343 return $(",LOWER(" + field + ")"); 1344 } 1345 1346 /** 1347 * append a string 1348 * <span style="color:blue">TRIM</span>.<br/> 1349 * 加入一個<span style="color:blue">TRIM</span>字串 1350 * 1351 * @return {@link JpqlHelper this} 1352 */ 1353 public JpqlHelper trim() { 1354 return $("TRIM"); 1355 } 1356 1357 /** 1358 * append a string 1359 * <span style="color:blue">,TRIM</span>.<br/> 1360 * 加入一個<span style="color:blue">,TRIM</span>字串 1361 * 1362 * @return {@link JpqlHelper this} 1363 */ 1364 public JpqlHelper cTrim() { 1365 return $(",TRIM"); 1366 } 1367 1368 /** 1369 * append a string 1370 * <span style="color:blue">TRIM</span>(<span style="color:#FF8000">field</span>).<br/> 1371 * 加入一個<span style="color:blue">TRIM</span>(<span style="color:#FF8000">field</span>)字串 1372 * 1373 * @param field 1374 * @return {@link JpqlHelper this} 1375 */ 1376 public JpqlHelper trim(String field) { 1377 return $("TRIM(" + field + ")"); 1378 } 1379 1380 /** 1381 * append a string 1382 * <span style="color:blue">,TRIM</span>(<span style="color:#FF8000">field</span>).<br/> 1383 * 加入一個<span style="color:blue">,TRIM</span>(<span style="color:#FF8000">field</span>)字串 1384 * 1385 * @param field 1386 * @return {@link JpqlHelper this} 1387 */ 1388 public JpqlHelper cTrim(String field) { 1389 return $(",TRIM(" + field + ")"); 1390 } 1391 1392 /** 1393 * append a string 1394 * <span style="color:blue">CONCAT</span>(<span style="color:#FF8000">first</span> , 1395 * <span style="color:#FF8000">second</span>).<br/> 1396 * 加入一個<span style="color:blue">CONCAT</span>(<span style="color:#FF8000">first</span> , 1397 * <span style="color:#FF8000">second</span>)字串 1398 * 1399 * @param first 1400 * @param second 1401 * @return {@link JpqlHelper this} 1402 */ 1403 public JpqlHelper concat(String first, String second) { 1404 return $("CONCAT(" + first + ", " + second + ")"); 1405 } 1406 1407 /** 1408 * append a string 1409 * <span style="color:blue">,CONCAT</span>(<span style="color:#FF8000">first</span> , 1410 * <span style="color:#FF8000">second</span>).<br/> 1411 * 加入一個<span style="color:blue">,CONCAT</span>(<span style="color:#FF8000">first</span> , 1412 * <span style="color:#FF8000">second</span>)字串 1413 * 1414 * @param first 1415 * @param second 1416 * @return {@link JpqlHelper this} 1417 */ 1418 public JpqlHelper cConcat(String first, String second) { 1419 return $(",CONCAT(" + first + ", " + second + ")"); 1420 } 1421 1422 /** 1423 * append a string 1424 * <span style="color:blue">SUBSTRING</span>(<span style="color:#FF8000">field</span> , 1425 * <span style="color:#FF8000">start</span> , <span style="color:#FF8000">end</span>).<br/> 1426 * 加入一個<span style="color:blue">SUBSTRING</span>(<span style="color:#FF8000">field</span> , 1427 * <span style="color:#FF8000">start</span> , <span style="color:#FF8000">end</span>)字串 1428 * 1429 * @param field 1430 * @param start 1431 * @param end 1432 * @return {@link JpqlHelper this} 1433 */ 1434 public JpqlHelper substring(String field, int start, int end) { 1435 return $("SUBSTRING(" + field + ", " + start + ", " + end + ")"); 1436 } 1437 1438 /** 1439 * append a string 1440 * <span style="color:blue">,SUBSTRING</span>(<span style="color:#FF8000">field</span> , 1441 * <span style="color:#FF8000">start</span> , <span style="color:#FF8000">end</span>).<br/> 1442 * 加入一個<span style="color:blue">,SUBSTRING</span>(<span style="color:#FF8000">field</span> , 1443 * <span style="color:#FF8000">start</span> , <span style="color:#FF8000">end</span>)字串 1444 * 1445 * @param field 1446 * @param start 1447 * @param end 1448 * @return {@link JpqlHelper this} 1449 */ 1450 public JpqlHelper cSubstring(String field, int start, int end) { 1451 return $(",SUBSTRING(" + field + ", " + start + ", " + end + ")"); 1452 } 1453 1454 /** 1455 * append a string 1456 * <span style="color:blue">LOCATE</span>(<span style="color:#FF8000">substr</span> , <span style="color:#FF8000">field</span>).<br/> 1457 * 加入一個<span style="color:blue">LOCATE</span>(<span style="color:#FF8000">substr</span> , <span style="color:#FF8000">field</span>)字串 1458 * 1459 * @param substr 1460 * @param field 1461 * @return {@link JpqlHelper this} 1462 */ 1463 public JpqlHelper locate(String substr, String field) { 1464 return $("LOCATE(" + substr + ", " + field + ")"); 1465 } 1466 1467 /** 1468 * append a string 1469 * <span style="color:blue">,LOCATE</span>(<span style="color:#FF8000">substr</span> , <span style="color:#FF8000">field</span>).<br/> 1470 * 加入一個<span style="color:blue">,LOCATE</span>(<span style="color:#FF8000">substr</span> , <span style="color:#FF8000">field</span>)字串 1471 * 1472 * @param substr 1473 * @param field 1474 * @return {@link JpqlHelper this} 1475 */ 1476 public JpqlHelper cLocate(String substr, String field) { 1477 return $(",LOCATE(" + substr + ", " + field + ")"); 1478 } 1479 1480 /** 1481 * append a string 1482 * <span style="color:blue">LENGTH</span>.<br/> 1483 * 加入一個<span style="color:blue">LENGTH</span>字串 1484 * 1485 * @return {@link JpqlHelper this} 1486 */ 1487 public JpqlHelper length() { 1488 return $("LENGTH"); 1489 } 1490 1491 /** 1492 * append a string 1493 * <span style="color:blue">,LENGTH</span>.<br/> 1494 * 加入一個<span style="color:blue">,LENGTH</span>字串 1495 * 1496 * @return {@link JpqlHelper this} 1497 */ 1498 public JpqlHelper cLength() { 1499 return $(",LENGTH"); 1500 } 1501 1502 /** 1503 * append a string 1504 * <span style="color:blue">LENGTH</span>(<span style="color:#FF8000">field</span>).<br/> 1505 * 加入一個<span style="color:blue">LENGTH</span>(<span style="color:#FF8000">field</span>)字串 1506 * 1507 * @param field 1508 * @return {@link JpqlHelper this} 1509 */ 1510 public JpqlHelper length(String field) { 1511 return $("LENGTH(" + field + ")"); 1512 } 1513 1514 /** 1515 * append a string 1516 * <span style="color:blue">,LENGTH</span>(<span style="color:#FF8000">field</span>).<br/> 1517 * 加入一個<span style="color:blue">,LENGTH</span>(<span style="color:#FF8000">field</span>)字串 1518 * 1519 * @param field 1520 * @return {@link JpqlHelper this} 1521 */ 1522 public JpqlHelper cLength(String field) { 1523 return $(",LENGTH(" + field + ")"); 1524 } 1525 1526 /** 1527 * append a string 1528 * <span style="color:blue">CURRENT_TIME</span>.<br/> 1529 * 加入一個<span style="color:blue">CURRENT_TIME</span>字串 1530 * 1531 * @return {@link JpqlHelper this} 1532 */ 1533 public JpqlHelper currTime() { 1534 return $("CURRENT_TIME"); 1535 } 1536 1537 /** 1538 * append a string 1539 * <span style="color:blue">,CURRENT_TIME</span>.<br/> 1540 * 加入一個<span style="color:blue">,CURRENT_TIME</span>字串 1541 * 1542 * @return {@link JpqlHelper this} 1543 */ 1544 public JpqlHelper cCurrTime() { 1545 return $(",CURRENT_TIME"); 1546 } 1547 1548 /** 1549 * append a string 1550 * <span style="color:blue">CURRENT_DATE</span>.<br/> 1551 * 加入一個<span style="color:blue">CURRENT_DATE</span>字串 1552 * 1553 * @return {@link JpqlHelper this} 1554 */ 1555 public JpqlHelper currDate() { 1556 return $("CURRENT_DATE"); 1557 } 1558 1559 /** 1560 * append a string 1561 * <span style="color:blue">,CURRENT_DATE</span>.<br/> 1562 * 加入一個<span style="color:blue">,CURRENT_DATE</span>字串 1563 * 1564 * @return {@link JpqlHelper this} 1565 */ 1566 public JpqlHelper cCurrDate() { 1567 return $(",CURRENT_DATE"); 1568 } 1569 1570 /** 1571 * append a string 1572 * <span style="color:blue">CURRENT_TIMESTAMP</span>.<br/> 1573 * 加入一個<span style="color:blue">CURRENT_TIMESTAMP</span>字串 1574 * 1575 * @return {@link JpqlHelper this} 1576 */ 1577 public JpqlHelper currTimeStamp() { 1578 return $("CURRENT_TIMESTAMP"); 1579 } 1580 1581 /** 1582 * append a string 1583 * <span style="color:blue">,CURRENT_TIMESTAMP</span>.<br/> 1584 * 加入一個<span style="color:blue">,CURRENT_TIMESTAMP</span>字串 1585 * 1586 * @return {@link JpqlHelper this} 1587 */ 1588 public JpqlHelper cCurrTimeStamp() { 1589 return $(",CURRENT_TIMESTAMP"); 1590 } 1591 1592 /** 1593 * append a string <span style="color:blue">NEW</span>.<br/> 1594 * 加入一個<span style="color:blue">NEW</span>字串 1595 * 1596 * @return {@link JpqlHelper this} 1597 */ 1598 public JpqlHelper New() { 1599 return $("NEW"); 1600 } 1601 1602 /** 1603 * append " <span style="color:blue">NEW</span> 1604 * <span style="color:#FF8000">entityName</span>(<span style="color:#FF8000">field1</span> 1605 * [,<span style="color:#FF8000">field2</span>]) ".<br/> 1606 * 加入" <span style="color:blue">NEW</span> 1607 * <span style="color:#FF8000">entityName</span>(<span style="color:#FF8000">field1</span> 1608 * [,<span style="color:#FF8000">field2</span>]) " 1609 * 1610 * @param entityName 1611 * @param fields 1612 * @return NEW entityName,field1[,field2[,field3[...]]] 1613 */ 1614 public JpqlHelper New(String entityName, String... fields) { 1615 sb.append(" NEW ").append(entityName).append("("); 1616 if (fields != null && fields.length > 0) { 1617 int i = 0; 1618 for (String field : fields) { 1619 sb.append(i++ == 0 ? "" : ", ").append(field); 1620 } 1621 sb.append(") "); 1622 } 1623 return this; 1624 } 1625 1626 /** 1627 * append a string 1628 * <span style="color:blue">EXISTS</span>.<br/> 1629 * 加入一個<span style="color:blue">EXISTS</span>字串 1630 * 1631 * @return {@link JpqlHelper this} 1632 */ 1633 public JpqlHelper exists() { 1634 return $("EXISTS"); 1635 } 1636 1637 /** 1638 * append a string 1639 * <span style="color:blue">NOT EXISTS</span>.<br/> 1640 * 加入一個<span style="color:blue">NOT EXISTS</span>字串 1641 * 1642 * @return {@link JpqlHelper this} 1643 */ 1644 public JpqlHelper notExists() { 1645 return $("NOT EXISTS"); 1646 } 1647 1648 /** 1649 * append a string 1650 * <span style="color:blue">ALL</span>.<br/> 1651 * 加入一個<span style="color:blue">ALL</span>字串 1652 * 1653 * @return {@link JpqlHelper this} 1654 */ 1655 public JpqlHelper all() { 1656 return $("ALL"); 1657 } 1658 1659 /** 1660 * append a string 1661 * <span style="color:blue">ALL</span>(<span style="color:#FF8000">subquery</span>).<br/> 1662 * 加入一個<span style="color:blue">ALL</span>(<span style="color:#FF8000">subquery</span>)字串 1663 * 1664 * @param subquery 1665 * @return {@link JpqlHelper this} 1666 */ 1667 public JpqlHelper all(String subquery) { 1668 return $("ALL(" + subquery + ")"); 1669 } 1670 1671 /** 1672 * append a string 1673 * <span style="color:blue">ANY</span>.<br/> 1674 * 加入一個<span style="color:blue">ANY</span>字串 1675 * 1676 * @return {@link JpqlHelper this} 1677 */ 1678 public JpqlHelper any() { 1679 return $("ANY"); 1680 } 1681 1682 /** 1683 * append a string 1684 * <span style="color:blue">ANY</span>(<span style="color:#FF8000">subquery</span>).<br/> 1685 * 加入一個<span style="color:blue">ANY</span>(<span style="color:#FF8000">subquery</span>)字串 1686 * 1687 * @param subquery 1688 * @return {@link JpqlHelper this} 1689 */ 1690 public JpqlHelper any(String subquery) { 1691 return $("ANY(" + subquery + ")"); 1692 } 1693 1694 /** 1695 * append a string 1696 * <span style="color:blue">SOME</span>.<br/> 1697 * 加入一個<span style="color:blue">SOME</span>字串 1698 * 1699 * @return {@link JpqlHelper this} 1700 */ 1701 public JpqlHelper some() { 1702 return $("SOME"); 1703 } 1704 1705 /** 1706 * append a string 1707 * <span style="color:blue">SOME</span>(<span style="color:#FF8000">subquery</span>).<br/> 1708 * 加入一個<span style="color:blue">SOME</span>(<span style="color:#FF8000">subquery</span>)字串 1709 * 1710 * @param subquery 1711 * @return {@link JpqlHelper this} 1712 */ 1713 public JpqlHelper some(String subquery) { 1714 return $("SOME(" + subquery + ")"); 1715 } 1716 1717 /** 1718 * append a string 1719 * <span style="color:blue">SET</span>.<br/> 1720 * 加入一個<span style="color:blue">SET</span>字串 1721 * 1722 * @return {@link JpqlHelper this} 1723 */ 1724 public JpqlHelper set() { 1725 return $("SET"); 1726 } 1727 1728 /** 1729 * append a string 1730 * <span style="color:blue">SET</span> <span style="color:#FF8000">left</span><span style="color:blue">=</span><span style="color:#FF8000">right</span>.<br/> 1731 * 加入一個<span style="color:blue">SET</span> <span style="color:#FF8000">left</span><span style="color:blue">=</span><span style="color:#FF8000">right</span>字串 1732 * 1733 * @param left 1734 * @param right 1735 * @return {@link JpqlHelper this} 1736 */ 1737 public JpqlHelper set(String left, String right) { 1738 return $("SET " + left + " = " + right); 1739 } 1740 1741 /** 1742 * append a string 1743 * <span style="color:blue">=</span>.<br/> 1744 * 加入一個<span style="color:blue">=</span>字串 1745 * 1746 * @return {@link JpqlHelper this} 1747 */ 1748 public JpqlHelper eq() { 1749 return $("="); 1750 } 1751 1752 /** 1753 * append a string 1754 * <span style="color:blue">=</span><span style="color:#FF8000">right</span>.<br/> 1755 * 加入一個<span style="color:blue">=</span><span style="color:#FF8000">right</span>字串 1756 * 1757 * @param right 1758 * @return {@link JpqlHelper this} 1759 */ 1760 public JpqlHelper eq(String right) { 1761 return $(" = " + right); 1762 } 1763 1764 /** 1765 * append a string 1766 * <span style="color:#FF8000">left</span><span style="color:blue">=</span><span style="color:#FF8000">right</span>.<br/> 1767 * 加入一個<span style="color:#FF8000">left</span><span style="color:blue">=</span><span style="color:#FF8000">right</span>字串 1768 * 1769 * @param left 1770 * @param right 1771 * @return {@link JpqlHelper this} 1772 */ 1773 public JpqlHelper eq(String left, String right) { 1774 return $(left + " = " + right); 1775 } 1776 1777 /** 1778 * 1779 * @param args A 1780 * <a href="http://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax">format 1781 * string</a> 1782 * @return String.format({@link #toString() toString()},args); 1783 */ 1784 public String format(Object... args) { 1785 return String.format(toString(), args); 1786 } 1787 1788 /** 1789 * EclipseLink support:<br/> 1790 * append a string 1791 * <span style="color:blue">CAST</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">typeValue</span>).<br/> 1792 * 加入一個<span style="color:blue">CAST</span>(<span style="color:#FF8000">field</span> , <span style="color:#FF8000">typeValue</span>)字串 1793 * 1794 * @param field 1795 * @param typeValue 1796 * @return {@link JpqlHelper this} 1797 */ 1798 public JpqlHelper cast(String field, String typeValue) { 1799 return $("CAST(" + field + ", " + typeValue + ")"); 1800 } 1801 1802 /** 1803 * EclipseLink support:<br/> 1804 * append a string 1805 * <span style="color:blue">EXTRACT</span>(<span style="color:#FF8000">dt</span> , <span style="color:#FF8000">field</span>).<br/> 1806 * 加入一個<span style="color:blue">EXTRACT</span>(<span style="color:#FF8000">dt</span> , <span style="color:#FF8000">field</span>)字串 1807 * 1808 * @param dt 1809 * @param field 1810 * @return {@link JpqlHelper this} 1811 */ 1812 public JpqlHelper extract(String dt, String field) { 1813 return $("EXTRACT(" + dt + ", " + field + ")"); 1814 } 1815 1816 /** 1817 * EclipseLink support:<br/> 1818 * append a string 1819 * <span style="color:blue">,EXTRACT</span>(<span style="color:#FF8000">dt</span> , <span style="color:#FF8000">field</span>).<br/> 1820 * 加入一個<span style="color:blue">,EXTRACT</span>(<span style="color:#FF8000">dt</span> , <span style="color:#FF8000">field</span>)字串 1821 * 1822 * @param dt 1823 * @param field 1824 * @return {@link JpqlHelper this} 1825 */ 1826 public JpqlHelper cExtract(String dt, String field) { 1827 return $(",EXTRACT(" + dt + ", " + field + ")"); 1828 } 1829 1830 /** 1831 * append " <span style="color:blue">FUNCTION(</span> 1832 * <span style="color:#FF8000">name</span>, [<span style="color:#FF8000">value1, 1833 * [<span style="color:#FF8000">field2</span>]</span>]".<br/> 1834 * 加入" <span style="color:blue">FUNCTION(</span> 1835 * <span style="color:#FF8000">name</span>, [<span style="color:#FF8000">value1, 1836 * [<span style="color:#FF8000">field2</span>]</span>]" 1837 * 1838 * @param name 1839 * @param values 1840 * @return FUNCTION('name',valu1[,valu2[,valu3[...]]]) 1841 */ 1842 public JpqlHelper function(String name, String... values) { 1843 sb.append(" ").append("FUNCTION('").append(name).append("'"); 1844 if (values != null && values.length > 0) { 1845 for (String value : values) { 1846 sb.append(", ").append(value); 1847 } 1848 } 1849 sb.append(")"); 1850 return this; 1851 } 1852 1853 /** 1854 * EclipseLink support:<br/> 1855 * OPERATOR is similar to 1856 * {@link #function(java.lang.String, java.lang.String...) function()}.<br/> 1857 * OPERATOR 相似於 1858 * {@link #function(java.lang.String, java.lang.String...) function()} 1859 * 1860 * @param name 1861 * @param values 1862 * @return OPERATOR('name',valu1[,valu2[,valu3[...]]]) 1863 */ 1864 public JpqlHelper operator(String name, String... values) { 1865 sb.append(" ").append("OPERATOR('").append(name).append("'"); 1866 if (values != null && values.length > 0) { 1867 for (String value : values) { 1868 sb.append(", ").append(value); 1869 } 1870 } 1871 sb.append(")"); 1872 return this; 1873 } 1874 1875 /** 1876 * append 1877 * <span style="color:blue">TREAT</span>(<span style="color:#FF8000">entity</span>).<br/> 1878 * 加入 1879 * <span style="color:blue">TREAT</span>(<span style="color:#FF8000">entity</span>) 1880 * 字串 1881 * 1882 * @param entity 1883 * @return TREAT(entity) 1884 */ 1885 public JpqlHelper treat(String entity) { 1886 return $("TREAT(" + entity + ")"); 1887 } 1888 1889 /** 1890 * EclipseLink support:<br/> 1891 * append a string <span style="color:blue">REGEXP</span>.<br/> 1892 * 加入一個<span style="color:blue">REGEXP</span>字串 1893 * 1894 * @return {@link JpqlHelper this} 1895 */ 1896 public JpqlHelper regexp() { 1897 return $("REGEXP"); 1898 } 1899 1900 /** 1901 * append a string 1902 * <span style="color:#FF8000">field</span> <span style="color:blue">REGEXP</span> <span style="color:#FF8000">regexpr</span>.<br/> 1903 * 加入一個<span style="color:#FF8000">field</span> <span style="color:blue">REGEXP</span> <span style="color:#FF8000">regexpr</span>字串 1904 * 1905 * @param field 1906 * @param regexpr 1907 * @return {@link JpqlHelper this} 1908 */ 1909 public JpqlHelper regexp(String field, String regexpr) { 1910 return $(field + " REGEXP " + regexpr); 1911 } 1912 1913 /** 1914 * EclipseLink support:<br/> 1915 * append a string 1916 * <span style="color:#FF8000">COLUMN</span>('<span style="color:#FF8000">field</span>, <span style="color:#FF8000">entityOrAlias</span>).<br/> 1917 * 加入<span style="color:#FF8000">COLUMN</span>('<span style="color:#FF8000">field</span>, <span style="color:#FF8000">entityOrAlias</span>).<br/>字串 1918 * 1919 * @param field 1920 * @param entityOrAlias 1921 * @return {@link JpqlHelper this} 1922 */ 1923 public JpqlHelper column(String field, String entityOrAlias) { 1924 return $("COLUMN('" + field + "', " + entityOrAlias + ")"); 1925 } 1926 1927 /** 1928 * EclipseLink support:<br/> 1929 * append 1930 * <span style="color:blue">TABLE</span>(<span style="color:#FF8000">name</span>).<br/> 1931 * 加入 1932 * <span style="color:blue">TABLE</span>(<span style="color:#FF8000">name</span>) 1933 * 字串 1934 * 1935 * @param name 1936 * @return TABLE('name') 1937 */ 1938 public JpqlHelper table(String name) { 1939 return $("TABLE('" + name + "')"); 1940 } 1941 1942 @Override 1943 public String toString() { 1944 int pos = 0; 1945 while ((pos = sb.indexOf(" ", pos)) != -1) { 1946 sb.delete(pos, pos + 1); 1947 } 1948 logger.debug("JPQL:{}", sb.toString()); 1949 while (sb.length() > 0 && sb.charAt(0) == ' ') { 1950 sb.delete(0, 1); 1951 } 1952 while (sb.length() > 0 && sb.charAt(sb.length() - 1) == ' ') { 1953 sb.delete(sb.length() - 1, sb.length()); 1954 } 1955 return sb.toString(); 1956 } 1957 1958 /** 1959 * Alias for {@link #toString() toString()}.<br/> 1960 * 輸入JPQL 1961 * 1962 * @return {@link #toString() toString()} 1963 */ 1964 public String ql() { 1965 return toString(); 1966 } 1967 1968}