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.annotations;
020:
021: import org.apache.openjpa.jdbc.conf.*;
022: import org.apache.openjpa.jdbc.meta.*;
023: import org.apache.openjpa.jdbc.meta.strats.*;
024: import org.apache.openjpa.persistence.OpenJPAEntityManager;
025:
026: import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
027: import junit.framework.*;
028:
029: import org.apache.openjpa.persistence.common.utils.*;
030:
031: /**
032: * <p>Test that InheritanceType.TABLE_PER_CLASS JPA mapping is translated
033: * correctly. See the <code>kodo.jdbc.meta.tableperclass</code> test package
034: * for more detailed tests of functionality.</p>
035: *
036: * @author Abe White
037: */
038: public class TestTablePerClassInheritance extends AnnotationTestCase {
039:
040: public TestTablePerClassInheritance(String name) {
041: super (name, "annotationcactusapp");
042: }
043:
044: /** public void testMapping() {
045: ClassMapping mapping = ((JDBCConfiguration) getConfiguration()).
046: getMappingRepositoryInstance().getMapping(TablePerClass2.class,
047: null, true);
048: assertTrue(mapping.getStrategy() instanceof FullClassStrategy);
049: assertTrue(mapping.getDiscriminator().getStrategy()
050: instanceof NoneDiscriminatorStrategy);
051: assertNull(mapping.getJoinForeignKey());
052: assertNull(mapping.getJoinablePCSuperclassMapping());
053: assertEquals("TPC_BASIC", mapping.getFieldMapping("basic").
054: getColumns()[0].getName());
055: ClassMapping embed = mapping.getFieldMapping("embed").
056: currentEntityManager()beddedMapping();
057: assertEquals("TPC_EMB_BASIC", embed.getFieldMapping("basic").
058: getColumns()[0].getName());
059:
060: ClassMapping sup = mapping.getPCSuperclassMapping();
061: assertEquals(TablePerClass1.class, sup.getDescribedType());
062: assertTrue(sup.getStrategy() instanceof FullClassStrategy);
063: assertTrue(sup.getDiscriminator().getStrategy()
064: instanceof NoneDiscriminatorStrategy);
065: assertEquals("TPC_BASIC", sup.getFieldMapping("basic").
066: getColumns()[0].getName());
067: embed = sup.getFieldMapping("embed").currentEntityManager()beddedMapping();
068: assertEquals("TPC_EMB_BASIC", embed.getFieldMapping("basic").
069: getColumns()[0].getName());
070: }**/
071:
072: public void testInsertAndRetrieve() {
073: deleteAll(TablePerClass1.class);
074:
075: OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
076: startTx(em);
077: TablePerClass1 tpc1 = new TablePerClass1();
078: tpc1.setBasic(1);
079: EmbedValue ev = new EmbedValue();
080: ev.setBasic("11");
081: tpc1.setEmbed(ev);
082: TablePerClass2 tpc2 = new TablePerClass2();
083: tpc2.setBasic(2);
084: tpc2.setBasic2("2");
085: ev = new EmbedValue();
086: ev.setBasic("22");
087: tpc2.setEmbed(ev);
088: em.persistAll(tpc1, tpc2);
089: endTx(em);
090: int id1 = tpc1.getPk();
091: int id2 = tpc2.getPk();
092: endEm(em);
093:
094: em = (OpenJPAEntityManager) currentEntityManager();
095: tpc1 = em.find(TablePerClass1.class, id1);
096: assertEquals(1, tpc1.getBasic());
097: assertEquals("11", tpc1.getEmbed().getBasic());
098: tpc2 = (TablePerClass2) em.find(TablePerClass1.class, id2);
099: assertEquals(2, tpc2.getBasic());
100: assertEquals("2", tpc2.getBasic2());
101: assertEquals("22", tpc2.getEmbed().getBasic());
102: endEm(em);
103: }
104: }
|