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.cmp2.cmrtree.ejb;
023:
024: import java.util.Collection;
025: import org.apache.log4j.Category;
026:
027: import javax.ejb.SessionBean;
028: import javax.ejb.SessionContext;
029: import javax.ejb.CreateException;
030:
031: /**
032: * @ejb:bean type="Stateless"
033: * name="Facade"
034: * view-type="remote"
035: * @ejb.util generate="physical"
036: * @ejb:transaction type="Required"
037: * @ejb:transaction-type type="Container"
038: *
039: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
040: * @version <tt>$Revision: 57211 $</tt>
041: */
042: public class FacadeSessionBean implements SessionBean {
043: private static Category log = Category
044: .getInstance(FacadeSessionBean.class);
045:
046: SessionContext ctx;
047:
048: // Business methods
049:
050: /**
051: * @ejb.interface-method
052: * @ejb.transaction type="RequiresNew"
053: */
054: public void setup() throws Exception {
055: final long startTime = System.currentTimeMillis();
056: log.debug("SETUP>");
057:
058: ALocal a = AUtil.getLocalHome().create(1, "A", "1.A");
059: BLocal b1 = BUtil.getLocalHome().create(1, "B1", "1.B1");
060: b1.setAMinorId("A");
061:
062: BLocal b2 = BUtil.getLocalHome().create(1, "B2", "1.B2");
063: b2.setParent(b1);
064:
065: log.debug("SETUP> done in "
066: + (System.currentTimeMillis() - startTime) + " ms.");
067: }
068:
069: /**
070: * @ejb.interface-method
071: * @ejb.transaction type="RequiresNew"
072: */
073: public void test(long sleep) throws Exception {
074: final long startTime = System.currentTimeMillis();
075: log.debug("RUN>");
076:
077: AUtil.getLocalHome().remove(new APK(1, "A"));
078:
079: log.debug("RUN> done in "
080: + (System.currentTimeMillis() - startTime) + " ms.");
081: }
082:
083: /**
084: * @ejb.interface-method
085: * @ejb.transaction type="RequiresNew"
086: */
087: public void tearDown() throws Exception {
088: final long startTime = System.currentTimeMillis();
089: log.debug("TEAR DOWN>");
090:
091: log.debug("TEAR DOWN> done in "
092: + (System.currentTimeMillis() - startTime) + " ms.");
093: }
094:
095: /**
096: * @ejb.interface-method
097: * @ejb.transaction type="RequiresNew"
098: */
099: public void setup2() throws Exception {
100: final long startTime = System.currentTimeMillis();
101: log.debug("SETUP2>");
102:
103: ALocal a = AUtil.getLocalHome().create(1, "A", "1.A");
104: BLocal b1 = BUtil.getLocalHome().create(1, "B1", "some name");
105: b1.setA(a);
106:
107: log.debug("SETUP2> done in "
108: + (System.currentTimeMillis() - startTime) + " ms.");
109: }
110:
111: /**
112: * @ejb.interface-method
113: * @ejb.transaction type="RequiresNew"
114: */
115: public void setBNameToNull() throws Exception {
116: ALocal a = AUtil.getLocalHome().findByPrimaryKey(
117: new APK(1, "A"));
118: Collection bs = a.getB();
119: if (bs.size() != 1) {
120: throw new IllegalStateException(
121: "Expected only one B but got " + bs);
122: }
123:
124: BLocal b = (BLocal) bs.iterator().next();
125: b.setName(null);
126: }
127:
128: /**
129: * @ejb.interface-method
130: * @ejb.transaction type="RequiresNew"
131: */
132: public String getBName() throws Exception {
133: BLocal b = BUtil.getLocalHome().findByPrimaryKey(
134: new BPK(1, "B1"));
135: return b.getName();
136: }
137:
138: // SessionBean implementation
139:
140: /**
141: * @throws CreateException Description of Exception
142: * @ejb.create-method
143: */
144: public void ejbCreate() throws CreateException {
145: }
146:
147: public void ejbActivate() {
148: }
149:
150: public void ejbPassivate() {
151: }
152:
153: public void ejbRemove() {
154: }
155:
156: public void setSessionContext(SessionContext ctx) {
157: this.ctx = ctx;
158: }
159: }
|