KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > runtime > pnameiterator > TestSingleNameIterator


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.pnameiterator;
25
26 import org.objectweb.jorm.runtime.TestRuntimeHelper;
27 import org.objectweb.jorm.runtime.namedef.NameDefAccessor;
28 import org.objectweb.jorm.naming.api.PBinder;
29 import org.objectweb.jorm.naming.api.PNameCoder;
30 import org.objectweb.jorm.naming.api.PName;
31 import org.objectweb.jorm.type.api.PType;
32 import org.objectweb.jorm.type.api.PTypeSpace;
33 import org.objectweb.jorm.facility.naming.basidir.BasidBinder;
34 import org.objectweb.jorm.api.PClassMapping;
35 import org.objectweb.jorm.api.PBinding;
36 import org.objectweb.util.monolog.api.BasicLevel;
37
38 import java.util.Iterator JavaDoc;
39
40 /**
41  *
42  * @author P. Dechamboux
43  */

44 public class TestSingleNameIterator extends TestRuntimeHelper {
45
46     private final static String JavaDoc LOGGER_NAME
47             = "test.org.objectweb.jorm.singlename";
48
49     public TestSingleNameIterator(String JavaDoc name) throws Exception JavaDoc {
50         super(name);
51     }
52
53     protected String JavaDoc getLoggerName() {
54         return LOGGER_NAME;
55     }
56
57     protected PBinder getBinder(String JavaDoc className) throws Exception JavaDoc {
58         int idx = className.lastIndexOf('.');
59         String JavaDoc cn = className.substring(idx + 1);
60         PType type = null;
61         int ct = -1;
62         Object JavaDoc nullvalue = null;
63         if (cn.equals("ASingleIntId")) {
64             type = PTypeSpace.INT;
65             ct = PNameCoder.CTINT;
66             nullvalue = new Integer JavaDoc(-1);
67         } else {
68             throw new Exception JavaDoc(
69                     "Unable to find the type of the binder for the class: "
70                     + className);
71         }
72         logger.log(BasicLevel.DEBUG, "Allocate a BasidBinder to manage "
73                 + type.getJormName());
74         PBinder binder = new BasidBinder();
75         binder.setNullPName(nullvalue);
76         ((BasidBinder) binder).setCodingType(ct);
77         return binder;
78     }
79
80     private final static String JavaDoc CNINT = "org.objectweb.jorm.pobject.singlename.ASingleIntId";
81
82     public void trueTester(int NBOBJ, boolean prefetch) throws Exception JavaDoc {
83         PClassMapping pcm = getMapping(CNINT);
84         Object JavaDoc conn = mapper.getConnection();
85         for (int i = 0; i < NBOBJ; i++) {
86             PBinding pb = export(CNINT, new Integer JavaDoc(i));
87             NameDefAccessor accwrite = new NameDefAccessor(i, pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
88             pb.write(conn, accwrite);
89         }
90         Iterator JavaDoc it = pcm.getPNameIterator(conn, false, prefetch, conn);
91         int nbiter = 0;
92         PBinding[] pb = new PBinding[NBOBJ];
93         NameDefAccessor accread = new NameDefAccessor();
94         while (it.hasNext()) {
95             PName pn = (PName) it.next();
96             pb[nbiter] = bind(CNINT, pn);
97             pb[nbiter].read(conn, accread, conn);
98             assertEquals("Bad object pname and F1 should be equal", accread.f1, pn.encodeInt());
99             nbiter++;
100         }
101         assertEquals("Wrong number of objects iterated", NBOBJ, nbiter);
102         mapper.getPrefetchCache().invalidatePrefetchBuffer(conn);
103         mapper.closeConnection(conn);
104         mapper.getPMapCluster(CNINT).deleteData();
105     }
106
107     public void testIntNameIteratorNoPrefetchNoElem() throws Exception JavaDoc {
108         int NBOBJ = 0;
109         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
110         trueTester(NBOBJ, false);
111         logger.log(BasicLevel.DEBUG, "testInt end");
112     }
113
114     public void testIntNameIteratorNoPrefetchOneElem() throws Exception JavaDoc {
115         int NBOBJ = 1;
116         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
117         trueTester(NBOBJ, false);
118         logger.log(BasicLevel.DEBUG, "testInt end");
119     }
120
121     public void testIntNameIteratorNoPrefetch10Elem() throws Exception JavaDoc {
122         int NBOBJ = 10;
123         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
124         trueTester(NBOBJ, false);
125         logger.log(BasicLevel.DEBUG, "testInt end");
126     }
127
128     public void testIntNameIteratorNoPrefetch100Elem() throws Exception JavaDoc {
129         int NBOBJ = 100;
130         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
131         trueTester(NBOBJ, false);
132         logger.log(BasicLevel.DEBUG, "testInt end");
133     }
134
135     public void testIntNameIteratorNoPrefetch1000Elem() throws Exception JavaDoc {
136         int NBOBJ = 1000;
137         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
138         trueTester(NBOBJ, false);
139         logger.log(BasicLevel.DEBUG, "testInt end");
140     }
141
142     public void testIntNameIteratorPrefetchNoElem() throws Exception JavaDoc {
143         int NBOBJ = 0;
144         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
145         trueTester(NBOBJ, true);
146         logger.log(BasicLevel.DEBUG, "testInt end");
147     }
148
149     public void testIntNameIteratorPrefetchOneElem() throws Exception JavaDoc {
150         int NBOBJ = 1;
151         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
152         trueTester(NBOBJ, true);
153         logger.log(BasicLevel.DEBUG, "testInt end");
154     }
155
156     public void testIntNameIteratorPrefetch10Elem() throws Exception JavaDoc {
157         int NBOBJ = 10;
158         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
159         trueTester(NBOBJ, true);
160         logger.log(BasicLevel.DEBUG, "testInt end");
161     }
162
163     public void testIntNameIteratorPrefetch100Elem() throws Exception JavaDoc {
164         int NBOBJ = 100;
165         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
166         trueTester(NBOBJ, true);
167         logger.log(BasicLevel.DEBUG, "testInt end");
168     }
169
170     public void testIntNameIteratorPrefetch1000Elem() throws Exception JavaDoc {
171         int NBOBJ = 1000;
172         changeLogger(LOGGER_NAME + ".int." + NBOBJ);
173         trueTester(NBOBJ, true);
174         logger.log(BasicLevel.DEBUG, "testInt end");
175     }
176 }
177
Popular Tags