PageRenderTime 45ms CodeModel.GetById 15ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 642 lines | 505 code | 119 blank | 18 comment | 0 complexity | a9dc9b42df70dc116c68bd2dd3bb8b6a 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 com.google.appengine.api.datastore.Key;
 19
 20import java.util.ArrayList;
 21import java.util.List;
 22
 23import javax.jdo.annotations.Extension;
 24import javax.jdo.annotations.Extensions;
 25import javax.jdo.annotations.IdGeneratorStrategy;
 26import javax.jdo.annotations.IdentityType;
 27import javax.jdo.annotations.Inheritance;
 28import javax.jdo.annotations.Order;
 29import javax.jdo.annotations.PersistenceCapable;
 30import javax.jdo.annotations.Persistent;
 31import javax.jdo.annotations.PrimaryKey;
 32
 33/**
 34 * @author Max Ross <maxr@google.com>
 35 */
 36public class IllegalMappingsJDO {
 37
 38  @PersistenceCapable(identityType = IdentityType.APPLICATION)
 39  public static class HasLongPkWithKeyAncestor {
 40
 41    @SuppressWarnings("unused")
 42    @PrimaryKey
 43    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 44    private Long id;
 45
 46    @SuppressWarnings("unused")
 47    @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
 48    @Persistent
 49    private Key illegal;
 50  }
 51
 52  @PersistenceCapable(identityType = IdentityType.APPLICATION)
 53  public static class HasLongPkWithStringAncestor {
 54
 55    @SuppressWarnings("unused")
 56    @PrimaryKey
 57    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 58    private Long id;
 59
 60    @SuppressWarnings("unused")
 61    @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
 62    @Persistent
 63    private String illegal;
 64  }
 65
 66  @PersistenceCapable(identityType = IdentityType.APPLICATION)
 67  public static class HasUnencodedStringPkWithKeyAncestor {
 68
 69    @PrimaryKey
 70    public String id;
 71
 72    @SuppressWarnings("unused")
 73    @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
 74    @Persistent
 75    private Key illegal;
 76  }
 77
 78  @PersistenceCapable(identityType = IdentityType.APPLICATION)
 79  public static class HasUnencodedStringPkWithStringAncestor {
 80
 81    @PrimaryKey
 82    public String id;
 83
 84    @SuppressWarnings("unused")
 85    @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
 86    @Persistent
 87    private String illegal;
 88  }
 89
 90  @PersistenceCapable(identityType = IdentityType.APPLICATION)
 91  public static class HasMultiplePkNameFields {
 92
 93    @SuppressWarnings("unused")
 94    @PrimaryKey
 95    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 96    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
 97    private String id;
 98
 99    @SuppressWarnings("unused")
100    @Extension(vendorName = "datanucleus", key = "gae.pk-name", value = "true")
101    @Persistent
102    private String firstIsOk;
103
104    @SuppressWarnings("unused")
105    @Extension(vendorName = "datanucleus", key = "gae.pk-name", value = "true")
106    @Persistent
107    private String secondIsIllegal;
108  }
109
110  @PersistenceCapable(identityType = IdentityType.APPLICATION)
111  public static class HasMultiplePkIdFields {
112
113    @SuppressWarnings("unused")
114    @PrimaryKey
115    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
116    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
117    private String id;
118
119    @SuppressWarnings("unused")
120    @Extension(vendorName = "datanucleus", key = "gae.pk-id", value = "true")
121    @Persistent
122    private Long firstIsOk;
123
124    @SuppressWarnings("unused")
125    @Extension(vendorName = "datanucleus", key = "gae.pk-id", value = "true")
126    @Persistent
127    private Long secondIsIllegal;
128  }
129
130  @PersistenceCapable(identityType = IdentityType.APPLICATION)
131  public static class MultipleAncestors {
132
133    @SuppressWarnings("unused")
134    @PrimaryKey
135    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
136    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
137    private String id;
138
139    @SuppressWarnings("unused")
140    @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
141    @Persistent
142    private String firstIsOk;
143
144    @SuppressWarnings("unused")
145    @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
146    @Persistent
147    private String secondIsIllegal;
148  }
149
150  @PersistenceCapable(identityType = IdentityType.APPLICATION)
151  public static class EncodedPkOnNonPrimaryKeyField {
152
153    @PrimaryKey
154    public String id;
155
156    @SuppressWarnings("unused")
157    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
158    @Persistent
159    private String illegal;
160  }
161
162  @PersistenceCapable(identityType = IdentityType.APPLICATION)
163  public static class EncodedPkOnNonStringPrimaryKeyField {
164
165    @SuppressWarnings("unused")
166    @PrimaryKey
167    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
168    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
169    private Long id;
170  }
171
172  @PersistenceCapable(identityType = IdentityType.APPLICATION)
173  public static class PkNameOnNonStringField {
174
175    @SuppressWarnings("unused")
176    @PrimaryKey
177    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
178    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
179    private String id;
180
181    @SuppressWarnings("unused")
182    @Persistent
183    @Extension(vendorName = "datanucleus", key = "gae.pk-name", value = "true")
184    private Long illegal;
185  }
186
187  @PersistenceCapable(identityType = IdentityType.APPLICATION)
188  public static class PkIdOnNonLongField {
189
190    @SuppressWarnings("unused")
191    @PrimaryKey
192    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
193    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
194    private String id;
195
196    @SuppressWarnings("unused")
197    @Persistent
198    @Extension(vendorName = "datanucleus", key = "gae.pk-id", value = "true")
199    private String illegal;
200  }
201
202  @PersistenceCapable(identityType = IdentityType.APPLICATION)
203  public static class PkMarkedAsAncestor {
204
205    @SuppressWarnings("unused")
206    @PrimaryKey
207    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
208    @Extensions({
209      @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true"),
210      @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")}
211    )
212    private String illegal;
213  }
214
215  @PersistenceCapable(identityType = IdentityType.APPLICATION)
216  public static class PkMarkedAsPkId {
217
218    @SuppressWarnings("unused")
219    @PrimaryKey
220    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
221    @Extension(vendorName = "datanucleus", key = "gae.pk-id", value = "true")
222    private Long illegal;
223  }
224
225  @PersistenceCapable(identityType = IdentityType.APPLICATION)
226  public static class PkMarkedAsPkName {
227
228    @SuppressWarnings("unused")
229    @PrimaryKey
230    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
231    @Extension(vendorName = "datanucleus", key = "gae.pk-name", value = "true")
232    private String illegal;
233  }
234
235  @PersistenceCapable(identityType = IdentityType.APPLICATION)
236  public static class PkIdWithUnencodedStringPrimaryKey {
237
238    @PrimaryKey
239    public String id;
240
241    @SuppressWarnings("unused")
242    @Persistent
243    @Extension(vendorName = "datanucleus", key = "gae.pk-id", value = "true")
244    private Long illegal;
245  }
246
247  @PersistenceCapable(identityType = IdentityType.APPLICATION)
248  public static class PkNameWithUnencodedStringPrimaryKey {
249
250    @PrimaryKey
251    public String id;
252
253    @SuppressWarnings("unused")
254    @Persistent
255    @Extension(vendorName = "datanucleus", key = "gae.pk-name", value = "true")
256    private String illegal;
257  }
258
259  @PersistenceCapable(identityType = IdentityType.APPLICATION)
260  public static class OneToManyParentWithRootOnlyLongUniChild {
261    @PrimaryKey
262    public String id;
263
264    @SuppressWarnings("unused")
265    @Persistent
266    private List<HasLongPkJDO> uniChildren = new ArrayList<HasLongPkJDO>();
267  }
268
269  @PersistenceCapable(identityType = IdentityType.APPLICATION)
270  public static class OneToManyParentWithRootOnlyLongBiChild {
271    @PrimaryKey
272    public String id;
273
274    @SuppressWarnings("unused")
275    @Persistent(mappedBy = "parent")
276    private List<RootOnlyLongBiOneToManyChild> biChildren = new ArrayList<RootOnlyLongBiOneToManyChild>();
277  }
278
279  @SuppressWarnings("unused")
280  @PersistenceCapable(identityType = IdentityType.APPLICATION)
281  public static class RootOnlyLongBiOneToManyChild {
282    @PrimaryKey
283    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
284    private Long id;
285
286    @Persistent
287    private OneToManyParentWithRootOnlyLongBiChild parent;
288  }
289
290  @PersistenceCapable(identityType = IdentityType.APPLICATION)
291  public static class OneToManyParentWithRootOnlyStringUniChild {
292    @PrimaryKey
293    public String id;
294
295    @SuppressWarnings("unused")
296    @Persistent
297    private List<HasUnencodedStringPkJDO> uniChildren = new ArrayList<HasUnencodedStringPkJDO>();
298  }
299
300  @PersistenceCapable(identityType = IdentityType.APPLICATION)
301  public static class OneToManyParentWithRootOnlyStringBiChild {
302    @PrimaryKey
303    public String id;
304
305    @SuppressWarnings("unused")
306    @Persistent(mappedBy = "parent")
307    private List<RootOnlyStringBiOneToManyChild> biChildren = new ArrayList<RootOnlyStringBiOneToManyChild>();
308  }
309
310  @PersistenceCapable(identityType = IdentityType.APPLICATION)
311  public static class RootOnlyStringBiOneToManyChild {
312    @PrimaryKey
313    public String id;
314
315    @SuppressWarnings("unused")
316    @Persistent
317    private OneToManyParentWithRootOnlyStringBiChild parent;
318  }
319
320  @PersistenceCapable(identityType = IdentityType.APPLICATION)
321  public static class OneToOneParentWithRootOnlyLongUniChild {
322    @PrimaryKey
323    public String id;
324
325    @SuppressWarnings("unused")
326    @Persistent
327    private HasLongPkJDO uniChild;
328  }
329
330  @PersistenceCapable(identityType = IdentityType.APPLICATION)
331  public static class OneToOneParentWithRootOnlyLongBiChild {
332    @PrimaryKey
333    public String id;
334
335    @SuppressWarnings("unused")
336    private RootOnlyLongBiOneToManyChild biChild;
337  }
338
339  @PersistenceCapable(identityType = IdentityType.APPLICATION)
340  public static class RootOnlyLongBiOneToOneChild {
341    @SuppressWarnings("unused")
342    @PrimaryKey
343    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
344    private Long id;
345
346    @SuppressWarnings("unused")
347    @Persistent(mappedBy = "biChild")
348    private OneToOneParentWithRootOnlyLongBiChild parent;
349  }
350
351  @PersistenceCapable(identityType = IdentityType.APPLICATION)
352  public static class OneToOneParentWithRootOnlyStringUniChild {
353    @PrimaryKey
354    public String id;
355
356    @SuppressWarnings("unused")
357    @Persistent
358    private HasUnencodedStringPkJDO uniChild;
359  }
360
361  @PersistenceCapable(identityType = IdentityType.APPLICATION)
362  public static class OneToOneParentWithRootOnlyStringBiChild {
363    @PrimaryKey
364    public String id;
365
366    @SuppressWarnings("unused")
367    @Persistent
368    private RootOnlyStringBiOneToManyChild biChild;
369  }
370
371  @PersistenceCapable(identityType = IdentityType.APPLICATION)
372  public static class RootOnlyStringBiOneToOneChild {
373    @PrimaryKey
374    public String id;
375
376    @SuppressWarnings("unused")
377    @Persistent(mappedBy = "biChild")
378    private OneToOneParentWithRootOnlyStringBiChild parent;
379  }
380
381  @PersistenceCapable(identityType = IdentityType.APPLICATION)
382  public static class LongParent {
383    @SuppressWarnings("unused")
384    @PrimaryKey
385    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
386    private Long id;
387
388    @SuppressWarnings("unused")
389    @Persistent
390    @Extension(vendorName = "datanucleus", key="gae.parent-pk", value="true")
391    private Long illegal;
392  }
393
394  @PersistenceCapable(identityType = IdentityType.APPLICATION)
395  public static class ManyToMany1 {
396    @SuppressWarnings("unused")
397    @PrimaryKey
398    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
399    private Key id;
400
401    @SuppressWarnings("unused")
402    @Persistent(mappedBy = "manyToMany")
403    private List<ManyToMany2> manyToMany;
404  }
405
406  @PersistenceCapable(identityType = IdentityType.APPLICATION)
407  public static class ManyToMany2 {
408    @SuppressWarnings("unused")
409    @PrimaryKey
410    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
411    private Key id;
412
413    @SuppressWarnings("unused")
414    @Persistent(mappedBy = "manyToMany")
415    private List<ManyToMany1> manyToMany;
416  }
417
418  @PersistenceCapable(identityType = IdentityType.APPLICATION)
419  public static class SequenceOnEncodedStringPk {
420    @SuppressWarnings("unused")
421    @PrimaryKey
422    @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE)
423    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
424    private String id;
425  }
426
427  @PersistenceCapable(identityType = IdentityType.APPLICATION)
428  public static class SequenceOnKeyPk {
429    @SuppressWarnings("unused")
430    @PrimaryKey
431    @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE)
432    private Key id;
433  }
434
435  @PersistenceCapable(identityType = IdentityType.APPLICATION)
436  public static class Has2CollectionsOfSameType {
437    @SuppressWarnings("unused")
438    @PrimaryKey
439    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
440    private Key id;
441
442    @SuppressWarnings("unused")
443    @Persistent
444    private List<Flight> flights1;
445
446    @SuppressWarnings("unused")
447    @Persistent
448    private List<Flight> flights2;
449  }
450
451  @PersistenceCapable(identityType = IdentityType.APPLICATION)
452  public static class Has2OneToOnesOfSameType {
453    @SuppressWarnings("unused")
454    @PrimaryKey
455    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
456    private Key id;
457
458    @SuppressWarnings("unused")
459    @Persistent
460    private Flight f1;
461
462    @SuppressWarnings("unused")
463    @Persistent
464    private Flight f2;
465  }
466
467  @PersistenceCapable(identityType = IdentityType.APPLICATION)
468  public static class HasOneToOneAndOneToManyOfSameType {
469    @SuppressWarnings("unused")
470    @PrimaryKey
471    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
472    private Key id;
473
474    @SuppressWarnings("unused")
475    @Persistent
476    private List<Flight> flights;
477
478    @SuppressWarnings("unused")
479    @Persistent
480    private Flight f2;
481  }
482
483  @PersistenceCapable(identityType = IdentityType.APPLICATION)
484  @Inheritance(customStrategy = "complete-table")
485  public static class Has2CollectionsOfSameTypeParent {
486    @SuppressWarnings("unused")
487    @PrimaryKey
488    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
489    private Key id;
490
491    @SuppressWarnings("unused")
492    @Persistent
493    @Order(extensions = @Extension(vendorName = "datanucleus", key="list-ordering", value="name DESC"))
494    private List<Flight> flights1;
495  }
496
497  @PersistenceCapable(identityType = IdentityType.APPLICATION)
498  public static class Has2CollectionsOfSameTypeChild extends Has2CollectionsOfSameTypeParent {
499    @SuppressWarnings("unused")
500    @Persistent
501    @Order(extensions = @Extension(vendorName = "datanucleus", key="list-ordering", value="name DESC"))
502    private List<Flight> flights2;
503  }
504
505  @PersistenceCapable(identityType = IdentityType.APPLICATION)
506  @Inheritance(customStrategy = "complete-table")
507  public static class Has2CollectionsOfAssignableBaseTypeSuper {
508    @SuppressWarnings("unused")
509    @PrimaryKey
510    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
511    private Key id;
512
513    @SuppressWarnings("unused")
514    @Persistent
515    private String name;
516  }
517
518  @PersistenceCapable(identityType = IdentityType.APPLICATION)
519  public static class Has2CollectionsOfAssignableBaseTypeSub extends Has2CollectionsOfAssignableBaseTypeSuper {
520    @SuppressWarnings("unused")
521    private String str;
522  }
523
524  @PersistenceCapable(identityType = IdentityType.APPLICATION)
525  public static class Has2CollectionsOfAssignableType {
526    @SuppressWarnings("unused")
527    @PrimaryKey
528    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
529    private Key id;
530
531    @SuppressWarnings("unused")
532    @Persistent
533    @Order(extensions = @Extension(vendorName = "datanucleus", key="list-ordering", value="name DESC"))
534    private List<Has2CollectionsOfAssignableBaseTypeSuper> superList;
535
536    @SuppressWarnings("unused")
537    @Persistent
538    @Order(extensions = @Extension(vendorName = "datanucleus", key="list-ordering", value="name DESC"))
539    private List<Has2CollectionsOfAssignableBaseTypeSub> subList;
540  }
541
542  @PersistenceCapable(identityType = IdentityType.APPLICATION)
543  @Inheritance(customStrategy = "complete-table")
544  public static class Has2CollectionsOfAssignableTypeSuper {
545    @SuppressWarnings("unused")
546    @PrimaryKey
547    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
548    private Key id;
549
550    @SuppressWarnings("unused")
551    @Persistent
552    @Order(extensions = @Extension(vendorName = "datanucleus", key="list-ordering", value="name DESC"))
553    private List<Has2CollectionsOfAssignableBaseTypeSuper> superList;
554  }
555
556  @PersistenceCapable(identityType = IdentityType.APPLICATION)
557  public static class Has2CollectionsOfAssignableTypeSub extends Has2CollectionsOfAssignableTypeSuper {
558    @SuppressWarnings("unused")
559    @Persistent
560    @Order(extensions = @Extension(vendorName = "datanucleus", key="list-ordering", value="name DESC"))
561    private List<Has2CollectionsOfAssignableBaseTypeSub> subList;
562  }
563
564  @PersistenceCapable(identityType = IdentityType.APPLICATION)
565  public static class HasTwoOneToOnesWithSharedBaseClass {
566    @SuppressWarnings("unused")
567    @PrimaryKey
568    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
569    private Long id;
570
571    @Persistent
572    private HasSharedBaseClass1 hsbc1;
573
574    @Persistent
575    private HasSharedBaseClass2 hsbc2;
576
577    public HasSharedBaseClass1 getHsbc1() {
578      return hsbc1;
579    }
580
581    public void setHsbc1(HasSharedBaseClass1 hsbc1) {
582      this.hsbc1 = hsbc1;
583    }
584
585    public HasSharedBaseClass2 getHsbc2() {
586      return hsbc2;
587    }
588
589    public void setHsbc2(HasSharedBaseClass2 hsbc2) {
590      this.hsbc2 = hsbc2;
591    }
592  }
593
594  @PersistenceCapable(identityType = IdentityType.APPLICATION)
595  public abstract static class SharedBaseClass {
596    @SuppressWarnings("unused")
597    @PrimaryKey
598    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
599    private Key id;
600
601  }
602
603  @PersistenceCapable(identityType = IdentityType.APPLICATION)
604  @Inheritance(customStrategy = "complete-table")
605  public static class HasSharedBaseClass1 extends SharedBaseClass {
606    @SuppressWarnings("unused")
607    private String str;
608  }
609
610  @PersistenceCapable(identityType = IdentityType.APPLICATION)
611  @Inheritance(customStrategy = "complete-table")
612  public static class HasSharedBaseClass2 extends SharedBaseClass {
613    @SuppressWarnings("unused")
614    private String str;
615  }
616
617  @PersistenceCapable(identityType = IdentityType.APPLICATION)
618  public static class HasPkIdSortOnOneToMany {
619    @SuppressWarnings("unused")
620    @PrimaryKey
621    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
622    private Key id;
623
624    @SuppressWarnings("unused")
625    @Persistent
626    @Order(extensions = @Extension(vendorName = "datanucleus", key="list-ordering", value="id"))
627    private List<HasEncodedStringPkSeparateIdFieldJDO> list;
628  }
629
630  @PersistenceCapable(identityType = IdentityType.APPLICATION)
631  public static class HasPkNameSortOnOneToMany {
632    @SuppressWarnings("unused")
633    @PrimaryKey
634    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
635    private Key id;
636
637    @SuppressWarnings("unused")
638    @Persistent
639    @Order(extensions = @Extension(vendorName = "datanucleus", key="list-ordering", value="name"))
640    private List<HasEncodedStringPkSeparateNameFieldJDO> list;
641  }
642}