1 22 package org.jboss.tm; 23 24 import javax.naming.Context ; 25 import javax.naming.InitialContext ; 26 import javax.naming.NamingException ; 27 import javax.transaction.Transaction ; 28 import javax.transaction.TransactionManager ; 29 30 import org.jboss.logging.Logger; 31 32 38 public class TMUtil 39 { 40 41 private static final Logger log = 42 Logger.getLogger(TMUtil.class); 43 44 private static TransactionManager tm; 45 46 private TMUtil() 48 { 49 } 50 51 54 public static Transaction getTransaction(LocalId localId) 55 { 56 TransactionPropagationContextImporter tpcImporter = 57 TransactionPropagationContextUtil.getTPCImporter(); 58 59 return tpcImporter.importTransactionPropagationContext(localId); 60 } 61 62 65 public static TransactionManager getTransactionManager() 66 { 67 if (tm == null) 68 { 69 try 70 { 71 Context ctx = new InitialContext (); 72 tm = (TransactionManager )ctx.lookup("java:/TransactionManager"); 73 } 74 catch (NamingException ex) 75 { 76 log.error("java:/TransactionManager lookup failed", ex); 77 } 78 } 79 return tm; 80 } 81 82 85 public static int divideAndRoundUp(long m, long n) 86 { 87 long retval = m / n; 88 89 if ((m % n) != 0) 90 retval = retval + 1; 91 return (int)retval ; 92 } 93 94 } 95 | Popular Tags |