Hi everyone,
Is there any way that an arbitrary class can participate in a transaction?
What I'm looking for is the equivalent of the SessionSynchronization class,
but more generic so that it can be used outside of an EJB environment by any
old arbitrary class. I'm thinking that such an object can register itself as
a transaction "listener", and then provide methods within itself to handle
the rollback and commit methods. That way a client that uses such a class
doesn't have to worry about handling the rollback and commit functionality
for that object, and the client can be sure that the object is consistent.
To illustrate, let's say there's a class...
public interface TransactionListener {
public void afterBegin();
public void afterCompletion(boolean wasCommitted);
public void beforeCompletion();
}
public class SomeClass implements TransactionListener {
private String someValue;
private String stashedSomeValue;
public void setSomeValue(String someValue) {
this.someValue = someValue;
}
public String getSomeValue() {
return someValue;
}
public void afterBegin() {
stashedSomeValue = someValue;
}
public void afterCompletion(boolean wasCommitted) {
if (!wasCommitted) {
someValue = stashedSomeValue;
}
}
public void beforeCompletion() {
//
}
}
I looked at the JTA documentation and didn't see anything like this. Is
there a specific reason that this kind of functionality isn't available?
Thanks,
Kirk
_______________________
Kirk True
Software Engineer
paper2net.com
http://www.paper2net.com