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

http://datanucleus-appengine.googlecode.com/ · Java · 139 lines · 91 code · 30 blank · 18 comment · 0 complexity · f40662e2267fe67b7162a8ab532f59e8 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.jdo.annotations.Extension;
  15. import javax.jdo.annotations.IdGeneratorStrategy;
  16. import javax.jdo.annotations.IdentityType;
  17. import javax.jdo.annotations.PersistenceCapable;
  18. import javax.jdo.annotations.Persistent;
  19. import javax.jdo.annotations.PrimaryKey;
  20. import javax.jdo.annotations.Sequence;
  21. import javax.jdo.annotations.SequenceStrategy;
  22. /**
  23. * @author Max Ross <maxr@google.com>
  24. */
  25. public final class SequenceExamplesJDO {
  26. private SequenceExamplesJDO() {
  27. }
  28. @PersistenceCapable(identityType = IdentityType.APPLICATION)
  29. public static class HasSequence {
  30. @PrimaryKey
  31. @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE)
  32. private Long id;
  33. private String val;
  34. public Long getId() {
  35. return id;
  36. }
  37. public String getVal() {
  38. return val;
  39. }
  40. public void setVal(String val) {
  41. this.val = val;
  42. }
  43. }
  44. @PersistenceCapable(identityType = IdentityType.APPLICATION)
  45. @Sequence(name = "jdo1", datastoreSequence = "jdothat", strategy = SequenceStrategy.NONTRANSACTIONAL,
  46. extensions = @Extension(vendorName = "datanucleus", key="key-cache-size", value="12"))
  47. public static class HasSequenceWithSequenceGenerator {
  48. @PrimaryKey
  49. @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE, sequence = "jdo1")
  50. private Long id;
  51. private String val;
  52. public Long getId() {
  53. return id;
  54. }
  55. public String getVal() {
  56. return val;
  57. }
  58. public void setVal(String val) {
  59. this.val = val;
  60. }
  61. }
  62. @PersistenceCapable(identityType = IdentityType.APPLICATION)
  63. @Sequence(name = "jdo2", strategy = SequenceStrategy.NONTRANSACTIONAL,
  64. extensions = @Extension(vendorName = "datanucleus", key="key-cache-size", value="12"))
  65. public static class HasSequenceWithNoSequenceName {
  66. @PrimaryKey
  67. @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE, sequence = "jdo2")
  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. @PersistenceCapable(identityType = IdentityType.APPLICATION)
  77. public static class HasSequenceWithUnencodedStringPk {
  78. @PrimaryKey
  79. @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE)
  80. private String id;
  81. public String getId() {
  82. return id;
  83. }
  84. }
  85. @PersistenceCapable(identityType = IdentityType.APPLICATION)
  86. public static class HasSequenceOnNonPkFields {
  87. @PrimaryKey
  88. private String id;
  89. @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE)
  90. private long val1;
  91. @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE)
  92. private long val2;
  93. public void setId(String id) {
  94. this.id = id;
  95. }
  96. public String getId() {
  97. return id;
  98. }
  99. public long getVal1() {
  100. return val1;
  101. }
  102. public long getVal2() {
  103. return val2;
  104. }
  105. }
  106. }