HibernateStatementDynamicField.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.primeton.dgs.kernel.core.dao.hibernate;
  2. import java.util.concurrent.atomic.AtomicInteger;
  3. public class HibernateStatementDynamicField extends HibernateStatementField
  4. {
  5. private static final long serialVersionUID = 1L;
  6. private String property;
  7. private String onEmpty;
  8. public String getProperty()
  9. {
  10. return this.property;
  11. }
  12. public void setProperty(String property) {
  13. this.property = property;
  14. }
  15. public String getOnEmpty() {
  16. return this.onEmpty;
  17. }
  18. public void setOnEmpty(String onEmpty) {
  19. this.onEmpty = onEmpty;
  20. }
  21. public boolean onEmpty()
  22. {
  23. return ("true".equalsIgnoreCase(this.onEmpty)) || ("yes".equalsIgnoreCase(this.onEmpty));
  24. }
  25. public HibernateStatementDynamicField()
  26. {
  27. }
  28. public HibernateStatementDynamicField(String property, String onEmpty)
  29. {
  30. this.property = property;
  31. this.onEmpty = onEmpty;
  32. }
  33. public StringBuffer getRawText(Object vo)
  34. {
  35. return getText(vo, true, new AtomicInteger(0));
  36. }
  37. @Override
  38. public StringBuffer getText(Object vo, AtomicInteger index)
  39. {
  40. return getText(vo, false, index);
  41. }
  42. private StringBuffer getText(Object vo, boolean isRaw, AtomicInteger index)
  43. {
  44. StringBuffer sb = null;
  45. boolean isEmptyValue = isEmpty(getBeanProperty(vo, this.property));
  46. if ((onEmpty()) && (isEmptyValue)) {
  47. sb = isRaw ? getChildrenRawText(vo) : getChildrenText(vo, index);
  48. }
  49. if ((!onEmpty()) && (!isEmptyValue)) {
  50. sb = isRaw ? getChildrenRawText(vo) : getChildrenText(vo, index);
  51. }
  52. return sb;
  53. }
  54. }