Migrate to Asciidoctor Tabs
This commit is contained in:
@@ -61,8 +61,11 @@ do not need any special exception treatment (or both). However, Spring lets exce
|
||||
translation be applied transparently through the `@Repository` annotation. The following
|
||||
examples (one for Java configuration and one for XML configuration) show how to do so:
|
||||
|
||||
[tabs]
|
||||
======
|
||||
Java::
|
||||
+
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
----
|
||||
@Repository
|
||||
public class ProductDaoImpl implements ProductDao {
|
||||
@@ -71,8 +74,10 @@ examples (one for Java configuration and one for XML configuration) show how to
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
Kotlin::
|
||||
+
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
@Repository
|
||||
class ProductDaoImpl : ProductDao {
|
||||
@@ -81,6 +86,7 @@ examples (one for Java configuration and one for XML configuration) show how to
|
||||
|
||||
}
|
||||
----
|
||||
======
|
||||
|
||||
[source,xml,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
|
||||
@@ -95,8 +95,11 @@ one current `Session` per transaction. This is roughly equivalent to Spring's
|
||||
synchronization of one Hibernate `Session` per transaction. A corresponding DAO
|
||||
implementation resembles the following example, based on the plain Hibernate API:
|
||||
|
||||
[tabs]
|
||||
======
|
||||
Java::
|
||||
+
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
----
|
||||
public class ProductDaoImpl implements ProductDao {
|
||||
|
||||
@@ -114,8 +117,10 @@ implementation resembles the following example, based on the plain Hibernate API
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Kotlin::
|
||||
+
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
class ProductDaoImpl(private val sessionFactory: SessionFactory) : ProductDao {
|
||||
|
||||
@@ -127,6 +132,7 @@ implementation resembles the following example, based on the plain Hibernate API
|
||||
}
|
||||
}
|
||||
----
|
||||
======
|
||||
|
||||
This style is similar to that of the Hibernate reference documentation and examples,
|
||||
except for holding the `SessionFactory` in an instance variable. We strongly recommend
|
||||
@@ -192,8 +198,11 @@ You can annotate the service layer with `@Transactional` annotations and instruc
|
||||
Spring container to find these annotations and provide transactional semantics for
|
||||
these annotated methods. The following example shows how to do so:
|
||||
|
||||
[tabs]
|
||||
======
|
||||
Java::
|
||||
+
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
----
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
|
||||
@@ -215,8 +224,10 @@ these annotated methods. The following example shows how to do so:
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Kotlin::
|
||||
+
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
class ProductServiceImpl(private val productDao: ProductDao) : ProductService {
|
||||
|
||||
@@ -230,6 +241,7 @@ these annotated methods. The following example shows how to do so:
|
||||
fun findAllProducts() = productDao.findAllProducts()
|
||||
}
|
||||
----
|
||||
======
|
||||
|
||||
In the container, you need to set up the `PlatformTransactionManager` implementation
|
||||
(as a bean) and a `<tx:annotation-driven/>` entry, opting into `@Transactional`
|
||||
@@ -295,8 +307,11 @@ and an example for a business method implementation:
|
||||
</beans>
|
||||
----
|
||||
|
||||
[tabs]
|
||||
======
|
||||
Java::
|
||||
+
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
----
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
|
||||
@@ -321,8 +336,10 @@ and an example for a business method implementation:
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Kotlin::
|
||||
+
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
class ProductServiceImpl(transactionManager: PlatformTransactionManager,
|
||||
private val productDao: ProductDao) : ProductService {
|
||||
@@ -337,6 +354,7 @@ and an example for a business method implementation:
|
||||
}
|
||||
}
|
||||
----
|
||||
======
|
||||
|
||||
Spring's `TransactionInterceptor` lets any checked application exception be thrown
|
||||
with the callback code, while `TransactionTemplate` is restricted to unchecked
|
||||
|
||||
@@ -293,8 +293,11 @@ using an injected `EntityManagerFactory` or `EntityManager`. Spring can understa
|
||||
if a `PersistenceAnnotationBeanPostProcessor` is enabled. The following example shows a plain JPA DAO implementation
|
||||
that uses the `@PersistenceUnit` annotation:
|
||||
|
||||
[tabs]
|
||||
======
|
||||
Java::
|
||||
+
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
----
|
||||
public class ProductDaoImpl implements ProductDao {
|
||||
|
||||
@@ -320,8 +323,10 @@ that uses the `@PersistenceUnit` annotation:
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Kotlin::
|
||||
+
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
class ProductDaoImpl : ProductDao {
|
||||
|
||||
@@ -340,6 +345,7 @@ that uses the `@PersistenceUnit` annotation:
|
||||
}
|
||||
}
|
||||
----
|
||||
======
|
||||
|
||||
The preceding DAO has no dependency on Spring and still fits nicely into a Spring
|
||||
application context. Moreover, the DAO takes advantage of annotations to require the
|
||||
@@ -382,8 +388,11 @@ the factory. You can avoid this by requesting a transactional `EntityManager` (a
|
||||
called a "`shared EntityManager`" because it is a shared, thread-safe proxy for the actual
|
||||
transactional EntityManager) to be injected instead of the factory. The following example shows how to do so:
|
||||
|
||||
[tabs]
|
||||
======
|
||||
Java::
|
||||
+
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
----
|
||||
public class ProductDaoImpl implements ProductDao {
|
||||
|
||||
@@ -397,8 +406,10 @@ transactional EntityManager) to be injected instead of the factory. The followin
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Kotlin::
|
||||
+
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
class ProductDaoImpl : ProductDao {
|
||||
|
||||
@@ -412,6 +423,7 @@ transactional EntityManager) to be injected instead of the factory. The followin
|
||||
}
|
||||
}
|
||||
----
|
||||
======
|
||||
|
||||
The `@PersistenceContext` annotation has an optional attribute called `type`, which defaults to
|
||||
`PersistenceContextType.TRANSACTION`. You can use this default to receive a shared
|
||||
|
||||
Reference in New Issue
Block a user