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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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>
  23. * the incomplete condition data type
  24. */
  25. public class TestCondition<A> {
  26. private A x;
  27. public TestCondition(A x) {
  28. this.x = x;
  29. }
  30. public Boolean is(A y) {
  31. Boolean o = Utils.newObject(Boolean.class);
  32. return Db.registerToken(o, new Function("=", x, y) {
  33. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  34. stat.appendSQL("(");
  35. query.appendSQL(stat, x[0]);
  36. stat.appendSQL(" = ");
  37. query.appendSQL(stat, x[1]);
  38. stat.appendSQL(")");
  39. }
  40. });
  41. }
  42. public Boolean bigger(A y) {
  43. Boolean o = Utils.newObject(Boolean.class);
  44. return Db.registerToken(o, new Function(">", x, y) {
  45. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  46. stat.appendSQL("(");
  47. query.appendSQL(stat, x[0]);
  48. stat.appendSQL(" > ");
  49. query.appendSQL(stat, x[1]);
  50. stat.appendSQL(")");
  51. }
  52. });
  53. }
  54. public Boolean biggerEqual(A y) {
  55. Boolean o = Utils.newObject(Boolean.class);
  56. return Db.registerToken(o, new Function(">=", x, y) {
  57. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  58. stat.appendSQL("(");
  59. query.appendSQL(stat, x[0]);
  60. stat.appendSQL(" >= ");
  61. query.appendSQL(stat, x[1]);
  62. stat.appendSQL(")");
  63. }
  64. });
  65. }
  66. public Boolean smaller(A y) {
  67. Boolean o = Utils.newObject(Boolean.class);
  68. return Db.registerToken(o, new Function("<", x, y) {
  69. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  70. stat.appendSQL("(");
  71. query.appendSQL(stat, x[0]);
  72. stat.appendSQL(" < ");
  73. query.appendSQL(stat, x[1]);
  74. stat.appendSQL(")");
  75. }
  76. });
  77. }
  78. public Boolean smallerEqual(A y) {
  79. Boolean o = Utils.newObject(Boolean.class);
  80. return Db.registerToken(o, new Function("<=", x, y) {
  81. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  82. stat.appendSQL("(");
  83. query.appendSQL(stat, x[0]);
  84. stat.appendSQL(" <= ");
  85. query.appendSQL(stat, x[1]);
  86. stat.appendSQL(")");
  87. }
  88. });
  89. }
  90. public Boolean like(A pattern) {
  91. Boolean o = Utils.newObject(Boolean.class);
  92. return Db.registerToken(o, new Function("LIKE", x, pattern) {
  93. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  94. stat.appendSQL("(");
  95. query.appendSQL(stat, x[0]);
  96. stat.appendSQL(" LIKE ");
  97. query.appendSQL(stat, x[1]);
  98. stat.appendSQL(")");
  99. }
  100. });
  101. }
  102. }