はじめまして
阿部と申します
PlayFramework2.2.xでDBFluteを使用しています
※とりあえずざらっと(あとでどこかでまとめたいと思っています...)
トランザクション処理はSpringを使用しています
build.sbt (抜粋)
libraryDependencies ++= Seq(
javaJdbc,
"com.google.inject" % "guice" % "3.0",
"org.seasar.dbflute" % "dbflute-runtime" % "1.0.5A",
"org.springframework" % "spring-jdbc" % "3.2.4.RELEASE",
"org.springframework" % "spring-aop" % "3.2.4.RELEASE"
)
resolvers += "The Seasar Foundation Maven2 Repository" at "http://maven.seasar.org/maven2"
Global.java (抜粋)
public void onStart(Application app) {
super.onStart(app);
List<Module> moduleList = new ArrayList<Module>();
DataSource dataSource = DB.getDataSource();
moduleList.add(new TransactionModule(dataSource));
moduleList.add(new DBFluteModule(new TransactionAwareDataSourceProxy(dataSource)));
Injector injector;
if (app.isProd())
injector = Guice.createInjector(Stage.PRODUCTION, moduleList.toArray(new Module[] {}));
else
injector = Guice.createInjector(Stage.DEVELOPMENT, moduleList.toArray(new Module[] {}));
}
protected static class TransactionModule extends AbstractModule {
protected DataSource dataSource;
public TransactionModule(DataSource dataSource) {
if (dataSource == null) {
String msg = "The argument 'dataSource' should not be null!";
throw new IllegalArgumentException(msg);
}
this.dataSource = dataSource;
}
@Override
protected void configure() {
// TransactionManager
PlatformTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
// TransactionInterceptor
Properties properties = new Properties();
properties.setProperty("*", "PROPAGATION_REQUIRED");
TransactionInterceptor transactionInterceptor = new TransactionInterceptor(transactionManager, properties);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), transactionInterceptor);
bind(PlatformTransactionManager.class).toInstance(transactionManager);
//bind(DataSource.class).toInstance(dataSource);
}
}
これで、あとはコントローラー等で Transactional アノテーションをつければトランザクション処理されます
@Transactional
public Result test() {
fooBhv.update(entity);
return ok(result);
}
それと、conf/application-logger.xml に以下のような記述をしておくと開発しやすいかと思います
application-logger.xml (抜粋)
<logger name="com.jolbox.bonecp" level="TRACE" />
<logger name="org.springframework" level="DEBUG" />
<logger name="org.seasar.dbflute" level="INFO" />
<logger name="org.seasar.dbflute.QLog" level="DEBUG" />