01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence.kernel;
20:
21: import javax.persistence.EntityManager;
22:
23: import org.apache.openjpa.persistence.kernel.common.apps.AImplB;
24: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
25: import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
26:
27: public class TestEJBGetObjectByIdValue extends AbstractTestCase {
28:
29: private Object[] oids;
30:
31: public TestEJBGetObjectByIdValue(String name) {
32: super (name, "kernelcactusapp");
33: }
34:
35: public void setUp() throws Exception {
36: deleteAll(RuntimeTest1.class);
37: deleteAll(AImplB.class);
38:
39: EntityManager em = currentEntityManager();
40: startTx(em);
41: em.flush();
42: endTx(em);
43: endEm(em);
44: }
45:
46: public void testDatastore() {
47: EntityManager em = currentEntityManager();
48: startTx(em);
49:
50: RuntimeTest1 pc = new RuntimeTest1(1);
51: pc.setStringField("foo");
52: em.persist(pc);
53:
54: endTx(em);
55: endEm(em);
56:
57: em = currentEntityManager();
58: pc = (RuntimeTest1) em.find(RuntimeTest1.class, 1);
59: assertEquals("foo", pc.getStringField());
60: em.close();
61:
62: em = currentEntityManager();
63: pc = (RuntimeTest1) em.find(RuntimeTest1.class, pc
64: .getIntField());
65: assertEquals("foo", pc.getStringField());
66: endEm(em);
67: }
68:
69: public void testAppId() {
70: EntityManager em = currentEntityManager();
71: startTx(em);
72: AImplB pc = new AImplB("foo", 1, "pk");
73: em.persist(pc);
74: AImplB.Idkey oid = new AImplB.Idkey();
75: oid.pk1 = 1;
76: oid.pk2 = "pk";
77: endTx(em);
78: endEm(em);
79:
80: em = currentEntityManager();
81: pc = (AImplB) em.find(AImplB.class, oid);
82: assertEquals("foo", pc.getName());
83: endEm(em);
84:
85: em = currentEntityManager();
86: pc = (AImplB) em.find(AImplB.class, oid.toString());
87: assertEquals("foo", pc.getName());
88: endEm(em);
89: }
90: }
|