/tests/com/google/appengine/datanucleus/test/BidirectionalSingleTableChildSetJPA.java
Java | 329 lines | 240 code | 74 blank | 15 comment | 30 complexity | fb8e9a9ee3dc8d041f4859bc13f1750e MD5 | raw file
1/********************************************************************** 2Copyright (c) 2011 Google Inc. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15**********************************************************************/ 16package com.google.appengine.datanucleus.test; 17 18import com.google.appengine.api.datastore.KeyFactory; 19import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirBottom; 20import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirBottomLongPk; 21import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirBottomUnencodedStringPk; 22import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirMiddle; 23import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirMiddleLongPk; 24import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirMiddleUnencodedStringPk; 25import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTop; 26import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTopLongPk; 27import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildJPA.BidirTopUnencodedStringPk; 28import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyJPA; 29import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyLongPkJPA; 30import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyUnencodedStringPkJPA; 31import com.google.appengine.datanucleus.test.HasPolymorphicRelationsSetJPA.HasOneToManyLongPkSetJPA; 32import com.google.appengine.datanucleus.test.HasPolymorphicRelationsSetJPA.HasOneToManySetJPA; 33import com.google.appengine.datanucleus.test.HasPolymorphicRelationsSetJPA.HasOneToManyUnencodedStringPkSetJPA; 34 35import org.datanucleus.api.jpa.annotations.Extension; 36 37import javax.persistence.DiscriminatorColumn; 38import javax.persistence.DiscriminatorType; 39import javax.persistence.DiscriminatorValue; 40import javax.persistence.Entity; 41import javax.persistence.FetchType; 42import javax.persistence.GeneratedValue; 43import javax.persistence.GenerationType; 44import javax.persistence.Id; 45import javax.persistence.ManyToOne; 46 47import static com.google.appengine.datanucleus.PolymorphicTestUtils.getEntityKind; 48 49public class BidirectionalSingleTableChildSetJPA { 50 51 @Entity 52 @DiscriminatorColumn(name = "DTYPE") 53 public static class BidirTopSet implements BidirTop { 54 @Id 55 @GeneratedValue(strategy=GenerationType.IDENTITY) 56 @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") 57 private String id; 58 59 @ManyToOne(fetch = FetchType.LAZY) 60 private HasOneToManySetJPA parent; 61 62 private String childVal; 63 64 public BidirTopSet() { 65 } 66 67 public BidirTopSet(String id) { 68 this.id = KeyFactory.createKeyString(getEntityKind(BidirTopSet.class), id); 69 } 70 71 public HasOneToManySetJPA getParent() { 72 return parent; 73 } 74 75 public void setParent(HasOneToManyJPA parent) { 76 this.parent = (HasOneToManySetJPA) parent; 77 } 78 79 public String getId() { 80 return id; 81 } 82 83 public String getChildVal() { 84 return childVal; 85 } 86 87 public void setChildVal(String childVal) { 88 this.childVal = childVal; 89 } 90 91 public boolean equals(Object o) { 92 if (this == o) { 93 return true; 94 } 95 if (o == null || getClass() != o.getClass()) { 96 return false; 97 } 98 99 BidirTopSet that = (BidirTopSet) o; 100 101 if (id != null ? !id.equals(that.id) : that.id != null) { 102 return false; 103 } 104 105 return true; 106 } 107 108 public int hashCode() { 109 return (id != null ? id.hashCode() : 0); 110 } 111 112 public int getPropertyCount() { 113 return 2; 114 } 115 116 } 117 118 @Entity 119 public static class BidirMiddleSet extends BidirTopSet implements BidirMiddle { 120 121 public BidirMiddleSet() { 122 } 123 124 public BidirMiddleSet(String id) { 125 super(id); 126 } 127 128 private Long middleChildVal; 129 130 public Long getMiddleChildVal() { 131 return middleChildVal; 132 } 133 134 public void setMiddleChildVal(Long middleChildVal) { 135 this.middleChildVal = middleChildVal; 136 } 137 138 public int getPropertyCount() { 139 return 3; 140 } 141 } 142 143 @Entity 144 public static class BidirBottomSet extends BidirMiddleSet implements BidirBottom { 145 146 public BidirBottomSet() { 147 } 148 149 public BidirBottomSet(String id) { 150 super(id); 151 } 152 153 private Double bottomChildVal; 154 155 public Double getBottomChildVal() { 156 return bottomChildVal; 157 } 158 159 public void setBottomChildVal(Double bottomChildVal) { 160 this.bottomChildVal = bottomChildVal; 161 } 162 163 public int getPropertyCount() { 164 return 4; 165 } 166 } 167 168 @Entity 169 @DiscriminatorValue(value = "T") 170 public static class BidirTopLongPkSet implements BidirTopLongPk { 171 @Id 172 @GeneratedValue(strategy=GenerationType.IDENTITY) 173 @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") 174 private String id; 175 176 @ManyToOne(fetch = FetchType.LAZY) 177 private HasOneToManyLongPkSetJPA parent; 178 179 private String childVal; 180 181 public HasOneToManyLongPkJPA getParent() { 182 return parent; 183 } 184 185 public void setParent(HasOneToManyLongPkJPA parent) { 186 this.parent = (HasOneToManyLongPkSetJPA) parent; 187 } 188 189 public String getId() { 190 return id; 191 } 192 193 public String getChildVal() { 194 return childVal; 195 } 196 197 public void setChildVal(String childVal) { 198 this.childVal = childVal; 199 } 200 201 public boolean equals(Object o) { 202 if (this == o) { 203 return true; 204 } 205 if (o == null || getClass() != o.getClass()) { 206 return false; 207 } 208 209 BidirTopLongPkSet that = (BidirTopLongPkSet) o; 210 211 if (id != null ? !id.equals(that.id) : that.id != null) { 212 return false; 213 } 214 215 return true; 216 } 217 218 public int hashCode() { 219 return (id != null ? id.hashCode() : 0); 220 } 221 222 } 223 224 @Entity 225 @DiscriminatorValue(value = "M") 226 public static class BidirMiddleLongPkSet extends BidirTopLongPkSet implements BidirMiddleLongPk { 227 } 228 229 @Entity 230 @DiscriminatorValue(value = "B") 231 public static class BidirBottomLongPkSet extends BidirMiddleLongPkSet implements BidirBottomLongPk { 232 } 233 234 @Entity 235 @DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.CHAR) 236 @DiscriminatorValue(value = "A") 237 public static class BidirTopUnencodedStringPkSet implements BidirTopUnencodedStringPk { 238 @Id 239 @GeneratedValue(strategy=GenerationType.IDENTITY) 240 @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") 241 private String id; 242 243 @ManyToOne(fetch = FetchType.LAZY) 244 private HasOneToManyUnencodedStringPkSetJPA parent; 245 246 private String childVal; 247 248 public HasOneToManyUnencodedStringPkSetJPA getParent() { 249 return parent; 250 } 251 252 public void setParent(HasOneToManyUnencodedStringPkJPA parent) { 253 this.parent = (HasOneToManyUnencodedStringPkSetJPA) parent; 254 } 255 256 public String getId() { 257 return id; 258 } 259 260 public String getChildVal() { 261 return childVal; 262 } 263 264 public void setChildVal(String childVal) { 265 this.childVal = childVal; 266 } 267 268 public boolean equals(Object o) { 269 if (this == o) { 270 return true; 271 } 272 if (o == null || getClass() != o.getClass()) { 273 return false; 274 } 275 276 BidirTopUnencodedStringPkSet that = (BidirTopUnencodedStringPkSet) o; 277 278 if (id != null ? !id.equals(that.id) : that.id != null) { 279 return false; 280 } 281 282 return true; 283 } 284 285 public int hashCode() { 286 return (id != null ? id.hashCode() : 0); 287 } 288 289 public int getPropertyCount() { 290 return 2; 291 } 292 } 293 294 @Entity 295 @DiscriminatorValue(value = "B") 296 public static class BidirMiddleUnencodedStringPkSet extends BidirTopUnencodedStringPkSet implements BidirMiddleUnencodedStringPk { 297 private String middleChildVal; 298 299 public String getMiddleChildVal() { 300 return middleChildVal; 301 } 302 303 public void setMiddleChildVal(String middleChildVal) { 304 this.middleChildVal = middleChildVal; 305 } 306 307 public int getPropertyCount() { 308 return 3; 309 } 310 } 311 312 @Entity 313 @DiscriminatorValue(value = "C") 314 public static class BidirBottomUnencodedStringPkSet extends BidirMiddleUnencodedStringPkSet implements BidirBottomUnencodedStringPk { 315 private String bottomChildVal; 316 317 public String getBottomChildVal() { 318 return bottomChildVal; 319 } 320 321 public void setBottomChildVal(String bottomChildVal) { 322 this.bottomChildVal = bottomChildVal; 323 } 324 325 public int getPropertyCount() { 326 return 4; 327 } 328 } 329}