Паша Финкельштейн
@Transactional
@Transactional
class MySmartService(repo1: Repository1, repo2: Repository2) {
fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
@Transactional
@Transactional
class MySmartService(repo1: Repository1, repo2: Repository2) {
fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
@Transactional
@Transactional
class MySmartService(repo1: Repository1, repo2: Repository2) {
fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
@Transactional
@Transactional
class MySmartService(repo1: Repository1, repo2: Repository2) {
fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
@Transactional
@Transactional
class MySmartService(repo1: Repository1, repo2: Repository2) {
fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
@Transactional
@Transactional
open class MySmartService(repo1: Repository1, repo2: Repository2) {
open fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
@Transactional
@Transactional
class MySmartService(repo1: Repository1, repo2: Repository2) {
fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
@Transactional
kotlin-allopen + kotlin-spring
@Transactional
@Transactional
open class MySmartService(repo1: Repository1, repo2: Repository2) {
open fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
Что может пойти не так?@Transactional
@Transactional
open class MySmartService(repo1: Repository1, repo2: Repository2) {
open fun complex(datum: String): Result {
val interim = repo1.save(datum)
return repo2.destroy(someOp(interim))
}
fun someOp(input: String) =
if (notLucky(input)) throw Exception("Sorry, bro") else input
Как они устроены?
public static RuntimeException sneakyThrow(Throwable t) {
if (t == null) throw new NullPointerException("t");
return Lombok.<RuntimeException>sneakyThrow0(t);
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> T sneakyThrow0(Throwable t) throws T {
throw (T)t;
}
public static RuntimeException sneakyThrow(Throwable t) {
if (t == null) throw new NullPointerException("t");
return Lombok.<RuntimeException>sneakyThrow0(t);
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> T sneakyThrow0(Throwable t) throws T {
throw (T)t;
}
@Transactional
Не откатываются транзакции
Внимательно следить за сторонними исключениями
Не создавать свои checked
inline
@Transactional
open class SomeService(val repo: SomeRepo){
open fun someFunc(mapper: (DTO)->Long): List<Long> =
repo
.someAction()
.map{ mapper(it) }
inline
@Transactional
open class SomeService(val repo: SomeRepo){
open fun someFunc(mapper: (DTO)->Long): List<Long> =
repo
.someAction()
.map{ mapper(it) }
inline
@Transactional
open class SomeService(val repo: SomeRepo){
open fun someFunc(mapper: (DTO)->Long): List<Long> =
repo
.someAction()
.map{ mapper(it) }
inline
@Transactional
open class SomeService(val repo: SomeRepo){
open fun someFunc(mapper: (DTO)->Long): List<Long> =
repo
.someAction()
.map{ mapper(it) }
Но есть же inline
Улучшаем!
inline
@Transactional
open class SomeService(val repo: SomeRepo){
inline open fun someFunc(mapper: (DTO)->Long): List<Long> =
repo
.someAction()
.map{ mapper(it) }
inline
inline
инлайнится даже когда не надоinline
kotlin-maven-plugin
org.jetbrains.kotlin
jpa
org.jetbrains.kotlin
kotlin-maven-noarg
kotlin-maven-plugin
org.jetbrains.kotlin
jpa
org.jetbrains.kotlin
kotlin-maven-noarg
kotlin-maven-plugin
org.jetbrains.kotlin
jpa
org.jetbrains.kotlin
kotlin-maven-noarg
kotlin-maven-plugin
org.jetbrains.kotlin
jpa
org.jetbrains.kotlin
kotlin-maven-noarg