1 27 package org.objectweb.speedo.j2eedo.ejb; 28 import javax.ejb.CreateException ; 29 import javax.ejb.SessionBean ; 30 import javax.ejb.SessionContext ; 31 import javax.jdo.PersistenceManagerFactory; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 35 import org.objectweb.speedo.j2eedo.common.PMHolder; 36 import org.objectweb.speedo.j2eedo.bo.DatabaseImpl; 37 43 public class StoreServicesBean implements SessionBean { 44 45 private final static String PMF_JNDI_NAME = "speedo"; 46 47 private DatabaseImpl databaseImpl = null; 48 49 public StoreServicesBean() { 50 } 51 52 public void ejbCreate() throws CreateException { 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 ctx) { 65 } 66 67 74 public String doAction(PMHolder persistenceManagerHolder, String action) 75 throws Exception { 76 if (databaseImpl == null) { 77 databaseImpl = new DatabaseImpl(persistenceManagerHolder); 78 } 79 return databaseImpl.doAction(action); 80 } 81 82 88 public String doAction(String action) throws Exception { 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 { 96 InitialContext ictx = null; 97 try { 98 ictx = new InitialContext (); 99 return (PersistenceManagerFactory) ictx.lookup(PMF_JNDI_NAME); 100 } catch (Exception 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 ne) { 108 System.err.println( 109 "Impossible to find persistenceManagerFactory " + ne); 110 ne.printStackTrace(); 111 } 112 } 113 } 114 } 115 } 116 | Popular Tags |