001: package hero.session;
002:
003: import hero.interfaces.BnNextNumberLocal;
004: import hero.interfaces.BnNextNumberLocalHome;
005: import hero.interfaces.InvalidValueException;
006: import hero.util.HeroException;
007:
008: import java.rmi.RemoteException;
009: import java.sql.Connection;
010: import java.sql.Statement;
011: import java.sql.ResultSet;
012: import java.sql.SQLException;
013:
014: import javax.ejb.CreateException;
015: import javax.ejb.EJBException;
016: import javax.ejb.SessionBean;
017: import javax.ejb.SessionContext;
018: import javax.naming.Context;
019: import javax.naming.InitialContext;
020: import javax.naming.NamingException;
021: import javax.naming.ServiceUnavailableException;
022: import javax.sql.DataSource;
023:
024: /**
025: * Encapsulates the retrival of DB data
026: *
027: * @author Andreas Schaefer
028: * @version $Revision: 1.7 $
029: *
030: * @ejb:bean name="SequenceGenerator"
031: * display-name="Generates unique Identifier for an Entity"
032: * type="Stateless"
033: * jndi-name="ejb/hero/SequenceGenerator"
034: * local-jndi-name="ejb/hero/SequenceGenerator_L"
035: * @ejb.permission role-name="BONITAUSER,SuperAdmin"
036: *
037: * @ejb:transaction type="Supports"
038: *
039: * @jonas.bean
040: * ejb-name="SequenceGenerator"
041: * jndi-name="ejb/hero/SequenceGenerator"
042: *
043: *
044: * @ejb.resource-ref res-ref-name="jdbc/myDS"
045: * res-type="javax.sql.DataSource"
046: * res-auth="Application"
047: * @jonas.resource
048: * res-ref-name="jdbc/myDS"
049: * jndi-name="bonita"
050: *
051: * @jboss.container-configuration name="Standard Stateless SessionBean for Bonita"
052: */
053: public class SequenceGeneratorBean implements SessionBean {
054:
055: // -------------------------------------------------------------------------
056: // Static
057: // -------------------------------------------------------------------------
058:
059: // -------------------------------------------------------------------------
060: // Members
061: // -------------------------------------------------------------------------
062:
063: private SessionContext mContext;
064: // Only for test purposes
065: private int mNextNumber = 0;
066:
067: // -------------------------------------------------------------------------
068: // Methods
069: // -------------------------------------------------------------------------
070:
071: /**
072: * Delivers the next sequence number from the given Sequence Name
073: *
074: * @param pSequenceName Name of the Sequence Generator
075: *
076: * @return Next sequence number
077: *
078: * @throws RemoteException
079: *
080: * @ejb:interface-method view-type="local"
081: * @ejb:transaction type="Required"
082: **/
083: public int getNextNumber(String pSequenceName) throws HeroException {
084: BnNextNumberLocalHome nHome = null;
085: try {
086: nHome = hero.interfaces.BnNextNumberUtil.getLocalHome();
087: } catch (javax.naming.NamingException be) {
088: throw new HeroException(be.getMessage());
089: }
090:
091: try {
092: BnNextNumberLocal nLocal = nHome.findByName(pSequenceName);
093: nLocal.setMax(nLocal.getMax() + 1);
094: return (nLocal.getMax());
095: } catch (javax.ejb.FinderException pe) {
096: try {
097: BnNextNumberLocal nLocal = nHome.create(pSequenceName);
098: return (nLocal.getMax());
099: } catch (CreateException ce) {
100: throw new HeroException(ce.getMessage());
101: } catch (InvalidValueException ie) {
102: throw new HeroException(ie.getMessage());
103: }
104: }
105:
106: }
107:
108: /**
109: * Create the Session Bean
110: *
111: * @throws CreateException
112: *
113: * @ejb:create-method view-type="remote"
114: **/
115: public void ejbCreate() throws CreateException {
116: }
117:
118: /**
119: * Describes the instance and its content for debugging purpose
120: *
121: * @return Debugging information about the instance and its content
122: * @ejb:transaction type="Supports"
123: **/
124: public String toString() {
125: return "SequenceGeneratorBean [ " + " ]";
126: }
127:
128: // -------------------------------------------------------------------------
129: // Framework Callbacks
130: // -------------------------------------------------------------------------
131:
132: public void setSessionContext(SessionContext aContext)
133: throws EJBException {
134: mContext = aContext;
135: }
136:
137: public void ejbActivate() throws EJBException {
138: }
139:
140: public void ejbPassivate() throws EJBException {
141: }
142:
143: public void ejbRemove() throws EJBException {
144: }
145:
146: }
|