PageRenderTime 17ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 183 lines | 126 code | 39 blank | 18 comment | 0 complexity | 250712b7c7a73bb3dd10c24f2595e356 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Copyright (C) 2010 Google Inc
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of 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,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.google.appengine.datanucleus.test;
  17. import com.google.appengine.api.datastore.Key;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import javax.persistence.CascadeType;
  21. import javax.persistence.Entity;
  22. import javax.persistence.FetchType;
  23. import javax.persistence.GeneratedValue;
  24. import javax.persistence.GenerationType;
  25. import javax.persistence.Id;
  26. import javax.persistence.Inheritance;
  27. import javax.persistence.InheritanceType;
  28. import javax.persistence.OneToMany;
  29. import javax.persistence.OrderBy;
  30. /**
  31. * @author Max Ross <max.ross@gmail.com>
  32. */
  33. public class UnidirectionalOneToManySubclassesJPA {
  34. @Entity
  35. @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  36. public static class SuperParentWithSuperChild {
  37. @Id
  38. @GeneratedValue(strategy= GenerationType.IDENTITY)
  39. private Long id;
  40. private String superParentString;
  41. @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  42. @OrderBy(value = "aString desc")
  43. private List<SuperChild> superChildren = new ArrayList<SuperChild>();
  44. public Long getId() {
  45. return id;
  46. }
  47. public void setId(Long id) {
  48. this.id = id;
  49. }
  50. public String getSuperParentString() {
  51. return superParentString;
  52. }
  53. public void setSuperParentString(String superParentString) {
  54. this.superParentString = superParentString;
  55. }
  56. public List<SuperChild> getSuperParentSuperChildren() {
  57. return superChildren;
  58. }
  59. public void setSuperParentSuperChildren(
  60. List<SuperChild> superChildren) {
  61. this.superChildren = superChildren;
  62. }
  63. }
  64. @Entity
  65. @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  66. public static class SuperParentWithSubChild {
  67. @Id
  68. @GeneratedValue(strategy= GenerationType.IDENTITY)
  69. private Long id;
  70. private String superParentString;
  71. @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  72. @OrderBy(value = "aString desc")
  73. private List<SubChild> subChildren = new ArrayList<SubChild>();
  74. public Long getId() {
  75. return id;
  76. }
  77. public String getSuperParentString() {
  78. return superParentString;
  79. }
  80. public void setSuperParentString(String superParentString) {
  81. this.superParentString = superParentString;
  82. }
  83. public void setId(Long id) {
  84. this.id = id;
  85. }
  86. public List<SubChild> getSuperParentSubChildren() {
  87. return subChildren;
  88. }
  89. public void setSuperParentSubChildren(
  90. List<SubChild> subChildren) {
  91. this.subChildren = subChildren;
  92. }
  93. }
  94. @Entity
  95. public static class SubParentWithSuperChild extends SuperParentWithSuperChild {
  96. private String subParentString;
  97. public String getSubParentString() {
  98. return subParentString;
  99. }
  100. public void setSubParentString(String subParentString) {
  101. this.subParentString = subParentString;
  102. }
  103. }
  104. @Entity
  105. public static class SubParentWithSubChild extends SuperParentWithSubChild {
  106. private String subParentString;
  107. public String getSubParentString() {
  108. return subParentString;
  109. }
  110. public void setSubParentString(String subParentString) {
  111. this.subParentString = subParentString;
  112. }
  113. }
  114. @Entity
  115. @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  116. public static class SuperChild {
  117. @Id
  118. @GeneratedValue(strategy= GenerationType.IDENTITY)
  119. private Key id;
  120. private String aString;
  121. public Key getId() {
  122. return id;
  123. }
  124. public void setId(Key id) {
  125. this.id = id;
  126. }
  127. public String getAString() {
  128. return aString;
  129. }
  130. public void setAString(String aString) {
  131. this.aString = aString;
  132. }
  133. }
  134. @Entity
  135. public static class SubChild extends SuperChild {
  136. private String bString;
  137. public String getBString() {
  138. return bString;
  139. }
  140. public void setBString(String bString) {
  141. this.bString = bString;
  142. }
  143. }
  144. }