javax.transaction.TransactionScoped Java Examples

The following examples show how to use javax.transaction.TransactionScoped. 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: TransactionBeanWithEvents.java    From quarkus with Apache License 2.0 6 votes vote down vote up
void transactionScopePreDestroy(@Observes @BeforeDestroyed(TransactionScoped.class) final Object event,
        final BeanManager beanManager) throws SystemException {
    Transaction tx = tm.getTransaction();
    if (tx == null) {
        log.error("@BeforeDestroyed expects an active transaction");
        throw new IllegalStateException("@BeforeDestroyed expects an active transaction");
    }
    Context ctx;
    try {
        ctx = beanManager.getContext(TransactionScoped.class);
    } catch (Exception e) {
        log.error("Context on @Initialized is not available");
        throw e;
    }
    if (!ctx.isActive()) {
        log.error("Context on @BeforeDestroyed has to be active");
        throw new IllegalStateException("Context on @BeforeDestroyed has to be active");
    }
    if (!(event instanceof Transaction)) {
        log.error("@Intialized scope expects event payload being the " + Transaction.class.getName());
        throw new IllegalStateException("@Intialized scope expects event payload being the " + Transaction.class.getName());
    }

    beforeDestroyedCount++;
}
 
Example #2
Source File: TransactionBeanWithEvents.java    From quarkus with Apache License 2.0 5 votes vote down vote up
void transactionScopeActivated(@Observes @Initialized(TransactionScoped.class) final Object event,
        final BeanManager beanManager) throws SystemException {
    Transaction tx = tm.getTransaction();
    if (tx == null) {
        log.error("@Intialized expects an active transaction");
        throw new IllegalStateException("@Intialized expects an active transaction");
    }
    if (tx.getStatus() != Status.STATUS_ACTIVE) {
        log.error("@Initialized expects transaction is Status.STATUS_ACTIVE");
        throw new IllegalStateException("@Initialized expects transaction is Status.STATUS_ACTIVE");
    }
    Context ctx;
    try {
        ctx = beanManager.getContext(TransactionScoped.class);
    } catch (Exception e) {
        log.error("Context on @Initialized is not available");
        throw e;
    }
    if (!ctx.isActive()) {
        log.error("Context on @Initialized has to be active");
        throw new IllegalStateException("Context on @Initialized has to be active");
    }
    if (!(event instanceof Transaction)) {
        log.error("@Intialized scope expects event payload being the " + Transaction.class.getName());
        throw new IllegalStateException("@Intialized scope expects event payload being the " + Transaction.class.getName());
    }

    initializedCount++;
}
 
Example #3
Source File: TransactionBeanWithEvents.java    From quarkus with Apache License 2.0 5 votes vote down vote up
void transactionScopeDestroyed(@Observes @Destroyed(TransactionScoped.class) final Object event,
        final BeanManager beanManager) throws SystemException {
    Transaction tx = tm.getTransaction();
    if (tx != null)
        throw new IllegalStateException("@Destroyed expects no transaction");
    try {
        Context ctx = beanManager.getContext(TransactionScoped.class);
        throw new IllegalStateException("No bean in context expected but it's " + ctx);
    } catch (final ContextNotActiveException expected) {
    }

    destroyedCount++;
}
 
Example #4
Source File: NarayanaJtaProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
public void transactionContext(
        BuildProducer<ContextRegistrarBuildItem> contextRegistry) {

    contextRegistry.produce(new ContextRegistrarBuildItem(new ContextRegistrar() {
        @Override
        public void register(RegistrationContext registrationContext) {
            registrationContext.configure(TransactionScoped.class).normal().contextClass(TransactionContext.class).done();
        }
    }, TransactionScoped.class));
}
 
Example #5
Source File: TransactionContext.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends Annotation> getScope() {
    return TransactionScoped.class;
}
 
Example #6
Source File: TransactionContext.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends Annotation> getScope() {
    return TransactionScoped.class;
}
 
Example #7
Source File: TransactionContext.java    From tomee with Apache License 2.0 4 votes vote down vote up
public TransactionContext() {
    super(TransactionScoped.class);
}