1 22 package org.jboss.test.cmp2.cmrtransaction.ejb; 23 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 27 import javax.ejb.CreateException ; 28 import javax.ejb.EJBException ; 29 import javax.ejb.FinderException ; 30 import javax.ejb.ObjectNotFoundException ; 31 import javax.ejb.RemoveException ; 32 import javax.ejb.SessionBean ; 33 import javax.ejb.SessionContext ; 34 import javax.naming.InitialContext ; 35 import javax.naming.NamingException ; 36 import javax.rmi.PortableRemoteObject ; 37 38 import org.jboss.test.cmp2.cmrtransaction.interfaces.TreeLocalHome; 39 import org.jboss.test.cmp2.cmrtransaction.interfaces.TreeLocal; 40 41 42 46 public class TreeFacadeSession implements SessionBean 47 { 48 50 private transient TreeLocalHome treeHome = null; 51 52 54 55 public TreeFacadeSession() {} 56 57 public void ejbCreate() throws CreateException {} 58 public void setSessionContext(SessionContext sessionContext) {} 59 public void ejbRemove() throws EJBException {} 60 public void ejbActivate() throws EJBException {} 61 public void ejbPassivate() throws EJBException {} 62 63 65 66 public void setup() 67 { 68 try 69 { 70 TreeLocalHome tlh = getTreeLocalHome(); 71 TreeLocal tl = null; 72 try 73 { 74 tl = tlh.findByPrimaryKey("Parent"); 75 tl.remove(); 76 } 77 catch (ObjectNotFoundException f) {} 78 try 79 { 80 tl = tlh.findByPrimaryKey("Child 1"); 81 tl.remove(); 82 } 83 catch (ObjectNotFoundException f) {} 84 try 85 { 86 tl = tlh.findByPrimaryKey("Child 2"); 87 tl.remove(); 88 } 89 catch (ObjectNotFoundException f) {} 90 } 91 catch (NamingException n) 92 { 93 throw new EJBException (n); 94 } 95 catch (RemoveException r) 96 { 97 throw new EJBException (r); 98 } 99 catch (FinderException f) 100 { 101 throw new EJBException (f); 102 } 103 } 104 105 106 public void createNodes() 107 { 108 try 109 { 110 TreeLocalHome tlh = getTreeLocalHome(); 111 TreeLocal parent = null; 112 parent = tlh.create("Parent", null); 113 tlh.create("Child 1", parent); 114 tlh.create("Child 2", null); 115 } 116 catch (NamingException n) 117 { 118 throw new EJBException (n); 119 } 120 catch (CreateException c) 121 { 122 throw new EJBException (c); 123 } 124 } 125 126 127 public void rearrangeNodes() 128 { 129 try 130 { 131 TreeLocalHome tlh = getTreeLocalHome(); 132 TreeLocal target = tlh.findByPrimaryKey("Child 2"); 133 TreeLocal sibling = null; 134 sibling = tlh.findByPrimaryKey("Child 1"); 135 141 target.setMenuParent(sibling.getMenuParent()); 142 target.setPrecededBy(sibling); 143 } 144 catch (NamingException n) 145 { 146 throw new EJBException (n); 147 } 148 catch (FinderException f) 149 { 150 throw new EJBException (f); 151 } 152 } 153 154 155 157 private TreeLocalHome getTreeLocalHome() throws NamingException 158 { 159 if (treeHome == null) 160 { 161 InitialContext ctx = new InitialContext (); 162 Object obj = ctx.lookup("java:/comp/env/ejb/cmrTransactionTest/CMRTreeLocal"); 163 treeHome = (TreeLocalHome) 164 PortableRemoteObject.narrow(obj, TreeLocalHome.class); 165 } 166 return treeHome; 167 } 168 169 } 170 | Popular Tags |