Package org.objectweb.speedo.j2eedo.ejb

Source Code of org.objectweb.speedo.j2eedo.ejb.StoreServicesBean

/**
* Speedo: an implementation of JDO compliant personality on top of JORM generic
* I/O sub-system.
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*
*
* Contact: speedo@objectweb.org
*
* Authors: S.Chassande-Barrioz.
*
*/
package org.objectweb.speedo.j2eedo.ejb;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.jdo.PersistenceManagerFactory;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.objectweb.speedo.j2eedo.common.PMHolder;
import org.objectweb.speedo.j2eedo.bo.DatabaseImpl;
/**
* Class StoreServicesBean
*
* @author S.Rodiere
*/
public class StoreServicesBean implements SessionBean {

    private final static String PMF_JNDI_NAME = "speedo";
 
    PersistenceManagerFactory pmf = null;
   
    public StoreServicesBean() {
  }

  public void ejbCreate() throws CreateException {
  }

  public void ejbActivate() {
  }

  public void ejbPassivate() {
  }

  public void ejbRemove() {
  }

  public void setSessionContext(SessionContext ctx) {
  }
 
  /**
   * @param persistenceManagerHolder is the persistence manager holder
   * @param action is the action to be done
   * @see org.objectweb.speedo.j2eedo.database.DatabaseImpl
   * @return result of the method as a string
   * @throws Exception
   */
  public String doAction(PMHolder pmh, String action) {
    return DatabaseImpl.instance.doAction(
                action, false, pmh == null ? new PMHolder(getPMF()) : pmh);
  }

  /**
   * @param action is the action to be done
   * @see org.objectweb.speedo.j2eedo.database.DatabaseImpl
   * @return result of the method as a string
   * @throws Exception
   */
  public String doAction(String action) {
        return DatabaseImpl.instance.doAction(
                action, false, new PMHolder(getPMF()));
  }
 
  private PersistenceManagerFactory getPMF() {
        if (pmf == null) {
        InitialContext ictx = null;
        try {
          ictx = new InitialContext();
          pmf = (PersistenceManagerFactory) ictx.lookup(PMF_JNDI_NAME);
        } catch (Exception e) {
          System.err.println("Impossible to find persistance manager factory:" + e.getMessage());
          throw new RuntimeException(e);
        } finally {
          if (ictx != null) {
            try {
              ictx.close();
            } catch (NamingException ne) {
              System.err.println(
                "Impossible to find  persistenceManagerFactory " + ne);
              ne.printStackTrace();
            }
          }
        }
        }
        return pmf;
  }
}
TOP

Related Classes of org.objectweb.speedo.j2eedo.ejb.StoreServicesBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.