/tests/com/google/appengine/datanucleus/test/HasOneToManyListJDO.java

http://datanucleus-appengine.googlecode.com/ · Java · 167 lines · 113 code · 36 blank · 18 comment · 0 complexity · 5e4b8cd98c4f1a8e555388ee60d9eb9d MD5 · raw file

  1. /**********************************************************************
  2. Copyright (c) 2009 Google Inc.
  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.google.appengine.datanucleus.test;
  14. import java.io.Serializable;
  15. import java.util.ArrayList;
  16. import java.util.Collection;
  17. import java.util.List;
  18. import javax.jdo.annotations.Element;
  19. import javax.jdo.annotations.Extension;
  20. import javax.jdo.annotations.IdGeneratorStrategy;
  21. import javax.jdo.annotations.PersistenceCapable;
  22. import javax.jdo.annotations.Persistent;
  23. import javax.jdo.annotations.PrimaryKey;
  24. /**
  25. * @author Max Ross <maxr@google.com>
  26. */
  27. @PersistenceCapable(detachable = "true")
  28. public class HasOneToManyListJDO implements HasOneToManyJDO, Serializable {
  29. @PrimaryKey
  30. @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  31. @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value="true")
  32. private String id;
  33. @Persistent
  34. private String val;
  35. public void setId(String id) {
  36. this.id = id;
  37. }
  38. public String getId() {
  39. return id;
  40. }
  41. @Persistent(mappedBy = "parent")
  42. @Element(dependent = "true")
  43. private List<BidirectionalChildListJDO> bidirChildren = new ArrayList<BidirectionalChildListJDO>();
  44. @Persistent
  45. @Element(dependent = "true")
  46. private List<Flight> flights = new ArrayList<Flight>();
  47. @Persistent
  48. @Element(dependent = "true")
  49. private List<HasKeyPkJDO> hasKeyPks = new ArrayList<HasKeyPkJDO>();
  50. public List<BidirectionalChildJDO> getBidirChildren() {
  51. return (List) bidirChildren;
  52. }
  53. public void addBidirChild(BidirectionalChildJDO bidirChild) {
  54. bidirChildren.add((BidirectionalChildListJDO) bidirChild);
  55. }
  56. public List<Flight> getFlights() {
  57. return flights;
  58. }
  59. public void addFlight(Flight flight) {
  60. this.flights.add(flight);
  61. }
  62. public List<HasKeyPkJDO> getHasKeyPks() {
  63. return hasKeyPks;
  64. }
  65. public void addHasKeyPk(HasKeyPkJDO hasKeyPk) {
  66. this.hasKeyPks.add(hasKeyPk);
  67. }
  68. public String getVal() {
  69. return val;
  70. }
  71. public void setVal(String val) {
  72. this.val = val;
  73. }
  74. public void nullBidirChildren() {
  75. bidirChildren = null;
  76. }
  77. public void nullFlights() {
  78. flights = null;
  79. }
  80. public void nullHasKeyPks() {
  81. hasKeyPks = null;
  82. }
  83. public void clearBidirChildren() {
  84. bidirChildren.clear();
  85. }
  86. public void clearFlights() {
  87. flights.clear();
  88. }
  89. public void clearHasKeyPks() {
  90. hasKeyPks.clear();
  91. }
  92. public void addBidirChildAtPosition(BidirectionalChildJDO bidir, int pos) {
  93. bidirChildren.set(pos, (BidirectionalChildListJDO) bidir);
  94. }
  95. public void addFlightAtPosition(Flight f, int pos) {
  96. flights.set(pos, f);
  97. }
  98. public void addHasKeyPkAtPosition(HasKeyPkJDO hasKeyPk, int pos) {
  99. hasKeyPks.set(pos, hasKeyPk);
  100. }
  101. public void removeBidirChildAtPosition(int i) {
  102. bidirChildren.remove(i);
  103. }
  104. public void removeFlightAtPosition(int i) {
  105. flights.remove(i);
  106. }
  107. public void removeHasKeyPkAtPosition(int i) {
  108. hasKeyPks.remove(i);
  109. }
  110. public void addAtPosition(int i, BidirectionalChildJDO bidir) {
  111. bidirChildren.add(i, (BidirectionalChildListJDO) bidir);
  112. }
  113. public void addAtPosition(int i, Flight f) {
  114. flights.add(i, f);
  115. }
  116. public void addAtPosition(int i, HasKeyPkJDO hasKeyPk) {
  117. hasKeyPks.add(i, hasKeyPk);
  118. }
  119. public void removeFlights(Collection<Flight> flights) {
  120. this.flights.removeAll(flights);
  121. }
  122. public void removeBidirChildren(Collection<BidirectionalChildJDO> bidirChildren) {
  123. this.bidirChildren.removeAll(bidirChildren);
  124. }
  125. public void setBidirChildren(Collection<BidirectionalChildJDO> childList) {
  126. this.bidirChildren = (List) childList;
  127. }
  128. }