javax.transaction.NotSupportedException Java Examples

The following examples show how to use javax.transaction.NotSupportedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PeopleTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void createUsers() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException, NotSupportedException
    {
        txn = transactionService.getUserTransaction();
        txn.begin();
        for (UserInfo user : userInfos)
        {
            String username = user.getUserName();
            NodeRef nodeRef = personService.getPersonOrNull(username);
            boolean create = nodeRef == null;
            if (create)
            {
                PropertyMap testUser = new PropertyMap();
                testUser.put(ContentModel.PROP_USERNAME, username);
                testUser.put(ContentModel.PROP_FIRSTNAME, user.getFirstName());
                testUser.put(ContentModel.PROP_LASTNAME, user.getLastName());
                testUser.put(ContentModel.PROP_EMAIL, user.getUserName() + "@acme.test");
                testUser.put(ContentModel.PROP_PASSWORD, "password");

                nodeRef = personService.createPerson(testUser);
            }
            userNodeRefs.add(nodeRef);
//            System.out.println((create ? "create" : "existing")+" user " + username + " nodeRef=" + nodeRef);
        }
        txn.commit();
    }
 
Example #2
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void invokeRollbackInBegin(TransactionContext transactionContext) throws NotSupportedException, SystemException {
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	CompensableTransaction compensable = this.getCompensableTransactionQuietly();
	TransactionContext compensableContext = compensable.getTransactionContext();

	TransactionXid compensableXid = compensableContext.getXid();
	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMFAIL);
		transactionCoordinator.rollback(transactionXid);
	} catch (XAException tex) {
		logger.info("{}> begin-transaction: error occurred while starting jta-transaction: {}",
				ByteUtils.byteArrayToString(compensableXid.getGlobalTransactionId()),
				ByteUtils.byteArrayToString(transactionXid.getGlobalTransactionId()), tex);
	}
}
 
Example #3
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void begin() throws NotSupportedException, SystemException {
	XidFactory transactionXidFactory = this.beanFactory.getTransactionXidFactory();

	CompensableTransaction compensable = this.getCompensableTransactionQuietly();
	if (compensable == null || compensable.getTransaction() != null) {
		throw new SystemException(XAException.XAER_PROTO);
	}

	CompensableArchive archive = compensable.getCompensableArchive();

	// The current confirm/cancel operation has been assigned an xid.
	TransactionXid compensableXid = archive == null ? null : (TransactionXid) archive.getCompensableXid();
	TransactionXid transactionXid = compensableXid != null //
			? transactionXidFactory.createGlobalXid(compensableXid.getGlobalTransactionId())
			: transactionXidFactory.createGlobalXid();

	TransactionContext compensableContext = compensable.getTransactionContext();
	TransactionContext transactionContext = compensableContext.clone();
	transactionContext.setXid(transactionXid);

	this.invokeBegin(transactionContext, false);
}
 
Example #4
Source File: JtaTransactionManagerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void jtaTransactionManagerWithNotSupportedExceptionOnNestedBegin() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
	willThrow(new NotSupportedException("not supported")).given(ut).begin();

	try {
		JtaTransactionManager ptm = newJtaTransactionManager(ut);
		TransactionTemplate tt = new TransactionTemplate(ptm);
		tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);
		tt.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				// something transactional
			}
		});
		fail("Should have thrown NestedTransactionNotSupportedException");
	}
	catch (NestedTransactionNotSupportedException ex) {
		// expected
	}
}
 
Example #5
Source File: JtaTransactionManagerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void jtaTransactionManagerWithNotSupportedExceptionOnNestedBegin() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
	willThrow(new NotSupportedException("not supported")).given(ut).begin();

	try {
		JtaTransactionManager ptm = newJtaTransactionManager(ut);
		TransactionTemplate tt = new TransactionTemplate(ptm);
		tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);
		tt.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				// something transactional
			}
		});
		fail("Should have thrown NestedTransactionNotSupportedException");
	}
	catch (NestedTransactionNotSupportedException ex) {
		// expected
	}
}
 
Example #6
Source File: MicroserviceResourceProducerTest.java    From genericconnector with Apache License 2.0 6 votes vote down vote up
@Test
public void testFind() throws ResourceException, NotSupportedException, SystemException {
	MicroserviceResourceFactory msrFactory = mock(MicroserviceResourceFactory.class);
	MicroserviceXAResource xa = new MicroserviceXAResource("a", mock(CommitRollbackCallback.class));
	when(msrFactory.build()).thenReturn(xa);
	MicroserviceResourceProducer.registerMicroserviceResourceFactory("a", msrFactory);
	MicroserviceResourceProducer producer = MicroserviceResourceProducer.getProducers().values().iterator().next();

       BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
       try{
       	tm.begin();

       	//TEST
       	producer.getTransactionAssistant(); //enlists resource into TX and means we can then go find it
       	
       	XAResource found = producer.findXAResourceHolder(xa).getXAResource();
       	assertEquals(xa, found);
       }finally{
       	tm.rollback();
       }
}
 
Example #7
Source File: LazyUserTransaction.java    From lastaflute with Apache License 2.0 6 votes vote down vote up
@Override
protected void doBegin() throws NotSupportedException, SystemException {
    if (canLazyTransaction()) {
        if (!isLazyTransactionLazyBegun()) { // first transaction
            incrementHierarchyLevel();
            toBeLazyTransaction(); // not begin real transaction here for lazy
        } else { // lazy now, this begin() means nested transaction
            if (!isLazyTransactionRealBegun()) { // not begun lazy transaction yet
                beginRealTransactionLazily(); // forcedly begin outer transaction before e.g. 'requiresNew' scope
                suspendForcedlyBegunLazyTransactionIfNeeds(); // like requires new transaction
            }
            incrementHierarchyLevel();
            superDoBegin(); // nested transaction is not lazy fixedly
        }
    } else { // normal transaction
        superDoBegin();
    }
}
 
Example #8
Source File: TransactionUtil.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
protected static void internalBegin(UserTransaction ut, int timeout) throws SystemException, NotSupportedException {
    // set the timeout for THIS transaction
    if (timeout > 0) {
        ut.setTransactionTimeout(timeout);
        if (Debug.verboseOn()) {
            Debug.logVerbose("Set transaction timeout to : " + timeout + " seconds", module);
        }
    }

    // begin the transaction
    ut.begin();
    if (Debug.verboseOn()) {
        Debug.logVerbose("Transaction begun", module);
    }

    // reset the timeout to the default
    if (timeout > 0) {
        ut.setTransactionTimeout(0);
    }
}
 
Example #9
Source File: JPAResource.java    From boost with Eclipse Public License 1.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #10
Source File: JPAResource.java    From boost with Eclipse Public License 1.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #11
Source File: JPAResource.java    From boost with Eclipse Public License 1.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #12
Source File: RequiredInterceptor.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
@Override
protected State start() {
    try {
        final Transaction transaction = transactionManager.getTransaction();
        final Transaction current;
        if (transaction == null) {
            transactionManager.begin();
            current = transactionManager.getTransaction();
        } else {
            current = transaction;
        }
        return new State(transaction, current);
    } catch (final SystemException | NotSupportedException se) {
        throw new TransactionalException(se.getMessage(), se);
    }
}
 
Example #13
Source File: JtaTransaction.java    From cdi with Apache License 2.0 6 votes vote down vote up
private void attemptBegin() {
    logger.debug("Beginning JTA transaction if required and possible.");

    if (userTransaction != null) {
        try {
            if (owned) {
                logger.debug("Beginning BMT transaction.");
                userTransaction.begin();
            } else {
                logger.debug("Did not try to begin non-owned BMT transaction.");
            }
        } catch (SystemException | NotSupportedException ex) {
            logger.warn("Had trouble trying to start BMT transaction.", ex);
        }
    } else {
        if (registry != null) {
            logger.debug("Not allowed to begin CMT transaction, the current transaction status is {}.",
                    statusToString(registry.getTransactionStatus()));
        } else {
            logger.warn("No JTA APIs available in this context. No begin done.");
        }
    }
}
 
Example #14
Source File: UserCompensableImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void compensableRecoverySuspend() throws NotSupportedException, SystemException {
	CompensableManager compensableManager = this.beanFactory.getCompensableManager();
	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();
	if (compensable == null) {
		throw new IllegalStateException();
	}

	TransactionContext transactionContext = compensable.getTransactionContext();
	if (transactionContext.isCoordinator() == false) {
		throw new IllegalStateException();
	}

	TransactionParticipant compensableCoordinator = this.beanFactory.getCompensableNativeParticipant();

	TransactionContext compensableContext = compensable.getTransactionContext();
	try {
		compensableCoordinator.end(compensableContext, XAResource.TMSUCCESS);
	} catch (XAException ex) {
		logger.error("Error occurred while suspending an compensable transaction!", ex);
		throw new SystemException(ex.getMessage());
	}
}
 
Example #15
Source File: JPAResource.java    From microprofile-sandbox with Apache License 2.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #16
Source File: JPAResource.java    From microprofile-sandbox with Apache License 2.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #17
Source File: JtaTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Transaction createTransaction(String name, int timeout) throws NotSupportedException, SystemException {
	TransactionManager tm = getTransactionManager();
	Assert.state(tm != null, "No JTA TransactionManager available");
	if (timeout >= 0) {
		tm.setTransactionTimeout(timeout);
	}
	tm.begin();
	return new ManagedTransactionAdapter(tm);
}
 
Example #18
Source File: SimpleTransactionFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Transaction createTransaction(String name, int timeout) throws NotSupportedException, SystemException {
	if (timeout >= 0) {
		this.transactionManager.setTransactionTimeout(timeout);
	}
	this.transactionManager.begin();
	return new ManagedTransactionAdapter(this.transactionManager);
}
 
Example #19
Source File: TransactionManagerImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void begin() throws NotSupportedException,
                           SystemException
{
   Transaction tx = registry.getTransaction();
   
   if (tx != null)
      throw new NotSupportedException();

   registry.startTransaction();
}
 
Example #20
Source File: DumbTransactionFactory.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public TransactionManager getTransactionManager() {
    return new TransactionManager() {
        public void begin() throws NotSupportedException, SystemException {
        }

        public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        }

        public int getStatus() throws SystemException {
            return TransactionUtil.STATUS_NO_TRANSACTION;
        }

        public Transaction getTransaction() throws SystemException {
            return null;
        }

        public void resume(Transaction transaction) throws InvalidTransactionException, IllegalStateException, SystemException {
        }

        public void rollback() throws IllegalStateException, SecurityException, SystemException {
        }

        public void setRollbackOnly() throws IllegalStateException, SystemException {
        }

        public void setTransactionTimeout(int i) throws SystemException {
        }

        public Transaction suspend() throws SystemException {
            return null;
        }
    };
}
 
Example #21
Source File: UserTransactionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void begin() throws NotSupportedException,
                           SystemException
{
   Transaction tx = registry.getTransaction();

   if (tx != null && tx.getStatus() != Status.STATUS_UNKNOWN)
      throw new SystemException();

   registry.startTransaction();

   if (userTransactionRegistry != null)
      userTransactionRegistry.userTransactionStarted();
}
 
Example #22
Source File: SimpleTransactionFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Transaction createTransaction(String name, int timeout) throws NotSupportedException, SystemException {
	if (timeout >= 0) {
		this.transactionManager.setTransactionTimeout(timeout);
	}
	this.transactionManager.begin();
	return new ManagedTransactionAdapter(this.transactionManager);
}
 
Example #23
Source File: JtaTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Transaction createTransaction(String name, int timeout) throws NotSupportedException, SystemException {
	TransactionManager tm = getTransactionManager();
	Assert.state(tm != null, "No JTA TransactionManager available");
	if (timeout >= 0) {
		tm.setTransactionTimeout(timeout);
	}
	tm.begin();
	return new ManagedTransactionAdapter(tm);
}
 
Example #24
Source File: QueriesPeopleApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void createTestUsers() throws IllegalArgumentException, SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException
{
    AuthenticationUtil.setFullyAuthenticatedUser(user1);
    for (String[] properties: userProperties)
    {
        int l = properties.length;
        if (l > 0)
        {
            PersonInfo personInfo = newPersonInfo(properties);
            String originalUsername = personInfo.getUsername();
            String id = createUser(personInfo, networkOne);
            Person person = new Person(
                           id,
                           null, // Not set to originalUsername, as the returned JSON does not set it
                           true, // enabled
                personInfo.getFirstName(),
                personInfo.getLastName(),
                personInfo.getCompany(),
                personInfo.getSkype(),
                personInfo.getLocation(),
                personInfo.getTel(),
                personInfo.getMob(),
                personInfo.getInstantmsg(),
                personInfo.getGoogle(),
                           null); // description
            testUsernames.add(originalUsername);
            testPersons.add(person);

            // The following call to personService.getPerson(id) returns a NodeRef like:
            //    workspace://SpacesStore/9db76769-96de-4de4-bdb4-a127130af362
            // We call tenantService.getName(nodeRef) to get a fully qualified NodeRef as Solr returns this.
            // They look like:
            //    workspace://@org.alfresco.rest.api.tests.queriespeopleapitest@SpacesStore/9db76769-96de-4de4-bdb4-a127130af362
            NodeRef nodeRef = personService.getPerson(id);
            nodeRef = tenantService.getName(nodeRef);
            testPersonNodeRefs.add(nodeRef);
        }
    }
}
 
Example #25
Source File: RomanticTransaction.java    From lastaflute with Apache License 2.0 5 votes vote down vote up
@Override
public void begin() throws NotSupportedException, SystemException {
    if (ThreadCacheContext.exists()) { // in action or task
        requestPath = ThreadCacheContext.findRequestPath();
        entryMethod = ThreadCacheContext.findEntryMethod();
        userBean = ThreadCacheContext.findUserBean();
    }
    transactionBeginMillis = System.currentTimeMillis();
    super.begin(); // actually begin here
    saveRomanticTransactionToThread();
}
 
Example #26
Source File: KeyStoreTests.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setup() throws SystemException, NotSupportedException
{
   	transactionService = (TransactionService)ctx.getBean("transactionService");
   	keyStoreChecker = (KeyStoreChecker)ctx.getBean("keyStoreChecker");
   	encryptionKeysRegistry = (EncryptionKeysRegistry)ctx.getBean("encryptionKeysRegistry");
   	keyResourceLoader = (KeyResourceLoader)ctx.getBean("springKeyResourceLoader");
       backupEncryptor = (DefaultEncryptor)ctx.getBean("backupEncryptor");

   	toDelete = new ArrayList<String>(10);

       AuthenticationUtil.setRunAsUserSystem();
	UserTransaction txn = transactionService.getUserTransaction();
	txn.begin();
}
 
Example #27
Source File: AbstractLockStoreTxTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testNotOnlyCurrentLockOwnerCanChangeInfo() throws NotSupportedException, SystemException
{
    final TransactionService txService = (TransactionService) ctx.getBean("TransactionService");
    UserTransaction txA = txService.getUserTransaction();
    final NodeRef nodeRef = new NodeRef("workspace://SpacesStore/UUID-1");
    Date now = new Date();
    Date expires = new Date(now.getTime() + 180000);
    final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
                "jbloggs", expires, Lifetime.EPHEMERAL, null);
    
    txA.begin();
    try
    {
        AuthenticationUtil.setFullyAuthenticatedUser("jbloggs");
        
        // Set initial lock state
        lockStore.set(nodeRef, lockState1);
        
        // Set different lock state
        // Current lock owner is still authenticated (jbloggs)
        final LockState lockState2 = LockState.createWithOwner(lockState1, "csmith");
        lockStore.set(nodeRef, lockState2);
        
        // Check update
        assertEquals(lockState2, lockStore.get(nodeRef));

        // Incorrect lock owner - this shouldn't fail. See ACE-2181
        final LockState lockState3 = LockState.createWithOwner(lockState1, "dsmithers");

        lockStore.set(nodeRef, lockState3);
        
        // Check update.
        assertEquals(lockState3, lockStore.get(nodeRef));
    }
    finally
    {
        txA.rollback();
    }
}
 
Example #28
Source File: LockServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testLockRevertedOnRollback() throws NotSupportedException, SystemException
{
    // Preconditions of test
    assertEquals(LockStatus.NO_LOCK, lockService.getLockStatus(noAspectNode));
    assertFalse(lockService.isLocked(noAspectNode));
    assertEquals(LockStatus.NO_LOCK, lockService.getLockStatus(rootNodeRef));
    assertFalse(lockService.isLocked(rootNodeRef));
    
    // Lock noAspectNode
    lockService.lock(noAspectNode, LockType.WRITE_LOCK, 0, Lifetime.EPHEMERAL);
    
    // Lock rootNodeRef
    lockService.lock(rootNodeRef, LockType.NODE_LOCK, 0, Lifetime.EPHEMERAL);
    
    // Sometime later, a refresh occurs (so this should not be reverted to unlocked, but to this state)
    lockService.lock(rootNodeRef, LockType.NODE_LOCK, 3600, Lifetime.EPHEMERAL);
    
    // Rollback
    TestTransaction.end();
    
    // This lock should not be present.
    assertEquals(LockStatus.NO_LOCK, lockService.getLockStatus(noAspectNode));
    assertFalse(lockService.isLocked(noAspectNode));
    
    // This lock should still be present.
    assertEquals(LockStatus.LOCK_OWNER, lockService.getLockStatus(rootNodeRef));
    assertTrue(lockService.isLocked(rootNodeRef));
}
 
Example #29
Source File: UserCompensableImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public TransactionXid compensableBegin() throws NotSupportedException, SystemException {
	RemoteCoordinator compensableCoordinator = (RemoteCoordinator) this.beanFactory.getCompensableNativeParticipant();
	CompensableManager tompensableManager = this.beanFactory.getCompensableManager();
	XidFactory compensableXidFactory = this.beanFactory.getCompensableXidFactory();

	CompensableTransactionImpl compensable = (CompensableTransactionImpl) tompensableManager
			.getCompensableTransactionQuietly();
	if (compensable != null) {
		throw new NotSupportedException();
	}

	TransactionXid compensableXid = compensableXidFactory.createGlobalXid();

	TransactionContext compensableContext = new TransactionContext();
	compensableContext.setCoordinator(true);
	compensableContext.setPropagated(true);
	compensableContext.setCompensable(true);
	compensableContext.setStatefully(this.statefully);
	compensableContext.setXid(compensableXid);
	compensableContext.setPropagatedBy(compensableCoordinator.getIdentifier());
	compensable = new CompensableTransactionImpl(compensableContext);
	compensable.setBeanFactory(this.beanFactory);

	try {
		compensableCoordinator.start(compensableContext, XAResource.TMNOFLAGS);
	} catch (XAException ex) {
		logger.error("Error occurred while beginning an compensable transaction!", ex);
		throw new SystemException(ex.getMessage());
	}

	return compensableXid;
}
 
Example #30
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void invokeBegin(TransactionContext transactionContext, boolean createFlag)
		throws NotSupportedException, SystemException {
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	CompensableTransaction compensable = this.getCompensableTransactionQuietly();
	TransactionContext compensableContext = compensable.getTransactionContext();

	TransactionXid compensableXid = compensableContext.getXid();
	TransactionXid transactionXid = transactionContext.getXid();
	try {
		Transaction transaction = transactionCoordinator.start(transactionContext, XAResource.TMNOFLAGS);
		transaction.setTransactionalExtra(compensable);
		compensable.setTransactionalExtra(transaction);

		transaction.registerTransactionResourceListener(compensable);
		transaction.registerTransactionListener(compensable);

		CompensableSynchronization synchronization = this.beanFactory.getCompensableSynchronization();
		synchronization.afterBegin(compensable.getTransaction(), createFlag);
	} catch (XAException tex) {
		logger.info("{}> begin-transaction: error occurred while starting jta-transaction: {}",
				ByteUtils.byteArrayToString(compensableXid.getGlobalTransactionId()),
				ByteUtils.byteArrayToString(transactionXid.getGlobalTransactionId()), tex);
		try {
			transactionCoordinator.end(transactionContext, XAResource.TMFAIL);
			throw new SystemException("Error occurred while beginning a compensable-transaction!");
		} catch (XAException ignore) {
			throw new SystemException("Error occurred while beginning a compensable-transaction!");
		}
	}
}