1 25 package org.objectweb.easybeans.tests.common.resources; 26 27 import javax.annotation.Resource; 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.transaction.UserTransaction ; 31 32 import org.objectweb.easybeans.tests.common.exception.CustomException00; 33 34 35 41 public class UserTransactionTester { 42 43 46 @Resource 47 private UserTransaction utx; 48 49 52 public UserTransactionTester(){ 53 } 54 55 59 protected void access00() throws Exception { 60 checkInstance(utx); 61 } 62 63 68 public static void checkInstance(final UserTransaction utx) throws Exception { 69 if (utx == null){ 70 throw new CustomException00("UserTransaction reference is null."); 71 } 72 utx.begin(); 73 utx.commit(); 74 } 75 76 80 public static void checkJNDI() throws Exception { 81 Context ctx = new InitialContext (); 82 83 UserTransaction utx = (UserTransaction ) ctx.lookup("java:comp/env/UserTransaction"); 84 if (utx == null){ 85 throw new Exception ("UserTransaction reference obtained using JNDI API is null."); 86 } 87 } 88 } 89 | Popular Tags |