PageRenderTime 132ms CodeModel.GetById 81ms app.highlight 47ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://datanucleus-appengine.googlecode.com/
Java | 375 lines | 275 code | 82 blank | 18 comment | 0 complexity | 5c2da790fcf73980aa19344ba2bd2330 MD5 | raw file
  1/**********************************************************************
  2Copyright (c) 2009 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 javax.persistence.AttributeOverride;
 19import javax.persistence.AttributeOverrides;
 20import javax.persistence.Column;
 21import javax.persistence.DiscriminatorColumn;
 22import javax.persistence.Embeddable;
 23import javax.persistence.Embedded;
 24import javax.persistence.Entity;
 25import javax.persistence.GeneratedValue;
 26import javax.persistence.GenerationType;
 27import javax.persistence.Id;
 28import javax.persistence.Inheritance;
 29import javax.persistence.InheritanceType;
 30import javax.persistence.MappedSuperclass;
 31
 32/**
 33 * @author Max Ross <maxr@google.com>
 34 */
 35public class SubclassesJPA {
 36
 37  public interface Parent {
 38    Long getId();
 39    void setAString(String val);
 40    String getAString();
 41  }
 42
 43  public interface Child extends Parent {
 44    void setBString(String val);
 45    String getBString();
 46  }
 47
 48  public interface Grandchild extends Child {
 49    void setCString(String val);
 50    String getCString();
 51  }
 52
 53  @Entity
 54  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 55  public static class TablePerClass implements Parent {
 56    @Id
 57    @GeneratedValue(strategy= GenerationType.IDENTITY)
 58    private Long id;
 59
 60    private String aString;
 61
 62    public Long getId() {
 63      return id;
 64    }
 65
 66    public void setAString(String aString) {
 67      this.aString = aString;
 68    }
 69
 70    public String getAString() {
 71      return aString;
 72    }
 73  }
 74
 75  @Entity
 76  public static class TablePerClassChild extends TablePerClass implements Child {
 77    private String bString;
 78
 79    public void setBString(String bString) {
 80      this.bString = bString;
 81    }
 82
 83    public String getBString() {
 84      return bString;
 85    }
 86  }
 87
 88  @Entity
 89  public static class TablePerClassGrandchild extends TablePerClassChild implements Grandchild {
 90    private String cString;
 91
 92    public void setCString(String cString) {
 93      this.cString = cString;
 94    }
 95
 96    public String getCString() {
 97      return cString;
 98    }
 99  }
100
101  @Entity
102  @Inheritance(strategy = InheritanceType.JOINED)
103  public static class Joined implements Parent {
104    @Id
105    @GeneratedValue(strategy = GenerationType.IDENTITY)
106    private Long id;
107
108    private String aString;
109
110    public Long getId() {
111      return id;
112    }
113
114    public void setAString(String aString) {
115      this.aString = aString;
116    }
117
118    public String getAString() {
119      return aString;
120    }
121  }
122
123  @Entity
124  public static class JoinedChild extends Joined implements Child {
125    private String bString;
126
127    public void setBString(String bString) {
128      this.bString = bString;
129    }
130
131    public String getBString() {
132      return bString;
133    }
134  }
135
136  @Entity
137  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
138  @DiscriminatorColumn(name = "TYPE")
139  public static class SingleTable implements Parent {
140    @Id
141    @GeneratedValue(strategy = GenerationType.IDENTITY)
142    private Long id;
143
144    private String aString;
145
146    public Long getId() {
147      return id;
148    }
149
150    public void setAString(String aString) {
151      this.aString = aString;
152    }
153
154    public String getAString() {
155      return aString;
156    }
157  }
158
159  @Entity
160  public static class SingleTableChild extends SingleTable implements Child {
161    private String bString;
162
163    public void setBString(String bString) {
164      this.bString = bString;
165    }
166
167    public String getBString() {
168      return bString;
169    }
170  }
171
172  @MappedSuperclass
173  public static class MappedSuperclassParent implements Parent {
174    @Id
175    @GeneratedValue(strategy = GenerationType.IDENTITY)
176    private Long id;
177
178    private String aString;
179    private String overriddenString;
180
181    public Long getId() {
182      return id;
183    }
184
185    public void setAString(String aString) {
186      this.aString = aString;
187    }
188
189    public String getAString() {
190      return aString;
191    }
192
193    public String getOverriddenString() {
194      return overriddenString;
195    }
196
197    public void setOverriddenString(String overriddenString) {
198      this.overriddenString = overriddenString;
199    }
200  }
201
202  @Entity
203  @AttributeOverride(name = "overriddenString", column = @Column(name = "overridden_string"))
204  public static class MappedSuperclassChild extends MappedSuperclassParent implements Child {
205    private String bString;
206
207    public void setBString(String bString) {
208      this.bString = bString;
209    }
210
211    public String getBString() {
212      return bString;
213    }
214  }
215
216  @Entity
217  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
218  public static class TablePerClassParentWithEmbedded implements Parent {
219    @Id
220    @GeneratedValue(strategy = GenerationType.IDENTITY)
221    private Long id;
222
223    @Embedded
224    private IsEmbeddedWithEmbeddedSuperclass embedded;
225
226    @Embedded
227    @AttributeOverrides({@AttributeOverride(name="val0", column=@Column(name="VAL0"))})
228    private IsEmbeddedBase embeddedBase;
229
230    private String aString;
231
232    public Long getId() {
233      return id;
234    }
235
236    public IsEmbeddedWithEmbeddedSuperclass getEmbedded() {
237      return embedded;
238    }
239
240    public void setEmbedded(IsEmbeddedWithEmbeddedSuperclass embedded) {
241      this.embedded = embedded;
242    }
243
244    public String getAString() {
245      return aString;
246    }
247
248    public void setAString(String aString) {
249      this.aString = aString;
250    }
251
252    public IsEmbeddedBase getEmbeddedBase() {
253      return embeddedBase;
254    }
255
256    public void setEmbeddedBase(IsEmbeddedBase embeddedBase) {
257      this.embeddedBase = embeddedBase;
258    }
259  }
260
261  @Entity
262  public static class ChildEmbeddedInTablePerClass extends TablePerClassParentWithEmbedded {
263    private String bString;
264
265    @Embedded
266    @AttributeOverrides({@AttributeOverride(name="val2", column=@Column(name="VAL2"))})
267    private IsEmbeddedBase2 embeddedBase2;
268
269    @Embedded
270    private IsEmbeddedWithEmbeddedSuperclass2 embedded2;
271
272    public void setBString(String bString) {
273      this.bString = bString;
274    }
275
276    public String getBString() {
277      return bString;
278    }
279
280    public IsEmbeddedWithEmbeddedSuperclass2 getEmbedded2() {
281      return embedded2;
282    }
283
284    public void setEmbedded2(IsEmbeddedWithEmbeddedSuperclass2 embedded2) {
285      this.embedded2 = embedded2;
286    }
287
288    public IsEmbeddedBase2 getEmbeddedBase2() {
289      return embeddedBase2;
290    }
291
292    public void setEmbeddedBase2(IsEmbeddedBase2 embeddedBase2) {
293      this.embeddedBase2 = embeddedBase2;
294    }
295  }
296
297  @Embeddable
298  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
299  public static class IsEmbeddedBase2 {
300
301    private String val2;
302
303    public String getVal2() {
304      return val2;
305    }
306
307    public void setVal2(String val2) {
308      this.val2 = val2;
309    }
310  }
311
312  @Embeddable
313  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
314  public static class IsEmbeddedBase {
315
316    private String val0;
317
318    public String getVal0() {
319      return val0;
320    }
321
322    public void setVal0(String val0) {
323      this.val0 = val0;
324    }
325  }
326
327  public static class NondurableParent {
328    private Long id;
329
330    private String str;
331
332    public Long getId() {
333      return id;
334    }
335
336    public void setId(Long id) {
337      this.id = id;
338    }
339
340    public String getStr() {
341      return str;
342    }
343
344    public void setStr(String str) {
345      this.str = str;
346    }
347  }
348
349  @Entity
350  public static class DurableChild extends NondurableParent {
351
352    @Override
353    @Id
354    @GeneratedValue(strategy = GenerationType.IDENTITY)
355    public Long getId() {
356      return super.getId();
357    }
358
359    @Override
360    public String getStr() {
361      return super.getStr();
362    }
363
364    @Override
365    public void setId(Long id) {
366      super.setId(id);
367    }
368
369    @Override
370    public void setStr(String str) {
371      super.setStr(str);
372    }
373  }
374
375}