1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| package tutorial.ejb;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import tutorial.entity.Customer;
/**
* @ejb.bean name="Fibo"
* display-name="Name for Fibo"
* description="Description for Fibo"
* jndi-name="ejb/Fibo"
* type="Stateless"
* view-type="remote"
*/
public class FiboBean implements SessionBean {
@PersistenceContext
protected EntityManager em;
public FiboBean() {
// TODO Auto-generated constructor stub
}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void setSessionContext(SessionContext ctx)
throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
/**
* Default create method
*
* @throws CreateException
* @ejb.create-method
*/
public void ejbCreate() throws CreateException {
// TODO Auto-generated method stub
}
/**
* Business method
* @ejb.interface-method view-type = "remote"
*/
public double[] compute(int number) {
if (number < 0) {
throw new EJBException("Argument should be positive");
}
double[] suite = new double[number + 1];
suite[0] = 0;
if (number == 0) {
return suite;
}
suite[1] = 1;
for (int i = 2; i <= number; i++) {
suite[i] = suite[i - 1] + suite[i - 2];
}
Customer customer = new Customer(1,"Pierre", "Martin","pmartin8@gmail.com");
em.persist(customer);
return suite;
}
} |