KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > sequence > SequenceSesSL


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: SequenceSesSL.java,v 1.2 2005/04/22 07:43:55 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.sequence;
27
28
29 import java.rmi.RemoteException JavaDoc;
30
31 import javax.ejb.CreateException JavaDoc;
32 import javax.ejb.EJBException JavaDoc;
33 import javax.ejb.FinderException JavaDoc;
34 import javax.ejb.RemoveException JavaDoc;
35 import javax.ejb.SessionBean JavaDoc;
36 import javax.ejb.SessionContext JavaDoc;
37 import javax.naming.InitialContext JavaDoc;
38 import javax.naming.NamingException JavaDoc;
39
40
41 /**
42  * The SequenceSessionBean is a wrapper for the Sequence and Sequenceline entity beans.
43  * The session bean is what is accessed by the SequenceEntry application. This
44  * bean also implements the getCustStatus method to retrieve all common
45  * belonging to a particular customer.
46  */

47 public class SequenceSesSL implements SessionBean JavaDoc {
48
49     private SessionContext JavaDoc sessionContext;
50     private SequenceHomeLocal sequenceHome;
51
52     public void ejbCreate() {
53     }
54
55     /**
56      * nextKey: provides the next unique key from a sequence id.
57      * keys are not guaranteed to be issued in order and without gaps.
58      * The only guarantee is that the key is unique in this sequence id.
59      * @param id - Id of the sequence
60      * @return - an available integer key
61      * @exception FinderException - the sequence id is invalid
62      */

63     public int nextKey(String JavaDoc id) throws FinderException JavaDoc {
64         SequenceLocal sequence = null;
65         int ret = 0;
66
67         try {
68             sequence = sequenceHome.findByPrimaryKey(id);
69             ret = sequence.getUniqPk();
70         } catch (EJBException JavaDoc e) {
71             e.printStackTrace();
72             throw e;
73         }
74         System.out.println(">>>> Next PK: " + ret);
75         return ret;
76     }
77
78     public void ejbRemove() {
79     }
80
81     public void ejbActivate() {
82     }
83
84     public void ejbPassivate() {
85     }
86
87     public void setSessionContext(SessionContext JavaDoc sessionContext) {
88
89         this.sessionContext = sessionContext;
90
91         InitialContext JavaDoc initCtx = null;
92         try {
93             initCtx = new InitialContext JavaDoc();
94         } catch( NamingException JavaDoc ne ) {
95             ne.printStackTrace(System.err);
96             throw new EJBException JavaDoc(ne);
97         }
98
99         try {
100             // the homes are available via EJB links
101
sequenceHome = (SequenceHomeLocal) initCtx.lookup("java:comp/env/ejb/SequenceHomeLocal");
102         } catch( NamingException JavaDoc e ) {
103             e.printStackTrace();
104             throw new EJBException JavaDoc(e);
105         }
106
107     }
108 }
109
110
Popular Tags