PageRenderTime 28ms CodeModel.GetById 12ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 130 lines | 90 code | 25 blank | 15 comment | 11 complexity | 3dbdacfc0f13233b3de5c732df186957 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 com.google.appengine.api.datastore.KeyFactory;
 19
 20import org.datanucleus.api.jpa.annotations.Extension;
 21
 22import javax.persistence.DiscriminatorValue;
 23import javax.persistence.Entity;
 24import javax.persistence.GeneratedValue;
 25import javax.persistence.GenerationType;
 26import javax.persistence.Id;
 27
 28public class UnidirectionalSingeTableChildJPA {
 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  @Entity
 35  @DiscriminatorValue(value = DISCRIMINATOR_TOP)
 36  public static class UnidirTop {
 37    @Id
 38    @GeneratedValue(strategy=GenerationType.IDENTITY)
 39    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
 40    private String id;
 41    
 42    private String str;
 43    private String name;
 44
 45    public UnidirTop(String namedKey) {
 46      this.id = namedKey == null ? null :
 47                KeyFactory.keyToString(KeyFactory.createKey(UnidirectionalSingeTableChildJPA.getEntityKind(UnidirTop.class), namedKey));
 48    }
 49
 50    public void setId(String id) {
 51      this.id = id;
 52    }
 53
 54    public UnidirTop() {
 55      this(null);
 56    }
 57
 58    public String getId() {
 59      return id;
 60    }
 61
 62    public String getStr() {
 63      return str;
 64    }
 65
 66    public void setStr(String str) {
 67      this.str = str;
 68    }
 69
 70    public String getName() {
 71      return name;
 72    }
 73
 74    public void setName(String name) {
 75      this.name = name;
 76    }
 77
 78    @Override
 79    public String toString() {
 80      return "\n\nid: " + id + "\nstr: " + str + "\nname: " + name;
 81    }
 82
 83    @Override
 84    public boolean equals(Object o) {
 85      if (this == o) {
 86        return true;
 87      }
 88      if (o == null || getClass() != o.getClass()) {
 89        return false;
 90      }
 91
 92      UnidirTop book = (UnidirTop) o;
 93
 94      if (id != null ? !id.equals(book.id) : book.id != null) {
 95        return false;
 96      }
 97
 98      return true;
 99    }
100
101    @Override
102    public int hashCode() {
103      return (id != null ? id.hashCode() : 0);
104    }
105  }
106  
107  @Entity
108  @DiscriminatorValue(value = DISCRIMINATOR_MIDDLE)
109  public static class UnidirMiddle extends UnidirTop {
110    public UnidirMiddle() {
111      this(null);
112    }
113    
114    public UnidirMiddle(String namedKey) {
115      super(namedKey);
116    }
117  }
118  
119  @Entity
120  @DiscriminatorValue(value = DISCRIMINATOR_BOTTOM)
121  public static class UnidirBottom extends UnidirMiddle {
122    public UnidirBottom(String namedKey) {
123      super(namedKey);
124    }
125  }
126  
127  public static String getEntityKind(Class<?> clazz) {
128    return clazz.getName().substring(clazz.getPackage().getName().length() + 1);
129  }
130}