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

http://datanucleus-appengine.googlecode.com/ · Java · 137 lines · 91 code · 28 blank · 18 comment · 0 complexity · 3d29c20442619373d88d8a9e0f507cbf 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 javax.persistence.Entity;
  15. import javax.persistence.GeneratedValue;
  16. import javax.persistence.GenerationType;
  17. import javax.persistence.Id;
  18. import javax.persistence.SequenceGenerator;
  19. /**
  20. * @author Max Ross <maxr@google.com>
  21. */
  22. public final class SequenceExamplesJPA {
  23. private SequenceExamplesJPA() {}
  24. @Entity
  25. public static class HasSequence {
  26. @Id
  27. @GeneratedValue(strategy = GenerationType.SEQUENCE)
  28. private Long id;
  29. private String val;
  30. public Long getId() {
  31. return id;
  32. }
  33. public void setId(Long id) {
  34. this.id = id;
  35. }
  36. public String getVal() {
  37. return val;
  38. }
  39. public void setVal(String val) {
  40. this.val = val;
  41. }
  42. }
  43. @Entity
  44. public static class HasSequenceWithSequenceGenerator {
  45. @Id
  46. @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "jpa1")
  47. @SequenceGenerator(name = "jpa1", sequenceName = "jpathat", allocationSize = 12)
  48. private Long id;
  49. private String val;
  50. public Long getId() {
  51. return id;
  52. }
  53. public void setId(Long id) {
  54. this.id = id;
  55. }
  56. public String getVal() {
  57. return val;
  58. }
  59. public void setVal(String val) {
  60. this.val = val;
  61. }
  62. }
  63. @Entity
  64. public static class HasSequenceWithNoSequenceName {
  65. @Id
  66. @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "jpa2")
  67. @SequenceGenerator(name = "jpa2", allocationSize = 12)
  68. private Long id;
  69. public Long getId() {
  70. return id;
  71. }
  72. public void setId(Long id) {
  73. this.id = id;
  74. }
  75. }
  76. @Entity
  77. public static class HasSequenceWithUnencodedStringPk {
  78. @Id
  79. @GeneratedValue(strategy = GenerationType.SEQUENCE)
  80. private String id;
  81. public String getId() {
  82. return id;
  83. }
  84. }
  85. @Entity
  86. public static class HasSequenceOnNonPkFields {
  87. @Id
  88. private String id;
  89. @GeneratedValue(strategy = GenerationType.SEQUENCE)
  90. private long val;
  91. @GeneratedValue(strategy = GenerationType.SEQUENCE)
  92. private long val2;
  93. public String getId() {
  94. return id;
  95. }
  96. public void setId(String id) {
  97. this.id = id;
  98. }
  99. public long getVal() {
  100. return val;
  101. }
  102. public long getVal2() {
  103. return val2;
  104. }
  105. }
  106. }