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.

TestCondition.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright 2004-2011 H2 Group.
  3. * Copyright 2011 James Moger.
  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. import com.iciql.util.Utils;
  19. /**
  20. * This class represents an incomplete condition.
  21. *
  22. * @param <A> the incomplete condition data type
  23. */
  24. public class TestCondition<A> {
  25. private A x;
  26. public TestCondition(A x) {
  27. this.x = x;
  28. }
  29. public Boolean is(A y) {
  30. Boolean o = Utils.newObject(Boolean.class);
  31. return Db.registerToken(o, new Function("=", x, y) {
  32. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  33. stat.appendSQL("(");
  34. query.appendSQL(stat, null, x[0]);
  35. stat.appendSQL(" = ");
  36. query.appendSQL(stat, x[0], x[1]);
  37. stat.appendSQL(")");
  38. }
  39. });
  40. }
  41. public Boolean exceeds(A y) {
  42. Boolean o = Utils.newObject(Boolean.class);
  43. return Db.registerToken(o, new Function(">", x, y) {
  44. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  45. stat.appendSQL("(");
  46. query.appendSQL(stat, null, x[0]);
  47. stat.appendSQL(" > ");
  48. query.appendSQL(stat, x[0], x[1]);
  49. stat.appendSQL(")");
  50. }
  51. });
  52. }
  53. public Boolean atLeast(A y) {
  54. Boolean o = Utils.newObject(Boolean.class);
  55. return Db.registerToken(o, new Function(">=", x, y) {
  56. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  57. stat.appendSQL("(");
  58. query.appendSQL(stat, null, x[0]);
  59. stat.appendSQL(" >= ");
  60. query.appendSQL(stat, x[0], x[1]);
  61. stat.appendSQL(")");
  62. }
  63. });
  64. }
  65. public Boolean lessThan(A y) {
  66. Boolean o = Utils.newObject(Boolean.class);
  67. return Db.registerToken(o, new Function("<", x, y) {
  68. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  69. stat.appendSQL("(");
  70. query.appendSQL(stat, null, x[0]);
  71. stat.appendSQL(" < ");
  72. query.appendSQL(stat, x[0], x[1]);
  73. stat.appendSQL(")");
  74. }
  75. });
  76. }
  77. public Boolean atMost(A y) {
  78. Boolean o = Utils.newObject(Boolean.class);
  79. return Db.registerToken(o, new Function("<=", x, y) {
  80. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  81. stat.appendSQL("(");
  82. query.appendSQL(stat, null, x[0]);
  83. stat.appendSQL(" <= ");
  84. query.appendSQL(stat, x[0], x[1]);
  85. stat.appendSQL(")");
  86. }
  87. });
  88. }
  89. public Boolean like(A pattern) {
  90. Boolean o = Utils.newObject(Boolean.class);
  91. return Db.registerToken(o, new Function("LIKE", x, pattern) {
  92. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  93. stat.appendSQL("(");
  94. query.appendSQL(stat, null, x[0]);
  95. stat.appendSQL(" LIKE ");
  96. query.appendSQL(stat, x[0], x[1]);
  97. stat.appendSQL(")");
  98. }
  99. });
  100. }
  101. }