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.

RowItem.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.sqlcontainer;
  5. import java.util.ArrayList;
  6. import java.util.Collection;
  7. import java.util.Collections;
  8. import com.vaadin.data.Item;
  9. import com.vaadin.data.Property;
  10. /**
  11. * RowItem represents one row of a result set obtained from a QueryDelegate.
  12. *
  13. * Note that depending on the QueryDelegate in use this does not necessarily map
  14. * into an actual row in a database table.
  15. */
  16. public final class RowItem implements Item {
  17. private static final long serialVersionUID = -6228966439127951408L;
  18. private SQLContainer container;
  19. private RowId id;
  20. private Collection<ColumnProperty> properties;
  21. /**
  22. * Prevent instantiation without required parameters.
  23. */
  24. @SuppressWarnings("unused")
  25. private RowItem() {
  26. }
  27. public RowItem(SQLContainer container, RowId id,
  28. Collection<ColumnProperty> properties) {
  29. if (container == null) {
  30. throw new IllegalArgumentException("Container cannot be null.");
  31. }
  32. if (id == null) {
  33. throw new IllegalArgumentException("Row ID cannot be null.");
  34. }
  35. this.container = container;
  36. this.properties = properties;
  37. /* Set this RowItem as owner to the properties */
  38. if (properties != null) {
  39. for (ColumnProperty p : properties) {
  40. p.setOwner(this);
  41. }
  42. }
  43. this.id = id;
  44. }
  45. public Property getItemProperty(Object id) {
  46. if (id instanceof String && id != null) {
  47. for (ColumnProperty cp : properties) {
  48. if (id.equals(cp.getPropertyId())) {
  49. return cp;
  50. }
  51. }
  52. }
  53. return null;
  54. }
  55. public Collection<?> getItemPropertyIds() {
  56. Collection<String> ids = new ArrayList<String>(properties.size());
  57. for (ColumnProperty cp : properties) {
  58. ids.add(cp.getPropertyId());
  59. }
  60. return Collections.unmodifiableCollection(ids);
  61. }
  62. /**
  63. * Adding properties is not supported. Properties are generated by
  64. * SQLContainer.
  65. */
  66. public boolean addItemProperty(Object id, Property property)
  67. throws UnsupportedOperationException {
  68. throw new UnsupportedOperationException();
  69. }
  70. /**
  71. * Removing properties is not supported. Properties are generated by
  72. * SQLContainer.
  73. */
  74. public boolean removeItemProperty(Object id)
  75. throws UnsupportedOperationException {
  76. throw new UnsupportedOperationException();
  77. }
  78. public RowId getId() {
  79. return id;
  80. }
  81. public SQLContainer getContainer() {
  82. return container;
  83. }
  84. public boolean isModified() {
  85. if (properties != null) {
  86. for (ColumnProperty p : properties) {
  87. if (p.isModified()) {
  88. return true;
  89. }
  90. }
  91. }
  92. return false;
  93. }
  94. @Override
  95. public String toString() {
  96. StringBuffer s = new StringBuffer();
  97. s.append("ID:");
  98. s.append(getId().toString());
  99. for (Object propId : getItemPropertyIds()) {
  100. s.append("|");
  101. s.append(propId.toString());
  102. s.append(":");
  103. s.append(getItemProperty(propId).toString());
  104. }
  105. return s.toString();
  106. }
  107. public void commit() {
  108. if (properties != null) {
  109. for (ColumnProperty p : properties) {
  110. p.commit();
  111. }
  112. }
  113. }
  114. }