PageRenderTime 61ms CodeModel.GetById 29ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 183 lines | 126 code | 39 blank | 18 comment | 0 complexity | 250712b7c7a73bb3dd10c24f2595e356 MD5 | raw file
  1/*
  2 * Copyright (C) 2010 Google Inc
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 *
  8 * http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS,
 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 * See the License for the specific language governing permissions and
 14 * limitations 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.persistence.CascadeType;
 24import javax.persistence.Entity;
 25import javax.persistence.FetchType;
 26import javax.persistence.GeneratedValue;
 27import javax.persistence.GenerationType;
 28import javax.persistence.Id;
 29import javax.persistence.Inheritance;
 30import javax.persistence.InheritanceType;
 31import javax.persistence.OneToMany;
 32import javax.persistence.OrderBy;
 33
 34/**
 35 * @author Max Ross <max.ross@gmail.com>
 36 */
 37public class UnidirectionalOneToManySubclassesJPA {
 38
 39  @Entity
 40  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 41  public static class SuperParentWithSuperChild {
 42    @Id
 43    @GeneratedValue(strategy= GenerationType.IDENTITY)
 44    private Long id;
 45
 46    private String superParentString;
 47
 48    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
 49    @OrderBy(value = "aString desc")
 50    private List<SuperChild> superChildren = new ArrayList<SuperChild>();
 51
 52    public Long getId() {
 53      return id;
 54    }
 55
 56    public void setId(Long id) {
 57      this.id = id;
 58    }
 59
 60    public String getSuperParentString() {
 61      return superParentString;
 62    }
 63
 64    public void setSuperParentString(String superParentString) {
 65      this.superParentString = superParentString;
 66    }
 67
 68    public List<SuperChild> getSuperParentSuperChildren() {
 69      return superChildren;
 70    }
 71
 72    public void setSuperParentSuperChildren(
 73        List<SuperChild> superChildren) {
 74      this.superChildren = superChildren;
 75    }
 76  }
 77
 78  @Entity
 79  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 80  public static class SuperParentWithSubChild {
 81    @Id
 82    @GeneratedValue(strategy= GenerationType.IDENTITY)
 83    private Long id;
 84
 85    private String superParentString;
 86
 87    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
 88    @OrderBy(value = "aString desc")
 89    private List<SubChild> subChildren = new ArrayList<SubChild>();
 90
 91    public Long getId() {
 92      return id;
 93    }
 94
 95    public String getSuperParentString() {
 96      return superParentString;
 97    }
 98
 99    public void setSuperParentString(String superParentString) {
100      this.superParentString = superParentString;
101    }
102
103    public void setId(Long id) {
104      this.id = id;
105    }
106
107    public List<SubChild> getSuperParentSubChildren() {
108      return subChildren;
109    }
110
111    public void setSuperParentSubChildren(
112        List<SubChild> subChildren) {
113      this.subChildren = subChildren;
114    }
115  }
116
117  @Entity
118  public static class SubParentWithSuperChild extends SuperParentWithSuperChild {
119    private String subParentString;
120
121    public String getSubParentString() {
122      return subParentString;
123    }
124
125    public void setSubParentString(String subParentString) {
126      this.subParentString = subParentString;
127    }
128  }
129
130  @Entity
131  public static class SubParentWithSubChild extends SuperParentWithSubChild {
132
133    private String subParentString;
134
135    public String getSubParentString() {
136      return subParentString;
137    }
138
139    public void setSubParentString(String subParentString) {
140      this.subParentString = subParentString;
141    }
142  }
143
144  @Entity
145  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
146  public static class SuperChild {
147    @Id
148    @GeneratedValue(strategy= GenerationType.IDENTITY)
149    private Key id;
150
151    private String aString;
152
153    public Key getId() {
154      return id;
155    }
156
157    public void setId(Key id) {
158      this.id = id;
159    }
160
161    public String getAString() {
162      return aString;
163    }
164
165    public void setAString(String aString) {
166      this.aString = aString;
167    }
168  }
169
170  @Entity
171  public static class SubChild extends SuperChild {
172
173    private String bString;
174
175    public String getBString() {
176      return bString;
177    }
178
179    public void setBString(String bString) {
180      this.bString = bString;
181    }
182  }
183}