PageRenderTime 69ms CodeModel.GetById 12ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 910 lines | 581 code | 170 blank | 159 comment | 0 complexity | 41892e72d2efa1d310b0b8db4be7a25f 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.jdo.annotations.Column;
 19import javax.jdo.annotations.Embedded;
 20import javax.jdo.annotations.EmbeddedOnly;
 21import javax.jdo.annotations.IdGeneratorStrategy;
 22import javax.jdo.annotations.IdentityType;
 23import javax.jdo.annotations.Inheritance;
 24import javax.jdo.annotations.InheritanceStrategy;
 25import javax.jdo.annotations.PersistenceCapable;
 26import javax.jdo.annotations.Persistent;
 27import javax.jdo.annotations.PrimaryKey;
 28
 29/**
 30 * There is a ton of duplication in these classes.  The reason is that the
 31 * runtime enhancer gets unhappy when there are multiple persistent classes
 32 * extending one persistent class.  So, in order to get all the permutations
 33 * of inheritance strategies that we want to test, we have to create a large
 34 * number of very narrow trees.  Annoying.
 35 *
 36 * @author Max Ross <maxr@google.com>
 37 */
 38public class SubclassesJDO {
 39
 40  public interface Parent {
 41    Long getId();
 42    void setAString(String val);
 43    String getAString();
 44  }
 45
 46  public interface Child extends Parent {
 47    void setBString(String val);
 48    String getBString();
 49  }
 50
 51  public interface Grandchild extends Child {
 52    void setCString(String val);
 53    String getCString();
 54  }
 55
 56  @PersistenceCapable(identityType = IdentityType.APPLICATION)
 57  @Inheritance(customStrategy = "complete-table")
 58  public static class CompleteTableParentWithCompleteTableChild implements Parent {
 59    @PrimaryKey
 60    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 61    private Long id;
 62
 63    @Persistent
 64    private String aString;
 65
 66    public Long getId() {
 67      return id;
 68    }
 69
 70    public void setAString(String aString) {
 71      this.aString = aString;
 72    }
 73
 74    public String getAString() {
 75      return aString;
 76    }
 77
 78    @PersistenceCapable(identityType = IdentityType.APPLICATION)
 79    @Inheritance(customStrategy = "complete-table")
 80    public static class Child extends CompleteTableParentWithCompleteTableChild
 81        implements SubclassesJDO.Child {
 82
 83      @Persistent
 84      private String bString;
 85
 86      public void setBString(String bString) {
 87        this.bString = bString;
 88      }
 89
 90      public String getBString() {
 91        return bString;
 92      }
 93
 94      @PersistenceCapable(identityType = IdentityType.APPLICATION)
 95      @Inheritance(customStrategy = "complete-table")
 96      public static class Grandchild extends Child implements SubclassesJDO.Grandchild {
 97        @Persistent
 98        private String cString;
 99
100        public void setCString(String cString) {
101          this.cString = cString;
102        }
103
104        public String getCString() {
105          return cString;
106        }
107      }
108    }
109  }
110
111  @PersistenceCapable(identityType = IdentityType.APPLICATION)
112  @Inheritance(customStrategy = "complete-table")
113  public static class CompleteTableParentWithNewTableChild implements Parent {
114    @PrimaryKey
115    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
116    private Long id;
117
118    @Persistent
119    private String aString;
120
121    public Long getId() {
122      return id;
123    }
124
125    public void setAString(String aString) {
126      this.aString = aString;
127    }
128
129    public String getAString() {
130      return aString;
131    }
132
133    @PersistenceCapable(identityType = IdentityType.APPLICATION)
134    @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
135    public static class Child extends CompleteTableParentWithNewTableChild implements SubclassesJDO.Child {
136
137      @Persistent
138      private String bString;
139
140      public void setBString(String bString) {
141        this.bString = bString;
142      }
143
144      public String getBString() {
145        return bString;
146      }
147    }
148  }
149
150  @PersistenceCapable(identityType = IdentityType.APPLICATION)
151  @Inheritance(customStrategy = "complete-table")
152  public static class CompleteTableParentWithSubclassTableChild implements Parent {
153    @PrimaryKey
154    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
155    private Long id;
156
157    @Persistent
158    private String aString;
159
160    public Long getId() {
161      return id;
162    }
163
164    public void setAString(String aString) {
165      this.aString = aString;
166    }
167
168    public String getAString() {
169      return aString;
170    }
171
172    @PersistenceCapable(identityType = IdentityType.APPLICATION)
173    @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
174    public static class Child extends CompleteTableParentWithSubclassTableChild
175        implements SubclassesJDO.Child {
176
177      @Persistent
178      private String bString;
179
180      public void setBString(String bString) {
181        this.bString = bString;
182      }
183
184      public String getBString() {
185        return bString;
186      }
187    }
188
189  // Enhancer rejects this
190  //    @PersistenceCapable(identityType = IdentityType.APPLICATION)
191  //    @Inheritance(strategy = InheritanceStrategy.SUPERCLASS_TABLE)
192  //    public static class SuperChild extends CompleteParent {
193  //
194  //      @Persistent
195  //      private String bString;
196  //
197  //      public void setBString(String bString) {
198  //        this.bString = bString;
199  //      }
200  //
201  //      public String getBString() {
202  //        return bString;
203  //      }
204  //    }
205  }
206
207  @PersistenceCapable(identityType = IdentityType.APPLICATION)
208  @Inheritance(customStrategy = "complete-table")
209  public static class CompleteTableParentNoChildStrategy implements Parent {
210    @PrimaryKey
211    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
212    private Long id;
213
214    @Persistent
215    private String aString;
216
217    public Long getId() {
218      return id;
219    }
220
221    public void setAString(String aString) {
222      this.aString = aString;
223    }
224
225    public String getAString() {
226      return aString;
227    }
228
229    @PersistenceCapable(identityType = IdentityType.APPLICATION)
230    public static class Child
231        extends CompleteTableParentNoChildStrategy implements SubclassesJDO.Child {
232
233      @Persistent
234      private String bString;
235
236      public void setBString(String bString) {
237        this.bString = bString;
238      }
239
240      public String getBString() {
241        return bString;
242      }
243
244      @PersistenceCapable(identityType = IdentityType.APPLICATION)
245      public static class Grandchild extends Child implements SubclassesJDO.Grandchild {
246        @Persistent
247        private String cString;
248
249        public void setCString(String cString) {
250          this.cString = cString;
251        }
252  
253        public String getCString() {
254          return cString;
255        }
256      }
257    }
258  }
259
260  @PersistenceCapable(identityType = IdentityType.APPLICATION)
261  @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
262  public static class NewTableParentWithCompleteTableChild implements Parent {
263    @PrimaryKey
264    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
265    private Long id;
266
267    @Persistent
268    private String aString;
269
270    public Long getId() {
271      return id;
272    }
273
274    public void setAString(String aString) {
275      this.aString = aString;
276    }
277
278    public String getAString() {
279      return aString;
280    }
281
282    @PersistenceCapable(identityType = IdentityType.APPLICATION)
283    @Inheritance(customStrategy = "complete-table")
284    public static class Child extends NewTableParentWithCompleteTableChild implements
285                                                                           SubclassesJDO.Child {
286
287      @Persistent
288      private String bString;
289
290      public void setBString(String bString) {
291        this.bString = bString;
292      }
293
294      public String getBString() {
295        return bString;
296      }
297    }
298  }
299
300  @PersistenceCapable(identityType = IdentityType.APPLICATION)
301  @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
302  public static class NewTableParentWithNewTableChild implements Parent {
303    @PrimaryKey
304    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
305    private Long id;
306
307    @Persistent
308    private String aString;
309
310    public Long getId() {
311      return id;
312    }
313
314    public void setAString(String aString) {
315      this.aString = aString;
316    }
317
318    public String getAString() {
319      return aString;
320    }
321
322    @PersistenceCapable(identityType = IdentityType.APPLICATION)
323    @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
324    public static class Child extends NewTableParentWithNewTableChild implements SubclassesJDO.Child {
325
326      @Persistent
327      private String bString;
328
329      public void setBString(String bString) {
330        this.bString = bString;
331      }
332
333      public String getBString() {
334        return bString;
335      }
336    }
337  }
338
339  @PersistenceCapable(identityType = IdentityType.APPLICATION)
340  @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
341  public static class NewTableParentWithSubclassTableChild implements Parent {
342    @PrimaryKey
343    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
344    private Long id;
345
346    @Persistent
347    private String aString;
348
349    public Long getId() {
350      return id;
351    }
352
353    public void setAString(String aString) {
354      this.aString = aString;
355    }
356
357    public String getAString() {
358      return aString;
359    }
360
361    @PersistenceCapable(identityType = IdentityType.APPLICATION)
362    @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
363    public static class Child extends NewTableParentWithSubclassTableChild implements
364                                                                           SubclassesJDO.Child {
365
366      @Persistent
367      private String bString;
368
369      public void setBString(String bString) {
370        this.bString = bString;
371      }
372
373      public String getBString() {
374        return bString;
375      }
376    }
377
378// enhancer rejects this
379//    @PersistenceCapable(identityType = IdentityType.APPLICATION)
380//    @Inheritance(strategy = InheritanceStrategy.SUPERCLASS_TABLE)
381//    public static class SuperChild extends NewParent {
382//
383//      @Persistent
384//      private String bString;
385//
386//      public void setBString(String bString) {
387//        this.bString = bString;
388//      }
389//
390//      public String getBString() {
391//        return bString;
392//      }
393//    }
394  }
395
396  @PersistenceCapable(identityType = IdentityType.APPLICATION)
397  @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
398  public static class SubclassTableParentWithCompleteTableChild implements Parent {
399    @PrimaryKey
400    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
401    private Long id;
402
403    @Persistent
404    private String aString;
405
406    @SuppressWarnings("unused")
407    @Persistent
408    private String overriddenString;
409
410    public Long getId() {
411      return id;
412    }
413
414    public void setAString(String aString) {
415      this.aString = aString;
416    }
417
418    public String getAString() {
419      return aString;
420    }
421
422    @PersistenceCapable(identityType = IdentityType.APPLICATION)
423    @Inheritance(customStrategy = "complete-table")
424    public static class Child extends SubclassTableParentWithCompleteTableChild
425        implements SubclassesJDO.Child {
426
427      @Persistent
428      private String bString;
429
430      public void setBString(String bString) {
431        this.bString = bString;
432      }
433
434      public String getBString() {
435        return bString;
436      }
437
438      @PersistenceCapable(identityType = IdentityType.APPLICATION)
439      @Inheritance(customStrategy = "complete-table")
440      public static class Grandchild extends Child implements SubclassesJDO.Grandchild {
441        @Persistent
442        private String cString;
443
444        public void setCString(String cString) {
445          this.cString = cString;
446        }
447
448        public String getCString() {
449          return cString;
450        }
451      }
452    }
453  }
454
455  @PersistenceCapable(identityType = IdentityType.APPLICATION)
456  @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
457  public static class SubclassTableParentWithNewTableChild implements Parent {
458    @PrimaryKey
459    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
460    private Long id;
461
462    @Persistent
463    private String aString;
464
465    public Long getId() {
466      return id;
467    }
468
469    public void setAString(String aString) {
470      this.aString = aString;
471    }
472
473    public String getAString() {
474      return aString;
475    }
476
477    @PersistenceCapable(identityType = IdentityType.APPLICATION)
478    @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
479    public static class Child extends SubclassTableParentWithNewTableChild implements SubclassesJDO.Child {
480
481      @Persistent
482      private String bString;
483
484      public void setBString(String bString) {
485        this.bString = bString;
486      }
487
488      public String getBString() {
489        return bString;
490      }
491
492      @PersistenceCapable(identityType = IdentityType.APPLICATION)
493      @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
494      public static class Grandchild extends Child implements SubclassesJDO.Grandchild {
495        @Persistent
496        private String cString;
497
498        public void setCString(String cString) {
499          this.cString = cString;
500        }
501
502        public String getCString() {
503          return cString;
504        }
505      }
506    }
507  }
508
509  @PersistenceCapable(identityType = IdentityType.APPLICATION)
510  @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
511  public static class SubclassTableParentWithSubclassTableChild implements Parent {
512    @PrimaryKey
513    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
514    private Long id;
515
516    @Persistent
517    private String aString;
518
519    public Long getId() {
520      return id;
521    }
522
523    public void setAString(String aString) {
524      this.aString = aString;
525    }
526
527    public String getAString() {
528      return aString;
529    }
530
531    @PersistenceCapable(identityType = IdentityType.APPLICATION)
532    @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
533    public static class Child extends SubclassTableParentWithSubclassTableChild
534        implements SubclassesJDO.Child {
535
536      @Persistent
537      private String bString;
538
539      public void setBString(String bString) {
540        this.bString = bString;
541      }
542
543      public String getBString() {
544        return bString;
545      }
546    }
547
548// enhancer rejects this
549//    @PersistenceCapable(identityType = IdentityType.APPLICATION)
550//    @Inheritance(strategy = InheritanceStrategy.SUPERCLASS_TABLE)
551//    public static class SuperChild extends SubParent {
552//
553//      @Persistent
554//      private String bString;
555//
556//      public void setBString(String bString) {
557//        this.bString = bString;
558//      }
559//
560//      public String getBString() {
561//        return bString;
562//      }
563//    }
564  }
565
566// rejected by enhancer
567//  @PersistenceCapable(identityType = IdentityType.APPLICATION)
568//  @Inheritance(strategy = InheritanceStrategy.SUPERCLASS_TABLE)
569//  public static class SuperParent {
570//    @PrimaryKey
571//    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
572//    private Long id;
573//
574//    @Persistent
575//    private String aString;
576//
577//    public Long getId() {
578//      return id;
579//    }
580//
581//    public void setAString(String aString) {
582//      this.aString = aString;
583//    }
584//
585//    public String getAString() {
586//      return aString;
587//    }
588//
589//    @PersistenceCapable(identityType = IdentityType.APPLICATION)
590//    @Inheritance(customStrategy = "complete-table")
591//    public static class CompleteChild extends SuperParent {
592//
593//      @Persistent
594//      private String bString;
595//
596//      public void setBString(String bString) {
597//        this.bString = bString;
598//      }
599//
600//      public String getBString() {
601//        return bString;
602//      }
603//    }
604//
605//    @PersistenceCapable(identityType = IdentityType.APPLICATION)
606//    @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
607//    public static class NewChild extends SuperParent {
608//
609//      @Persistent
610//      private String bString;
611//
612//      public void setBString(String bString) {
613//        this.bString = bString;
614//      }
615//
616//      public String getBString() {
617//        return bString;
618//      }
619//    }
620//
621//    @PersistenceCapable(identityType = IdentityType.APPLICATION)
622//    @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
623//    public static class SubChild extends SuperParent {
624//
625//      @Persistent
626//      private String bString;
627//
628//      public void setBString(String bString) {
629//        this.bString = bString;
630//      }
631//
632//      public String getBString() {
633//        return bString;
634//      }
635//    }
636//
637//    @PersistenceCapable(identityType = IdentityType.APPLICATION)
638//    @Inheritance(strategy = InheritanceStrategy.SUPERCLASS_TABLE)
639//    public static class SuperChild extends SuperParent {
640//
641//      @Persistent
642//      private String bString;
643//
644//      public void setBString(String bString) {
645//        this.bString = bString;
646//      }
647//
648//      public String getBString() {
649//        return bString;
650//      }
651//    }
652//  }
653
654  @PersistenceCapable(identityType = IdentityType.APPLICATION)
655  @Inheritance(customStrategy = "complete-table")
656  public static class OverrideParent implements Parent {
657    @PrimaryKey
658    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
659    private Long id;
660
661    @Persistent
662    private String aString;
663
664    @Persistent
665    private String overriddenString;
666
667    public Long getId() {
668      return id;
669    }
670
671    public void setAString(String aString) {
672      this.aString = aString;
673    }
674
675    public String getAString() {
676      return aString;
677    }
678
679    public String getOverriddenString() {
680      return overriddenString;
681    }
682
683    public void setOverriddenString(String overriddenString) {
684      this.overriddenString = overriddenString;
685    }
686
687    @PersistenceCapable(identityType = IdentityType.APPLICATION)
688    public static class Child extends OverrideParent implements SubclassesJDO.Child {
689
690      @Persistent
691      private String bString;
692
693      @Persistent(column = "overridden_string")
694      private String overriddenString;
695
696      public void setBString(String bString) {
697        this.bString = bString;
698      }
699
700      public String getBString() {
701        return bString;
702      }
703
704      @Override
705      public String getOverriddenString() {
706        return overriddenString;
707      }
708
709      @Override
710      public void setOverriddenString(String overriddenString) {
711        this.overriddenString = overriddenString;
712      }
713    }
714  }
715
716  @PersistenceCapable
717  @EmbeddedOnly
718  @Inheritance(customStrategy = "complete-table")
719  public static class IsEmbeddedOnlyBase {
720    private String val0;
721
722    public String getVal0() {
723      return val0;
724    }
725
726    public void setVal0(String val0) {
727      this.val0 = val0;
728    }
729  }
730
731  @PersistenceCapable
732  @EmbeddedOnly
733  public static class IsEmbeddedOnly extends IsEmbeddedOnlyBase {
734    private String val1;
735
736    public String getVal1() {
737      return val1;
738    }
739
740    public void setVal1(String val1) {
741      this.val1 = val1;
742    }
743  }
744
745  @PersistenceCapable
746  @EmbeddedOnly
747  @Inheritance(customStrategy = "complete-table")
748  public static class IsEmbeddedOnlyBase2 {
749    private String val2;
750
751    public String getVal2() {
752      return val2;
753    }
754
755    public void setVal2(String val2) {
756      this.val2 = val2;
757    }
758  }
759
760  @PersistenceCapable
761  @EmbeddedOnly
762  public static class IsEmbeddedOnly2 extends IsEmbeddedOnlyBase2 {
763    private String val3;
764
765    public String getVal3() {
766      return val3;
767    }
768
769    public void setVal3(String val3) {
770      this.val3 = val3;
771    }
772  }
773
774  @PersistenceCapable(identityType = IdentityType.APPLICATION)
775  @Inheritance(customStrategy = "complete-table")
776  public static class CompleteTableParentWithEmbedded implements Parent {
777    @PrimaryKey
778    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
779    private Long id;
780
781    @Persistent
782    @Embedded
783    private IsEmbeddedOnly embedded;
784
785    @Persistent
786    @Embedded(members={
787                @Persistent(name="val0", columns=@Column(name="VAL0"))
788                })
789    private IsEmbeddedOnlyBase embeddedBase;
790
791    private String aString;
792
793    public Long getId() {
794      return id;
795    }
796
797    public IsEmbeddedOnly getEmbedded() {
798      return embedded;
799    }
800
801    public void setEmbedded(IsEmbeddedOnly embedded) {
802      this.embedded = embedded;
803    }
804
805    public String getAString() {
806      return aString;
807    }
808
809    public void setAString(String aString) {
810      this.aString = aString;
811    }
812
813    public IsEmbeddedOnlyBase getEmbeddedBase() {
814      return embeddedBase;
815    }
816
817    public void setEmbeddedBase(IsEmbeddedOnlyBase embeddedBase) {
818      this.embeddedBase = embeddedBase;
819    }
820
821    @PersistenceCapable(identityType = IdentityType.APPLICATION)
822    public static class Child extends CompleteTableParentWithEmbedded {
823      @Persistent
824      private String bString;
825
826      @Persistent
827      @Embedded(members={
828                  @Persistent(name="val2", columns=@Column(name="VAL2"))
829                  })
830      private IsEmbeddedOnlyBase2 embeddedBase2;
831
832      @Persistent
833      @Embedded
834      private IsEmbeddedOnly2 embedded2;
835
836      public void setBString(String bString) {
837        this.bString = bString;
838      }
839
840      public String getBString() {
841        return bString;
842      }
843
844      public IsEmbeddedOnly2 getEmbedded2() {
845        return embedded2;
846      }
847
848      public void setEmbedded2(IsEmbeddedOnly2 embedded2) {
849        this.embedded2 = embedded2;
850      }
851
852      public IsEmbeddedOnlyBase2 getEmbeddedBase2() {
853        return embeddedBase2;
854      }
855
856      public void setEmbeddedBase2(IsEmbeddedOnlyBase2 embeddedBase2) {
857        this.embeddedBase2 = embeddedBase2;
858      }
859    }
860  }
861
862  public static class NondurableParent {
863    private Long id;
864
865    private String str;
866
867    public Long getId() {
868      return id;
869    }
870
871    public void setId(Long id) {
872      this.id = id;
873    }
874
875    public String getStr() {
876      return str;
877    }
878
879    public void setStr(String str) {
880      this.str = str;
881    }
882  }
883
884  @PersistenceCapable(identityType = IdentityType.APPLICATION)
885  public static class DurableChild extends NondurableParent {
886
887    @Override
888    @PrimaryKey
889    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
890    public Long getId() {
891      return super.getId();
892    }
893
894    @Override
895    @Persistent
896    public String getStr() {
897      return super.getStr();
898    }
899
900    @Override
901    public void setId(Long id) {
902      super.setId(id);
903    }
904
905    @Override
906    public void setStr(String str) {
907      super.setStr(str);
908    }
909  }
910}