Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

RowValidatorEvalContext.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.InvalidValueException;
  16. import com.healthmarketscience.jackcess.impl.expr.Expressionator;
  17. /**
  18. *
  19. * @author James Ahlborn
  20. */
  21. public class RowValidatorEvalContext extends RowEvalContext
  22. {
  23. private final TableImpl _table;
  24. private String _helpStr;
  25. public RowValidatorEvalContext(TableImpl table) {
  26. super(table.getDatabase());
  27. _table = table;
  28. }
  29. RowValidatorEvalContext setExpr(String exprStr, String helpStr) {
  30. setExpr(Expressionator.Type.RECORD_VALIDATOR, exprStr);
  31. _helpStr = helpStr;
  32. return this;
  33. }
  34. @Override
  35. protected TableImpl getTable() {
  36. return _table;
  37. }
  38. public void validate(Object[] row) throws IOException {
  39. try {
  40. setRow(row);
  41. Boolean result = (Boolean)eval();
  42. if(!result) {
  43. String msg = ((_helpStr != null) ? _helpStr : "Invalid row");
  44. throw new InvalidValueException(withErrorContext(msg));
  45. }
  46. } finally {
  47. reset();
  48. }
  49. }
  50. @Override
  51. protected String withErrorContext(String msg) {
  52. return _table.withErrorContext(msg);
  53. }
  54. }