KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > cascade > InsuranceBean


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: InsuranceBean.java,v 1.2 2004/07/02 16:04:32 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.relation.cascade;
27
28 import java.rmi.RemoteException JavaDoc;
29 import javax.ejb.CreateException JavaDoc;
30 import javax.ejb.EntityContext JavaDoc;
31 import javax.ejb.EntityBean JavaDoc;
32 import javax.ejb.RemoveException JavaDoc;
33
34 import org.objectweb.jonas.common.Log;
35 import org.objectweb.util.monolog.api.BasicLevel;
36 import org.objectweb.util.monolog.api.Logger;
37
38 /**
39  * Implementation for bean Insurance
40  * @author Ph Durieux
41  */

42 public abstract class InsuranceBean implements EntityBean JavaDoc {
43    
44     static protected Logger logger = null;
45     protected EntityContext JavaDoc ejbContext = null;
46
47     public Integer JavaDoc ejbCreate(String JavaDoc number) throws CreateException JavaDoc {
48         logger.log(BasicLevel.DEBUG, "");
49         setNumber(number);
50         return null;
51     }
52
53     public void ejbPostCreate(String JavaDoc number) {
54         logger.log(BasicLevel.DEBUG, "");
55     }
56
57     // persistent fields
58
public abstract Integer JavaDoc getId();
59     public abstract void setId(Integer JavaDoc id);
60     public abstract String JavaDoc getNumber();
61     public abstract void setNumber(String JavaDoc number);
62
63     // persistent relationships
64
public abstract CarL getCar();
65     public abstract void setCar(CarL car);
66
67     
68     public void setEntityContext(EntityContext JavaDoc ec) {
69         if (logger == null)
70             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
71         logger.log(BasicLevel.DEBUG, "");
72         ejbContext = ec;
73     }
74
75     public void unsetEntityContext() {
76         logger.log(BasicLevel.DEBUG, "");
77         ejbContext = null;
78     }
79
80     public void ejbLoad() {
81         logger.log(BasicLevel.DEBUG, "");
82     }
83
84     public void ejbStore() {
85         logger.log(BasicLevel.DEBUG, "");
86     }
87
88     public void ejbActivate() {
89         logger.log(BasicLevel.DEBUG, "");
90     }
91
92     public void ejbPassivate() {
93         logger.log(BasicLevel.DEBUG, "");
94     }
95
96     /**
97      * this instance is being removed.
98      * we must be able to access bean fields here, including the CMRs
99      */

100     public void ejbRemove() throws javax.ejb.RemoveException JavaDoc {
101         logger.log(BasicLevel.DEBUG, "");
102         CarL mycar = getCar();
103         if (mycar == null) {
104             logger.log(BasicLevel.ERROR, "CMR field is null");
105             throw new RemoveException JavaDoc("Cannot access CMR field inside ejbRemove");
106         }
107         String JavaDoc carnumber = mycar.getNumber();
108         if (! getNumber().equals("000" + carnumber)) {
109             throw new RemoveException JavaDoc("Bad car number while removing Insurance:" + carnumber);
110         }
111         CustomerL cust = mycar.getCustomer();
112         if (cust == null) {
113             logger.log(BasicLevel.ERROR, "Cannot get customer from insurance");
114             throw new RemoveException JavaDoc("Cannot get customer from insurance");
115         }
116     }
117 }
118
Popular Tags