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

http://datanucleus-appengine.googlecode.com/ · Java · 189 lines · 131 code · 43 blank · 15 comment · 0 complexity · 18c0f821e66c2fa017a5574c6edd2a14 MD5 · raw file

  1. /**********************************************************************
  2. Copyright (c) 2011 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 com.google.appengine.api.datastore.Key;
  15. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTop;
  16. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTopLongPk;
  17. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTopUnencodedStringPk;
  18. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildSetJPA.BidirTopLongPkSet;
  19. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildSetJPA.BidirTopSet;
  20. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildSetJPA.BidirTopUnencodedStringPkSet;
  21. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyJPA;
  22. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyKeyPkJPA;
  23. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyLongPkJPA;
  24. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyUnencodedStringPkJPA;
  25. import com.google.appengine.datanucleus.test.UnidirectionalSingeTableChildJPA.UnidirTop;
  26. import org.datanucleus.api.jpa.annotations.Extension;
  27. import java.util.Collection;
  28. import java.util.HashSet;
  29. import java.util.Set;
  30. import javax.persistence.CascadeType;
  31. import javax.persistence.Entity;
  32. import javax.persistence.GeneratedValue;
  33. import javax.persistence.GenerationType;
  34. import javax.persistence.Id;
  35. import javax.persistence.OneToMany;
  36. public class HasPolymorphicRelationsSetJPA {
  37. @Entity
  38. public static class HasOneToManySetJPA implements HasOneToManyJPA {
  39. @Id
  40. @GeneratedValue(strategy = GenerationType.IDENTITY)
  41. @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
  42. private String id;
  43. private String val;
  44. @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
  45. private Set<BidirTopSet> bidirChildren = new HashSet<BidirTopSet>();
  46. @OneToMany(cascade = CascadeType.ALL)
  47. private Set<UnidirTop> unidirChildren = new HashSet<UnidirTop>();
  48. @OneToMany(cascade = CascadeType.ALL)
  49. private Set<HasKeyPkJPA> hasKeyPks = new HashSet<HasKeyPkJPA>();
  50. public String getId() {
  51. return id;
  52. }
  53. public Set<BidirTop> getBidirChildren() {
  54. return (Set) bidirChildren;
  55. }
  56. public void nullBidirChildren() {
  57. this.bidirChildren = null;
  58. }
  59. public Set<UnidirTop> getUnidirChildren() {
  60. return unidirChildren;
  61. }
  62. public void nullUnidirChildren() {
  63. this.unidirChildren = null;
  64. }
  65. public Set<HasKeyPkJPA> getHasKeyPks() {
  66. return hasKeyPks;
  67. }
  68. public void nullHasKeyPks() {
  69. this.hasKeyPks = null;
  70. }
  71. public String getVal() {
  72. return val;
  73. }
  74. public void setVal(String val) {
  75. this.val = val;
  76. }
  77. }
  78. @Entity
  79. public static class HasOneToManyKeyPkSetJPA implements HasOneToManyKeyPkJPA {
  80. @Id
  81. @GeneratedValue(strategy=GenerationType.IDENTITY)
  82. private Key id;
  83. @OneToMany(cascade = CascadeType.ALL)
  84. private Set<UnidirTop> unidirChildren = new HashSet<UnidirTop>();
  85. public Key getId() {
  86. return id;
  87. }
  88. public Set<UnidirTop> getUnidirChildren() {
  89. return unidirChildren;
  90. }
  91. public void nullBooks() {
  92. this.unidirChildren = null;
  93. }
  94. }
  95. @Entity
  96. public static class HasOneToManyLongPkSetJPA implements HasOneToManyLongPkJPA {
  97. @Id
  98. @GeneratedValue(strategy=GenerationType.IDENTITY)
  99. private Long id;
  100. @OneToMany(cascade = CascadeType.ALL)
  101. private Set<UnidirTop> unidirChildren = new HashSet<UnidirTop>();
  102. @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
  103. private Set<BidirTopLongPkSet> bidirChildren =
  104. new HashSet<BidirTopLongPkSet>();
  105. public Long getId() {
  106. return id;
  107. }
  108. public Set<UnidirTop> getUnidirChildren() {
  109. return unidirChildren;
  110. }
  111. public void unidirChildren() {
  112. this.unidirChildren = null;
  113. }
  114. public Collection<BidirTopLongPk> getBidirChildren() {
  115. return (Set) bidirChildren;
  116. }
  117. }
  118. @Entity
  119. public static class HasOneToManyUnencodedStringPkSetJPA implements HasOneToManyUnencodedStringPkJPA {
  120. @Id
  121. private String id;
  122. @OneToMany(cascade = CascadeType.ALL)
  123. private Set<UnidirTop> books = new HashSet<UnidirTop>();
  124. @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
  125. private Set<BidirTopUnencodedStringPkSet> bidirChildren =
  126. new HashSet<BidirTopUnencodedStringPkSet>();
  127. public String getId() {
  128. return id;
  129. }
  130. public void setId(String id) {
  131. this.id = id;
  132. }
  133. public Set<UnidirTop> getUnidirChildren() {
  134. return books;
  135. }
  136. public void nullBooks() {
  137. this.books = null;
  138. }
  139. public Collection<BidirTopUnencodedStringPk> getBidirChildren() {
  140. return (Set) bidirChildren;
  141. }
  142. }
  143. }