1 7 package org.jboss.test.hibernate.ejb; 8 9 import org.jboss.test.hibernate.model.User; 10 import org.jboss.test.hibernate.ejb.interfaces.ProfileServiceHome; 11 import org.jboss.test.hibernate.ejb.interfaces.ProfileServiceUtil; 12 import org.jboss.test.hibernate.ejb.interfaces.ProfileService; 13 14 import javax.ejb.SessionBean ; 15 import javax.ejb.EJBException ; 16 import javax.ejb.SessionContext ; 17 import javax.ejb.CreateException ; 18 import javax.naming.NamingException ; 19 import java.rmi.RemoteException ; 20 import java.util.List ; 21 22 35 public class AggregateProfileBean implements SessionBean 36 { 37 41 public User storeUser(User user) throws EJBException 42 { 43 ProfileService service = null; 44 try 45 { 46 service = locateService(); 47 return service.storeUser( user ); 48 } 49 catch( EJBException e ) 50 { 51 throw e; 52 } 53 catch( RemoteException e ) 54 { 55 throw new EJBException ( "Unable to access profile service", e ); 56 } 57 finally 58 { 59 release( service ); 60 } 61 } 62 63 67 public User loadUser(long id) throws EJBException 68 { 69 ProfileService service = null; 70 try 71 { 72 service = locateService(); 73 return service.loadUser(id); 74 } 75 catch( EJBException e ) 76 { 77 throw e; 78 } 79 catch( RemoteException e ) 80 { 81 throw new EJBException ( "Unable to access profile service", e ); 82 } 83 finally 84 { 85 release( service ); 86 } 87 } 88 89 93 public User loadUser(Long id) throws EJBException 94 { 95 ProfileService service = null; 96 try 97 { 98 service = locateService(); 99 return service.loadUser(id); 100 } 101 catch( EJBException e ) 102 { 103 throw e; 104 } 105 catch( RemoteException e ) 106 { 107 throw new EJBException ( "Unable to access profile service", e ); 108 } 109 finally 110 { 111 release( service ); 112 } 113 } 114 115 119 public List listUsers() throws EJBException 120 { 121 ProfileService service = null; 122 try 123 { 124 service = locateService(); 125 return service.listUsers(); 126 } 127 catch( EJBException e ) 128 { 129 throw e; 130 } 131 catch( RemoteException e ) 132 { 133 throw new EJBException ( "Unable to access profile service", e ); 134 } 135 finally 136 { 137 release( service ); 138 } 139 } 140 141 144 public void ejbCreate() 145 { 146 } 147 148 public void ejbActivate() throws EJBException , RemoteException 149 { 150 } 151 152 public void ejbPassivate() throws EJBException , RemoteException 153 { 154 } 155 156 public void ejbRemove() throws EJBException , RemoteException 157 { 158 } 159 160 public void setSessionContext(SessionContext ctx) throws EJBException , RemoteException 161 { 162 } 163 164 private ProfileService locateService() throws EJBException 165 { 166 try 167 { 168 ProfileServiceHome home = ProfileServiceUtil.getHome(); 169 return home.create(); 170 } 171 catch( NamingException e ) 172 { 173 throw new EJBException ( "Unable to locate profile service", e ); 174 } 175 catch( CreateException e ) 176 { 177 throw new EJBException ( "Unable to create ref to profile service", e ); 178 } 179 catch( RemoteException e ) 180 { 181 throw new EJBException ( "Unable to access profile service", e ); 182 } 183 } 184 185 private void release(ProfileService service) 186 { 187 if ( service != null ) 188 { 189 try 190 { 191 service.remove(); 192 } 193 catch( Throwable ignore ) 194 { 195 } 196 } 197 } 198 } 199 | Popular Tags |