== Context Recovery Interface

In the previous section, we described a Transaction Context holding two maps: a
_transient_ map and a _persistent_ one.

In situations where the TransactionManager dies (e.g., during a power failure), a transaction could 
have been in its preparing, committing or aborting phase.

Either the commit or abort methods will be called on all participants, but
before that happens, the TransactionManager gives the developer the
opportunity to let the participants know that we are not dealing with a 
normal commit/abort but a recovery situation.

The developer may choose to implement the 
link:http://jpos.org/doc/javadoc/org/jpos/transaction/ContextRecovery.html[ContextRecovery]
interface:

[source,java]
-------------
public interface ContextRecovery {
    public Serializable recover (long id, Serializable context, boolean commit); <1>
}
-------------
<1> the +commit+ boolean parameter indicates whether the transaction is going to commit or abort.

The TransactionManager provides the opportunity to build up the transient part
of the Context (e.g., re-establishing a JDBC connection, re-fetching a database
record based on some persistent ID number , etc.).

[TIP]
=====
While many participants can implement this interface, it is reasonable to have a single
one, similar to the initial +PrepareContext+, that can put a recovery flag in the Context,
re-establish JDBC connections, etc.
=====

