KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > container > jorm > RdbFactory


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
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.1 of the License, or 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
19  * USA
20  *
21  * Initial developer(s):
22  * Contributor(s):
23  *
24  * --------------------------------------------------------------------------
25  * $Id: RdbFactory.java,v 1.15 2005/04/15 13:03:55 joaninh Exp $
26  * --------------------------------------------------------------------------
27  */

28
29
30 package org.objectweb.jonas_ejb.container.jorm;
31
32 import javax.sql.DataSource JavaDoc;
33
34 import org.objectweb.jonas_ejb.container.JContainer;
35 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
36
37 import org.objectweb.jorm.api.PClassMapping;
38 import org.objectweb.jorm.api.PException;
39 import org.objectweb.jorm.lib.MapperJCA;
40 import org.objectweb.jorm.mapper.rdb.genclass.RdbGenClassProp;
41 import org.objectweb.jorm.mapper.rdb.lib.MapperJDBC;
42 import org.objectweb.jorm.mapper.rdb.lib.RdbPrefetchablePCM;
43
44 /**
45  * @author Sebastien Chassande-Barrioz
46  * @author Philippe Durieux (new Jorm mapping)
47  */

48 public abstract class RdbFactory extends MedorFactory {
49
50     public RdbFactory() {
51         super();
52     }
53
54     public void init(EntityDesc dd, JContainer cont, String JavaDoc mapperName) {
55         super.init(dd, cont, mapperName);
56     }
57
58     public Object JavaDoc getConnection(Object JavaDoc hints) throws PException {
59         if (hints == null) {
60             return mapper.getConnection();
61         } else {
62             return mapper.getConnection(hints);
63         }
64     }
65
66     public void releaseConnection(Object JavaDoc conn) throws PException {
67         mapper.closeConnection(conn);
68     }
69
70     protected void setMapper(String JavaDoc mapperName) throws PException {
71         MapperManager mm = MapperManager.getInstance();
72         synchronized (mm) {
73             mapper = mm.getMapper(cont, datasource);
74             if (mapper == null) {
75                 // datasource has been found by its JNDI name in the bean DD
76
if (datasource instanceof DataSource JavaDoc) {
77                     mapper = new MapperJDBC(mm.getJormConfigurator());
78                 } else {
79                     mapper = new MapperJCA(mm.getJormConfigurator());
80                 }
81                 mapper.setMapperName(mapperName);
82
83                 // to redirect getConnection() on our DataSource
84
mapper.setConnectionFactory(datasource);
85
86                 //register and finish to configure the new mapper
87
mm.addMapper(mapper, cont, datasource);
88             }
89         }
90     }
91     
92     /**
93      * It initializes the prefetching of a genclassMapping with the
94      * PClassMapping of the target class of the multivalued CMR.
95      * @param gcm is the GenClassMapping to initialized
96      * @param targetPCM is the PClassMapping of the target class
97      */

98     protected void initGenClassPrefetch(PClassMapping gcm, PClassMapping targetPCM) {
99         if (gcm instanceof RdbGenClassProp && targetPCM instanceof RdbPrefetchablePCM) {
100             ((RdbGenClassProp) gcm).setPrefetchElementPCM((RdbPrefetchablePCM) targetPCM);
101         }
102     }
103
104 }
105
Popular Tags