選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

QueryJoin.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 a join.
  20. */
  21. public class QueryJoin<T> {
  22. private Query<T> query;
  23. private SelectTable<T> join;
  24. QueryJoin(Query<T> query, SelectTable<T> join) {
  25. this.query = query;
  26. this.join = join;
  27. }
  28. public QueryJoinCondition<T, Boolean> on(boolean x) {
  29. query.getFrom().getAliasDefinition().checkMultipleBooleans();
  30. return addPrimitive(x);
  31. }
  32. public QueryJoinCondition<T, Byte> on(byte x) {
  33. return addPrimitive(x);
  34. }
  35. public QueryJoinCondition<T, Short> on(short x) {
  36. return addPrimitive(x);
  37. }
  38. public QueryJoinCondition<T, Integer> on(int x) {
  39. return addPrimitive(x);
  40. }
  41. public QueryJoinCondition<T, Long> on(long x) {
  42. return addPrimitive(x);
  43. }
  44. public QueryJoinCondition<T, Float> on(float x) {
  45. return addPrimitive(x);
  46. }
  47. public QueryJoinCondition<T, Double> on(double x) {
  48. return addPrimitive(x);
  49. }
  50. private <A> QueryJoinCondition<T, A> addPrimitive(A x) {
  51. A alias = query.getPrimitiveAliasByValue(x);
  52. if (alias == null) {
  53. // this will result in an unmapped field exception
  54. return new QueryJoinCondition<T, A>(query, join, x);
  55. }
  56. return new QueryJoinCondition<T, A>(query, join, alias);
  57. }
  58. public <A> QueryJoinCondition<T, A> on(A x) {
  59. return new QueryJoinCondition<T, A>(query, join, x);
  60. }
  61. }