/tests/com/google/appengine/datanucleus/test/UnidirectionalSuperclassTableChildJDO.java
Java | 221 lines | 152 code | 49 blank | 20 comment | 12 complexity | bead00bc072f5e938b4f248db4bf3166 MD5 | raw file
1/********************************************************************** 2 Copyright (c) 2011 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 java.util.Date; 19 20import javax.jdo.annotations.Discriminator; 21import javax.jdo.annotations.DiscriminatorStrategy; 22import javax.jdo.annotations.Extension; 23import javax.jdo.annotations.IdGeneratorStrategy; 24import javax.jdo.annotations.PersistenceCapable; 25import javax.jdo.annotations.Persistent; 26import javax.jdo.annotations.PrimaryKey; 27 28public class UnidirectionalSuperclassTableChildJDO { 29 30 public static final String DISCRIMINATOR_TOP = "Top"; 31 public static final String DISCRIMINATOR_MIDDLE = "Middle"; 32 public static final String DISCRIMINATOR_BOTTOM = "Bottom"; 33 34 @PersistenceCapable(detachable = "true") 35 @Discriminator(strategy = DiscriminatorStrategy.VALUE_MAP, column = "TYPE", value = DISCRIMINATOR_TOP) 36 public static class UnidirTop { 37 38 @PrimaryKey 39 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 40 @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value="true") 41 private String id; 42 43 private String str; 44 45 private String name; 46 47 public String getId() { 48 return id; 49 } 50 51 public String getStr() { 52 return str; 53 } 54 55 public void setStr(String str) { 56 this.str = str; 57 } 58 59 public String getName() { 60 return name; 61 } 62 63 public void setName(String name) { 64 this.name = name; 65 } 66 67 public void setId(String id) { 68 this.id = id; 69 } 70 71 /** 72 * We get weird test failures if we give Flight an equals() method due to 73 * attempts to read fields of deleted objects. TODO(maxr) Straighten this 74 * out. 75 */ 76 public boolean customEquals(Object o) { 77 if (this == o) { 78 return true; 79 } 80 if (o == null || getClass() != o.getClass()) { 81 return false; 82 } 83 84 UnidirTop unidir = (UnidirTop) o; 85 86 if (str != null ? !str.equals(unidir.str) : unidir.str != null) { 87 return false; 88 } 89 if (name != null ? !name.equals(unidir.name) : unidir.name != null) { 90 return false; 91 } 92 93 return true; 94 } 95 96 public int getPropertyCount() { 97 return 3; // str, name, TYPE 98 } 99 } 100 101 @PersistenceCapable(detachable = "true") 102 @Discriminator(value = DISCRIMINATOR_MIDDLE) 103 public static class UnidirMiddle extends UnidirTop { 104 private Date date; 105 106 public Date getDate() { 107 return date; 108 } 109 110 public void setDate(Date date) { 111 this.date = date; 112 } 113 114 public int getPropertyCount() { 115 return 4; // str, name, date, TYPE 116 } 117 } 118 119 @PersistenceCapable(detachable = "true") 120 @Discriminator(value = DISCRIMINATOR_BOTTOM) 121 public static class UnidirBottom extends UnidirMiddle { 122 private Integer integer; 123 124 public Integer getInteger() { 125 return integer; 126 } 127 128 public void setInteger(Integer integer) { 129 this.integer = integer; 130 } 131 132 public int getPropertyCount() { 133 return 5; // str, name, date, integer, TYPE 134 } 135} 136 137 138 @PersistenceCapable(detachable = "true") 139 public static class UnidirTopWithIndexColumn { 140 141 @PrimaryKey 142 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 143 @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value="true") 144 private String id; 145 146 private String str; 147 148 private String name; 149 150 @SuppressWarnings("unused") 151 private int index; 152 153 public String getId() { 154 return id; 155 } 156 157 public String getStr() { 158 return str; 159 } 160 161 public void setStr(String str) { 162 this.str = str; 163 } 164 165 public String getName() { 166 return name; 167 } 168 169 public void setName(String name) { 170 this.name = name; 171 } 172 173 } 174 175 @PersistenceCapable 176 public static class UnidirTopWithOverriddenIdColumn { 177 @SuppressWarnings("unused") 178 @PrimaryKey 179 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY, column = "something_else") 180 @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value="true") 181 private String id; 182 } 183 184 @PersistenceCapable(detachable = "true") 185 @Discriminator(column = "TYPE") 186 public static class UnidirTopEncodedStringPkSeparateNameField { 187 @PrimaryKey 188 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 189 @Extension(vendorName = "datanucleus", key="gae.encoded-pk", value="true") 190 private String id; 191 192 @Persistent 193 @Extension(vendorName = "datanucleus", key="gae.pk-name", value="true") 194 private String name; 195 196 public String getId() { 197 return id; 198 } 199 200 public void setId(String id) { 201 this.id = id; 202 } 203 204 public String getName() { 205 return name; 206 } 207 208 public void setName(String name) { 209 this.name = name; 210 } 211 } 212 213 @PersistenceCapable(detachable = "true") 214 public static class UnidirMiddleEncodedStringPkSeparateNameField extends UnidirTopEncodedStringPkSeparateNameField { 215 } 216 217 @PersistenceCapable(detachable = "true") 218 public static class UnidirBottomEncodedStringPkSeparateNameField extends UnidirMiddleEncodedStringPkSeparateNameField { 219 } 220 221}