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

http://datanucleus-appengine.googlecode.com/ · Java · 96 lines · 58 code · 20 blank · 18 comment · 10 complexity · c946b0b0623c6a9fa12d31f947a396c2 MD5 · raw file

  1. /**********************************************************************
  2. Copyright (c) 2009 Google Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. **********************************************************************/
  13. package com.google.appengine.datanucleus.test;
  14. import com.google.appengine.api.datastore.Key;
  15. import com.google.appengine.api.datastore.KeyFactory;
  16. import org.datanucleus.api.jpa.annotations.Extension;
  17. import javax.persistence.Basic;
  18. import javax.persistence.Entity;
  19. import javax.persistence.GeneratedValue;
  20. import javax.persistence.GenerationType;
  21. import javax.persistence.Id;
  22. /**
  23. * @author Max Ross <maxr@google.com>
  24. */
  25. @Entity
  26. public class HasKeyPkJPA {
  27. @Extension(vendorName="datanucleus", key="gae.parent-pk", value="true")
  28. @Basic
  29. private Key ancestorId;
  30. @Id
  31. @GeneratedValue(strategy=GenerationType.IDENTITY)
  32. private Key id;
  33. String str;
  34. public HasKeyPkJPA() {
  35. }
  36. public HasKeyPkJPA(String name) {
  37. id = KeyFactory.createKey(getClass().getSimpleName(), name);
  38. }
  39. public Key getAncestorId() {
  40. return ancestorId;
  41. }
  42. public Key getId() {
  43. return id;
  44. }
  45. public void setAncestorId(Key ancestorId) {
  46. this.ancestorId = ancestorId;
  47. }
  48. public void setId(Key id) {
  49. this.id = id;
  50. }
  51. public String getStr() {
  52. return str;
  53. }
  54. public void setStr(String str) {
  55. this.str = str;
  56. }
  57. public boolean equals(Object o) {
  58. if (this == o) {
  59. return true;
  60. }
  61. if (o == null || getClass() != o.getClass()) {
  62. return false;
  63. }
  64. HasKeyPkJPA that = (HasKeyPkJPA) o;
  65. if (id != null ? !id.equals(that.id) : that.id != null) {
  66. return false;
  67. }
  68. return true;
  69. }
  70. public int hashCode() {
  71. return (id != null ? id.hashCode() : 0);
  72. }
  73. }