PageRenderTime 42ms CodeModel.GetById 17ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 389 lines | 278 code | 96 blank | 15 comment | 0 complexity | 4b7ca894031f06363eaad15328fd2ea4 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.Key;
 19import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildListJPA.BidirTopList;
 20import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildListJPA.BidirTopLongPkList;
 21import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildListJPA.BidirTopStringPkList;
 22import com.google.appengine.datanucleus.test.BidirectionalSingleTableChildListJPA.BidirTopUnencodedStringPkList;
 23import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyJPA;
 24import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyKeyPkJPA;
 25import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyLongPkJPA;
 26import com.google.appengine.datanucleus.test.HasPolymorphicRelationsJPA.HasOneToManyUnencodedStringPkJPA;
 27import com.google.appengine.datanucleus.test.SubclassesJPA.MappedSuperclassParent;
 28import com.google.appengine.datanucleus.test.SubclassesJPA.TablePerClass;
 29import com.google.appengine.datanucleus.test.UnidirectionalSingeTableChildJPA.UnidirTop;
 30
 31import org.datanucleus.api.jpa.annotations.Extension;
 32
 33import java.util.ArrayList;
 34import java.util.Collection;
 35import java.util.List;
 36
 37import javax.persistence.CascadeType;
 38import javax.persistence.Entity;
 39import javax.persistence.FetchType;
 40import javax.persistence.GeneratedValue;
 41import javax.persistence.GenerationType;
 42import javax.persistence.Id;
 43import javax.persistence.JoinColumn;
 44import javax.persistence.OneToMany;
 45import javax.persistence.OneToOne;
 46import javax.persistence.OrderBy;
 47
 48public class HasPolymorphicRelationsListJPA {
 49  @Entity
 50  public static class HasOneToManyListJPA implements HasOneToManyJPA {
 51
 52    @Id
 53    @GeneratedValue(strategy=GenerationType.IDENTITY)
 54    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
 55    private String id;
 56
 57    private String val;
 58
 59    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
 60    private List<BidirTopList> bidirChildren = new ArrayList<BidirTopList>();
 61
 62    @OneToMany(cascade = CascadeType.ALL)
 63    private List<UnidirTop> unidirChildren = new ArrayList<UnidirTop>();
 64
 65    @OneToMany(cascade = CascadeType.ALL)
 66    private List<HasKeyPkJPA> hasKeyPks = new ArrayList<HasKeyPkJPA>();
 67
 68    public String getId() {
 69      return id;
 70    }
 71
 72    public List<BidirectionalSingleTableChildJPA.BidirTop> getBidirChildren() {
 73      return (List) bidirChildren;
 74    }
 75
 76    public void nullBidirChildren() {
 77      this.bidirChildren = null;
 78    }
 79
 80    public List<UnidirTop> getUnidirChildren() {
 81      return unidirChildren;
 82    }
 83
 84    public void nullUnidirChildren() {
 85      this.unidirChildren = null;
 86    }
 87
 88    public List<HasKeyPkJPA> getHasKeyPks() {
 89      return hasKeyPks;
 90    }
 91
 92    public void nullHasKeyPks() {
 93      this.hasKeyPks = null;
 94    }
 95
 96    public String getVal() {
 97      return val;
 98    }
 99
100    public void setVal(String val) {
101      this.val = val;
102    }
103  }
104  
105  @Entity
106  public static class HasOneToManyLongPkListJPA implements HasOneToManyLongPkJPA {
107
108    @Id
109    @GeneratedValue(strategy=GenerationType.IDENTITY)
110    private Long id;
111
112    private String val;
113
114    @OneToMany(cascade = CascadeType.ALL)
115    private List<UnidirTop> unidirChildren = new ArrayList<UnidirTop>();
116
117    @OneToMany(cascade = CascadeType.ALL)
118    private List<HasKeyPkJPA> hasKeyPks = new ArrayList<HasKeyPkJPA>();
119
120    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
121    private List<BidirTopLongPkList> bidirChildren =
122        new ArrayList<BidirTopLongPkList>();
123
124    public Long getId() {
125      return id;
126    }
127
128    public List<UnidirTop> getUnidirChildren() {
129      return unidirChildren;
130    }
131
132    public void nullUnidirChildren() {
133      this.unidirChildren = null;
134    }
135
136    public Collection<BidirectionalSingleTableChildJPA.BidirTopLongPk> getBidirChildren() {
137      return (List) bidirChildren;
138    }
139
140    public List<HasKeyPkJPA> getHasKeyPks() {
141      return hasKeyPks;
142    }
143
144    public String getVal() {
145      return val;
146    }
147
148    public void setVal(String val) {
149      this.val = val;
150    }
151  }
152  
153  @Entity
154  public static class HasOneToManyStringPkListJPA {
155
156    @Id
157    private String id;
158
159    private String val;
160
161    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
162    private List<BidirTopStringPkList> bidirChildren =
163        new ArrayList<BidirTopStringPkList>();
164
165    @OneToMany(cascade = CascadeType.ALL)
166    private List<UnidirTop> unidirChildren = new ArrayList<UnidirTop>();
167
168    @OneToMany(cascade = CascadeType.ALL)
169    private List<HasKeyPkJPA> hasKeyPks = new ArrayList<HasKeyPkJPA>();
170
171    public String getId() {
172      return id;
173    }
174
175    public void setId(String id) {
176      this.id = id;
177    }
178
179    public List<BidirTopStringPkList> getBidirChildren() {
180      return (List) bidirChildren;
181    }
182
183    public void nullBidirChildren() {
184      this.bidirChildren = null;
185    }
186
187    public List<UnidirTop> getUnidirChildren() {
188      return unidirChildren;
189    }
190
191    public void nullUnidirChildren() {
192      this.unidirChildren = null;
193    }
194
195    public List<HasKeyPkJPA> getHasKeyPks() {
196      return hasKeyPks;
197    }
198
199    public void nullHasKeyPks() {
200      this.hasKeyPks = null;
201    }
202
203    public String getVal() {
204      return val;
205    }
206
207    public void setVal(String val) {
208      this.val = val;
209    }
210    
211  }
212
213  @Entity
214  public static class HasOneToManyKeyPkListJPA implements HasOneToManyKeyPkJPA {
215
216    @Id
217    @GeneratedValue(strategy=GenerationType.IDENTITY)
218    private Key id;
219
220    @OneToMany(cascade = CascadeType.ALL)
221    private List<UnidirTop> unidirChildren = new ArrayList<UnidirTop>();
222
223    public Key getId() {
224      return id;
225    }
226
227    public List<UnidirTop> getUnidirChildren() {
228      return unidirChildren;
229    }
230
231    public void nullUnidirChildren() {
232      this.unidirChildren = null;
233    }
234
235  }
236  
237  @Entity
238  public static class HasOneToManyUnencodedStringPkListJPA implements HasOneToManyUnencodedStringPkJPA {
239
240    @Id
241    private String id;
242
243    @OneToMany(cascade = CascadeType.ALL)
244    private List<UnidirTop> unidirChildren = new ArrayList<UnidirTop>();
245
246    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
247    private List<BidirTopUnencodedStringPkList> bidirChildren =
248        new ArrayList<BidirTopUnencodedStringPkList>();
249
250    public String getId() {
251      return id;
252    }
253
254    public void setId(String id) {
255      this.id = id;
256    }
257
258    public List<UnidirTop> getUnidirChildren() {
259      return unidirChildren;
260    }
261
262    public void nullUnidirChildren() {
263      this.unidirChildren = null;
264    }
265
266    public Collection<BidirectionalSingleTableChildJPA.BidirTopUnencodedStringPk> getBidirChildren() {
267      return (Collection) bidirChildren; 
268    }
269  }
270
271  @Entity
272  public static class HasOneToManyWithOrderByJPA {
273  
274    @Id
275    @GeneratedValue(strategy=GenerationType.IDENTITY)
276    private Long id;
277  
278    private String val;
279  
280    @OneToMany(cascade = CascadeType.ALL)
281    @OrderBy("name DESC, str ASC")
282    private List<UnidirTop> unidirByNameAndStr = new ArrayList<UnidirTop>();
283  
284    @OneToMany(cascade = CascadeType.ALL)
285    @OrderBy("id DESC, name ASC")
286    private List<UnidirTop> unidirByIdAndName = new ArrayList<UnidirTop>();
287  
288    @OneToMany(cascade = CascadeType.ALL)
289    @OrderBy("name DESC, id ASC")
290    private List<UnidirTop> unidirByNameAndId = new ArrayList<UnidirTop>();
291  
292    public Long getId() {
293      return id;
294    }
295  
296    public List<UnidirTop> getUnidirByNameAndStr() {
297      return unidirByNameAndStr;
298    }
299  
300    public void setUnidirByNameAndStr(List<UnidirTop> unidirByNameAndStr) {
301      this.unidirByNameAndStr = unidirByNameAndStr;
302    }
303  
304    public List<UnidirTop> getUnidirByIdAndName() {
305      return unidirByIdAndName;
306    }
307  
308    public void setUnidirByIdAndName(List<UnidirTop> unidirByIdAndName) {
309      this.unidirByIdAndName = unidirByIdAndName;
310    }
311  
312    public List<UnidirTop> getUnidirByNameAndId() {
313      return unidirByNameAndId;
314    }
315  
316    public void setUnidirByNameAndId(List<UnidirTop> unidirByNameAndId) {
317      this.unidirByNameAndId = unidirByNameAndId;
318    }
319  
320    public String getVal() {
321      return val;
322    }
323  
324    public void setVal(String val) {
325      this.val = val;
326    }
327  }
328
329  @Entity
330  public static class HasOneToManyChildAtMultipleLevelsJPA {
331  
332    @Id
333    @GeneratedValue(strategy= GenerationType.IDENTITY)
334    private Key id;
335  
336    @OneToMany(cascade = CascadeType.ALL)
337    private List<UnidirTop> unidirChildren;
338  
339    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
340    @JoinColumn(name = "child_id")
341    private HasOneToManyChildAtMultipleLevelsJPA child;
342  
343    public Key getId() {
344      return id;
345    }
346  
347    public List<UnidirTop> getUnidirChildren() {
348      return unidirChildren;
349    }
350  
351    public void setUnidirChildren(List<UnidirTop> unidirChildren) {
352      this.unidirChildren = unidirChildren;
353    }
354  
355    public HasOneToManyChildAtMultipleLevelsJPA getChild() {
356      return child;
357    }
358  
359    public void setChild(HasOneToManyChildAtMultipleLevelsJPA child) {
360      this.child = child;
361    }
362  }
363  
364  @Entity
365  public static class HasOneToManyWithUnsupportedInheritanceList {
366    @Id
367    @GeneratedValue(strategy= GenerationType.IDENTITY)
368    private Key id;
369    
370    @OneToMany(cascade = CascadeType.ALL)
371    private List<TablePerClass> children1 = new ArrayList<TablePerClass>();
372
373    @OneToMany(cascade = CascadeType.ALL)
374    private List<MappedSuperclassParent> children2 = new ArrayList<MappedSuperclassParent>();
375
376    public Key getId() {
377      return id;
378    }
379
380    public List<TablePerClass> getChildren1() {
381      return children1;
382    }
383
384    public List<MappedSuperclassParent> getChildren2() {
385      return children2;
386    }
387    
388  }
389}