/tests/com/google/appengine/datanucleus/test/SequenceExamplesJDO.java
Java | 139 lines | 91 code | 30 blank | 18 comment | 0 complexity | f40662e2267fe67b7162a8ab532f59e8 MD5 | raw file
1/********************************************************************** 2 Copyright (c) 2009 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 javax.jdo.annotations.Extension; 19import javax.jdo.annotations.IdGeneratorStrategy; 20import javax.jdo.annotations.IdentityType; 21import javax.jdo.annotations.PersistenceCapable; 22import javax.jdo.annotations.Persistent; 23import javax.jdo.annotations.PrimaryKey; 24import javax.jdo.annotations.Sequence; 25import javax.jdo.annotations.SequenceStrategy; 26 27/** 28 * @author Max Ross <maxr@google.com> 29 */ 30public final class SequenceExamplesJDO { 31 32 private SequenceExamplesJDO() { 33 } 34 35 @PersistenceCapable(identityType = IdentityType.APPLICATION) 36 public static class HasSequence { 37 38 @PrimaryKey 39 @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE) 40 private Long id; 41 42 private String val; 43 44 public Long getId() { 45 return id; 46 } 47 48 public String getVal() { 49 return val; 50 } 51 52 public void setVal(String val) { 53 this.val = val; 54 } 55 } 56 57 @PersistenceCapable(identityType = IdentityType.APPLICATION) 58 @Sequence(name = "jdo1", datastoreSequence = "jdothat", strategy = SequenceStrategy.NONTRANSACTIONAL, 59 extensions = @Extension(vendorName = "datanucleus", key="key-cache-size", value="12")) 60 public static class HasSequenceWithSequenceGenerator { 61 62 @PrimaryKey 63 @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE, sequence = "jdo1") 64 private Long id; 65 66 private String val; 67 68 public Long getId() { 69 return id; 70 } 71 72 public String getVal() { 73 return val; 74 } 75 76 public void setVal(String val) { 77 this.val = val; 78 } 79 } 80 81 @PersistenceCapable(identityType = IdentityType.APPLICATION) 82 @Sequence(name = "jdo2", strategy = SequenceStrategy.NONTRANSACTIONAL, 83 extensions = @Extension(vendorName = "datanucleus", key="key-cache-size", value="12")) 84 public static class HasSequenceWithNoSequenceName { 85 86 @PrimaryKey 87 @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE, sequence = "jdo2") 88 private Long id; 89 90 public Long getId() { 91 return id; 92 } 93 94 public void setId(Long id) { 95 this.id = id; 96 } 97 } 98 99 @PersistenceCapable(identityType = IdentityType.APPLICATION) 100 public static class HasSequenceWithUnencodedStringPk { 101 102 @PrimaryKey 103 @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE) 104 private String id; 105 106 public String getId() { 107 return id; 108 } 109 } 110 111 @PersistenceCapable(identityType = IdentityType.APPLICATION) 112 public static class HasSequenceOnNonPkFields { 113 114 @PrimaryKey 115 private String id; 116 117 @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE) 118 private long val1; 119 120 @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE) 121 private long val2; 122 123 public void setId(String id) { 124 this.id = id; 125 } 126 127 public String getId() { 128 return id; 129 } 130 131 public long getVal1() { 132 return val1; 133 } 134 135 public long getVal2() { 136 return val2; 137 } 138 } 139}