|
2006-09-12 10:34
|
|
|
Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); props.put(Context.PROVIDER_URL, "t3://waily:7001"); Context ctx = new InitialContext(props); // UserTransaction接口实现 UserTransaction utx = (UserTransaction) ctx.lookup( "weblogic.transaction.UserTransaction"); utx.begin(); utx.commit(); // TransactionManager&Transaction接口 TransactionManager txm=(TransactionManager)ctx.lookup("weblogic.transaction.TransactionManager"); Transaction tx=txm.getTransaction(); if(tx==null)txm.begin(); // 单个事务提交:tx.commit(); // 全局事务提交:tmx.commit(); // USE IN EJB /* <transaction-type>Container[||Bean]</transaction-type> <trans-attribute>...</trans-attribute> NotSupport 保证底层组件实例不在全局事务中;如果从事务中调用方法,那么容器在组件的方法前挂起,当组件方法返回时,容器将控制权交给客户前恢复客户事务 Entity EJB事务全由容器管理 Supports 保证在所有客户启动的事务中都包含底层组件事务;不管方法是否从全局事务中调用的,方法总是调用成功 Mandatory 保证只有当客户把全局事务传递给组件时,客户才可以调用方法;如果方法不是在事务中调用的,则抛出TransactionRequiredException Required 迫使对组件方法的调用总是在一个由客户或者容器启动的事务中进行;如果方法不是在事务中调用的 则启动一个新事务 RequiredNew 保证容器总是启动一个新事务,迫使组件只在一个由容器启动的新事务中执行 Never 方法调用不在事务中发生,否则抛出一个RemoteException */ | |
| 共:1条记录 |