KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > runtime > jdo > lib > Connector


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.pss.runtime.jdo.lib;
28
29 //Package dependencies
30
import javax.jdo.PersistenceManagerFactory;
31 import javax.jdo.PersistenceManager;
32
33 /**
34  * This is a class to connect a jdo implementation.
35  *
36  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
37  *
38  * @version 0.1
39  */

40
41 public class Connector
42      extends org.objectweb.openccm.pss.runtime.common.lib.ConnectorBase
43   implements org.objectweb.openccm.pss.runtime.jdo.api.Connector
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     // ==================================================================
52
//
53
// Constructor.
54
//
55
// ==================================================================
56

57     /**
58      * The default constructor.
59      */

60     public Connector()
61     {
62         super("org.objectweb.openccm.pss.runtime.JDO");
63     }
64
65     // ==================================================================
66
//
67
// Internal methods.
68
//
69
// ==================================================================
70

71     // ==================================================================
72
//
73
// Public methods.
74
//
75
// ==================================================================
76

77     // ==================================================================
78
//
79
// Methods for org.omg.CosPersistentState.Connector
80
//
81
// ==================================================================
82

83     /**
84      * Create a basic session.
85      */

86     public org.omg.CosPersistentState.Session
87     create_basic_session(short access_mode,
88                          org.omg.CosPersistentState.Parameter[] additional_parameters)
89     {
90         String JavaDoc pmf_class = null,
91                db_url = null,
92                db_driver = null,
93                user_name = null,
94                password = null;
95         org.omg.CosPersistentState.Parameter param = null;
96
97         if (additional_parameters.length < 3)
98             return null;
99
100         for (int i=0; i<additional_parameters.length; i++)
101         {
102             param = additional_parameters[i];
103
104             if (param.name.compareTo(Connector.PM_FACTORY_KEY) == 0)
105             {
106                 // Get the Persistence Manager factory class
107
pmf_class = param.val.extract_string();
108             }
109             else if (param.name.compareTo(Connector.DB_URL_KEY) == 0)
110             {
111                 // Get the DataBase URL
112
db_url = param.val.extract_string();
113             }
114             else if (param.name.compareTo(Connector.DB_DRIVER_KEY) == 0)
115             {
116                 // Get the DataBase Driver
117
db_driver = param.val.extract_string();
118             }
119             else if (param.name.compareTo(Connector.USER_NAME_KEY) == 0)
120             {
121                 // Get the User name
122
user_name = param.val.extract_string();
123             }
124             else if (param.name.compareTo(Connector.PASSWORD_KEY) == 0)
125             {
126                 // Get the User password
127
password = param.val.extract_string();
128             }
129        }
130
131        // Create and set up a persistence manager factory
132
try {
133             PersistenceManagerFactory pmf =
134                 (PersistenceManagerFactory) Class.forName(pmf_class).newInstance();
135             pmf.setConnectionURL(db_url);
136             pmf.setConnectionDriverName(db_driver);
137             if (user_name != null)
138                 pmf.setConnectionUserName(user_name);
139             if (password != null)
140                 pmf.setConnectionPassword(password);
141
142             PersistenceManager pm = pmf.getPersistenceManager();
143
144             return new org.objectweb.openccm.pss.runtime.jdo.lib.Session(get_free_id(), pm);
145         } catch (Exception JavaDoc e) {
146             e.printStackTrace();
147         }
148         return null;
149     }
150
151     /**
152      * Create a transactional session.
153      */

154     public org.omg.CosPersistentState.TransactionalSession
155     create_transactional_session(short access_mode,
156                                  short default_isolation_level,
157                                  org.omg.CosPersistentState.EndOfAssociationCallback callback,
158                                  org.omg.CosPersistentState.Parameter[] additional_parameters)
159     {
160         // TO DO
161
return null;
162     }
163
164     /**
165      * Create a session pool.
166      */

167     public org.omg.CosPersistentState.SessionPool
168     create_session_pool(short access_mode,
169                         short tx_policy,
170                         org.omg.CosPersistentState.Parameter[] additional_parameters)
171     {
172         // TO DO
173
return null;
174     }
175
176     /**
177      * Get the current session.
178      */

179     public org.omg.CosPersistentState.TransactionalSession
180     current_session()
181     {
182         // TO DO
183
return null;
184     }
185
186     /**
187      * Get sessions.
188      */

189     public org.omg.CosPersistentState.TransactionalSession[]
190     sessions(org.omg.CosTransactions.Coordinator transaction)
191     {
192         // TO DO
193
return null;
194     }
195
196
197     // ==================================================================
198
//
199
// Methods for org.objectweb.openccm.pss.runtime.api.Connector
200
//
201
// ==================================================================
202

203 }
204
Popular Tags