KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > j2eedo > ejb > StoreServicesBean


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
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  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27 package org.objectweb.speedo.j2eedo.ejb;
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.SessionBean JavaDoc;
30 import javax.ejb.SessionContext JavaDoc;
31 import javax.jdo.PersistenceManagerFactory;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34
35 import org.objectweb.speedo.j2eedo.common.PMHolder;
36 import org.objectweb.speedo.j2eedo.bo.DatabaseImpl;
37 /**
38  * Class StoreServicesBean
39  *
40  * @author S.Rodiere
41  *
42  */

43 public class StoreServicesBean implements SessionBean JavaDoc {
44
45     private final static String JavaDoc PMF_JNDI_NAME = "speedo";
46     
47     private DatabaseImpl databaseImpl = null;
48     
49     public StoreServicesBean() {
50     }
51
52     public void ejbCreate() throws CreateException JavaDoc {
53     }
54
55     public void ejbActivate() {
56     }
57
58     public void ejbPassivate() {
59     }
60
61     public void ejbRemove() {
62     }
63
64     public void setSessionContext(SessionContext JavaDoc ctx) {
65     }
66     
67     /**
68      * @param persistenceManagerHolder is the persistence manager holder
69      * @param action is the action to be done
70      * @see org.objectweb.speedo.j2eedo.database.DatabaseImpl
71      * @return result of the method as a string
72      * @throws Exception
73      */

74     public String JavaDoc doAction(PMHolder persistenceManagerHolder, String JavaDoc action)
75         throws Exception JavaDoc {
76         if (databaseImpl == null) {
77             databaseImpl = new DatabaseImpl(persistenceManagerHolder);
78         }
79         return databaseImpl.doAction(action);
80     }
81
82     /**
83      * @param action is the action to be done
84      * @see org.objectweb.speedo.j2eedo.database.DatabaseImpl
85      * @return result of the method as a string
86      * @throws Exception
87      */

88     public String JavaDoc doAction(String JavaDoc action) throws Exception JavaDoc {
89         if (databaseImpl == null) {
90             databaseImpl = new DatabaseImpl(new PMHolder(getPMF()));
91         }
92         return databaseImpl.doAction(action);
93     }
94     
95     private PersistenceManagerFactory getPMF() throws Exception JavaDoc {
96         InitialContext JavaDoc ictx = null;
97         try {
98             ictx = new InitialContext JavaDoc();
99             return (PersistenceManagerFactory) ictx.lookup(PMF_JNDI_NAME);
100         } catch (Exception JavaDoc e) {
101             System.err.println("Impossible to find persistance manager factory:" + e.getMessage());
102             throw e;
103         } finally {
104             if (ictx != null) {
105                 try {
106                     ictx.close();
107                 } catch (NamingException JavaDoc ne) {
108                     System.err.println(
109                         "Impossible to find persistenceManagerFactory " + ne);
110                     ne.printStackTrace();
111                 }
112             }
113         }
114     }
115 }
116
Popular Tags