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 ejb load was called.
033: *
034: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
035: * @version $Revision: 57211 $
036: */
037: public class EJBLoadBean implements EntityBean {
038: private static final Logger log = Logger
039: .getLogger(EJBLoadBean.class);
040:
041: private EntityContext entityContext;
042:
043: private String name;
044:
045: private boolean ejbLoadCalled = false;
046:
047: private boolean active = false;
048:
049: public String getName() {
050: log.info("getName");
051: assertActive();
052: return name;
053: }
054:
055: public boolean wasEJBLoadCalled() {
056: log.info("wasEJBLoadCalled");
057: assertActive();
058: boolean result = ejbLoadCalled;
059: ejbLoadCalled = false;
060: return result;
061: }
062:
063: public void noTransaction() {
064: log.info("noTransaction");
065: assertActive();
066: ejbLoadCalled = false;
067: }
068:
069: public String ejbCreate(String name) throws CreateException {
070: assertActive();
071: log.info("ejbCreate");
072: this .name = name;
073: return name;
074: }
075:
076: public void ejbPostCreate(String name) throws CreateException {
077: assertActive();
078: log.info("ejbPostCreate");
079: }
080:
081: public String ejbFindByPrimaryKey(String name) {
082: log.info("ejbFindByPrimaryKey");
083: return name;
084: }
085:
086: public void ejbActivate() {
087: log.info("ejbActivate");
088: active = true;
089: }
090:
091: public void ejbLoad() {
092: log.info("ejbLoad");
093: ejbLoadCalled = true;
094: assertActive();
095: }
096:
097: public void ejbPassivate() {
098: log.info("ejbPassivate");
099: assertActive();
100: active = false;
101: }
102:
103: public void ejbRemove() throws RemoveException {
104: log.info("ejbRemove");
105: assertActive();
106: active = false;
107: }
108:
109: public void ejbStore() {
110: log.info("ejbStore");
111: assertActive();
112: }
113:
114: public void setEntityContext(EntityContext context) {
115: log.info("setEntityContext");
116: entityContext = context;
117: }
118:
119: public void unsetEntityContext() {
120: log.info("unsetEntityContext");
121: entityContext = null;
122: }
123:
124: private void assertActive() {
125: if (active == false)
126: throw new RuntimeException("The bean is not active");
127: }
128: }
|