001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program 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
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: KeyGenLockEJB.java,v 1.9 2007/06/26 12:29:50 drmlipp Exp $
021: *
022: * $Log: KeyGenLockEJB.java,v $
023: * Revision 1.9 2007/06/26 12:29:50 drmlipp
024: * Made constant schema compliant.
025: *
026: * Revision 1.8 2006/10/11 09:06:28 drmlipp
027: * Fixed EJB naming.
028: *
029: * Revision 1.7 2006/09/29 12:32:08 drmlipp
030: * Consistently using WfMOpen as projct name now.
031: *
032: * Revision 1.6 2005/04/08 11:28:02 drmlipp
033: * Merged changes from 1.3 branch up to 1.3p6.
034: *
035: * Revision 1.4.2.2 2005/04/04 20:08:55 drmlipp
036: * Changed WLS transaction isolation.
037: *
038: * Revision 1.5 2005/02/23 15:42:59 drmlipp
039: * Synchronized with 1.3.
040: *
041: * Revision 1.4.2.1 2005/02/15 14:46:14 drmlipp
042: * Fixed reentrant attribute (must be capitalized after all).
043: *
044: * Revision 1.4 2004/12/20 22:20:14 drmlipp
045: * Fixed reentrant attribute.
046: *
047: * Revision 1.3 2004/09/17 13:27:39 drmlipp
048: * Started J2EESDK port.
049: *
050: * Revision 1.2 2004/09/10 12:44:28 drmlipp
051: * Enabled call by reference for weblogic by default.
052: *
053: * Revision 1.1.1.3 2004/08/18 15:17:34 drmlipp
054: * Update to 1.2
055: *
056: * Revision 1.3 2004/06/23 15:06:38 lipp
057: * Started JOnAS port.
058: *
059: * Revision 1.2 2004/01/14 07:59:44 lipp
060: * Added transaction isolation attribute for WLS.
061: *
062: * Revision 1.1 2003/10/20 14:01:48 lipp
063: * Better support for data bases without SELECT FOR UPDATE.
064: *
065: */
066: package de.danet.an.util;
067:
068: import javax.ejb.CreateException;
069: import javax.ejb.EntityBean;
070: import javax.ejb.EntityContext;
071: import javax.ejb.FinderException;
072:
073: /**
074: * This class is a helper used to synchronize key generators within an
075: * application server if the data base does not support SELECT FOR UPDATE.
076: *
077: * @author <a href="mailto:lipp@danet.de">Michael Lipp</a>
078: * @version $Revision: 1.9 $
079: * @ejb.bean name="KeyGenLock" display-name="Key Generator Lock"
080: * jndi-name="ejb/@@@_Utility-EJBs_KeyGenLockEJB_JNDI_Name_@@@"
081: * type="BMP" reentrant="false" view-type="remote"
082: * @jonas.bean ejb-name="KeyGenLock"
083: * @ejb.pk class="java.lang.String" generate="false"
084: * @ejb.transaction type="Required"
085: * @weblogic.enable-call-by-reference True
086: */
087: public class KeyGenLockEJB implements EntityBean {
088:
089: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
090: .getLog(KeyGenLockEJB.class);
091:
092: /** Entity context. */
093: private EntityContext ctx;
094:
095: /**
096: * Set the associated entity context. The container calls this method
097: * after the instance creation.
098: * @see javax.ejb.EntityBean
099: * @param context - A SessionContext interface for the instance
100: */
101: public void setEntityContext(EntityContext context) {
102: ctx = context;
103: }
104:
105: /**
106: * Unset the associated entity context.
107: * @see javax.ejb.EntityBean
108: */
109: public void unsetEntityContext() {
110: ctx = null;
111: }
112:
113: /**
114: * The activate method is called when the instance is activated from its
115: * "passive" state. The instance should acquire any resource that it has
116: * released earlier in the ejbPassivate() method.
117: * This method gets the primary key from container.
118: * @see javax.ejb.EntityBean
119: */
120: public void ejbActivate() {
121: }
122:
123: /**
124: * The passivate method is called before the instance enters the
125: * "passive" state. The instance should release any resources that it
126: * can re-acquire later in the ejbActivate() method.
127: * @see javax.ejb.EntityBean
128: */
129: public void ejbPassivate() {
130: }
131:
132: /**
133: * A container invokes this method before it ends the life of the session
134: * object. This happens as a result of a client's invoking a remove
135: * operation, or when a container decides to terminate the session object
136: * after a timeout.
137: * @see javax.ejb.EntityBean
138: */
139: public void ejbRemove() {
140: }
141:
142: /**
143: * Called by the container to load persistent data.
144: */
145: public void ejbStore() {
146: }
147:
148: /**
149: * Called by the container to save persistent data.
150: */
151: public void ejbLoad() {
152: }
153:
154: /**
155: * Create an new instance. Not needed.
156: * @param key the key
157: * @return primary key of the bean
158: * @throws CreateException thrown if the EJB cannot be create.
159: */
160: public String ejbCreate(String key) throws CreateException {
161: return key;
162: }
163:
164: /**
165: * Called after creating a new instance.
166: * @param key the key
167: * @throws CreateException if the EJB cannot be create.
168: */
169: public void ejbPostCreate(String key) throws CreateException {
170: }
171:
172: /**
173: * Find an EJB.
174: * @param pk The primary key of the bean
175: * @return the primary key
176: * @throws FinderException (<code>ObjectNotFoundException</code>)
177: * if no EJB was found
178: */
179: public String ejbFindByPrimaryKey(String pk) throws FinderException {
180: return pk;
181: }
182:
183: /**
184: * Just a dummy method that return the key.
185: * @return the key
186: *
187: * @ejb.interface-method view-type="remote"
188: */
189: public String key() {
190: return (String) ctx.getPrimaryKey();
191: }
192: }
|