KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > runtime > multitable > TestPrimitiveMultitable


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.runtime.multitable;
25
26 import org.objectweb.jorm.api.PException;
27 import org.objectweb.jorm.api.PBinding;
28 import org.objectweb.jorm.facility.naming.basidir.BasidBinder;
29 import org.objectweb.jorm.facility.naming.polymorphid.PolymorphIdBinder;
30 import org.objectweb.jorm.facility.naming.polymorphid.PolymorphIdPNG;
31 import org.objectweb.jorm.naming.api.PBinder;
32 import org.objectweb.jorm.naming.api.PNameCoder;
33 import org.objectweb.jorm.runtime.TestRuntimeHelper;
34 import org.objectweb.util.monolog.api.BasicLevel;
35
36 /**
37  * @author S.Chassande-Barrioz
38  */

39 public class TestPrimitiveMultitable extends TestRuntimeHelper {
40
41     private final static String JavaDoc LOGGER_NAME
42         = "test.org.objectweb.jorm.multitable.primitive";
43
44     private final static String JavaDoc Primitive_SN_MT
45         = "org.objectweb.jorm.pobject.multitable.Primitive_SN_MT";
46     private final static String JavaDoc Primitive_CN_MT
47         = "org.objectweb.jorm.pobject.multitable.Primitive_CN_MT";
48
49     public TestPrimitiveMultitable(String JavaDoc s) throws Exception JavaDoc {
50         super(s);
51     }
52
53     protected String JavaDoc getLoggerName() {
54         return LOGGER_NAME;
55     }
56
57     protected PBinder getBinder(String JavaDoc className) throws Exception JavaDoc {
58         try {
59             if (Primitive_SN_MT.equals(className)) {
60                 PBinder binder = new BasidBinder();
61                 binder.setNullPName(new Long JavaDoc(-1));
62                 ((BasidBinder) binder).setCodingType(PNameCoder.CTLONG);
63                 return binder;
64             } else if (Primitive_CN_MT.equals(className)) {
65                 PBinder binder = new PolymorphIdBinder();
66                 binder.setNullPName(new PolyIdPNG());
67                 return binder;
68             }
69         } catch (PException e) {
70             Exception JavaDoc current = e;
71             while (current instanceof PException
72                     && ((PException) current).getNestedException() != null) {
73                 current = ((PException) current).getNestedException();
74             }
75             throw current;
76         }
77         throw new PException("Unmanaged class " + className);
78     }
79
80     public class PolyIdPNG implements PolymorphIdPNG {
81         public long cid = -1;
82         public long oid = -1;
83
84         public PolyIdPNG() {
85         }
86
87         public PolyIdPNG(long cid, long oid) {
88             this.cid = cid;
89             this.oid = oid;
90         }
91
92         public long pnGetObjectId(Object JavaDoc o) throws PException {
93             return oid;
94         }
95
96         public long pnGetClassId(Object JavaDoc o) throws PException {
97             return cid;
98         }
99     }
100
101     private void primitiveTest(PBinding pb) {
102         Primitive_MT acc1 = new Primitive_MT();
103         acc1.setFx(1, 2, 3, 4, 5, 6, 7, 8);
104         Primitive_MT acc2 = new Primitive_MT();
105         logger.log(BasicLevel.DEBUG, "create and read");
106         writeRead(pb, acc1, acc2);
107         assertEquals("bad values", acc1, acc2);
108         Primitive_MT acc3 = new Primitive_MT();
109         acc3.setFx(-1, -2, 3, 4, -5, -6, 7, 8);
110         logger.log(BasicLevel.DEBUG, "update and read");
111         writeRead(pb, acc3, acc2);
112         assertEquals("bad values", acc3, acc2);
113         logger.log(BasicLevel.DEBUG, "remove");
114         unexport(pb, acc1);
115     }
116
117     public void testPrimitiveSingle() {
118         changeLogger(LOGGER_NAME + ".single");
119         logger.log(BasicLevel.DEBUG, "testPrimitiveSingle begin");
120         primitiveTest(export(Primitive_SN_MT, new Long JavaDoc(45)));
121         logger.log(BasicLevel.DEBUG, "testPrimitiveSingle end");
122     }
123
124     public void testPrimitiveComposite() {
125         changeLogger(LOGGER_NAME + ".composite");
126         logger.log(BasicLevel.DEBUG, "testPrimitiveComposite begin");
127         primitiveTest(export(Primitive_CN_MT, new PolyIdPNG(56, 78)));
128         logger.log(BasicLevel.DEBUG, "testPrimitiveComposite end");
129     }
130 }
131
Popular Tags