KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > ejbql > CruiseBean


1 package org.objectweb.jonas.jtests.beans.ejbql;
2
3 import java.util.Collection JavaDoc;
4
5 import javax.ejb.CreateException JavaDoc;
6 import javax.ejb.EntityContext JavaDoc;
7 import javax.ejb.FinderException JavaDoc;
8 import javax.ejb.RemoveException JavaDoc;
9 import javax.naming.InitialContext JavaDoc;
10
11 public abstract class CruiseBean implements javax.ejb.EntityBean JavaDoc {
12
13     private SequenceSessionLocalHome seqHome = null;
14     private SequenceSessionLocal seqLocal = null;
15     private ShipHomeLocal shipHome = null;
16
17     public Integer JavaDoc ejbCreate(String JavaDoc name,Integer JavaDoc ship) throws CreateException JavaDoc {
18     setName(name);
19     int id = seqLocal.getNextNumberInSequence("Cruise");
20     setId(new Integer JavaDoc(id));
21     return null;
22     }
23     
24     public void ejbPostCreate(String JavaDoc name, Integer JavaDoc ship) {
25         try {
26            ShipLocal shiploc = shipHome.findByPrimaryKey(ship);
27        setShip(shiploc);
28     } catch (FinderException JavaDoc e) {
29         System.out.println("Ship not found during Cruise creation :"+ship);
30     }
31     }
32
33     // persistent fields
34

35     public abstract void setId(Integer JavaDoc id);
36     public abstract Integer JavaDoc getId();
37     public abstract void setName(String JavaDoc name);
38     public abstract String JavaDoc getName( );
39
40     public abstract void setShip(ShipLocal ship);
41     public abstract ShipLocal getShip( );
42
43     // relationship fields
44

45     public abstract void setReservations(Collection JavaDoc res);
46     public abstract Collection JavaDoc getReservations( );
47
48     // standard call back methods
49

50     public void setEntityContext(EntityContext JavaDoc ec){
51     try {
52         InitialContext JavaDoc cntx = new InitialContext JavaDoc( );
53         SequenceSessionLocalHome seqHome =
54         (SequenceSessionLocalHome)cntx.lookup("java:comp/env/ejb/SequenceSessionLocalHome");
55         shipHome =
56         (ShipHomeLocal)cntx.lookup("java:comp/env/ejb/ShipLocalHome");
57
58         seqLocal = seqHome.create();
59     } catch(Exception JavaDoc e) {
60         throw new javax.ejb.EJBException JavaDoc(e);
61     }
62     }
63
64     public void unsetEntityContext(){}
65     public void ejbLoad(){}
66     public void ejbStore(){}
67     public void ejbActivate(){}
68     public void ejbPassivate(){}
69     public void ejbRemove() throws RemoveException JavaDoc {}
70
71 }
72
Popular Tags