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.

RuntimeParameter.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2012 James Moger.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.iciql;
  17. /**
  18. * A runtime parameter is used to generate x=? conditions so that iciql can
  19. * build re-usable dynamic queries with parameter substitution done manually at
  20. * runtime.
  21. *
  22. * @param <A> the operand type
  23. */
  24. class RuntimeParameter<A> implements Token {
  25. public final static String PARAMETER = "";
  26. A x;
  27. CompareType compareType;
  28. RuntimeParameter(A x, CompareType type) {
  29. this.x = x;
  30. this.compareType = type;
  31. }
  32. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  33. query.appendSQL(stat, null, x);
  34. stat.appendSQL(" ");
  35. stat.appendSQL(compareType.getString());
  36. if (compareType.hasRightExpression()) {
  37. stat.appendSQL(" ");
  38. query.appendSQL(stat, x, PARAMETER);
  39. }
  40. }
  41. }