Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright (c) 2018 James Ahlborn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.impl;
  14. import java.text.SimpleDateFormat;
  15. import java.util.Map;
  16. import com.healthmarketscience.jackcess.expr.EvalConfig;
  17. import com.healthmarketscience.jackcess.expr.Function;
  18. import com.healthmarketscience.jackcess.expr.TemporalConfig;
  19. import com.healthmarketscience.jackcess.impl.expr.DefaultFunctions;
  20. import com.healthmarketscience.jackcess.impl.expr.Expressionator;
  21. import com.healthmarketscience.jackcess.impl.expr.RandomContext;
  22. /**
  23. *
  24. * @author James Ahlborn
  25. */
  26. public class DBEvalContext implements Expressionator.ParseContext, EvalConfig
  27. {
  28. private static final int MAX_CACHE_SIZE = 10;
  29. private final DatabaseImpl _db;
  30. private Map<String,SimpleDateFormat> _sdfs;
  31. private TemporalConfig _temporal;
  32. private final RandomContext _rndCtx = new RandomContext();
  33. public DBEvalContext(DatabaseImpl db)
  34. {
  35. _db = db;
  36. }
  37. protected DatabaseImpl getDatabase() {
  38. return _db;
  39. }
  40. public TemporalConfig getTemporalConfig() {
  41. return _temporal;
  42. }
  43. public void setTemporalConfig(TemporalConfig temporal) {
  44. _temporal = temporal;
  45. }
  46. public void putCustomExpressionFunction(Function func) {
  47. // FIXME writeme
  48. }
  49. public Function getCustomExpressionFunction(String name) {
  50. // FIXME writeme
  51. return null;
  52. }
  53. public SimpleDateFormat createDateFormat(String formatStr) {
  54. if(_sdfs == null) {
  55. _sdfs = new SimpleCache<String,SimpleDateFormat>(MAX_CACHE_SIZE);
  56. }
  57. SimpleDateFormat sdf = _sdfs.get(formatStr);
  58. if(formatStr == null) {
  59. sdf = _db.createDateFormat(formatStr);
  60. _sdfs.put(formatStr, sdf);
  61. }
  62. return sdf;
  63. }
  64. public float getRandom(Integer seed) {
  65. return _rndCtx.getRandom(seed);
  66. }
  67. public Function getExpressionFunction(String name) {
  68. // FIXME, support custom function context?
  69. return DefaultFunctions.getFunction(name);
  70. }
  71. }