Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RowItem.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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
  29. public final class RowItem implements Item {
  30. private static final long serialVersionUID = -6228966439127951408L;
  31. private SQLContainer container;
  32. private RowId id;
  33. private Collection<ColumnProperty> properties;
  34. /**
  35. * Prevent instantiation without required parameters.
  36. */
  37. @SuppressWarnings("unused")
  38. private RowItem() {
  39. }
  40. public RowItem(SQLContainer container, RowId id,
  41. Collection<ColumnProperty> properties) {
  42. if (container == null) {
  43. throw new IllegalArgumentException("Container cannot be null.");
  44. }
  45. if (id == null) {
  46. throw new IllegalArgumentException("Row ID cannot be null.");
  47. }
  48. this.container = container;
  49. this.properties = properties;
  50. /* Set this RowItem as owner to the properties */
  51. if (properties != null) {
  52. for (ColumnProperty p : properties) {
  53. p.setOwner(this);
  54. }
  55. }
  56. this.id = id;
  57. }
  58. @Override
  59. public Property getItemProperty(Object id) {
  60. if (id instanceof String && id != null) {
  61. for (ColumnProperty cp : properties) {
  62. if (id.equals(cp.getPropertyId())) {
  63. return cp;
  64. }
  65. }
  66. }
  67. return null;
  68. }
  69. @Override
  70. public Collection<?> getItemPropertyIds() {
  71. Collection<String> ids = new ArrayList<String>(properties.size());
  72. for (ColumnProperty cp : properties) {
  73. ids.add(cp.getPropertyId());
  74. }
  75. return Collections.unmodifiableCollection(ids);
  76. }
  77. /**
  78. * Adding properties is not supported. Properties are generated by
  79. * SQLContainer.
  80. */
  81. @Override
  82. public boolean addItemProperty(Object id, Property property)
  83. throws UnsupportedOperationException {
  84. throw new UnsupportedOperationException();
  85. }
  86. /**
  87. * Removing properties is not supported. Properties are generated by
  88. * SQLContainer.
  89. */
  90. @Override
  91. public boolean removeItemProperty(Object id)
  92. throws UnsupportedOperationException {
  93. throw new UnsupportedOperationException();
  94. }
  95. public RowId getId() {
  96. return id;
  97. }
  98. public SQLContainer getContainer() {
  99. return container;
  100. }
  101. public boolean isModified() {
  102. if (properties != null) {
  103. for (ColumnProperty p : properties) {
  104. if (p.isModified()) {
  105. return true;
  106. }
  107. }
  108. }
  109. return false;
  110. }
  111. @Override
  112. public String toString() {
  113. StringBuffer s = new StringBuffer();
  114. s.append("ID:");
  115. s.append(getId().toString());
  116. for (Object propId : getItemPropertyIds()) {
  117. s.append("|");
  118. s.append(propId.toString());
  119. s.append(":");
  120. Object value = getItemProperty(propId).getValue();
  121. s.append((null != value) ? value.toString() : null);
  122. }
  123. return s.toString();
  124. }
  125. public void commit() {
  126. if (properties != null) {
  127. for (ColumnProperty p : properties) {
  128. p.commit();
  129. }
  130. }
  131. }
  132. }