001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.j2eedo.ejb;
027:
028: import javax.ejb.CreateException;
029: import javax.ejb.SessionBean;
030: import javax.ejb.SessionContext;
031: import javax.jdo.PersistenceManagerFactory;
032: import javax.naming.InitialContext;
033: import javax.naming.NamingException;
034:
035: import org.objectweb.speedo.j2eedo.common.PMHolder;
036: import org.objectweb.speedo.j2eedo.bo.DatabaseImpl;
037:
038: /**
039: * Class StoreServicesBean
040: *
041: * @author S.Rodiere
042: *
043: */
044: public class StoreServicesBean implements SessionBean {
045:
046: private final static String PMF_JNDI_NAME = "speedo";
047:
048: PersistenceManagerFactory pmf = null;
049:
050: public StoreServicesBean() {
051: }
052:
053: public void ejbCreate() throws CreateException {
054: }
055:
056: public void ejbActivate() {
057: }
058:
059: public void ejbPassivate() {
060: }
061:
062: public void ejbRemove() {
063: }
064:
065: public void setSessionContext(SessionContext ctx) {
066: }
067:
068: /**
069: * @param persistenceManagerHolder is the persistence manager holder
070: * @param action is the action to be done
071: * @see org.objectweb.speedo.j2eedo.database.DatabaseImpl
072: * @return result of the method as a string
073: * @throws Exception
074: */
075: public String doAction(PMHolder pmh, String action) {
076: return DatabaseImpl.instance.doAction(action, false,
077: pmh == null ? new PMHolder(getPMF()) : pmh);
078: }
079:
080: /**
081: * @param action is the action to be done
082: * @see org.objectweb.speedo.j2eedo.database.DatabaseImpl
083: * @return result of the method as a string
084: * @throws Exception
085: */
086: public String doAction(String action) {
087: return DatabaseImpl.instance.doAction(action, false,
088: new PMHolder(getPMF()));
089: }
090:
091: private PersistenceManagerFactory getPMF() {
092: if (pmf == null) {
093: InitialContext ictx = null;
094: try {
095: ictx = new InitialContext();
096: pmf = (PersistenceManagerFactory) ictx
097: .lookup(PMF_JNDI_NAME);
098: } catch (Exception e) {
099: System.err
100: .println("Impossible to find persistance manager factory:"
101: + e.getMessage());
102: throw new RuntimeException(e);
103: } finally {
104: if (ictx != null) {
105: try {
106: ictx.close();
107: } catch (NamingException ne) {
108: System.err
109: .println("Impossible to find persistenceManagerFactory "
110: + ne);
111: ne.printStackTrace();
112: }
113: }
114: }
115: }
116: return pmf;
117: }
118: }
|