當前位置: 首頁>>代碼示例>>Java>>正文


Java UserTransaction.rollback方法代碼示例

本文整理匯總了Java中javax.transaction.UserTransaction.rollback方法的典型用法代碼示例。如果您正苦於以下問題:Java UserTransaction.rollback方法的具體用法?Java UserTransaction.rollback怎麽用?Java UserTransaction.rollback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.transaction.UserTransaction的用法示例。


在下文中一共展示了UserTransaction.rollback方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRollback

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
public void testRollback() throws Throwable
{
    UserTransaction txn = transactionService.getUserTransaction();
    try
    {
        txn.begin();
        
        singleton.put(INTEGER_TWO);
        check(INTEGER_TWO, true);
        check(null, false);
        
        // rollback
        txn.rollback();
    }
    catch (Throwable e)
    {
        try { txn.rollback(); } catch (Throwable ee) {}
        throw e;
    }
    check(null, true);
    check(null, false);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:23,代碼來源:TransactionAwareSingletonTest.java

示例2: testNullValue

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
/**
 * Starts off with a <tt>null</tt> in the backing cache and adds a value to the
 * transactional cache.  There should be no problem with this.
 */
public void testNullValue() throws Throwable
{
    TransactionService transactionService = serviceRegistry.getTransactionService();
    UserTransaction txn = transactionService.getUserTransaction();

    txn.begin();
    
    TransactionalCache.putSharedCacheValue(backingCache, "A", null, null);
    transactionalCache.put("A", "AAA");
    
    try
    {
        txn.commit();
    }
    catch (Throwable e)
    {
        try {txn.rollback();} catch (Throwable ee) {}
        throw e;
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:25,代碼來源:CacheTest.java

示例3: deleteUser

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
private void deleteUser(String userName) throws Exception
{
    UserTransaction txn = transactionService.getUserTransaction();
    try
    {
        txn.begin();

        personService.deletePerson(userName);

        txn.commit();
    }
    catch (Exception e)
    {
        txn.rollback();
        throw e;
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:18,代碼來源:SiteServiceTestHuge.java

示例4: behaviourHierarchyTestWork

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
public void behaviourHierarchyTestWork(QName createDocType, ClassFilter... disableTypes) throws Exception
{
    UserTransaction transaction = trxService.getUserTransaction();
    try
    {
        transaction.begin();
        disableBehaviours(disableTypes);
        try
        {
            createDocOfType(createDocType);
        }
        finally
        {
            enableBehaviours(disableTypes);
        }
        transaction.commit();
    }
    catch(Exception e)
    {
        try { transaction.rollback(); } catch (IllegalStateException ee) {}
        throw e;
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:24,代碼來源:PolicyComponentTransactionTest.java

示例5: checkForAdminUserName

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
/**
 * Check if the user is an administrator user name
 * 
 * @param cInfo ClientInfo
 */
protected final void checkForAdminUserName(ClientInfo cInfo) {
	
	// Check if the user name is an administrator

	UserTransaction tx = getTransactionService().getUserTransaction();

	try {
		tx.begin();

		if ( cInfo.getLogonType() == ClientInfo.LogonNormal && getAuthorityService().isAdminAuthority(cInfo.getUserName())) {
			
			// Indicate that this is an administrator logon

			cInfo.setLogonType(ClientInfo.LogonAdmin);
		}
		tx.commit();
	}
	catch (Throwable ex) {
		try {
			tx.rollback();
		}
		catch (Throwable ex2) {
			logger.error("Failed to rollback transaction", ex2);
		}

		// Re-throw the exception

		if ( ex instanceof RuntimeException) {
			throw (RuntimeException) ex;
		}
		else {
			throw new RuntimeException("Error during execution of transaction.", ex);
		}
	}
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:41,代碼來源:FTPAuthenticatorBase.java

示例6: testReplicationExecutionLocking

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
/**
 * Check that the locking works.
 * Take a 10 second lock on the job, then execute.
 * Ensure that we really wait a little over 10 seconds.
 */
public void testReplicationExecutionLocking() throws Exception
{
   // We need the test transfer target for this test
   makeTransferTarget();

   // Create a task
   ReplicationDefinition rd = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
   rd.setTargetName(TRANSFER_TARGET);
   rd.getPayload().add(folder1);
   rd.getPayload().add(folder2);
   
   // Get the lock, and run
   long start = System.currentTimeMillis();
   String token = jobLockService.getLock(
         rd.getReplicationQName(),
         10 * 1000,
         1,
         1
   );
   
   UserTransaction txn = transactionService.getUserTransaction();
   txn.begin();
   try {
       actionService.executeAction(rd, replicationRoot);
   } catch(ReplicationServiceException e) {
       // This shouldn't happen normally! Something is wrong!
       // Tidy up before we throw the exception
       txn.rollback();
       throw e;
   }
   txn.commit();
   long end = System.currentTimeMillis();
   
   assertTrue(
        "Should wait for the lock, but didn't (waited " + 
           ((end-start)/1000.0) + " seconds, not 10)",
        end-start > 10000
   );
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:45,代碼來源:ReplicationServiceIntegrationTest.java

示例7: testStartNewTransaction

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
public void testStartNewTransaction() throws Exception
{
    // MNT-10096
    class CustomListenerAdapter extends TransactionListenerAdapter
    {
        private String newTxnId;

        @Override
        public void afterRollback()
        {
            newTxnId = txnHelper.doInTransaction(new RetryingTransactionCallback<String>()
            {
                @Override
                public String execute() throws Throwable
                {
                    return AlfrescoTransactionSupport.getTransactionId();
                }
            }, true, false);
        }
    }

    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    String txnId = AlfrescoTransactionSupport.getTransactionId();
    CustomListenerAdapter listener = new CustomListenerAdapter();

    AlfrescoTransactionSupport.bindListener(listener);
    txn.rollback();

    assertFalse("New transaction has not started", txnId.equals(listener.newTxnId));
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:32,代碼來源:RetryingTransactionHelperTest.java

示例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();
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:34,代碼來源:TransactionServiceImplTest.java

示例9: executeAndCheck

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
/** Execute the callback and ensure that the backing cache is left with the expected value */
private void executeAndCheck(
        RetryingTransactionCallback<Object> callback,
        boolean readOnly,
        String key,
        Object expectedValue,
        boolean mustContainKey) throws Throwable
{
    if (expectedValue != null && !mustContainKey)
    {
        throw new IllegalArgumentException("Why have a value when the key should not be there?");
    }
    
    TransactionService transactionService = serviceRegistry.getTransactionService();
    UserTransaction txn = transactionService.getUserTransaction(readOnly);
    try
    {
        txn.begin();
        callback.execute();
        txn.commit();
    }
    finally
    {
        try { txn.rollback(); } catch (Throwable ee) {}
    }
    Object actualValue = TransactionalCache.getSharedCacheValue(backingCache, key, null);
    assertEquals("Backing cache value was not correct", expectedValue, actualValue);
    assertEquals("Backing cache contains(key): ", mustContainKey, backingCache.contains(key));
    
    // Clear the backing cache to ensure that subsequent tests don't run into existing data
    backingCache.clear();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:33,代碼來源:CacheTest.java

示例10: testMaxSizeOverrun

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
/**
 * Add 50K objects into the transactional cache and checks that the first object added
 * has been discarded.
 */
public void testMaxSizeOverrun() throws Exception
{
    TransactionService transactionService = serviceRegistry.getTransactionService();
    UserTransaction txn = transactionService.getUserTransaction();
    try
    {
        txn.begin();
        
        Object startValue = new Integer(-1);
        String startKey = startValue.toString();
        transactionalCache.put(startKey, startValue);
        
        assertEquals("The start value isn't correct", startValue, transactionalCache.get(startKey));
        
        for (int i = 0; i < 205000; i++)
        {
            Object value = Integer.valueOf(i);
            String key = value.toString();
            transactionalCache.put(key, value);
        }
        
        // Is the start value here?
        Object checkStartValue = transactionalCache.get(startKey);
        // Now, the cache should no longer contain the first value
        assertNull("The start value didn't drop out of the cache", checkStartValue);
        
        txn.commit();
    }
    finally
    {
        try { txn.rollback(); } catch (Throwable ee) {}
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:38,代碼來源:CacheTest.java

示例11: testLazyLoadIssue

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
/**
 * Deletes a child node and then iterates over the children of the parent node,
 * getting the QName.  This caused some issues after we did some optimization
 * using lazy loading of the associations.
 */
public void testLazyLoadIssue() throws Exception
{
    Map<QName, ChildAssociationRef> assocRefs = buildNodeGraph();
    // commit results
    setComplete();
    endTransaction();

    UserTransaction userTransaction = txnService.getUserTransaction();
    
    try
    {
        userTransaction.begin();
        
        ChildAssociationRef n6pn8Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n6_p_n8"));
        NodeRef n6Ref = n6pn8Ref.getParentRef();
        NodeRef n8Ref = n6pn8Ref.getChildRef();
        
        // delete n8
        nodeService.deleteNode(n8Ref);
        
        // get the parent children
        List<ChildAssociationRef> assocs = nodeService.getChildAssocs(n6Ref);
        for (ChildAssociationRef assoc : assocs)
        {
            // just checking
        }
        
        userTransaction.commit();
    }
    catch(Exception e)
    {
        try { userTransaction.rollback(); } catch (IllegalStateException ee) {}
        throw e;
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:41,代碼來源:DbNodeServiceImplTest.java

示例12: testBehaviourHierarchySequence1

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
/**
 * Test for MNT-13836 (new API)
 * @throws Exception
 */
public void testBehaviourHierarchySequence1() throws Exception
{
    UserTransaction transaction = trxService.getUserTransaction();
    try
    {
        transaction.begin();
        disableBehaviours(new ClassFilter(A_TYPE, true), new ClassFilter(B_TYPE, true));

        behaviourFilter.enableBehaviour(B_TYPE);
        // Should be still disabled
        checkBehaviour(B_TYPE, companyHome, true, false, false, true);
        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;
    }
    assertFalse("Behavior should not be executed for a_type.", aTypeBehavior.isExecuted());
    assertEquals(0, aTypeBehavior.getExecutionCount());
    assertFalse("Behavior should not be executed for b_type.", bTypeBehavior.isExecuted());
    assertEquals(0, bTypeBehavior.getExecutionCount());
    assertFalse("Behavior should not be executed for c_type.", cTypeBehavior.isExecuted());
    assertEquals(0, cTypeBehavior.getExecutionCount());
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:38,代碼來源:PolicyComponentTransactionTest.java

示例13: authenticate

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
public boolean authenticate(RequiredAuthentication required, boolean isGuest)
{
    // first look for the username key in the session - we add this by hand for some portals
    // when the WebScriptPortletRequest is created
    String portalUser = (String)req.getPortletSession().getAttribute(WebScriptPortletRequest.ALFPORTLETUSERNAME);
    if (portalUser == null)
    {
        portalUser = req.getRemoteUser();
    }
    
    if (logger.isDebugEnabled())
    {
        logger.debug("JSR-168 Remote user: " + portalUser);
    }
    
    if (isGuest || portalUser == null)
    {
        if (logger.isDebugEnabled())
            logger.debug("Authenticating as Guest");
        
        // authenticate as guest
        AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
    }
    else
    {
        if (logger.isDebugEnabled())
            logger.debug("Authenticating as user " + portalUser);

        UserTransaction txn = null;
        try
        {
        	txn = txnService.getUserTransaction();
        	txn.begin();

        	if (!unprotAuthenticationService.authenticationExists(portalUser))
        	{
        		throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "User " + portalUser + " is not a known Alfresco user");
        	}
        	AuthenticationUtil.setFullyAuthenticatedUser(portalUser);
        }
        catch (Throwable err)
        {
        	throw new AlfrescoRuntimeException("Error authenticating user: " + portalUser, err);
        }
        finally
        {
        	try
        	{
        		if (txn != null)
        		{
        			txn.rollback();
        		}
        	}
        	catch (Exception tex)
        	{
        		// nothing useful we can do with this
        	}
        }
    }
    
    return true;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:63,代碼來源:JSR168PortletAuthenticatorFactory.java

示例14: testGetReaderWriter

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
public void testGetReaderWriter() throws Exception
{
    // testing a failure
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();

    FileInfo dirInfo = getByName(NAME_L0_FOLDER_A, true);

    UserTransaction rollbackTxn = null;
    try
    {
        rollbackTxn = transactionService.getNonPropagatingUserTransaction();
        rollbackTxn.begin();
        fileFolderService.getWriter(dirInfo.getNodeRef());
        fail("Failed to detect content write to folder");
    }
    catch (RuntimeException e)
    {
        // expected
    }
    finally
    {
        rollbackTxn.rollback();
    }

    FileInfo fileInfo = getByName(NAME_L1_FILE_A, false);

    ContentWriter writer = fileFolderService.getWriter(fileInfo.getNodeRef());
    assertNotNull("Writer is null", writer);
    // write some content
    String content = "ABC";
    writer.putContent(content);
    // read the content
    ContentReader reader = fileFolderService.getReader(fileInfo.getNodeRef());
    assertNotNull("Reader is null", reader);
    String checkContent = reader.getContentString();
    assertEquals("Content mismatch", content, checkContent);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:40,代碼來源:FileFolderServiceImplTest.java

示例15: updateComment

import javax.transaction.UserTransaction; //導入方法依賴的package包/類
/**
 * 
 * @param nodeRef
 * @param user
 * @param expectedStatus
 * @return
 * @throws Exception
 */
private Response updateComment(NodeRef nodeRef, String user, int expectedStatus) throws Exception
{
    Response response = null;
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    AuthenticationUtil.setFullyAuthenticatedUser(user);

    String now = System.currentTimeMillis()+"";

    JSONObject comment = new JSONObject();
    comment.put("title", "Test title updated "+now);
    comment.put("content", "Test comment updated "+now);

    response = sendRequest(new PutRequest(MessageFormat.format(URL_PUT_COMMENT,
            new Object[] {nodeRef.getStoreRef().getProtocol(), nodeRef.getStoreRef().getIdentifier(), nodeRef.getId()}), comment.toString(), JSON), expectedStatus);

    assertEquals(expectedStatus, response.getStatus());

    // Normally, webscripts are in their own transaction.  The test infrastructure here forces us to have a transaction
    // around the calls.  if the WebScript fails, then we should rollback.
    if (response.getStatus() == 500)
    {
        txn.rollback();
    }
    else
    {
        txn.commit();
    }
    
    return response;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:40,代碼來源:CommentsApiTest.java


注:本文中的javax.transaction.UserTransaction.rollback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。