KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > mapper > rdb > inheritance > TestRdbViewExtent


1 /**
2  * Copyright (C) 2003-2004
3  * - France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Release: 1.0
20  *
21  * Authors: Olivier Lobry (olivier.lobry@francetelecom.com)
22  * Date: 27 sept. 2004
23  * Time: 17:41:59
24  */

25
26 package org.objectweb.jorm.mapper.rdb.inheritance;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 import org.objectweb.jorm.api.PClassMapping;
32 import org.objectweb.jorm.api.PException;
33 import org.objectweb.jorm.facility.naming.generator.LongGenMgr;
34 import org.objectweb.jorm.facility.naming.generator.rdb.LongGenIncrMapping;
35 import org.objectweb.jorm.naming.api.PBinder;
36 import org.objectweb.jorm.pobject.inheritance.extent.AnimalIdBinder;
37 import org.objectweb.jorm.runtime.TestRuntimeHelper;
38
39 /**
40  * Test that the view representing the extents are correctly
41  * generated. By extents, we mean here the collection of all
42  * instances belonging to a given class or its sub-classes.
43  */

44 public class TestRdbViewExtent extends TestRuntimeHelper {
45     private final static String JavaDoc LOGGER_NAME
46              = "test.org.objectweb.jorm.mapper.rdb.inheritance";
47     private final static String JavaDoc CNPREFIX
48              = "org.objectweb.jorm.pobject.inheritance.extent.";
49     private ArrayList JavaDoc animals = new ArrayList JavaDoc();
50
51     static LongGenMgr longgenmgr;
52
53     public TestRdbViewExtent(String JavaDoc testName) throws Exception JavaDoc {
54         super(testName);
55     }
56
57     protected void setUp() throws Exception JavaDoc {
58         super.setUp();
59         synchronized(TestRdbViewExtent.class) {
60             if (longgenmgr == null) {
61                 longgenmgr = new LongGenIncrMapping();
62                 longgenmgr.init(mapper, PClassMapping.CREATE_STRUCTURE_IF_NEEDED);
63             }
64         }
65     }
66
67     protected String JavaDoc getLoggerName() {
68         return LOGGER_NAME;
69     }
70     protected PBinder getBinder(String JavaDoc className) throws Exception JavaDoc {
71         AnimalIdBinder binder = new AnimalIdBinder();
72         binder.setACFLid(longgenmgr.getLongGen(className));
73         return binder;
74      }
75
76     private void createAnimal(Animal a) throws PException {
77         String JavaDoc className;
78         if (a instanceof Kangaroo) {
79             className = CNPREFIX + "Kangaroo";
80         } else if (a instanceof Koala) {
81             className = CNPREFIX + "Koala";
82         } else if (a instanceof Eagle) {
83             className = CNPREFIX + "Eagle";
84         } else if (a instanceof Pigeon) {
85             className = CNPREFIX + "Pigeon";
86         } else {
87             throw new PException("Unknown persistance class");
88         }
89         if (!performIO(className, a, a, a, false)) {
90             throw new PException("cannot create animal");
91         }
92     }
93
94     public void testView() throws Exception JavaDoc {
95         animals.add(new Kangaroo(true, 120, 40, (float) 6.5));
96         animals.add(new Kangaroo(false, 132, 40, (float) 6.5));
97         animals.add(new Koala(true, 78, 30, 20));
98         animals.add(new Koala(false, 70, 30, 20));
99         animals.add(new Eagle(true, 80, "Italy", 100));
100         animals.add(new Eagle(false, 85, "France", 100));
101         animals.add(new Pigeon(true, 32, "Belgique", 123));
102         animals.add(new Pigeon(false, 31, "France", 123));
103
104
105         for (Iterator JavaDoc it = animals.iterator(); it.hasNext();) {
106             Animal animal = (Animal) it.next();
107             createAnimal(animal);
108         }
109      }
110
111
112 }
113
Popular Tags