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.jdbc.annotations;
20:
21: import javax.persistence.EntityManager;
22:
23: import org.apache.openjpa.persistence.OpenJPAEntityManager;
24: import org.apache.openjpa.persistence.test.SingleEMFTestCase;
25:
26: public class TestPropertyAccess extends SingleEMFTestCase {
27:
28: public void setUp() {
29: setUp(PropertyAccess1.class, CLEAR_TABLES);
30: }
31:
32: public void testPropertyAccessBasicCreation() {
33: OpenJPAEntityManager em = emf.createEntityManager();
34: em.getTransaction().begin();
35: PropertyAccess1 pa1_1 = new PropertyAccess1(10);
36: pa1_1.setName("foo");
37: em.persist(pa1_1);
38: em.getTransaction().commit();
39:
40: // getting a new EM should not be necessary once the extended PC stuff
41: // is complete.
42: em = emf.createEntityManager();
43:
44: PropertyAccess1 pa1_2 = em.find(PropertyAccess1.class, 10);
45: assertNotSame(pa1_1, pa1_2);
46: assertNotNull(pa1_2);
47: assertEquals(10, pa1_2.getId());
48: assertEquals("foo", pa1_2.getName());
49: }
50:
51: public void testPropertyAccessBasicMutation() {
52: OpenJPAEntityManager em = emf.createEntityManager();
53: em.getTransaction().begin();
54: PropertyAccess1 pa1_1 = new PropertyAccess1(10);
55: pa1_1.setName("foo");
56: em.persist(pa1_1);
57: em.getTransaction().commit();
58:
59: // getting a new EM should not be necessary once the extended PC stuff
60: // is complete.
61: em = emf.createEntityManager();
62:
63: em.getTransaction().begin();
64: PropertyAccess1 pa1_2 = em.find(PropertyAccess1.class, 10);
65: pa1_2.setName(pa1_2.getName() + "bar");
66: em.getTransaction().commit();
67:
68: em = emf.createEntityManager();
69: PropertyAccess1 pa1_3 = em.find(PropertyAccess1.class, 10);
70: assertNotSame(pa1_2, pa1_3);
71: assertEquals("foobar", pa1_3.getName());
72: }
73:
74: public void testJPQL() {
75: EntityManager em = emf.createEntityManager();
76: em.createQuery(
77: "select o from PropertyAccess1 o where "
78: + "o.name = 'foo'").getResultList();
79: em.createQuery(
80: "select o from PropertyAccess1 o order by "
81: + "o.name asc").getResultList();
82: em.close();
83: }
84:
85: public void testJPQLWithFieldNameMismatch() {
86: EntityManager em = emf.createEntityManager();
87: em.createQuery(
88: "select o from PropertyAccess1 o where "
89: + "o.intValue = 0").getResultList();
90: em.createQuery(
91: "select o from PropertyAccess1 o order by "
92: + "o.intValue asc").getResultList();
93: em.close();
94: }
95: }
|