You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NestedConditions.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2009-2014, Architector Inc., Japan
  3. * All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.iciql;
  18. public abstract class NestedConditions<T> {
  19. public static class And<T> extends NestedConditions<T> {
  20. public And(Db db, T alias) {
  21. super(db, alias);
  22. }
  23. protected QueryCondition<T, Boolean> and(boolean x) {
  24. return where.and(x);
  25. }
  26. protected QueryCondition<T, Byte> and(byte x) {
  27. return where.and(x);
  28. }
  29. protected QueryCondition<T, Short> and(short x) {
  30. return where.and(x);
  31. }
  32. protected QueryCondition<T, Integer> and(int x) {
  33. return where.and(x);
  34. }
  35. protected QueryCondition<T, Long> and(long x) {
  36. return where.and(x);
  37. }
  38. protected QueryCondition<T, Float> and(float x) {
  39. return where.and(x);
  40. }
  41. protected QueryCondition<T, Double> and(double x) {
  42. return where.and(x);
  43. }
  44. protected <A> QueryCondition<T, A> and(A x) {
  45. return where.and(x);
  46. }
  47. protected QueryWhere<T> and(And<T> conditions) {
  48. where.andOpen();
  49. where.query.addConditionToken(conditions.where.query);
  50. return where.close();
  51. }
  52. protected QueryWhere<T> and(Or<T> conditions) {
  53. where.andOpen();
  54. where.query.addConditionToken(conditions.where.query);
  55. return where.close();
  56. }
  57. }
  58. public static class Or<T> extends NestedConditions<T> {
  59. public Or(Db db, T alias) {
  60. super(db, alias);
  61. }
  62. protected QueryCondition<T, Boolean> or(boolean x) {
  63. return where.or(x);
  64. }
  65. protected QueryCondition<T, Byte> or(byte x) {
  66. return where.or(x);
  67. }
  68. protected QueryCondition<T, Short> or(short x) {
  69. return where.or(x);
  70. }
  71. protected QueryCondition<T, Integer> or(int x) {
  72. return where.or(x);
  73. }
  74. protected QueryCondition<T, Long> or(long x) {
  75. return where.or(x);
  76. }
  77. protected QueryCondition<T, Float> or(float x) {
  78. return where.or(x);
  79. }
  80. protected QueryCondition<T, Double> or(double x) {
  81. return where.or(x);
  82. }
  83. protected <A> QueryCondition<T, A> or(A x) {
  84. return where.or(x);
  85. }
  86. protected QueryWhere<T> or(And<T> conditions) {
  87. where.orOpen();
  88. where.query.addConditionToken(conditions.where.query);
  89. return where.close();
  90. }
  91. protected QueryWhere<T> or(Or<T> conditions) {
  92. where.orOpen();
  93. where.query.addConditionToken(conditions.where.query);
  94. return where.close();
  95. }
  96. }
  97. QueryWhere<T> where;
  98. private NestedConditions(Db db, T alias) {
  99. where = new QueryWhere<T>(Query.rebuild(db, alias));
  100. }
  101. }