001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.entity.ejb;
023:
024: import javax.ejb.CreateException;
025: import javax.ejb.EntityBean;
026: import javax.ejb.EntityContext;
027: import javax.ejb.RemoveException;
028:
029: import org.jboss.logging.Logger;
030:
031: /**
032: * A bean to test whether unsetEntityContext is called.
033: *
034: * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
035: * @version $Revision: 57211 $
036: */
037: public class UnsetEntityContextBean implements EntityBean {
038: private static final Logger log = Logger
039: .getLogger(UnsetEntityContextBean.class);
040:
041: private static int setEntityContextCounter = 0;
042: private static int unsetEntityContextCounter = 0;
043:
044: private EntityContext entityContext;
045:
046: private String name;
047:
048: public void setEntityContext(EntityContext context) {
049: log.info("setEntityContext - " + name);
050: ++setEntityContextCounter;
051: entityContext = context;
052: }
053:
054: public void unsetEntityContext() {
055: log.info("unsetEntityContext - " + name);
056: ++unsetEntityContextCounter;
057: entityContext = null;
058: }
059:
060: public String getName() {
061: log.info("getName");
062: return name;
063: }
064:
065: public String ejbCreate(String name) throws CreateException {
066: log.info("ejbCreate - " + name);
067: this .name = name;
068: return name;
069: }
070:
071: public void ejbPostCreate(String name) throws CreateException {
072: log.info("ejbPostCreate - " + name);
073: }
074:
075: public String ejbFindByPrimaryKey(String name) {
076: log.info("ejbFindByPrimaryKey - " + name);
077: return name;
078: }
079:
080: public void ejbActivate() {
081: log.info("ejbActivate - " + name);
082: }
083:
084: public void ejbLoad() {
085: log.info("ejbLoad - " + name);
086: }
087:
088: public void ejbPassivate() {
089: log.info("ejbPassivate - " + name);
090: }
091:
092: public void ejbRemove() throws RemoveException {
093: log.info("ejbRemove - " + name);
094: }
095:
096: public void ejbStore() {
097: log.info("ejbStore - " + name);
098: }
099:
100: public int ejbHomeGetSetEntityContextCallCounter() {
101: return setEntityContextCounter;
102: }
103:
104: public int ejbHomeGetUnsetEntityContextCallCounter() {
105: return unsetEntityContextCounter;
106: }
107:
108: public void ejbHomeClearSetEntityContextCallCounter() {
109: log.info("ejbHomeClearSetEntityContextCallCounter - " + name);
110: setEntityContextCounter = 0;
111: }
112:
113: public void ejbHomeClearUnsetEntityContextCallCounter() {
114: log.info("ejbHomeClearUnsetEntityContextCallCounter - " + name);
115: unsetEntityContextCounter = 0;
116: }
117:
118: }
|