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
17package com.google.inject.persist;
18
19import static com.google.inject.matcher.Matchers.annotatedWith;
20import static com.google.inject.matcher.Matchers.any;
21
22import com.google.inject.AbstractModule;
23
24import org.aopalliance.intercept.MethodInterceptor;
25
26/**
27 * Install this module to add guice-persist library support for JPA persistence
28 * providers.
29 *
30 * @author dhanji@gmail.com (Dhanji R. Prasanna)
31 */
32public abstract class PersistModule extends AbstractModule {
33
34  @Override
35  protected final void configure() {
36    configurePersistence();
37
38    requireBinding(PersistService.class);
39    requireBinding(UnitOfWork.class);
40    /*if[AOP]*/
41    // wrapping in an if[AOP] just to allow this to compile in NO_AOP -- it won't be used
42
43    // class-level @Transacational
44    bindInterceptor(annotatedWith(Transactional.class), any(), getTransactionInterceptor());
45    // method-level @Transacational
46    bindInterceptor(any(), annotatedWith(Transactional.class), getTransactionInterceptor());
47    /*end[AOP]*/
48  }
49
50  protected abstract void configurePersistence();
51
52  protected abstract MethodInterceptor getTransactionInterceptor();
53}
54