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

http://datanucleus-appengine.googlecode.com/ · Java · 329 lines · 240 code · 74 blank · 15 comment · 30 complexity · fb8e9a9ee3dc8d041f4859bc13f1750e 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.KeyFactory;
  15. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirBottom;
  16. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirBottomLongPk;
  17. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirBottomUnencodedStringPk;
  18. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirMiddle;
  19. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirMiddleLongPk;
  20. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirMiddleUnencodedStringPk;
  21. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTop;
  22. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTopLongPk;
  23. import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTopUnencodedStringPk;
  24. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyJPA;
  25. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyLongPkJPA;
  26. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyUnencodedStringPkJPA;
  27. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsSetJPA.HasOneToManyLongPkSetJPA;
  28. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsSetJPA.HasOneToManySetJPA;
  29. import com.google.appengine.datanucleus.test.HasPolymorphicRelationsSetJPA.HasOneToManyUnencodedStringPkSetJPA;
  30. import org.datanucleus.api.jpa.annotations.Extension;
  31. import javax.persistence.DiscriminatorColumn;
  32. import javax.persistence.DiscriminatorType;
  33. import javax.persistence.DiscriminatorValue;
  34. import javax.persistence.Entity;
  35. import javax.persistence.FetchType;
  36. import javax.persistence.GeneratedValue;
  37. import javax.persistence.GenerationType;
  38. import javax.persistence.Id;
  39. import javax.persistence.ManyToOne;
  40. import static com.google.appengine.datanucleus.PolymorphicTestUtils.getEntityKind;
  41. public class BidirectionalSingleTableChildSetJPA {
  42. @Entity
  43. @DiscriminatorColumn(name = "DTYPE")
  44. public static class BidirTopSet implements BidirTop {
  45. @Id
  46. @GeneratedValue(strategy=GenerationType.IDENTITY)
  47. @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
  48. private String id;
  49. @ManyToOne(fetch = FetchType.LAZY)
  50. private HasOneToManySetJPA parent;
  51. private String childVal;
  52. public BidirTopSet() {
  53. }
  54. public BidirTopSet(String id) {
  55. this.id = KeyFactory.createKeyString(getEntityKind(BidirTopSet.class), id);
  56. }
  57. public HasOneToManySetJPA getParent() {
  58. return parent;
  59. }
  60. public void setParent(HasOneToManyJPA parent) {
  61. this.parent = (HasOneToManySetJPA) parent;
  62. }
  63. public String getId() {
  64. return id;
  65. }
  66. public String getChildVal() {
  67. return childVal;
  68. }
  69. public void setChildVal(String childVal) {
  70. this.childVal = childVal;
  71. }
  72. public boolean equals(Object o) {
  73. if (this == o) {
  74. return true;
  75. }
  76. if (o == null || getClass() != o.getClass()) {
  77. return false;
  78. }
  79. BidirTopSet that = (BidirTopSet) o;
  80. if (id != null ? !id.equals(that.id) : that.id != null) {
  81. return false;
  82. }
  83. return true;
  84. }
  85. public int hashCode() {
  86. return (id != null ? id.hashCode() : 0);
  87. }
  88. public int getPropertyCount() {
  89. return 2;
  90. }
  91. }
  92. @Entity
  93. public static class BidirMiddleSet extends BidirTopSet implements BidirMiddle {
  94. public BidirMiddleSet() {
  95. }
  96. public BidirMiddleSet(String id) {
  97. super(id);
  98. }
  99. private Long middleChildVal;
  100. public Long getMiddleChildVal() {
  101. return middleChildVal;
  102. }
  103. public void setMiddleChildVal(Long middleChildVal) {
  104. this.middleChildVal = middleChildVal;
  105. }
  106. public int getPropertyCount() {
  107. return 3;
  108. }
  109. }
  110. @Entity
  111. public static class BidirBottomSet extends BidirMiddleSet implements BidirBottom {
  112. public BidirBottomSet() {
  113. }
  114. public BidirBottomSet(String id) {
  115. super(id);
  116. }
  117. private Double bottomChildVal;
  118. public Double getBottomChildVal() {
  119. return bottomChildVal;
  120. }
  121. public void setBottomChildVal(Double bottomChildVal) {
  122. this.bottomChildVal = bottomChildVal;
  123. }
  124. public int getPropertyCount() {
  125. return 4;
  126. }
  127. }
  128. @Entity
  129. @DiscriminatorValue(value = "T")
  130. public static class BidirTopLongPkSet implements BidirTopLongPk {
  131. @Id
  132. @GeneratedValue(strategy=GenerationType.IDENTITY)
  133. @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
  134. private String id;
  135. @ManyToOne(fetch = FetchType.LAZY)
  136. private HasOneToManyLongPkSetJPA parent;
  137. private String childVal;
  138. public HasOneToManyLongPkJPA getParent() {
  139. return parent;
  140. }
  141. public void setParent(HasOneToManyLongPkJPA parent) {
  142. this.parent = (HasOneToManyLongPkSetJPA) parent;
  143. }
  144. public String getId() {
  145. return id;
  146. }
  147. public String getChildVal() {
  148. return childVal;
  149. }
  150. public void setChildVal(String childVal) {
  151. this.childVal = childVal;
  152. }
  153. public boolean equals(Object o) {
  154. if (this == o) {
  155. return true;
  156. }
  157. if (o == null || getClass() != o.getClass()) {
  158. return false;
  159. }
  160. BidirTopLongPkSet that = (BidirTopLongPkSet) o;
  161. if (id != null ? !id.equals(that.id) : that.id != null) {
  162. return false;
  163. }
  164. return true;
  165. }
  166. public int hashCode() {
  167. return (id != null ? id.hashCode() : 0);
  168. }
  169. }
  170. @Entity
  171. @DiscriminatorValue(value = "M")
  172. public static class BidirMiddleLongPkSet extends BidirTopLongPkSet implements BidirMiddleLongPk {
  173. }
  174. @Entity
  175. @DiscriminatorValue(value = "B")
  176. public static class BidirBottomLongPkSet extends BidirMiddleLongPkSet implements BidirBottomLongPk {
  177. }
  178. @Entity
  179. @DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.CHAR)
  180. @DiscriminatorValue(value = "A")
  181. public static class BidirTopUnencodedStringPkSet implements BidirTopUnencodedStringPk {
  182. @Id
  183. @GeneratedValue(strategy=GenerationType.IDENTITY)
  184. @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
  185. private String id;
  186. @ManyToOne(fetch = FetchType.LAZY)
  187. private HasOneToManyUnencodedStringPkSetJPA parent;
  188. private String childVal;
  189. public HasOneToManyUnencodedStringPkSetJPA getParent() {
  190. return parent;
  191. }
  192. public void setParent(HasOneToManyUnencodedStringPkJPA parent) {
  193. this.parent = (HasOneToManyUnencodedStringPkSetJPA) parent;
  194. }
  195. public String getId() {
  196. return id;
  197. }
  198. public String getChildVal() {
  199. return childVal;
  200. }
  201. public void setChildVal(String childVal) {
  202. this.childVal = childVal;
  203. }
  204. public boolean equals(Object o) {
  205. if (this == o) {
  206. return true;
  207. }
  208. if (o == null || getClass() != o.getClass()) {
  209. return false;
  210. }
  211. BidirTopUnencodedStringPkSet that = (BidirTopUnencodedStringPkSet) o;
  212. if (id != null ? !id.equals(that.id) : that.id != null) {
  213. return false;
  214. }
  215. return true;
  216. }
  217. public int hashCode() {
  218. return (id != null ? id.hashCode() : 0);
  219. }
  220. public int getPropertyCount() {
  221. return 2;
  222. }
  223. }
  224. @Entity
  225. @DiscriminatorValue(value = "B")
  226. public static class BidirMiddleUnencodedStringPkSet extends BidirTopUnencodedStringPkSet implements BidirMiddleUnencodedStringPk {
  227. private String middleChildVal;
  228. public String getMiddleChildVal() {
  229. return middleChildVal;
  230. }
  231. public void setMiddleChildVal(String middleChildVal) {
  232. this.middleChildVal = middleChildVal;
  233. }
  234. public int getPropertyCount() {
  235. return 3;
  236. }
  237. }
  238. @Entity
  239. @DiscriminatorValue(value = "C")
  240. public static class BidirBottomUnencodedStringPkSet extends BidirMiddleUnencodedStringPkSet implements BidirBottomUnencodedStringPk {
  241. private String bottomChildVal;
  242. public String getBottomChildVal() {
  243. return bottomChildVal;
  244. }
  245. public void setBottomChildVal(String bottomChildVal) {
  246. this.bottomChildVal = bottomChildVal;
  247. }
  248. public int getPropertyCount() {
  249. return 4;
  250. }
  251. }
  252. }