The basic workflow is as follows. When transient changes are to be persisted, a new ModeShape transaction is {@link #begin() begun}. The resulting ModeShape {@link Transaction} represents the local transaction, to register {@link TransactionFunction functions} that are to be called upon successful transaction commit, and then either {@link Transaction#commit() committed} or{@link Transaction#rollback() rolled back}. If committed, then any changes made should be forwarded to {@link #updateCache(WorkspaceCache,ChangeSet,Transaction)}.
In the typical case where no JTA transactions are being used with JCR, then each time changes are made to a Session and {@link javax.jcr.Session#save()} is called a new transaction will be created, the changes applied to the workspace, thetransaction will be committed, and the workspace cache will be updated based upon the changes.
However, when JTA (local or distributed) transactions are being used with JCR (that is, container-managed transactions or user-managed transactions), then {@link javax.jcr.Session#save()} still needs to be called (see Chapter 21 of the JSR-283specification), but the changes are not persisted until the transaction is completed. In other words, even when one or more Session.save() calls are made, the changes are persisted and made visible to the rest of the repository users only when the transaction successfully commits. In these cases, the current thread is already associated with a transaction when {@link javax.jcr.Session#save()} is called, and therefore ModeShape simply uses that transaction but defers the monitoring andcache update calls until after commit.
Note that when distributed (XA) transactions are used, ModeShape properly integrates and uses the XA transaction but does not register itself as an {@link XAResource}. (Note that the Infinispan cache is enlisted as a resource in the transaction.) Therefore, even when XA transactions only involve the JCR repository as the single resource, ModeShape enlists only a single resource, allowing the transaction manager to optimize the 2PC with a single resource as a 1PC transaction. (Rather than enlisting the repository as an XAResource, ModeShape registers a {@link Synchronization} with the transaction to be notifiedwhen the transaction commits successfully, and it uses this to dictate when the events and session's changes are made visible to other sessions.
|
|
|
|