本文整理汇总了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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
}
示例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
);
}
示例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));
}
示例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: 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();
}
示例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) {}
}
}
示例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;
}
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}