Revision: 1245
Author: dhanji
Date: Thu Sep 16 14:42:05 2010
Log: Edited wiki page Transactions through web user interface.
http://code.google.com/p/google-guice/source/detail?r=1245

Modified:
 /wiki/Transactions.wiki

=======================================
--- /wiki/Transactions.wiki     Thu Sep 16 14:37:57 2010
+++ /wiki/Transactions.wiki     Thu Sep 16 14:42:05 2010
@@ -40,12 +40,21 @@

 == Units of Work ==

-A unit of work is roughly the lifespan of an `EntityManager` (in JPA). It is the _session_ referred to in the `session-per-*` strategies. We have so far seen how to create a unit of work that spans a single transaction, and one that spans an entire HTTP request. +A unit of work is roughly the lifespan of an `EntityManager` (in JPA). It is the _session_ referred to in the `session-per-*` strategies. We have so far seen how to create a unit of work that spans a single transaction:
+
+http://warp-persist.googlecode.com/svn/wiki/txn_unitofwork.png
+
+...and one that spans an entire HTTP request:
+
+http://warp-persist.googlecode.com/svn/wiki/request_unitofwork.png

Sometimes you need to define a custom unit-of-work that doesn't fit into either requests or transactions. For example, you may want to do some background work in a timer thread, or some initialization work during startup. Or perhaps you are making a desktop app and have some other idea of a unit of work.

+http://warp-persist.googlecode.com/svn/wiki/custom_unitofwork.png
+
To start and end a unit of work arbitrarily, inject the `UnitOfWork` interface:

+{{{
 public class MyBackgroundWorker {
   @Inject private UnitOfWork unitOfWork;

@@ -59,5 +68,6 @@
     }
   }
 }
+}}}

You are free to call any `...@transactional` methods while a unit of work is in progress this way. When `end()` is called, any existing session is closed and discarded. It is safe to call `begin()` multiple times--if a unit of work is in progress, nothing happens. Similarly, if one is ended calling `end()` returns silently. `UnitOfWork` is threadsafe and can be cached for multiple uses or injected directly into singletons.

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to