Paul Robinson [
https://community.jboss.org/people/paul.robinson] created the discussion
"JTA 1.2 Implementation Work"
To view the discussion, visit:
https://community.jboss.org/message/816442#816442
--------------------------------------------------------------
h1. WARNING: THIS IS NOT YET READY FOR REVIEW.
This document discusses the outstanding issues and design decisions relating to our
implementation of the JTA 1.2 specification.
The JTA 1.2 Spec and JavaDoc can be obtained from
https://java.net/projects/jta-spec/sources/spec-source-repository/show here.
The two major changes are @Transactional (EJB-like transaction annotations for managed
beans) and @TransactionScoped (A CDI scope tied to the lifecycle of the active
transaction). Each of these is covered in it's own section bellow. There are some
smaller changes too, for which it is yet to be determinned if they require any code
changes. These are all discussed in the "Other Changes" section.
h3. @TransactionScoped
Implementing a new context in CDI is relativly straight-forward. You just need to
implement the javax.enterprise.context.spi.Context interface. Here's the pseudo code
for this impl:
public class TransactionContext implements Context {
private TransactionalBeanStore //Maintains a map of transaction to asociated beans.
Garbage collection method is open for discussion (see later)
public Class<? extends Annotation> getScope() {
return TransactionScoped.class;
}
public <T> T get(Contextual<T> contextual, CreationalContext<T>
creationalContext) {
bean = (PassivationCapabale) contextual
if (bean already in TransactionalBeanStore) {
return bean
} else if (creationalContext != null ) {
create new bean
add bean to TransactionalBeanStore
return bean
} else {
return null
}
}
public <T> T get(Contextual<T> contextual) {
return get(contextual, null);
}
public boolean isActive() {
return true if current transaction status in {STATUS_ACTIVE,
STATUS_MARKED_ROLLBACK, STATUS_PREPARED, STATUS_UNKNOWN, STATUS_PREPARING,
STATUS_COMMITTING, STATUS_ROLLING_BACK }
}
}
h4. Design Decisions
h6. Do we Implement from scratch or extend a Weld Abstract Context?
Weld implements many different Contexts (SessionScoped, ApplicationScoped, RequestScoped,
etc) and as a result many of the common implementation details have been abstracted into a
largish class heirachy, making the actual implementations of the specific Contexts much
simpler. We may be able to extend one of these Abstract Contexts. However, it's not
clear to me exactly which one should be extended. Also, this would place a dependency on
Weld, which I'm not sure is a good idea. I think it would be better to simply depend
on the CDI API, so that our implemntatin remains portable. Also the implementation of the
TransactionContext is quite simple, so we may be over-engineering the solution by
extending a Weld Context.
h6. How are the out-of-scope beans garbage-collected?
The 'isActive' method ensures that the context is recognised as inactive, outside
of an active transaction. However, the TransactionalBeanStore will collect garbage over
time and so needs clearing at some point after the Context is no longer active. These are
the current options that I think we have:
* AfterCompletion hook.
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/816442#816442]
Start a new discussion in JBoss Transactions Development at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]