KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > core > DelegatingPersistenceBroker


1 package org.apache.ojb.broker.core;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.broker.Identity;
19 import org.apache.ojb.broker.MtoNImplementor;
20 import org.apache.ojb.broker.ManageableCollection;
21 import org.apache.ojb.broker.PBKey;
22 import org.apache.ojb.broker.PBListener;
23 import org.apache.ojb.broker.PBState;
24 import org.apache.ojb.broker.PersistenceBroker;
25 import org.apache.ojb.broker.PersistenceBrokerEvent;
26 import org.apache.ojb.broker.PBLifeCycleEvent;
27 import org.apache.ojb.broker.PBStateEvent;
28 import org.apache.ojb.broker.PersistenceBrokerException;
29 import org.apache.ojb.broker.TransactionAbortedException;
30 import org.apache.ojb.broker.TransactionInProgressException;
31 import org.apache.ojb.broker.TransactionNotInProgressException;
32 import org.apache.ojb.broker.IdentityFactory;
33 import org.apache.ojb.broker.PersistenceBrokerInternal;
34 import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
35 import org.apache.ojb.broker.accesslayer.JdbcAccess;
36 import org.apache.ojb.broker.accesslayer.StatementManagerIF;
37 import org.apache.ojb.broker.accesslayer.RelationshipPrefetcherFactory;
38 import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
39 import org.apache.ojb.broker.cache.ObjectCache;
40 import org.apache.ojb.broker.core.proxy.ProxyFactory;
41 import org.apache.ojb.broker.metadata.ClassDescriptor;
42 import org.apache.ojb.broker.metadata.DescriptorRepository;
43 import org.apache.ojb.broker.query.Query;
44 import org.apache.ojb.broker.util.BrokerHelper;
45 import org.apache.ojb.broker.util.ObjectModification;
46 import org.apache.ojb.broker.util.configuration.Configuration;
47 import org.apache.ojb.broker.util.configuration.ConfigurationException;
48 import org.apache.ojb.broker.util.sequence.SequenceManager;
49
50 import java.util.Collection JavaDoc;
51 import java.util.Enumeration JavaDoc;
52 import java.util.Iterator JavaDoc;
53
54 /**
55  * Delegating implementation of a PersistenceBroker.
56  *
57  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
58  * @version $Id: DelegatingPersistenceBroker.java,v 1.11.2.7 2005/09/05 23:37:26 arminw Exp $
59  */

60 public class DelegatingPersistenceBroker implements PersistenceBrokerInternal, PBState
61 {
62     protected PersistenceBrokerInternal m_broker;
63
64     public DelegatingPersistenceBroker(PersistenceBrokerInternal broker)
65     {
66         this.m_broker = broker;
67     }
68
69     /**
70      * All delegated method use this method to
71      * get the wrapped broker.
72      */

73     protected PersistenceBrokerInternal getBroker()
74     {
75         if (m_broker != null)
76         {
77             return m_broker;
78         }
79         else
80         {
81             throw new IllegalStateException JavaDoc(
82                     "This PersistenceBroker instance is already closed and no longer useable." +
83                     " It's not possible to re-use a closed instance.");
84         }
85
86     }
87
88     /**
89      * Returns only the wrapped
90      * {@link org.apache.ojb.broker.PersistenceBroker} instance
91      */

92     public PersistenceBrokerInternal getDelegate()
93     {
94         return this.m_broker;
95     }
96
97     public void setDelegate(PersistenceBrokerInternal broker)
98     {
99         this.m_broker = broker;
100     }
101
102     /**
103      * If my underlying {@link org.apache.ojb.broker.PersistenceBroker}
104      * is not a {@link DelegatingPersistenceBroker}, returns it,
105      * otherwise recursively invokes this method on my delegate.
106      * <p>
107      * Hence this method will return the first
108      * delegate that is not a {@link DelegatingPersistenceBroker},
109      * or <tt>null</tt> when no non-{@link DelegatingPersistenceBroker}
110      * delegate can be found by transversing this chain.
111      * <p>
112      * This method is useful when you may have nested
113      * {@link DelegatingPersistenceBroker}s, and you want to make
114      * sure to obtain a "genuine" {@link org.apache.ojb.broker.PersistenceBroker}
115      * implementaion instance.
116      */

117     public PersistenceBroker getInnermostDelegate()
118     {
119         PersistenceBroker broker = this.m_broker;
120         while (broker != null && broker instanceof DelegatingPersistenceBroker)
121         {
122             broker = ((DelegatingPersistenceBroker) broker).getDelegate();
123             if (this == broker)
124             {
125                 return null;
126             }
127         }
128         return broker;
129     }
130
131     public boolean isManaged()
132     {
133         return m_broker.isManaged();
134     }
135
136     public void setManaged(boolean managed)
137     {
138         m_broker.setManaged(managed);
139     }
140
141     public QueryReferenceBroker getReferenceBroker()
142     {
143         return m_broker.getReferenceBroker();
144     }
145
146     public void checkRefreshRelationships(Object JavaDoc obj, Identity oid, ClassDescriptor cld)
147     {
148         m_broker.checkRefreshRelationships(obj, oid, cld);
149     }
150
151     public RelationshipPrefetcherFactory getRelationshipPrefetcherFactory()
152     {
153         return m_broker.getRelationshipPrefetcherFactory();
154     }
155
156     public void store(Object JavaDoc obj, Identity oid, ClassDescriptor cld, boolean insert, boolean ignoreReferences)
157     {
158         m_broker.store(obj, oid, cld, insert, ignoreReferences);
159     }
160
161     public void delete(Object JavaDoc obj, boolean ignoreReferences) throws PersistenceBrokerException
162     {
163         m_broker.delete(obj, ignoreReferences);
164     }
165
166     public boolean isInTransaction() throws PersistenceBrokerException
167     {
168         return m_broker != null && getBroker().isInTransaction();
169     }
170
171     public boolean isClosed()
172     {
173         return m_broker == null || getBroker().isClosed();
174     }
175
176     public void setClosed(boolean closed)
177     {
178         ((PBState) getBroker()).setClosed(closed);
179     }
180
181     public void beginTransaction()
182             throws TransactionInProgressException, TransactionAbortedException
183     {
184         getBroker().beginTransaction();
185     }
186
187     public void commitTransaction()
188             throws TransactionNotInProgressException, TransactionAbortedException
189     {
190         getBroker().commitTransaction();
191     }
192
193     public void abortTransaction() throws TransactionNotInProgressException
194     {
195         getBroker().abortTransaction();
196     }
197
198     public boolean close()
199     {
200         return getBroker().close();
201     }
202
203     public SqlGenerator serviceSqlGenerator()
204     {
205         return getBroker().serviceSqlGenerator();
206     }
207
208     public JdbcAccess serviceJdbcAccess()
209     {
210         return getBroker().serviceJdbcAccess();
211     }
212
213     public void delete(Object JavaDoc obj) throws PersistenceBrokerException
214     {
215         getBroker().delete(obj);
216     }
217
218     public void store(Object JavaDoc obj) throws PersistenceBrokerException
219     {
220         getBroker().store(obj);
221     }
222
223     public void store(Object JavaDoc obj,
224                       ObjectModification modification) throws PersistenceBrokerException
225     {
226         getBroker().store(obj, modification);
227     }
228
229     public PBKey getPBKey()
230     {
231         return getBroker().getPBKey();
232     }
233
234     public void removeFromCache(Object JavaDoc obj) throws PersistenceBrokerException
235     {
236         getBroker().removeFromCache(obj);
237     }
238
239     public void clearCache() throws PersistenceBrokerException
240     {
241         getBroker().clearCache();
242     }
243
244     public DescriptorRepository getDescriptorRepository()
245     {
246         return getBroker().getDescriptorRepository();
247     }
248
249     public void removeAllListeners() throws PersistenceBrokerException
250     {
251         getBroker().removeAllListeners();
252     }
253
254     public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
255     {
256         getBroker().removeAllListeners(permanent);
257     }
258
259     public void retrieveReference(Object JavaDoc pInstance, String JavaDoc pAttributeName) throws PersistenceBrokerException
260     {
261         getBroker().retrieveReference(pInstance, pAttributeName);
262     }
263
264     public void retrieveAllReferences(Object JavaDoc pInstance) throws PersistenceBrokerException
265     {
266         getBroker().retrieveAllReferences(pInstance);
267     }
268
269     public ConnectionManagerIF serviceConnectionManager()
270     {
271         return getBroker().serviceConnectionManager();
272     }
273
274     public StatementManagerIF serviceStatementManager()
275     {
276         return getBroker().serviceStatementManager();
277     }
278
279     public SequenceManager serviceSequenceManager()
280     {
281         return getBroker().serviceSequenceManager();
282     }
283
284     public BrokerHelper serviceBrokerHelper()
285     {
286         return getBroker().serviceBrokerHelper();
287     }
288
289     public ObjectCache serviceObjectCache()
290     {
291         return getBroker().serviceObjectCache();
292     }
293
294     public IdentityFactory serviceIdentity()
295     {
296         return getBroker().serviceIdentity();
297     }
298
299     public void fireBrokerEvent(PersistenceBrokerEvent event)
300     {
301         getBroker().fireBrokerEvent(event);
302     }
303
304     public void fireBrokerEvent(PBLifeCycleEvent event)
305     {
306         getBroker().fireBrokerEvent(event);
307     }
308
309     public void fireBrokerEvent(PBStateEvent event)
310     {
311         getBroker().fireBrokerEvent(event);
312     }
313
314     public void addListener(PBListener listener) throws PersistenceBrokerException
315     {
316         getBroker().addListener(listener);
317     }
318
319     public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException
320     {
321         getBroker().addListener(listener, permanent);
322     }
323
324     public void removeListener(PBListener listener) throws PersistenceBrokerException
325     {
326         //do nothing
327
}
328
329     public Class JavaDoc getTopLevelClass(Class JavaDoc clazz) throws PersistenceBrokerException
330     {
331         return getBroker().getTopLevelClass(clazz);
332     }
333
334     public boolean hasClassDescriptor(Class JavaDoc clazz)
335     {
336         return getBroker().hasClassDescriptor(clazz);
337     }
338
339     public ClassDescriptor getClassDescriptor(Class JavaDoc clazz) throws PersistenceBrokerException
340     {
341         return getBroker().getClassDescriptor(clazz);
342     }
343
344     public Enumeration JavaDoc getPKEnumerationByQuery(Class JavaDoc primaryKeyClass,
345                                                Query query) throws PersistenceBrokerException
346     {
347         return getBroker().getPKEnumerationByQuery(primaryKeyClass, query);
348     }
349
350     public Object JavaDoc getObjectByQuery(Query query) throws PersistenceBrokerException
351     {
352         return getBroker().getObjectByQuery(query);
353     }
354
355     public Object JavaDoc getObjectByIdentity(Identity id) throws PersistenceBrokerException
356     {
357         return getBroker().getObjectByIdentity(id);
358     }
359
360     public Iterator JavaDoc getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
361     {
362         return getBroker().getReportQueryIteratorByQuery(query);
363     }
364
365     public Iterator JavaDoc getIteratorByQuery(Query query) throws PersistenceBrokerException
366     {
367         return getBroker().getIteratorByQuery(query);
368     }
369
370     public ManageableCollection getCollectionByQuery(Class JavaDoc collectionClass, Query query)
371             throws PersistenceBrokerException
372     {
373         return getBroker().getCollectionByQuery(collectionClass, query);
374     }
375
376     public int getCount(Query query) throws PersistenceBrokerException
377     {
378         return getBroker().getCount(query);
379     }
380
381     public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
382     {
383         return getBroker().getCollectionByQuery(query);
384     }
385
386     public void configure(Configuration pConfig) throws ConfigurationException
387     {
388         getBroker().configure(pConfig);
389     }
390
391     public org.odbms.Query query()
392     {
393         return getBroker().query();
394     }
395
396     public void deleteByQuery(Query query) throws PersistenceBrokerException
397     {
398         getBroker().deleteByQuery(query);
399     }
400
401     /**
402      * @see org.apache.ojb.broker.PersistenceBroker#deleteMtoNImplementor
403      */

404     public void deleteMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException
405     {
406         getBroker().deleteMtoNImplementor(m2nImpl);
407     }
408
409     /**
410      * @see org.apache.ojb.broker.PersistenceBroker#addMtoNImplementor
411      */

412     public void addMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException
413     {
414         getBroker().addMtoNImplementor(m2nImpl);
415     }
416
417     public ProxyFactory getProxyFactory()
418     {
419        return getBroker().getProxyFactory();
420     }
421
422     public Object JavaDoc createProxy(Class JavaDoc proxyClass, Identity realSubjectsIdentity) {
423         return getBroker().createProxy(proxyClass, realSubjectsIdentity);
424     }
425     
426     
427     
428
429 }
430
Popular Tags