1 /*
2  * Copyright (C) 2010 Google, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.inject.persist;
18 
19 import static com.google.inject.matcher.Matchers.annotatedWith;
20 import static com.google.inject.matcher.Matchers.any;
21 
22 import com.google.inject.AbstractModule;
23 import org.aopalliance.intercept.MethodInterceptor;
24 
25 /**
26  * Install this module to add guice-persist library support for JPA persistence providers.
27  *
28  * @author dhanji@gmail.com (Dhanji R. Prasanna)
29  */
30 public abstract class PersistModule extends AbstractModule {
31 
32   @Override
configure()33   protected final void configure() {
34     configurePersistence();
35 
36     requireBinding(PersistService.class);
37     requireBinding(UnitOfWork.class);
38     /*if[AOP]*/
39     // wrapping in an if[AOP] just to allow this to compile in NO_AOP -- it won't be used
40 
41     // class-level @Transacational
42     bindInterceptor(annotatedWith(Transactional.class), any(), getTransactionInterceptor());
43     // method-level @Transacational
44     bindInterceptor(any(), annotatedWith(Transactional.class), getTransactionInterceptor());
45     /*end[AOP]*/
46   }
47 
configurePersistence()48   protected abstract void configurePersistence();
49 
getTransactionInterceptor()50   protected abstract MethodInterceptor getTransactionInterceptor();
51 }
52