|
Yes, desktop application can't use PersistFilter. But I get to this
a little later... First your example: public class DAO { private final Provider<EntityManager> emProvider; @Inject public DAO(Provider<EntityManager> emProvider) { checkNotNull(emProvider); this.emProvider = emProvider; } @Transactional public Object findMyObject(in id) { final EntityManager em = emProvdider.get(); // do your work here } } The only trick is, that emProvider.get() will always return a valid EntityManager instance. (If you want to you can look at the source: JpaPersistService). Now to the UnitOfWork: I think the easiest way is to use the @Transactiona annotation. The @Transaction annotation spans a UnitOfWork around the outer most transaction. For most applications this is sufficient. If you have a lot of small transactions which are triggered by an single user action it may introduce a little overhead because it will create a new EntityManager for every transaction. But until you can measure this overhead I wouldn't worry about it. (Remember the first rule about optimization: don't do it!) There is one thing you have to be aware of when using the @Transaction annotation. It will only work - when the instance is of the class has been instantiated by guice (i.e has been injected into your class or has been retrieved with injector.getInstance()) - when the method which is annotated is NOT private. Hope this helps Greets Stephan On 08/29/2012 10:29 PM, Arthur Gregório
wrote:
can you provide one example in how to use the Provider<EntiyManager> -- You received this message because you are subscribed to the Google Groups "google-guice" 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?hl=en. |
- JSE architecture to inject DAO's members Arthur Gregório
- Re: JSE architecture to inject DAO's members Stephan Classen
- Re: JSE architecture to inject DAO's members Arthur Gregório
- Re: JSE architecture to inject DAO's members Stephan Classen
- Re: JSE architecture to inject DAO's mem... Stephan Classen
- Re: JSE architecture to inject DAO'... Arthur Gregório
