01: /*
02: * TestSequence.java
03: *
04: * Created on October 13, 2006, 5:17 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09: /*
10: * Licensed to the Apache Software Foundation (ASF) under one
11: * or more contributor license agreements. See the NOTICE file
12: * distributed with this work for additional information
13: * regarding copyright ownership. The ASF licenses this file
14: * to you under the Apache License, Version 2.0 (the
15: * "License"); you may not use this file except in compliance
16: * with the License. You may obtain a copy of the License at
17: *
18: * http://www.apache.org/licenses/LICENSE-2.0
19: *
20: * Unless required by applicable law or agreed to in writing,
21: * software distributed under the License is distributed on an
22: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23: * KIND, either express or implied. See the License for the
24: * specific language governing permissions and limitations
25: * under the License.
26: */
27: package org.apache.openjpa.persistence.kernel;
28:
29: import org.apache.openjpa.persistence.kernel.common.apps.AImplB;
30:
31: import org.apache.openjpa.persistence.Generator;
32: import org.apache.openjpa.persistence.OpenJPAEntityManager;
33:
34: public class TestSequence extends BaseKernelTest {
35:
36: /**
37: * Creates a new instance of TestSequence
38: */
39: public TestSequence() {
40: }
41:
42: public TestSequence(String name) {
43: super (name);
44: }
45:
46: public void testSequence() {
47: OpenJPAEntityManager pm = getPM();
48: startTx(pm);
49: Generator seq = pm.getIdGenerator(AImplB.class);
50: assertNotNull(seq);
51: Number val = (Number) seq.next();
52: assertNotNull(val);
53: AImplB aib = new AImplB("x", val.intValue(), "y");
54: pm.persist(aib);
55:
56: for (int i = 0; i < 100; i++)
57: assertEquals(((Number) pm.getIdGenerator(AImplB.class)
58: .next()).longValue() + 1, ((Number) pm
59: .getIdGenerator(AImplB.class).next()).longValue());
60:
61: endTx(pm);
62: }
63: }
|