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.

CalcColEvalContext.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.io.IOException;
  15. import com.healthmarketscience.jackcess.expr.Value;
  16. import com.healthmarketscience.jackcess.impl.expr.Expressionator;
  17. /**
  18. *
  19. * @author James Ahlborn
  20. */
  21. public class CalcColEvalContext extends RowEvalContext
  22. {
  23. private final ColumnImpl _col;
  24. public CalcColEvalContext(ColumnImpl col) {
  25. super(col.getDatabase());
  26. _col = col;
  27. }
  28. CalcColEvalContext setExpr(String exprStr) {
  29. setExpr(Expressionator.Type.EXPRESSION, exprStr);
  30. return this;
  31. }
  32. @Override
  33. protected TableImpl getTable() {
  34. return _col.getTable();
  35. }
  36. @Override
  37. public Value.Type getResultType() {
  38. return toValueType(_col.getType());
  39. }
  40. public Object eval(Object[] row) throws IOException {
  41. try {
  42. setRow(row);
  43. return eval();
  44. } finally {
  45. reset();
  46. }
  47. }
  48. @Override
  49. protected String withErrorContext(String msg) {
  50. return _col.withErrorContext(msg);
  51. }
  52. }