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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.v7.data.util.sqlcontainer;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.Collections;
  20. import com.vaadin.v7.data.Item;
  21. import com.vaadin.v7.data.Property;
  22. /**
  23. * RowItem represents one row of a result set obtained from a QueryDelegate.
  24. *
  25. * Note that depending on the QueryDelegate in use this does not necessarily map
  26. * into an actual row in a database table.
  27. *
  28. * @deprecated As of 8.0, no replacement available.
  29. */
  30. @Deprecated
  31. public final class RowItem implements Item {
  32. private static final long serialVersionUID = -6228966439127951408L;
  33. private SQLContainer container;
  34. private RowId id;
  35. private Collection<ColumnProperty> properties;
  36. /**
  37. * Prevent instantiation without required parameters.
  38. */
  39. @SuppressWarnings("unused")
  40. private RowItem() {
  41. }
  42. public RowItem(SQLContainer container, RowId id,
  43. Collection<ColumnProperty> properties) {
  44. if (container == null) {
  45. throw new IllegalArgumentException("Container cannot be null.");
  46. }
  47. if (id == null) {
  48. throw new IllegalArgumentException("Row ID cannot be null.");
  49. }
  50. this.container = container;
  51. this.properties = properties;
  52. /* Set this RowItem as owner to the properties */
  53. if (properties != null) {
  54. for (ColumnProperty p : properties) {
  55. p.setOwner(this);
  56. }
  57. }
  58. this.id = id;
  59. }
  60. @Override
  61. public Property getItemProperty(Object id) {
  62. if (id instanceof String && id != null) {
  63. for (ColumnProperty cp : properties) {
  64. if (id.equals(cp.getPropertyId())) {
  65. return cp;
  66. }
  67. }
  68. }
  69. return null;
  70. }
  71. @Override
  72. public Collection<?> getItemPropertyIds() {
  73. Collection<String> ids = new ArrayList<String>(properties.size());
  74. for (ColumnProperty cp : properties) {
  75. ids.add(cp.getPropertyId());
  76. }
  77. return Collections.unmodifiableCollection(ids);
  78. }
  79. /**
  80. * Adding properties is not supported. Properties are generated by
  81. * SQLContainer.
  82. */
  83. @Override
  84. public boolean addItemProperty(Object id, Property property)
  85. throws UnsupportedOperationException {
  86. throw new UnsupportedOperationException();
  87. }
  88. /**
  89. * Removing properties is not supported. Properties are generated by
  90. * SQLContainer.
  91. */
  92. @Override
  93. public boolean removeItemProperty(Object id)
  94. throws UnsupportedOperationException {
  95. throw new UnsupportedOperationException();
  96. }
  97. public RowId getId() {
  98. return id;
  99. }
  100. public SQLContainer getContainer() {
  101. return container;
  102. }
  103. public boolean isModified() {
  104. if (properties != null) {
  105. for (ColumnProperty p : properties) {
  106. if (p.isModified()) {
  107. return true;
  108. }
  109. }
  110. }
  111. return false;
  112. }
  113. @Override
  114. public String toString() {
  115. StringBuilder s = new StringBuilder();
  116. s.append("ID:");
  117. s.append(getId());
  118. for (Object propId : getItemPropertyIds()) {
  119. s.append('|');
  120. s.append(propId);
  121. s.append(':');
  122. Object value = getItemProperty(propId).getValue();
  123. s.append(value);
  124. }
  125. return s.toString();
  126. }
  127. public void commit() {
  128. if (properties != null) {
  129. for (ColumnProperty p : properties) {
  130. p.commit();
  131. }
  132. }
  133. }
  134. }