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.

QueryJoinCondition.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /**
  19. * This class represents a query with join and an incomplete condition.
  20. *
  21. * @param <A> the incomplete condition data type
  22. */
  23. public class QueryJoinCondition<T, A> {
  24. private Query<T> query;
  25. private SelectTable<T> join;
  26. private A x;
  27. QueryJoinCondition(Query<T> query, SelectTable<T> join, A x) {
  28. this.query = query;
  29. this.join = join;
  30. this.x = x;
  31. }
  32. public Query<T> is(boolean y) {
  33. return addPrimitive(y);
  34. }
  35. public Query<T> is(byte y) {
  36. return addPrimitive(y);
  37. }
  38. public Query<T> is(short y) {
  39. return addPrimitive(y);
  40. }
  41. public Query<T> is(int y) {
  42. return addPrimitive(y);
  43. }
  44. public Query<T> is(long y) {
  45. return addPrimitive(y);
  46. }
  47. public Query<T> is(float y) {
  48. return addPrimitive(y);
  49. }
  50. public Query<T> is(double y) {
  51. return addPrimitive(y);
  52. }
  53. @SuppressWarnings("unchecked")
  54. private Query<T> addPrimitive(Object o) {
  55. A alias = query.getPrimitiveAliasByValue((A) o);
  56. if (alias == null) {
  57. join.addConditionToken(new Condition<A>(x, (A) o, CompareType.EQUAL));
  58. } else {
  59. join.addConditionToken(new Condition<A>(x, alias, CompareType.EQUAL));
  60. }
  61. return query;
  62. }
  63. public Query<T> is(A y) {
  64. join.addConditionToken(new Condition<A>(x, y, CompareType.EQUAL));
  65. return query;
  66. }
  67. }