001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: SequenceSesSL.java 6612 2005-04-22 07:43:55Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.sequence;
027:
028: import java.rmi.RemoteException;
029:
030: import javax.ejb.CreateException;
031: import javax.ejb.EJBException;
032: import javax.ejb.FinderException;
033: import javax.ejb.RemoveException;
034: import javax.ejb.SessionBean;
035: import javax.ejb.SessionContext;
036: import javax.naming.InitialContext;
037: import javax.naming.NamingException;
038:
039: /**
040: * The SequenceSessionBean is a wrapper for the Sequence and Sequenceline entity beans.
041: * The session bean is what is accessed by the SequenceEntry application. This
042: * bean also implements the getCustStatus method to retrieve all common
043: * belonging to a particular customer.
044: */
045: public class SequenceSesSL implements SessionBean {
046:
047: private SessionContext sessionContext;
048: private SequenceHomeLocal sequenceHome;
049:
050: public void ejbCreate() {
051: }
052:
053: /**
054: * nextKey: provides the next unique key from a sequence id.
055: * keys are not guaranteed to be issued in order and without gaps.
056: * The only guarantee is that the key is unique in this sequence id.
057: * @param id - Id of the sequence
058: * @return - an available integer key
059: * @exception FinderException - the sequence id is invalid
060: */
061: public int nextKey(String id) throws FinderException {
062: SequenceLocal sequence = null;
063: int ret = 0;
064:
065: try {
066: sequence = sequenceHome.findByPrimaryKey(id);
067: ret = sequence.getUniqPk();
068: } catch (EJBException e) {
069: e.printStackTrace();
070: throw e;
071: }
072: System.out.println(">>>> Next PK: " + ret);
073: return ret;
074: }
075:
076: public void ejbRemove() {
077: }
078:
079: public void ejbActivate() {
080: }
081:
082: public void ejbPassivate() {
083: }
084:
085: public void setSessionContext(SessionContext sessionContext) {
086:
087: this .sessionContext = sessionContext;
088:
089: InitialContext initCtx = null;
090: try {
091: initCtx = new InitialContext();
092: } catch (NamingException ne) {
093: ne.printStackTrace(System.err);
094: throw new EJBException(ne);
095: }
096:
097: try {
098: // the homes are available via EJB links
099: sequenceHome = (SequenceHomeLocal) initCtx
100: .lookup("java:comp/env/ejb/SequenceHomeLocal");
101: } catch (NamingException e) {
102: e.printStackTrace();
103: throw new EJBException(e);
104: }
105:
106: }
107: }
|