001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.persistence.jdbc.meta;
020:
021: import javax.persistence.EntityManager;
022:
023: import org.apache.openjpa.persistence.common.utils.*;
024:
025: import org.apache.openjpa.persistence.kernel.common.apps.*;
026: import junit.framework.*;
027:
028: public class TestEJBColumnIOMappings extends
029: org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest {
030: public TestEJBColumnIOMappings(String name) {
031: super (name);
032: }
033:
034: public void setUp() {
035: deleteAll(ColumnIOPC.class);
036: }
037:
038: public void testIgnoreInsert() {
039: ColumnIOPC pc = new ColumnIOPC(2);
040: pc.setName("pc");
041: pc.setIgnoreInsert(10);
042:
043: EntityManager pm = currentEntityManager();
044: startTx(pm);
045: pm.persist(pc);
046: assertEquals(10, pc.getIgnoreInsert());
047: endTx(pm);
048:
049: startTx(pm);
050: assertEquals(10, pc.getIgnoreInsert());
051: int oid = pc.getId();
052: endTx(pm);
053: endEm(pm);
054:
055: pm = currentEntityManager();
056: startTx(pm);
057: pc = pm.find(ColumnIOPC.class, oid);
058: assertNotNull(pc);
059: assertEquals(10, pc.getIgnoreInsert());
060: pc.setIgnoreInsert(10);
061: endTx(pm);
062: startTx(pm);
063: assertEquals(10, pc.getIgnoreInsert());
064: endTx(pm);
065: endEm(pm);
066:
067: pm = currentEntityManager();
068: startTx(pm);
069: pc = pm.find(ColumnIOPC.class, oid);
070: assertNotNull(pc);
071: assertEquals(10, pc.getIgnoreInsert());
072: endTx(pm);
073: endEm(pm);
074: }
075:
076: public void testIgnoreUpdate() {
077: ColumnIOPC pc = new ColumnIOPC(3);
078: pc.setName("pc");
079: pc.setIgnoreUpdate(10);
080:
081: EntityManager pm = currentEntityManager();
082: startTx(pm);
083: pm.persist(pc);
084: assertEquals(10, pc.getIgnoreUpdate());
085: endTx(pm);
086:
087: Object oid = pc.getId();
088: endEm(pm);
089:
090: pm = currentEntityManager();
091: startTx(pm);
092: pc = pm.find(ColumnIOPC.class, oid);
093: assertNotNull(pc);
094: assertEquals(10, pc.getIgnoreUpdate());
095: endTx(pm);
096:
097: startTx(pm);
098: pc.setIgnoreUpdate(100);
099: assertEquals(100, pc.getIgnoreUpdate());
100: endTx(pm);
101: endEm(pm);
102:
103: pm = currentEntityManager();
104: startTx(pm);
105: pc = pm.find(ColumnIOPC.class, oid);
106: assertNotNull(pc);
107: assertEquals(10, pc.getIgnoreUpdate());
108: endTx(pm);
109: endEm(pm);
110: }
111:
112: public void testPrimitiveMappedToFieldOfForeignKey() {
113: // have to make rel persistent before setting ident field b/c not
114: // insertable
115: ColumnIOPC rel = new ColumnIOPC(1);
116: rel.setName("rel");
117: EntityManager pm = currentEntityManager();
118: startTx(pm);
119: pm.persist(rel);
120: endTx(pm);
121:
122: startTx(pm);
123: ColumnIOPC pc = new ColumnIOPC(2);
124: pc.setName("pc");
125: rel = pm.find(ColumnIOPC.class, 1);
126: pc.setRel(rel);
127: rel.setIdent(10);
128: pm.persist(pc);
129: endTx(pm);
130:
131: endEm(pm);
132:
133: pm = currentEntityManager();
134: startTx(pm);
135: pc = pm.find(ColumnIOPC.class, 2);
136: assertNotNull(pc);
137: assertEquals(0, pc.getIdent());
138: assertNotNull(pc.getRel());
139: assertEquals("rel", pc.getRel().getName());
140:
141: pc.setIdent(50);
142: pc.setRel(new ColumnIOPC(3));
143: endTx(pm);
144: endEm(pm);
145:
146: pm = currentEntityManager();
147: startTx(pm);
148: pc = pm.find(ColumnIOPC.class, 2);
149: assertNotNull(pc);
150: assertEquals(50, pc.getIdent());
151: assertNotNull(pc.getRel());
152: endTx(pm);
153: endEm(pm);
154: }
155:
156: }
|