KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > genclass > SpeedoGenClassHome


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

18 package org.objectweb.speedo.genclass;
19
20 import org.objectweb.jorm.api.PAccessor;
21 import org.objectweb.jorm.api.PBinding;
22 import org.objectweb.jorm.api.PClassMapping;
23 import org.objectweb.jorm.api.PException;
24 import org.objectweb.jorm.api.PMapper;
25 import org.objectweb.jorm.api.PMappingCallback;
26 import org.objectweb.jorm.api.PMappingStructuresManager;
27 import org.objectweb.jorm.api.PNameIterator;
28 import org.objectweb.jorm.mapper.rdb.genclass.RdbGenClassMapping;
29 import org.objectweb.jorm.metainfo.api.MetaObject;
30 import org.objectweb.jorm.naming.api.PBinder;
31 import org.objectweb.jorm.naming.api.PName;
32 import org.objectweb.jorm.naming.api.PNameCoder;
33 import org.objectweb.jorm.type.api.PType;
34 import org.objectweb.jorm.util.api.Loggable;
35 import org.objectweb.medor.tuple.api.TupleCollection;
36 import org.objectweb.perseus.persistence.api.TransactionalPersistenceManager;
37 import org.objectweb.speedo.genclass.api.SpeedoGenClassProxy;
38 import org.objectweb.speedo.mim.api.SpeedoProxy;
39 import org.objectweb.speedo.mim.lib.SpeedoHomeImpl;
40 import org.objectweb.speedo.pm.api.ProxyManager;
41 import org.objectweb.speedo.pm.api.ProxyManagerFactory;
42 import org.objectweb.util.monolog.api.Logger;
43 import org.objectweb.util.monolog.api.LoggerFactory;
44
45 import java.util.HashMap JavaDoc;
46 import java.util.Iterator JavaDoc;
47 import java.util.Properties JavaDoc;
48
49 import javax.jdo.JDOUserException;
50
51 /**
52  * This implementation of SpeedoHome delegated the PClassMapping roles to
53  * another instance. This implementation is dedicated to GenClass.
54  *
55  * @author S.Chassande-Barrioz
56  */

57 public class SpeedoGenClassHome extends SpeedoHomeImpl {
58
59     PClassMapping pcm;
60     String JavaDoc path;
61     
62     public SpeedoGenClassHome(PClassMapping _pcm,
63             TransactionalPersistenceManager _tpm,
64             ProxyManagerFactory _pmf,
65             String JavaDoc p) {
66         super(_tpm, _pmf);
67         this.pcm = _pcm;
68         this.path = p;
69     }
70     
71     public void makePersistent(ProxyManager pm, SpeedoProxy sp, SpeedoGenClassProxy jdoProxy) {
72         if (!sp.jdoIsActive()) {
73             if (sp instanceof SpeedoGenClassProxy) {
74                 //Genclass contains genclass instances
75
SpeedoGenClassProxy sgcp = (SpeedoGenClassProxy) sp;
76                 if (sgcp.jdoGetPType() == null) {
77                     //Assign the PType to the generic class
78
sgcp.jdoSetPType(jdoProxy.jdoGetPType().getNestedPType());
79                 }
80                 sgcp.jdoSetLinkedField(jdoProxy.jdoGetGenClassId());
81                 sgcp.jdoSetPNameHints(jdoProxy.getPName());
82             }
83             if (pm == null) {
84                 pm = (ProxyManager) jdoProxy.jdoGetPersistenceManager();
85             }
86             if (pm == null) {
87                 throw new JDOUserException(
88                     "When a persistent object is used (read or write), " +
89                     "a PersistenceManager is needed");
90             }
91             pm.speedoMakePersistent(sp, true);
92         }
93     }
94
95     public void makePersistent(ProxyManager pm, Iterator it, SpeedoGenClassProxy jdoProxy) {
96         if (it == null) {
97             return;
98         }
99         while(it.hasNext()) {
100             Object JavaDoc o = it.next();
101             if (o instanceof SpeedoProxy) {
102                 makePersistent(pm, (SpeedoProxy) o, jdoProxy);
103             } else {
104                 // Optimisation: If the first element is not a SpeedoProxy, that
105
// means that ALL collection elements are not SpeedoProxy
106
// implementation
107
return;
108             }
109         }
110     }
111
112     // IMPLEMENTATION OF THE SpeedoHome INTERFACE //
113
//--------------------------------------------//
114

115     public boolean isDetachable() {
116         return false;
117     }
118
119     public byte getVersioningStrategy() {
120         return 0;
121     }
122
123     public Properties JavaDoc getClassProperties() {
124         return null;
125     }
126
127     public String JavaDoc getPath() {
128         return path;
129     }
130
131     public void setPrefetchOnGenClass(boolean prefetch) {
132         super.setPrefetchOnGenClass(prefetch);
133         if (pcm instanceof RdbGenClassMapping) {
134             ((RdbGenClassMapping) pcm).setPrefetchActivated(prefetch);
135         }
136     }
137     
138     // IMPLEMENTATION OF THE PClassMapping INTERFACE //
139
//-----------------------------------------------//
140

141     public String JavaDoc getProjectName() {
142         return pcm.getProjectName();
143     }
144
145     public PBinding createPBinding() throws PException {
146         PBinding pb = pcm.createPBinding();
147         pb.init(this);
148         return pb;
149         
150     }
151
152     public void init(PMappingCallback mapper, MetaObject metaclass)
153             throws PException {
154         pcm.init(mapper, metaclass);
155     }
156
157     public String JavaDoc getClassName() {
158         return pcm.getClassName();
159     }
160
161     public PClassMapping getGenClassMapping()
162             throws UnsupportedOperationException JavaDoc {
163         return pcm.getGenClassMapping();
164     }
165
166     public PClassMapping getGenClassMapping(String JavaDoc fn)
167             throws UnsupportedOperationException JavaDoc {
168         return pcm.getGenClassMapping(fn);
169     }
170
171     public MetaObject getMetaInfo() {
172         return pcm.getMetaInfo();
173     }
174
175     public PBinder getPBinder() {
176         return pcm.getPBinder();
177     }
178
179     public PMapper getPMapper() {
180         return pcm.getPMapper();
181     }
182
183     public PNameCoder getPNameCoder() throws UnsupportedOperationException JavaDoc {
184         return pcm.getPNameCoder();
185     }
186
187     public PNameCoder getPNameCoder(String JavaDoc fn)
188             throws UnsupportedOperationException JavaDoc {
189         return pcm.getPNameCoder(fn);
190     }
191
192     public PNameCoder getClassPNameCoder() {
193         return pcm.getClassPNameCoder();
194     }
195
196     public PNameIterator getPNameIterator(Object JavaDoc conn, boolean withSubType,
197             boolean prefetching, Object JavaDoc txctx) throws PException {
198         return pcm.getPNameIterator(conn, withSubType, prefetching, txctx);
199     }
200
201     public Iterator getPNameIterator(Object JavaDoc conn) throws PException {
202         return pcm.getPNameIterator(conn, false, false, null);
203     }
204
205     public PType getPType() {
206             return pcm.getPType();
207     }
208
209     public boolean isConform(String JavaDoc mappername) {
210         return pcm.isConform(mappername);
211     }
212
213     public void setPBinder(PBinder pb) throws PException {
214         pcm.setPBinder(pb);
215     }
216
217     public void configureRefFields(ReferenceConfigurator rc) throws PException,
218             UnsupportedOperationException JavaDoc {
219         pcm.configureRefFields(rc);
220     }
221
222     public boolean exist(PBinding pb, Object JavaDoc conn) throws PException {
223         return pcm.exist(pb, conn);
224     }
225
226     public void read(PBinding pb, Object JavaDoc conn, PAccessor pa) throws PException {
227         pcm.read(pb, conn, pa);
228     }
229
230     public void read(PBinding pb, Object JavaDoc conn, PAccessor pa, Object JavaDoc txctx)
231             throws PException {
232         pcm.read(pb, conn, pa, txctx);
233     }
234
235     public void write(PBinding pb, Object JavaDoc conn, PAccessor pa) throws PException {
236         pcm.write(pb, conn, pa);
237     }
238     
239     
240     // IMPLEMENTATION OF THE Loggable INTERFACE //
241
//------------------------------------------//
242

243     public Logger getLogger() {
244         return ((Loggable) pcm).getLogger();
245     }
246
247     public LoggerFactory getLoggerFactory() {
248         return ((Loggable) pcm).getLoggerFactory();
249     }
250
251     public void setLogger(Logger logger) {
252         ((Loggable) pcm).setLogger(logger);
253     }
254
255     public void setLoggerFactory(LoggerFactory loggerfactory) {
256         ((Loggable) pcm).setLoggerFactory(loggerfactory);
257     }
258
259     public PClassMapping[] getSubPCMs() throws PException {
260         return pcm.getSubPCMs();
261     }
262
263     public HashMap JavaDoc getAssociationTable() {
264         return pcm.getAssociationTable();
265     }
266
267     public void addAssociation(PClassMapping targetClass, int[] indexes) {
268         pcm.addAssociation(targetClass, indexes);
269     }
270
271     public int[] getIndexesTable(PClassMapping targetClass) {
272         return pcm.getIndexesTable(targetClass);
273     }
274
275     public PName resolve(Object JavaDoc conn, PName pname) throws PException{
276             return pcm.resolve(conn, pname);
277     }
278
279     public boolean match(Object JavaDoc obj, boolean b) throws PException{
280         return pcm.match(obj, b);
281     }
282     
283     public PName getDecodedPName(TupleCollection tc, PName pname, boolean intermediaryTuple) throws PException {
284         return pcm.getDecodedPName(tc, pname, intermediaryTuple);
285     }
286
287     public void init(PMappingStructuresManager pmsm) throws PException {
288         pcm.init(pmsm);
289     }
290
291     public void classDefined(PMappingStructuresManager pmsm) throws PException {
292         pcm.classDefined(pmsm);
293     }
294 }
295
Popular Tags