R
- The type of transaction or transaction state which this runnable requires.
A TransactionRunnable which alters a database through Hibernate would fail if it was
started outside of a TransactionRunnable which began and committed a transaction around
it. A class which extends TransactionRunnable<DatabaseTransaction>
can only be
run inside of another TransactionRunnable<DatabaseTransaction>
or inside of a
ProvidingTransactionRunnable<?, DatabaseTransaction>
Breaking that rule will be a compile time error.P
- the transaction state which this TransactionRunnable provides. Any
TransactionRunnable<P>
may be TransactionRunnable.runIn(TransactionRunnable)
This runnable.public class ProvidingTransactionRunnable<R,P extends R> extends TransactionRunnable<R>
// MyInterfaceWithDataA1 must extend DBTransaction because all
// ProvidingTransactionRunnables must provide more than they require.
public interface MyInterfaceWithDataA1 extends DBTransaction { Data getA1(); }
public class ImplementationWithDataA1 implements MyInterfaceWithDataA1 { ... }
public class TR1 extends ProvidingTransactionRunnable<DBTransaction, MyInterfaceWithDataA1>
{
private Data dataA1;
protected void onRun() { this.dataA1 = ..... }
@Override
protected MyInterfaceWithDataA1 getProvidedContext()
{
// this.getContext() will return a DBTransaction which our implementation can wrap.
return new ImplementationWithDataA1(this.getContext(), this.dataA1);
}
}
public class TR2 extends TransactionRunnable<DBTransaction> { ... }
public class TR3 extends TransactionRunnable<MyInterfaceWithDataA1>
{
protected void onRun()
{
final Data A1 = this.getContext();
...
}
}
To use these classes:
DBStartableTransactionRunnable run = new DBStartableTransactionRunnable(dataSourceName);
TransactionRunnable<MyInterfaceWithDataA1> tr1 = new TR1();
tr1.runIn(run);
TransactionRunnable<DBTransaction> tr2 = new TR2();
TransactionRunnable<MyInterfaceWithDataA1> tr2WithNewCapabilities = tr2.runIn(tr1.asProvider());
new TR3().runIn(tr2WithNewCapabilities);
// This would fail at compile time: new TR3().runIn(tr2);
run.start();
Constructor and Description |
---|
ProvidingTransactionRunnable() |
Modifier and Type | Method and Description |
---|---|
TransactionRunnable<P> |
asProvider()
View this as what it provides.
|
protected P |
getProvidedContext()
Get whatever is provided by this ProvidingTransactionRunnable.
|
commit, complete, getContext, onCommit, onComplete, onPreRun, onRollback, onRun, preRun, rollback, run, runIn
protected P getProvidedContext()
TransactionRunnable.getContext()
public TransactionRunnable<P> asProvider()
Copyright © 2004–2021 XWiki. All rights reserved.