KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > jca > JdoConnection


1 /**
2  * perseus/connector: this is an implementation of some JCA-related technologies
3  * (resource adapters and managers) for the ObjectWeb consortium.
4  * Copyright (C) 2001-2004 France Telecom R&D
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: speedo@objectweb.org
21  *
22  */

23
24 package org.objectweb.speedo.jca;
25
26 import org.objectweb.util.monolog.api.BasicLevel;
27 import org.objectweb.util.monolog.api.Logger;
28 import org.objectweb.speedo.api.Debug;
29 import org.objectweb.speedo.api.SpeedoProperties;
30
31 import java.util.Collection JavaDoc;
32
33 import javax.naming.Context JavaDoc;
34 import javax.naming.InitialContext JavaDoc;
35 import javax.resource.ResourceException JavaDoc;
36 import javax.resource.cci.Connection JavaDoc;
37 import javax.resource.cci.ConnectionMetaData JavaDoc;
38 import javax.resource.cci.Interaction JavaDoc;
39 import javax.resource.cci.LocalTransaction JavaDoc;
40 import javax.resource.cci.ResultSetInfo JavaDoc;
41 import javax.transaction.Synchronization JavaDoc;
42 import javax.transaction.UserTransaction JavaDoc;
43 import javax.jdo.datastore.JDOConnection;
44 import javax.jdo.datastore.Sequence;
45 import javax.jdo.listener.InstanceLifecycleListener;
46 import javax.jdo.FetchPlan;
47 import javax.jdo.PersistenceManager;
48 import javax.jdo.JDOException;
49 import javax.jdo.Transaction;
50 import javax.jdo.Query;
51 import javax.jdo.Extent;
52 import javax.jdo.PersistenceManagerFactory;
53
54 /**
55  * @author P. Dechamboux
56  */

57 public class JdoConnection
58     implements Connection JavaDoc, ConnectionMetaData JavaDoc, PersistenceManager, Transaction JavaDoc {
59     
60     private final static String JavaDoc NO_ACTIVE_CONNECTION =
61         "The JDO connection should be active!!";
62     
63     /**
64      * The logger into which traces about JdoConnection are produced.
65      */

66     private Logger logger;
67     /**
68      * The name of this storage sub-system.
69      */

70     private final static String JavaDoc EISPRODUCTNAME = "JDO Connector";
71     /**
72      * The ConnectionFactory that have requested the allocation of this
73      * Connection.
74      */

75     private JdoConnectionFactory connectionFactory;
76     /**
77      * The ManagedConnection associated with this Connection.
78      */

79     private JdoManagedConnection managedConnection = null;
80     /**
81      * The LocalTransaction allocated by this connection if any.
82      */

83     private LocalTransaction JavaDoc localTransaction = null;
84
85     /**
86      * The UserTransaction of JTA
87      */

88     private UserTransaction JavaDoc userTransaction = null;
89     
90     /**
91      * Constructs a JdoConnection.
92      * @param el The logger into which to produce Connection-related traces.
93      * @param fcf The ConnectionFactory that has requested the Connection
94      * creation.
95      */

96     JdoConnection(Logger el, JdoConnectionFactory fcf) {
97         logger = el;
98         connectionFactory = fcf;
99     }
100
101     /**
102      * Initializes a Connection to be linked with a ManagedConnection.
103      * @param mc The ManagedConnection to be linked to.
104      */

105     void initialize(JdoManagedConnection mc) {
106         managedConnection = mc;
107     }
108
109     // IMPLEMENTATION OF METHODS FROM THE (cci)Connection INTERFACE
110

111     /**
112      * No support for Interaction.
113      */

114     public Interaction JavaDoc createInteraction() throws ResourceException JavaDoc {
115         throw new ResourceException JavaDoc("JDO Connector: no support for Interaction.");
116     }
117
118     public LocalTransaction JavaDoc getLocalTransaction() throws ResourceException JavaDoc {
119         if (managedConnection == null) {
120             throw new ResourceException JavaDoc("JDO Connector: cannot get a LocalTransaction with no associated ManagedConnection.");
121         }
122         localTransaction = managedConnection;
123         return managedConnection;
124     }
125
126     /**
127      * The JdoConnection manages the metadata on its own.
128      */

129     public ConnectionMetaData JavaDoc getMetaData() throws ResourceException JavaDoc {
130         return this;
131     }
132
133     /**
134      * No support for ResultSet.
135      */

136     public ResultSetInfo JavaDoc getResultSetInfo() throws ResourceException JavaDoc {
137         throw new ResourceException JavaDoc("JDO Connector: no support for ResultSet.");
138     }
139
140     /**
141      * Closes this Connection. Dissociates from the ManagedConnection to which
142      * it is linked.
143      */

144     public void close() {
145         if (Debug.ON)
146             logger.log(BasicLevel.DEBUG, "Closes Connection: " + this);
147         if (managedConnection == null) {
148             // The connection is already closed
149
return;
150         }
151         if (localTransaction != null) {
152             if (!managedConnection.localTransactionTerminated()) {
153                 throw new JDOException("JDO Connector: cannot close connection while a LocalTransaction is still active.");
154             }
155         }
156         try {
157             managedConnection.dissociateConnection(this);
158         } catch (ResourceException JavaDoc e) {
159             throw new JDOException("JDO Connector: problem while closing a connection.", e);
160         } finally {
161             localTransaction = null;
162             managedConnection = null;
163         }
164     }
165
166     /**
167      * Sets the connection to the relevant auto-commit mode.
168      */

169     public void setAutoCommit(boolean b) throws ResourceException JavaDoc {
170         throw new ResourceException JavaDoc("No sense for a JDO connector.");
171     }
172
173     /**
174      * Gets the connection auto-commit mode.
175      */

176     public boolean getAutoCommit() throws ResourceException JavaDoc {
177         throw new ResourceException JavaDoc("No sense for a JDO connector.");
178     }
179
180     // IMPLEMENTATION OF METHODS FROM THE (cci)ConnectionMetaData INTERFACE
181

182     /**
183      * Returns the name of this storage sub-system.
184      * @return The storage sub-system name.
185      */

186     public String JavaDoc getEISProductName() throws ResourceException JavaDoc {
187         return EISPRODUCTNAME;
188     }
189
190     /**
191      * This is the same version number as the adapter.
192      * @return The storage sub-system version.
193      */

194     public String JavaDoc getEISProductVersion() throws ResourceException JavaDoc {
195         return connectionFactory.getAdapterVersion();
196     }
197
198     /**
199      * No support for user name.
200      * @return The empty string.
201      */

202     public String JavaDoc getUserName() throws ResourceException JavaDoc {
203         return "";
204     }
205
206     // IMPLEMENTATION OF METHODS FROM THE PersistenceManager INTERFACE
207
// Delegates execution to the associated ManagedConnection.
208

209     public boolean isClosed() {
210         return managedConnection == null;
211     }
212
213     public Transaction JavaDoc currentTransaction() {
214         if (managedConnection == null) {
215             throw new JDOException(NO_ACTIVE_CONNECTION);
216         }
217         //if transaction mode is not normal, return this
218
if (connectionFactory.getTransactionMode() != SpeedoProperties.TRANSACTION_BMODE_NORMAL) {
219             if(connectionFactory.getTransactionMode() == SpeedoProperties.TRANSACTION_BMODE_UT) {
220                 try {
221                     if (userTransaction == null) {
222                         Context JavaDoc ic = new InitialContext JavaDoc();
223                         userTransaction = (UserTransaction JavaDoc) ic.lookup("javax.transaction.UserTransaction");
224                     }
225                     logger.log(BasicLevel.DEBUG, "UserTransaction is used.");
226                 } catch (Exception JavaDoc e) {
227                     throw new JDOException("Error with JTA UserTransaction", e);
228                 }
229             }
230             return this;
231         } else {
232             return managedConnection.getProxyManager().currentTransaction();
233         }
234     }
235
236     public void evict(Object JavaDoc o) {
237         if (managedConnection == null) {
238             throw new JDOException(NO_ACTIVE_CONNECTION);
239         }
240         managedConnection.getProxyManager().evict(o);
241     }
242
243     public void evictAll(Object JavaDoc[] objects) {
244         if (managedConnection == null) {
245             throw new JDOException(NO_ACTIVE_CONNECTION);
246         }
247         managedConnection.getProxyManager().evictAll(objects);
248     }
249
250     public void evictAll(Collection JavaDoc collection) {
251         if (managedConnection == null) {
252             throw new JDOException(NO_ACTIVE_CONNECTION);
253         }
254         managedConnection.getProxyManager().evictAll(collection);
255     }
256
257     public void evictAll() {
258         if (managedConnection == null) {
259             throw new JDOException(NO_ACTIVE_CONNECTION);
260         }
261         managedConnection.getProxyManager().evictAll();
262     }
263
264     public void refresh(Object JavaDoc o) {
265         if (managedConnection == null) {
266             throw new JDOException(NO_ACTIVE_CONNECTION);
267         }
268         managedConnection.getProxyManager().refresh(o);
269     }
270
271     public void refreshAll(Object JavaDoc[] objects) {
272         if (managedConnection == null) {
273             throw new JDOException(NO_ACTIVE_CONNECTION);
274         }
275         managedConnection.getProxyManager().refreshAll(objects);
276     }
277
278     public void refreshAll(Collection JavaDoc collection) {
279         if (managedConnection == null) {
280             throw new JDOException(NO_ACTIVE_CONNECTION);
281         }
282         managedConnection.getProxyManager().refreshAll(collection);
283     }
284
285     public void refreshAll() {
286         if (managedConnection == null) {
287             throw new JDOException(NO_ACTIVE_CONNECTION);
288         }
289         managedConnection.getProxyManager().refreshAll();
290     }
291
292     public Query newQuery() {
293         if (managedConnection == null) {
294             throw new JDOException(NO_ACTIVE_CONNECTION);
295         }
296         return managedConnection.getProxyManager().newQuery();
297     }
298
299     public Query newQuery(String JavaDoc q) {
300         if (managedConnection == null) {
301             throw new JDOException(NO_ACTIVE_CONNECTION);
302         }
303         return managedConnection.getProxyManager().newQuery(q);
304     }
305
306     public Query newQuery(Object JavaDoc o) {
307         if (managedConnection == null) {
308             throw new JDOException(NO_ACTIVE_CONNECTION);
309         }
310         return managedConnection.getProxyManager().newQuery(o);
311     }
312
313     public Query newQuery(String JavaDoc s, Object JavaDoc o) {
314         if (managedConnection == null) {
315             throw new JDOException(NO_ACTIVE_CONNECTION);
316         }
317         return managedConnection.getProxyManager().newQuery(s, o);
318     }
319
320     public Query newQuery(Class JavaDoc aClass) {
321         if (managedConnection == null) {
322             throw new JDOException(NO_ACTIVE_CONNECTION);
323         }
324         return managedConnection.getProxyManager().newQuery(aClass);
325     }
326
327     public Query newQuery(Extent extent) {
328         if (managedConnection == null) {
329             throw new JDOException(NO_ACTIVE_CONNECTION);
330         }
331         return managedConnection.getProxyManager().newQuery(extent);
332     }
333
334     public Query newQuery(Class JavaDoc aClass, Collection JavaDoc collection) {
335         if (managedConnection == null) {
336             throw new JDOException(NO_ACTIVE_CONNECTION);
337         }
338         return managedConnection.getProxyManager().newQuery(aClass, collection);
339     }
340
341     public Query newQuery(Class JavaDoc aClass, String JavaDoc s) {
342         if (managedConnection == null) {
343             throw new JDOException(NO_ACTIVE_CONNECTION);
344         }
345         return managedConnection.getProxyManager().newQuery(aClass, s);
346     }
347
348     public Query newQuery(Class JavaDoc aClass, Collection JavaDoc collection, String JavaDoc s) {
349         if (managedConnection == null) {
350             throw new JDOException(NO_ACTIVE_CONNECTION);
351         }
352         return managedConnection.getProxyManager().newQuery(aClass, collection, s);
353     }
354
355     public Query newQuery(Extent extent, String JavaDoc s) {
356         if (managedConnection == null) {
357             throw new JDOException(NO_ACTIVE_CONNECTION);
358         }
359         return managedConnection.getProxyManager().newQuery(extent, s);
360     }
361
362     public Extent getExtent(Class JavaDoc aClass, boolean b) {
363         if (managedConnection == null) {
364             throw new JDOException(NO_ACTIVE_CONNECTION);
365         }
366         return managedConnection.getProxyManager().getExtent(aClass, b);
367     }
368
369     public Object JavaDoc getObjectById(Object JavaDoc o, boolean b) {
370         if (managedConnection == null) {
371             throw new JDOException(NO_ACTIVE_CONNECTION);
372         }
373         return managedConnection.getProxyManager().getObjectById(o, b);
374     }
375
376     public Collection JavaDoc getObjectsById(Collection JavaDoc arg0, boolean arg1) {
377         if (managedConnection == null) {
378             throw new JDOException(NO_ACTIVE_CONNECTION);
379         }
380         return managedConnection.getProxyManager().getObjectsById(arg0, arg1);
381     }
382     public Collection JavaDoc getObjectsById(Collection JavaDoc arg0) {
383         if (managedConnection == null) {
384             throw new JDOException(NO_ACTIVE_CONNECTION);
385         }
386         return managedConnection.getProxyManager().getObjectsById(arg0);
387     }
388     public Object JavaDoc[] getObjectsById(Object JavaDoc[] arg0, boolean arg1) {
389         if (managedConnection == null) {
390             throw new JDOException(NO_ACTIVE_CONNECTION);
391         }
392         return managedConnection.getProxyManager().getObjectsById(arg0, arg1);
393     }
394     public Object JavaDoc[] getObjectsById(Object JavaDoc[] arg0) {
395         if (managedConnection == null) {
396             throw new JDOException(NO_ACTIVE_CONNECTION);
397         }
398         return managedConnection.getProxyManager().getObjectsById(arg0);
399     }
400     public Sequence getSequence(String JavaDoc arg0) {
401         if (managedConnection == null) {
402             throw new JDOException(NO_ACTIVE_CONNECTION);
403         }
404         return managedConnection.getProxyManager().getSequence(arg0);
405     }
406     public Object JavaDoc getUserObject(Object JavaDoc arg0) {
407         if (managedConnection == null) {
408             throw new JDOException(NO_ACTIVE_CONNECTION);
409         }
410         return managedConnection.getProxyManager().getUserObject(arg0);
411     }
412     public Object JavaDoc newInstance(Class JavaDoc arg0) {
413         if (managedConnection == null) {
414             throw new JDOException(NO_ACTIVE_CONNECTION);
415         }
416         return managedConnection.getProxyManager().newInstance(arg0);
417     }
418     public Object JavaDoc putUserObject(Object JavaDoc arg0, Object JavaDoc arg1) {
419         if (managedConnection == null) {
420             throw new JDOException(NO_ACTIVE_CONNECTION);
421         }
422         return managedConnection.getProxyManager().putUserObject(arg0, arg1);
423     }
424     public Object JavaDoc removeUserObject(Object JavaDoc arg0) {
425         if (managedConnection == null) {
426             throw new JDOException(NO_ACTIVE_CONNECTION);
427         }
428         return managedConnection.getProxyManager().removeUserObject(arg0);
429     }
430     public Object JavaDoc getObjectId(Object JavaDoc o) {
431         if (managedConnection == null) {
432             throw new JDOException(NO_ACTIVE_CONNECTION);
433         }
434         return managedConnection.getProxyManager().getObjectId(o);
435     }
436
437     public Object JavaDoc getObjectById(Class JavaDoc clazz, Object JavaDoc o) {
438         if (managedConnection == null) {
439             throw new JDOException(NO_ACTIVE_CONNECTION);
440         }
441         return managedConnection.getProxyManager().getObjectById(clazz, o);
442     }
443     public Object JavaDoc getObjectById(Object JavaDoc o) {
444         if (managedConnection == null) {
445             throw new JDOException(NO_ACTIVE_CONNECTION);
446         }
447         return managedConnection.getProxyManager().getObjectById(o);
448     }
449     public Object JavaDoc getTransactionalObjectId(Object JavaDoc o) {
450         if (managedConnection == null) {
451             throw new JDOException(NO_ACTIVE_CONNECTION);
452         }
453         return managedConnection.getProxyManager().getTransactionalObjectId(o);
454     }
455
456     public Object JavaDoc newObjectIdInstance(Class JavaDoc aClass, Object JavaDoc s) {
457         if (managedConnection == null) {
458             throw new JDOException(NO_ACTIVE_CONNECTION);
459         }
460         return managedConnection.getProxyManager().newObjectIdInstance(aClass, s);
461     }
462
463     public void makePersistent(Object JavaDoc o) {
464         if (managedConnection == null) {
465             throw new JDOException(NO_ACTIVE_CONNECTION);
466         }
467         managedConnection.getProxyManager().makePersistent(o);
468     }
469
470     public void makePersistentAll(Object JavaDoc[] objects) {
471         if (managedConnection == null) {
472             throw new JDOException(NO_ACTIVE_CONNECTION);
473         }
474         managedConnection.getProxyManager().makePersistentAll(objects);
475     }
476
477     public void makePersistentAll(Collection JavaDoc collection) {
478         if (managedConnection == null) {
479             throw new JDOException(NO_ACTIVE_CONNECTION);
480         }
481         managedConnection.getProxyManager().makePersistentAll(collection);
482     }
483
484     public void deletePersistent(Object JavaDoc o) {
485         if (managedConnection == null) {
486             throw new JDOException(NO_ACTIVE_CONNECTION);
487         }
488         managedConnection.getProxyManager().deletePersistent(o);
489     }
490
491     public void deletePersistentAll(Object JavaDoc[] objects) {
492         if (managedConnection == null) {
493             throw new JDOException(NO_ACTIVE_CONNECTION);
494         }
495         managedConnection.getProxyManager().deletePersistentAll(objects);
496     }
497
498     public void deletePersistentAll(Collection JavaDoc collection) {
499         if (managedConnection == null) {
500             throw new JDOException(NO_ACTIVE_CONNECTION);
501         }
502         managedConnection.getProxyManager().deletePersistentAll(collection);
503     }
504
505     public void makeTransient(Object JavaDoc o) {
506         if (managedConnection == null) {
507             throw new JDOException(NO_ACTIVE_CONNECTION);
508         }
509         managedConnection.getProxyManager().makeTransient(o);
510     }
511
512     public void makeTransientAll(Object JavaDoc[] objects) {
513         if (managedConnection == null) {
514             throw new JDOException(NO_ACTIVE_CONNECTION);
515         }
516         managedConnection.getProxyManager().makeTransientAll(objects);
517     }
518
519     public void makeTransientAll(Collection JavaDoc collection) {
520         if (managedConnection == null) {
521             throw new JDOException(NO_ACTIVE_CONNECTION);
522         }
523         managedConnection.getProxyManager().makeTransientAll(collection);
524     }
525
526     public void makeTransactional(Object JavaDoc o) {
527         if (managedConnection == null) {
528             throw new JDOException(NO_ACTIVE_CONNECTION);
529         }
530         managedConnection.getProxyManager().makeTransactional(o);
531     }
532
533     public void makeTransactionalAll(Object JavaDoc[] objects) {
534         if (managedConnection == null) {
535             throw new JDOException(NO_ACTIVE_CONNECTION);
536         }
537         managedConnection.getProxyManager().makeTransactionalAll(objects);
538     }
539
540     public void makeTransactionalAll(Collection JavaDoc collection) {
541         if (managedConnection == null) {
542             throw new JDOException(NO_ACTIVE_CONNECTION);
543         }
544         managedConnection.getProxyManager().makeTransactionalAll(collection);
545     }
546
547     public void makeNontransactional(Object JavaDoc o) {
548         if (managedConnection == null) {
549             throw new JDOException(NO_ACTIVE_CONNECTION);
550         }
551         managedConnection.getProxyManager().makeNontransactional(o);
552     }
553
554     public void makeNontransactionalAll(Object JavaDoc[] objects) {
555         if (managedConnection == null) {
556             throw new JDOException(NO_ACTIVE_CONNECTION);
557         }
558         makeNontransactionalAll(objects);
559     }
560
561     public void makeNontransactionalAll(Collection JavaDoc collection) {
562         if (managedConnection == null) {
563             throw new JDOException(NO_ACTIVE_CONNECTION);
564         }
565         managedConnection.getProxyManager().makeNontransactionalAll(collection);
566     }
567
568     public void retrieve(Object JavaDoc o) {
569         if (managedConnection == null) {
570             throw new JDOException(NO_ACTIVE_CONNECTION);
571         }
572         managedConnection.getProxyManager().retrieve(o);
573     }
574
575     public void retrieveAll(Collection JavaDoc collection) {
576         if (managedConnection == null) {
577             throw new JDOException(NO_ACTIVE_CONNECTION);
578         }
579         managedConnection.getProxyManager().retrieveAll(collection);
580     }
581
582     public void retrieveAll(Object JavaDoc[] objects) {
583         if (managedConnection == null) {
584             throw new JDOException(NO_ACTIVE_CONNECTION);
585         }
586         managedConnection.getProxyManager().retrieveAll(objects);
587     }
588
589     public void retrieveAll(Collection JavaDoc collection, boolean b) {
590         if (managedConnection == null) {
591             throw new JDOException(NO_ACTIVE_CONNECTION);
592         }
593         managedConnection.getProxyManager().retrieveAll(collection, b);
594     }
595
596     public void retrieveAll(Object JavaDoc[] objects, boolean b) {
597         if (managedConnection == null) {
598             throw new JDOException(NO_ACTIVE_CONNECTION);
599         }
600         managedConnection.getProxyManager().retrieveAll(objects, b);
601     }
602
603     public void setUserObject(Object JavaDoc o) {
604         if (managedConnection == null) {
605             throw new JDOException(NO_ACTIVE_CONNECTION);
606         }
607         managedConnection.getProxyManager().setUserObject(o);
608     }
609
610     public Object JavaDoc getUserObject() {
611         if (managedConnection == null) {
612             throw new JDOException(NO_ACTIVE_CONNECTION);
613         }
614         return managedConnection.getProxyManager().getUserObject();
615     }
616
617     public PersistenceManagerFactory getPersistenceManagerFactory() {
618         if (managedConnection == null) {
619             throw new JDOException(NO_ACTIVE_CONNECTION);
620         }
621         return managedConnection.getProxyManager().getPersistenceManagerFactory();
622     }
623
624     public Class JavaDoc getObjectIdClass(Class JavaDoc aClass) {
625         if (managedConnection == null) {
626             throw new JDOException(NO_ACTIVE_CONNECTION);
627         }
628         return managedConnection.getProxyManager().getObjectIdClass(aClass);
629     }
630
631     public void setMultithreaded(boolean b) {
632         if (managedConnection == null) {
633             throw new JDOException(NO_ACTIVE_CONNECTION);
634         }
635         managedConnection.getProxyManager().setMultithreaded(b);
636     }
637
638     public boolean getMultithreaded() {
639         if (managedConnection == null) {
640             throw new JDOException(NO_ACTIVE_CONNECTION);
641         }
642         return managedConnection.getProxyManager().getMultithreaded();
643     }
644
645     public void setIgnoreCache(boolean b) {
646         if (managedConnection == null) {
647             throw new JDOException(NO_ACTIVE_CONNECTION);
648         }
649         managedConnection.getProxyManager().setIgnoreCache(b);
650     }
651
652     public boolean getIgnoreCache() {
653         if (managedConnection == null) {
654             throw new JDOException(NO_ACTIVE_CONNECTION);
655         }
656         return managedConnection.getProxyManager().getIgnoreCache();
657     }
658     
659     public void addInstanceLifecycleListener(InstanceLifecycleListener arg0, Class JavaDoc[] arg1) {
660         if (managedConnection == null) {
661             throw new JDOException(NO_ACTIVE_CONNECTION);
662         }
663         managedConnection.getProxyManager().addInstanceLifecycleListener(arg0, arg1);
664     }
665     public Object JavaDoc attachCopy(Object JavaDoc arg0, boolean arg1) {
666         if (managedConnection == null) {
667             throw new JDOException(NO_ACTIVE_CONNECTION);
668         }
669         return managedConnection.getProxyManager().attachCopy(arg0, arg1);
670     }
671     public Collection JavaDoc attachCopyAll(Collection JavaDoc arg0, boolean arg1) {
672         if (managedConnection == null) {
673             throw new JDOException(NO_ACTIVE_CONNECTION);
674         }
675         return managedConnection.getProxyManager().attachCopyAll(arg0, arg1);
676     }
677     public Object JavaDoc[] attachCopyAll(Object JavaDoc[] arg0, boolean arg1) {
678         if (managedConnection == null) {
679             throw new JDOException(NO_ACTIVE_CONNECTION);
680         }
681         return managedConnection.getProxyManager().attachCopyAll(arg0, arg1);
682     }
683     public Object JavaDoc detachCopy(Object JavaDoc arg0) {
684         if (managedConnection == null) {
685             throw new JDOException(NO_ACTIVE_CONNECTION);
686         }
687         return managedConnection.getProxyManager().detachCopy(arg0);
688     }
689     public Collection JavaDoc detachCopyAll(Collection JavaDoc arg0) {
690         if (managedConnection == null) {
691             throw new JDOException(NO_ACTIVE_CONNECTION);
692         }
693         return managedConnection.getProxyManager().detachCopyAll(arg0);
694     }
695     public Object JavaDoc[] detachCopyAll(Object JavaDoc[] arg0) {
696         if (managedConnection == null) {
697             throw new JDOException(NO_ACTIVE_CONNECTION);
698         }
699         return managedConnection.getProxyManager().detachCopyAll(arg0);
700     }
701     public void flush() {
702         if (managedConnection == null) {
703             throw new JDOException(NO_ACTIVE_CONNECTION);
704         }
705         managedConnection.getProxyManager().flush();
706     }
707     public void checkConsistency() {
708         if (managedConnection == null) {
709             throw new JDOException(NO_ACTIVE_CONNECTION);
710         }
711         managedConnection.getProxyManager().checkConsistency();
712     }
713     public JDOConnection getDataStoreConnection() {
714         if (managedConnection == null) {
715             throw new JDOException(NO_ACTIVE_CONNECTION);
716         }
717         return managedConnection.getProxyManager().getDataStoreConnection();
718     }
719     public Extent getExtent(Class JavaDoc arg0) {
720         if (managedConnection == null) {
721             throw new JDOException(NO_ACTIVE_CONNECTION);
722         }
723         return managedConnection.getProxyManager().getExtent(arg0);
724     }
725     public FetchPlan getFetchPlan() {
726         if (managedConnection == null) {
727             throw new JDOException(NO_ACTIVE_CONNECTION);
728         }
729         return managedConnection.getProxyManager().getFetchPlan();
730     }
731     public Query newNamedQuery(Class JavaDoc arg0, String JavaDoc arg1) {
732         if (managedConnection == null) {
733             throw new JDOException(NO_ACTIVE_CONNECTION);
734         }
735         return managedConnection.getProxyManager().newNamedQuery(arg0, arg1);
736     }
737     public void refreshAll(JDOException arg0) {
738         if (managedConnection == null) {
739             throw new JDOException(NO_ACTIVE_CONNECTION);
740         }
741         managedConnection.getProxyManager().refreshAll(arg0);
742     }
743     public void removeInstanceLifecycleListener(InstanceLifecycleListener arg0) {
744         if (managedConnection == null) {
745             throw new JDOException(NO_ACTIVE_CONNECTION);
746         }
747         managedConnection.getProxyManager().removeInstanceLifecycleListener(arg0);
748     }
749
750     //
751
// IMPLEMENTATION OF JDO.TRANSACTION INTERFACE
752
//
753

754     public void begin() {
755         if (connectionFactory.getTransactionMode() == SpeedoProperties.TRANSACTION_BMODE_UT) {
756             try {
757                 userTransaction.begin();
758             } catch(Exception JavaDoc e) {
759                 throw new JDOException("Error with JTA UserTransaction.begin().", e);
760             }
761         } else {
762             //do nothing
763
logger.log(BasicLevel.INFO, "Nothing is done on begin. The property ignoreJDOTransaction is activated.");
764         }
765     }
766
767     public void commit() {
768         if (connectionFactory.getTransactionMode() == SpeedoProperties.TRANSACTION_BMODE_UT) {
769             try {
770                 userTransaction.commit();
771                 logger.log(BasicLevel.DEBUG, "UserTransaction commit.");
772             } catch(Exception JavaDoc e) {
773                 throw new JDOException("Error with JTA UserTransaction.commit().", e);
774             }
775         } else {
776             // do nothing
777
logger.log(BasicLevel.INFO, "Nothing is done on commit. The property ignoreJDOTransaction is activated.");
778         }
779     }
780
781     public void rollback() {
782         if (connectionFactory.getTransactionMode() == SpeedoProperties.TRANSACTION_BMODE_UT) {
783             try {
784                 userTransaction.rollback();
785             } catch(Exception JavaDoc e) {
786                 throw new JDOException("Error with JTA UserTransaction.rollback().", e);
787             }
788         } else {
789             // do nothing
790
logger.log(BasicLevel.INFO, "Nothing is done on rollback. The property ignoreJDOTransaction is activated.");
791         }
792     }
793
794     public boolean isActive() {
795         // delegate
796
if (managedConnection == null) {
797             throw new JDOException(NO_ACTIVE_CONNECTION);
798         }
799         return managedConnection.getProxyManager().currentTransaction().isActive();
800     }
801
802     public boolean getRollbackOnly() {
803         //delegate
804
if (managedConnection == null) {
805             throw new JDOException(NO_ACTIVE_CONNECTION);
806         }
807         return managedConnection.getProxyManager().currentTransaction().getRollbackOnly();
808     }
809
810     public void setRollbackOnly() {
811         //delegate
812
if (managedConnection == null) {
813             throw new JDOException(NO_ACTIVE_CONNECTION);
814         }
815         managedConnection.getProxyManager().currentTransaction().setRollbackOnly();
816         
817     }
818
819
820     public void setNontransactionalRead(boolean nontransactionalRead) {
821         //delegate
822
if (managedConnection == null) {
823             throw new JDOException(NO_ACTIVE_CONNECTION);
824         }
825         managedConnection.getProxyManager().currentTransaction().setNontransactionalRead(nontransactionalRead);
826     }
827
828
829     public boolean getNontransactionalRead() {
830         //delegate
831
if (managedConnection == null) {
832             throw new JDOException(NO_ACTIVE_CONNECTION);
833         }
834         return managedConnection.getProxyManager().currentTransaction().getNontransactionalRead();
835     
836     }
837
838
839     public void setNontransactionalWrite(boolean nontransactionalWrite) {
840         //delegate
841
if (managedConnection == null) {
842             throw new JDOException(NO_ACTIVE_CONNECTION);
843         }
844         managedConnection.getProxyManager().currentTransaction().setNontransactionalWrite(nontransactionalWrite);
845     
846     }
847
848
849     public boolean getNontransactionalWrite() {
850         //delegate
851
if (managedConnection == null) {
852             throw new JDOException(NO_ACTIVE_CONNECTION);
853         }
854         return managedConnection.getProxyManager().currentTransaction().getNontransactionalWrite();
855     }
856
857
858     public void setRetainValues(boolean retainValues) {
859         //delegate
860
if (managedConnection == null) {
861             throw new JDOException(NO_ACTIVE_CONNECTION);
862         }
863         managedConnection.getProxyManager().currentTransaction().setRetainValues(retainValues);
864         
865     }
866
867
868     public boolean getRetainValues() {
869         //delegate
870
if (managedConnection == null) {
871             throw new JDOException(NO_ACTIVE_CONNECTION);
872         }
873         return managedConnection.getProxyManager().currentTransaction().getRetainValues();
874     }
875
876
877     public void setRestoreValues(boolean restoreValues) {
878         //delegate
879
if (managedConnection == null) {
880             throw new JDOException(NO_ACTIVE_CONNECTION);
881         }
882         managedConnection.getProxyManager().currentTransaction().setRestoreValues(restoreValues);
883     }
884
885
886     public boolean getRestoreValues() {
887         //delegate
888
if (managedConnection == null) {
889             throw new JDOException(NO_ACTIVE_CONNECTION);
890         }
891         return managedConnection.getProxyManager().currentTransaction().getRestoreValues();
892     }
893
894
895     public void setOptimistic(boolean optimistic) {
896         //delegate
897
if (managedConnection == null) {
898             throw new JDOException(NO_ACTIVE_CONNECTION);
899         }
900         managedConnection.getProxyManager().currentTransaction().setOptimistic(optimistic);
901     }
902
903
904     public boolean getOptimistic() {
905         //delegate
906
if (managedConnection == null) {
907             throw new JDOException(NO_ACTIVE_CONNECTION);
908         }
909         return managedConnection.getProxyManager().currentTransaction().getOptimistic();
910     }
911
912     
913     public void setSynchronization(Synchronization JavaDoc sync) {
914         //delegate
915
if (managedConnection == null) {
916             throw new JDOException(NO_ACTIVE_CONNECTION);
917         }
918         managedConnection.getProxyManager().currentTransaction().setSynchronization(sync);
919     }
920
921     
922     public Synchronization JavaDoc getSynchronization() {
923         //delegate
924
if (managedConnection == null) {
925             throw new JDOException(NO_ACTIVE_CONNECTION);
926         }
927         return managedConnection.getProxyManager().currentTransaction().getSynchronization();
928     }
929
930
931     public PersistenceManager getPersistenceManager() {
932         //delegate
933
if (managedConnection == null) {
934             throw new JDOException(NO_ACTIVE_CONNECTION);
935         }
936         return managedConnection.getProxyManager().currentTransaction().getPersistenceManager();
937     }
938 }
939
Popular Tags