本文整理汇总了Java中javax.transaction.UserTransaction.commit方法的典型用法代码示例。如果您正苦于以下问题:Java UserTransaction.commit方法的具体用法?Java UserTransaction.commit怎么用?Java UserTransaction.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.transaction.UserTransaction
的用法示例。
在下文中一共展示了UserTransaction.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveUserTransaction
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
/**
* If the given UserTransaction is not null, it is committed/rolledback,
* and then returned to the UserTransactionHelper.
*/
private void resolveUserTransaction(UserTransaction userTransaction) {
if (userTransaction != null) {
try {
if (userTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
userTransaction.rollback();
} else {
userTransaction.commit();
}
} catch (Throwable t) {
getLog().error("Failed to resolve UserTransaction for plugin: " + getName(), t);
} finally {
UserTransactionHelper.returnUserTransaction(userTransaction);
}
}
}
示例2: testIndexOnCommitForInvalidate
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
@Test
public void testIndexOnCommitForInvalidate() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
Region region = cache.createRegion("sample", af.create());
qs.createIndex("foo", IndexType.FUNCTIONAL, "age", "/sample");
Context ctx = cache.getJNDIContext();
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
Integer x = new Integer(0);
utx.begin();
region.create(x, new Person("xyz", 45));
utx.commit();
Query q = qs.newQuery("select * from /sample where age < 50");
assertEquals(1, ((SelectResults) q.execute()).size());
Person dsample = (Person) CopyHelper.copy(region.get(x));
dsample.setAge(55);
utx.begin();
region.invalidate(x);
utx.commit();
CacheUtils.log(((Person) region.get(x)));
assertEquals(0, ((SelectResults) q.execute()).size());
}
示例3: createUser
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
private void createUser(String userName) throws Exception
{
UserTransaction txn = transactionService.getUserTransaction();
try
{
txn.begin();
authenticationService.createAuthentication(userName, userName.toCharArray());
PropertyMap ppOne = new PropertyMap(4);
ppOne.put(ContentModel.PROP_USERNAME, userName);
ppOne.put(ContentModel.PROP_FIRSTNAME, userName.substring(0, userName.length()-4));
ppOne.put(ContentModel.PROP_LASTNAME, "user");
ppOne.put(ContentModel.PROP_EMAIL, userName + "@email.com");
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
personService.createPerson(ppOne);
txn.commit();
}
catch (Exception e)
{
txn.rollback();
throw e;
}
}
示例4: deleteGroup
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
private void deleteGroup(String groupName) throws Exception
{
UserTransaction txn = transactionService.getUserTransaction();
try
{
txn.begin();
String groupAuthorityName = authorityService.getName(AuthorityType.GROUP, groupName);
authorityService.deleteAuthority(groupAuthorityName, true);
txn.commit();
}
catch (Exception e)
{
txn.rollback();
throw e;
}
}
示例5: testIsEnabled2
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
/**
* Test for MNT-13836 (new API)
* @throws Exception
*/
public void testIsEnabled2() throws Exception
{
UserTransaction transaction = trxService.getUserTransaction();
try
{
transaction.begin();
disableBehaviours(new ClassFilter(B_TYPE, false));
try
{
assertEquals("Incorrect behaviour state: global: ", true, behaviourFilter.isEnabled());
// A_TYPE
assertEquals("Incorrect behaviour state: class: ", true, behaviourFilter.isEnabled(A_TYPE));
assertEquals("Incorrect behaviour state: classAndInstance", true, behaviourFilter.isEnabled(companyHome, A_TYPE));
assertEquals("Incorrect behaviour state: instance", true, behaviourFilter.isEnabled(companyHome));
// B_TYPE
assertEquals("Incorrect behaviour state: class: ", false, behaviourFilter.isEnabled(B_TYPE));
assertEquals("Incorrect behaviour state: classAndInstance", false, behaviourFilter.isEnabled(companyHome, B_TYPE));
assertEquals("Incorrect behaviour state: instance", true, behaviourFilter.isEnabled(companyHome));
// C_TYPE
assertEquals("Incorrect behaviour state: class: ", true, behaviourFilter.isEnabled(C_TYPE));
assertEquals("Incorrect behaviour state: classAndInstance", true, behaviourFilter.isEnabled(companyHome, C_TYPE));
assertEquals("Incorrect behaviour state: instance", true, behaviourFilter.isEnabled(companyHome));
}
finally
{
behaviourFilter.enableBehaviour(B_TYPE);
}
transaction.commit();
}
catch(Exception e)
{
try { transaction.rollback(); } catch (IllegalStateException ee) {}
throw e;
}
}
示例6: awaitExecution
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
public void awaitExecution(UserTransaction tx, Thread toWake, String type) throws Exception
{
this.wantedType = type;
synchronized (waitForExecutionLock)
{
// Have things begin working
if (tx != null)
{
tx.commit();
}
if (toWake != null)
{
toWake.interrupt();
}
// Now wait for them to finish
try
{
long now = System.currentTimeMillis();
waitForExecutionLock.wait(waitTime);
if (System.currentTimeMillis() - now >= waitTime)
{
System.err.println("Warning - trigger wasn't received");
}
}
catch (InterruptedException e)
{
}
}
}
示例7: commitNodeGraph
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
protected Map<QName, ChildAssociationRef> commitNodeGraph() throws Exception
{
UserTransaction tx = transactionService.getUserTransaction();
tx.begin();
Map<QName, ChildAssociationRef> answer = buildNodeGraph();
tx.commit();
return null;// answer;
}
示例8: testPropagatingTxn
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
public void testPropagatingTxn() throws Exception
{
// start a transaction
UserTransaction txnOuter = transactionService.getUserTransaction();
txnOuter.begin();
String txnIdOuter = AlfrescoTransactionSupport.getTransactionId();
// start a propagating txn
UserTransaction txnInner = transactionService.getUserTransaction();
txnInner.begin();
String txnIdInner = AlfrescoTransactionSupport.getTransactionId();
// the txn IDs should be the same
assertEquals("Txn ID not propagated", txnIdOuter, txnIdInner);
// rollback the inner
txnInner.rollback();
// check both transactions' status
assertEquals("Inner txn not marked rolled back", Status.STATUS_ROLLEDBACK, txnInner.getStatus());
assertEquals("Outer txn not marked for rolled back", Status.STATUS_MARKED_ROLLBACK, txnOuter.getStatus());
try
{
txnOuter.commit();
fail("Outer txn not marked for rollback");
}
catch (RollbackException e)
{
// expected
txnOuter.rollback();
}
}
示例9: setUp
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
protected void setUp() throws Exception
{
ctx = ApplicationContextHelper.getApplicationContext();
DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
// load the system model
ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
InputStream modelStream = cl.getResourceAsStream("alfresco/model/systemModel.xml");
assertNotNull(modelStream);
M2Model model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
// load the test model
modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
assertNotNull(modelStream);
model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
nodeService = (NodeService) ctx.getBean("dbNodeService");
transactionService = (TransactionService) ctx.getBean("transactionComponent");
this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
this.authenticationComponent.setSystemUserAsCurrentUser();
// create a first store directly
UserTransaction tx = transactionService.getUserTransaction();
tx.begin();
StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
rootNodeRef = nodeService.getRootNode(storeRef);
tx.commit();
}
示例10: tearDown
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
@Override
protected void tearDown() throws Exception
{
super.tearDown();
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
personManager.clearPeople();
// Zap any replication definitions we created
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
for(ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) {
replicationService.deleteReplicationDefinition(rd);
}
AuthenticationUtil.clearCurrentSecurityContext();
// Clear out the running actions
for(ExecutionSummary es : actionTrackingService.getAllExecutingActions())
{
executingActionsCache.remove(
AbstractActionWebscript.getRunningId(es)
);
}
txn.commit();
}
示例11: testBehaviourHierarchySequence2
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
/**
* Test for MNT-13836 (new API)
* @throws Exception
*/
public void testBehaviourHierarchySequence2() throws Exception
{
UserTransaction transaction = trxService.getUserTransaction();
try
{
transaction.begin();
disableBehaviours(new ClassFilter(A_TYPE, false), new ClassFilter(B_TYPE, true));
behaviourFilter.enableBehaviour(B_TYPE);
assertEquals("Incorrect behaviour state: class: ", true, behaviourFilter.isEnabled(B_TYPE));
assertEquals("Incorrect behaviour state: classAndInstance", true, behaviourFilter.isEnabled(companyHome, B_TYPE));
assertEquals("Incorrect behaviour state: instance", true, behaviourFilter.isEnabled(companyHome));
try
{
createDocOfType(C_TYPE);
}
finally
{
enableBehaviours(new ClassFilter(A_TYPE, true), new ClassFilter(B_TYPE, true));
}
transaction.commit();
}
catch(Exception e)
{
try { transaction.rollback(); } catch (IllegalStateException ee) {}
throw e;
}
assertTrue("Behavior should be executed for a_type.", aTypeBehavior.isExecuted());
assertEquals(1, aTypeBehavior.getExecutionCount());
assertTrue("Behavior should be executed for b_type.", bTypeBehavior.isExecuted());
assertEquals(1, bTypeBehavior.getExecutionCount());
assertTrue("Behavior should be executed for c_type.", cTypeBehavior.isExecuted());
assertEquals(1, cTypeBehavior.getExecutionCount());
}
示例12: testAfterCommitFailedOnTransactionWriterThrowWithJTA
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
/**
* make sure standard Cache(Listener,Writer) are not called during rollback due to transaction
* writer throw
*/
@Test
public void testAfterCommitFailedOnTransactionWriterThrowWithJTA() throws Exception {
installCacheListenerAndWriter();
((CacheTransactionManager) this.txMgr).setWriter(new TransactionWriter() {
public void beforeCommit(TransactionEvent event) throws TransactionWriterException {
throw new TransactionWriterException("Rollback now!");
}
public void close() {}
});
installTransactionListener();
UserTransaction userTx =
(UserTransaction) this.cache.getJNDIContext().lookup("java:/UserTransaction");
userTx.begin();
this.region.create("key1", "value1");
this.cbCount = 0;
try {
userTx.commit();
fail("Commit should have thrown RollbackException");
} catch (RollbackException expected) {
assertNotNull(expected.getCause());
assertTrue(expected.getCause() + " is not a SynchronizationCommitConflictException",
expected.getCause() instanceof SynchronizationCommitConflictException);
}
assertEquals(0, this.cbCount);
assertEquals(1, this.failedCommits);
assertEquals(0, this.afterCommits);
assertEquals(1, this.afterRollbacks);
}
示例13: setUp
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception
{
super.setUp();
ApplicationContext appContext = getServer().getApplicationContext();
nodeService = (NodeService)appContext.getBean("NodeService");
replicationService = (ReplicationService)appContext.getBean("ReplicationService");
actionTrackingService = (ActionTrackingService)appContext.getBean("actionTrackingService");
repositoryHelper = (Repository)appContext.getBean("repositoryHelper");
transactionService = (TransactionService)appContext.getBean("transactionService");
MutableAuthenticationService authenticationService = (MutableAuthenticationService)appContext.getBean("AuthenticationService");
PersonService personService = (PersonService)appContext.getBean("PersonService");
personManager = new TestPersonManager(authenticationService, personService, nodeService);
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
personManager.createPerson(USER_NORMAL);
// Ensure we start with no replication definitions
// (eg another test left them behind)
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
for(ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) {
replicationService.deleteReplicationDefinition(rd);
}
txn.commit();
// Grab a reference to the data dictionary
dataDictionary = nodeService.getChildByName(
repositoryHelper.getCompanyHome(),
ContentModel.ASSOC_CONTAINS,
"Data Dictionary"
);
AuthenticationUtil.clearCurrentSecurityContext();
}
示例14: test6CommitBeforeTimeOut
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
@Test
public void test6CommitBeforeTimeOut() throws Exception {
UserTransaction utx = new UserTransactionImpl();
utx.begin();
utx.setTransactionTimeout(6);
Thread.sleep(2000);
utx.commit();
}
示例15: testTransactionalCacheDisableSharedCaches
import javax.transaction.UserTransaction; //导入方法依赖的package包/类
public void testTransactionalCacheDisableSharedCaches() throws Throwable
{
// add item to global cache
TransactionalCache.putSharedCacheValue(backingCache, NEW_GLOBAL_ONE, NEW_GLOBAL_ONE, null);
TransactionalCache.putSharedCacheValue(backingCache, NEW_GLOBAL_TWO, NEW_GLOBAL_TWO, null);
TransactionalCache.putSharedCacheValue(backingCache, NEW_GLOBAL_THREE, NEW_GLOBAL_THREE, null);
TransactionService transactionService = serviceRegistry.getTransactionService();
UserTransaction txn = transactionService.getUserTransaction();
try
{
// begin a transaction
txn.begin();
// Go directly past ALL shared caches
transactionalCache.setDisableSharedCacheReadForTransaction(true);
// Try to get results in shared caches
assertNull("Read of mutable shared cache MUST NOT use backing cache", transactionalCache.get(NEW_GLOBAL_ONE));
assertNull("Value should not be in any cache", transactionalCache.get(UPDATE_TXN_THREE));
// Update the transactional caches
transactionalCache.put(NEW_GLOBAL_TWO, "An update");
transactionalCache.put(UPDATE_TXN_THREE, UPDATE_TXN_THREE);
// Try to get results in shared caches
assertNull("Read of mutable shared cache MUST NOT use backing cache", transactionalCache.get(NEW_GLOBAL_ONE));
assertEquals("Value should be in transactional cache", "An update", transactionalCache.get(NEW_GLOBAL_TWO));
assertEquals("Value should be in transactional cache", UPDATE_TXN_THREE, transactionalCache.get(UPDATE_TXN_THREE));
txn.commit();
// Now check that values were not written through for any caches
assertEquals("Out-of-txn read must return shared value", NEW_GLOBAL_ONE, transactionalCache.get(NEW_GLOBAL_ONE));
assertNull("Value should be removed from shared cache", transactionalCache.get(NEW_GLOBAL_TWO));
assertEquals("New values must be written to shared cache", UPDATE_TXN_THREE, transactionalCache.get(UPDATE_TXN_THREE));
}
catch (Throwable e)
{
if (txn.getStatus() == Status.STATUS_ACTIVE)
{
txn.rollback();
}
throw e;
}
}