diff --git a/README.md b/README.md index ca17a34..46a31f5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ libraryDependencies += "com.lingcreative" %% "play-dbx" % "1.0.1" class Module extends AbstractModule { override def configure(): Unit = { - //Use the out-of-boxed TransactionManagerLookup for DBApi, which create a individual DataSourceTransactionManager + //Use the out-of-boxed TransactionManagerLookup for DBApi, which create a + //individual DataSourceTransactionManager //for each DataSource looked up from `DBApi.database(name).datasource` bind(classOf[TransactionManagerLookup]).to(classOf[SimpleDBApiTransactionManagerLookup]) @@ -25,8 +26,8 @@ class Module extends AbstractModule { val transactionalKey = new TypeLiteral[Transactional[Connection]](){} bind(transactionalKey).to(classOf[SimpleDBApiTransactional]) - //Make the db named `default1` configured in application.conf as the default datasource, and set JDBC isolation level - //to repeatable read + //Make the db named `default1` configured in application.conf as the default datasource, + //and set JDBC isolation level to repeatable read //Refer [[dbx.transaction.Transactional]]、[[dbx.transaction.Transactional.TransactionSettings]] for details. val settings = TransactionSettings(isolation = Isolation.REPEATABLE_READ, resource = "default1") bind(classOf[TransactionSettings]).toInstance(settings) @@ -49,7 +50,9 @@ import dbx.api.Transactional case class Company(id: Option[Long] = None, name: String) @Singleton -class CompanyService @Inject() (transactional: Transactional[Connection]/*Inject the SimpleDBApiTransactional for JDBC operations*/) { +class CompanyService @Inject() ( + /*Inject the SimpleDBApiTransactional for JDBC operations*/ + transactional: Transactional[Connection]) { /** * Parse a Company from a ResultSet @@ -62,7 +65,8 @@ class CompanyService @Inject() (transactional: Transactional[Connection]/*Inject } /** - * Get connection from `default1` db configured in application.conf, and rollback if any `Exception` thrown + * Get connection from `default1` db configured in application.conf, + * and rollback if any `Exception` thrown */ def options: Seq[(String,String)] = transactional() { implicit connection => SQL("select * from company order by name").as(simple *). @@ -72,13 +76,19 @@ class CompanyService @Inject() (transactional: Transactional[Connection]/*Inject } /** - * Allow update and delete sql to execute, pick connection from `default`, and rollback if any `CompanyExistException`, - * it equals to `@Transactional(readOnly=true, transactionManager="default", rollbackFor={CompanyExistException.class})` in SpringFramework. + * Allow update and delete sql to execute, obtain connections from `default`, + * and rollback if any `CompanyExistException` thrown, it equals to + * `@Transactional(readOnly=true, transactionManager="default", rollbackFor={CompanyExistException.class})` + * in SpringFramework. */ - def save(company: Company): Unit = transactional(readOnly = false, resource = "default", rollbackFor = Array(classOf[CompanyExistException])) { implicit connection => + def save(company: Company): Unit = transactional(readOnly = false, resource = "default", + rollbackFor = Array(classOf[CompanyExistException])) { implicit connection => // execute sql update statements here ... } } ``` + + +**Enjoy it!** diff --git a/README_zh.md b/README_zh.md index 95f4986..7708175 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,4 +1,4 @@ -play-dbx中文说明 +play-dbx [English Version](README.md) ================ play-dbx是一个事务管理框架/类库,源代码移植于SpringFramework,并去除无关类和依赖。核心接口为`Transactional`和`TransactionManagerLookup`(也是需要用户扩展定制的Trait),并提供了DBApi的简单实现。 @@ -44,7 +44,8 @@ import dbx.api.Transactional case class Company(id: Option[Long] = None, name: String) @Singleton -class CompanyService @Inject() (transactional: Transactional[Connection]/*注入Module.scala中配置的Transactional*/) { +class CompanyService @Inject() ( + transactional: Transactional[Connection]/*注入Module.scala中配置的Transactional*/) { /** * Parse a Company from a ResultSet @@ -57,7 +58,8 @@ class CompanyService @Inject() (transactional: Transactional[Connection]/*注入 } /** - * 按照Module.scala中配置的属性执行事务操作, ` transactional ` 对象的使用方法与Spring的 ` @Transactional ` 注解一致 + * 按照Module.scala中配置的属性执行事务操作, ` transactional ` 对象的使用方法与Spring的 + * `@Transactional` 注解一致 */ def options: Seq[(String,String)] = transactional() { implicit connection => SQL("select * from company order by name").as(simple *). @@ -70,7 +72,8 @@ class CompanyService @Inject() (transactional: Transactional[Connection]/*注入 * 让 ` transactional ` 使用default数据源里的JDBC连接(及对应的事物管理器),并关闭只读属性(即可执行更新操作)。 * 与在Spring里给方法添加注解 ` @Transactional(readOnly=true, transactionManager="default") ` 一致 */ - def save(company: Company): Unit = transactional(readOnly = false, resource = "default") { implicit connection => + def save(company: Company): Unit = transactional(readOnly = false, resource = "default") { + implicit connection => // execute sql update statements here ... }