Skip to content

Commit c38e6b8

Browse files
committed
Cleaned code after migration from Bitbucket
1 parent 1feee06 commit c38e6b8

File tree

6 files changed

+12
-120
lines changed

6 files changed

+12
-120
lines changed

README.md

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,31 @@
1-
# `@Transactional` Sandbox
1+
Materials gathered for internal presentation
22

3-
## Transakcje
3+
## Transactions
44
* https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html
55
* https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative-attransactional-settings
66
* https://www.baeldung.com/java-transactions
77
* https://vladmihalcea.com/?s=transaction&submit=Go
8-
#### Pitfals
8+
9+
## Pitfals
910
* [5 common Spring @Transactional pitfalls](https://codete.com/blog/5-common-spring-transactional-pitfalls/)
1011
* [Checked and Unchecked Exceptions](https://www.codejava.net/java-core/exception/java-checked-and-unchecked-exceptions)
1112
* [Spring Transactional propagation modes](https://codete.com/blog/spring-transaction-propagation-modes/)
1213
* https://www.ibm.com/developerworks/java/library/j-ts1/index.html
1314
* https://www.javacodegeeks.com/2011/12/spring-pitfalls-transactional-tests.html
1415

15-
## Testowanie użycia annotacji `@Transactional`
16+
## Testing `@Transactional`
1617
* [ArchUnit - dokumentacja](https://www.archunit.org/getting-started)
1718
* [ArchUnit - gradle plugin](https://github.com/societe-generale/arch-unit-gradle-plugin)
1819

19-
20-
## read-only and read-write operation
20+
## Operation read-only and read-write
2121
* https://vladmihalcea.com/read-write-read-only-transaction-routing-spring/
2222
* https://fable.sh/blog/splitting-read-and-write-operations-in-spring-boot/
2323
* https://blog.pchudzik.com/201911/read-from-replica/
24-
## disable autocommit
24+
25+
## Disable autocommit
2526
* https://vladmihalcea.com/why-you-should-always-use-hibernate-connection-provider_disables_autocommit-for-resource-local-jpa-transactions/
2627
* https://dzone.com/articles/best-performance-practices-for-hibernate-5-and-spr
28+
2729
## Open session in view
2830
* https://vladmihalcea.com/the-open-session-in-view-anti-pattern/
2931
* [The OSIV Anti-Pattern](https://stackoverflow.com/questions/30549489/what-is-this-spring-jpa-open-in-view-true-property-in-spring-boot/48222934#48222934)
30-
31-
## Do zastanowienia się
32-
* jak działą Transactional(readOnly=true) jeżęli sesja jest otwierana przez OpenSessionInView któ©y chyba domyślnie jest read-write i wymusza commit nawet jeżęli tylko dane są odczytywane
33-
* zamiana save() -> @Transactional - zastąpienie zapisu Lad i Inerakcji tylko zapisem Lead ? - zapis encji + kolekcji (lead+interakcje)
34-
* zakres tansakcji przy imporcie bazy pacjentów - co poszło nie tak
35-
* różne poziomy izolacji transakcji
36-
* zdarzenia DDD ???
37-
* sprawdzić notatkic z szkolenia Kubryńskiego - Hibernate
38-
39-
#### Derby DB Replica
40-
http://db.apache.org/derby/docs/10.4/adminguide/cadminreplicstartrun.html
41-
42-
---
43-
## Podsumowanie:
44-
- wstęp do tego czym jest transakcja - nie koniecznie DB
45-
- Czy można ręczne zarządzać trasakcjami tak jak w EJB
46-
- Dziedziczenie i ukrywanie użycia annotacji
47-
- OSIV vs radOnly - komibtowanie zmian po zakonczeniu operacji
48-
- Rozwinąć opis Propagation.NESTED
49-
- Synchronizacja z transakcjami - createOrUpdateNotification - ja zapewnić że posiadamy poprawnie zapisany obiekt
50-
- REQUIRE_NEW
51-
- entityManager/transactionManager .synchronize ???
52-
53-
54-
start
55-
code
56-
code
57-
< exception >
58-
code
59-
commit / rolback
60-
61-
62-
63-
https://docstore.mik.ua/orelly/java-ent/ebeans/ch08_02.htm

build.gradle

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,9 @@ dependencies {
5353
exclude group: "org.codehaus.groovy", module: "groovy-testng"
5454
}
5555
testImplementation "org.springframework.boot:spring-boot-starter-test"
56-
5756
testImplementation 'com.tngtech.archunit:archunit:0.14.1'
58-
// testImplementation "org.springframework.security:spring-security-test"
5957
}
6058

6159
test {
6260
useJUnitPlatform()
6361
}
64-
65-
// Disabling ArchUnit in `build` phase
66-
//allprojects {
67-
// apply plugin: 'java'
68-
// apply plugin: 'com.societegenerale.commons.plugin.gradle.ArchUnitGradlePlugin'
69-
// archUnit {
70-
// excludedPaths = ["some/package"]
71-
// preConfiguredRules = [
72-
// "com.societegenerale.commons.plugin.rules.NoInjectedFieldTest",
73-
// "com.societegenerale.commons.plugin.rules.NoAutowiredFieldTest",
74-
// "com.societegenerale.commons.plugin.rules.NoTestIgnoreWithoutCommentRuleTest",
75-
// "com.societegenerale.commons.plugin.rules.NoPrefixForInterfacesRuleTest",
76-
// "com.societegenerale.commons.plugin.rules.NoPowerMockRuleTest",
77-
// "com.societegenerale.commons.plugin.rules.NoJodaTimeRuleTest",
78-
// "com.societegenerale.commons.plugin.rules.NoJunitAssertRuleTest",
79-
// "com.societegenerale.commons.plugin.rules.HexagonalArchitectureTest",
80-
// "com.societegenerale.commons.plugin.rules.DontReturnNullCollectionTest",
81-
// "com.societegenerale.commons.plugin.rules.StringFieldsThatAreActuallyDatesRuleTest"
82-
// ]
83-
// configurableRules = [configurableRule("com.tngtech.archunit.library.GeneralCodingRules", applyOn("com.example.demo", "main"))]
84-
// }
85-
//}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name = 'sandbox_transactional'
1+
rootProject.name = 'presentation_transactional'

src/main/java/com/example/demo/sandbox/TransactionPropagationService.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.example.demo.sandbox;
22

33
import lombok.RequiredArgsConstructor;
4-
import org.springframework.transaction.annotation.Propagation;
54
import org.springframework.transaction.annotation.Transactional;
65

76
@RequiredArgsConstructor
@@ -11,25 +10,6 @@ class TransactionPropagationService {
1110
private final LeadInteractionService leadInteractionService;
1211

1312

14-
// @Transactional
15-
// public void runFirst(String comment, String leadInteractionName) {
16-
//// runInTransaction1(comment);
17-
// }
18-
//
19-
//
20-
// @Transactional(propagation = Propagation.REQUIRED)
21-
// @Transactional(propagation = Propagation.REQUIRES_NEW)
22-
// @Transactional(propagation = Propagation.MANDATORY)
23-
// @Transactional(propagation = Propagation.SUPPORTS)
24-
// @Transactional(propagation = Propagation.NOT_SUPPORTED)
25-
// @Transactional(propagation = Propagation.NEVER)
26-
// @Transactional(propagation = Propagation.NESTED)
27-
// public void runInTransaction1(String comment, String leadInteractionName) {
28-
// Lead lead = new Lead();
29-
// lead.setComment(comment);
30-
// }
31-
32-
3313
@Transactional
3414
public Lead runInTransaction(String comment, String leadInteractionName) {
3515
Lead lead = new Lead();

src/main/java/com/example/demo/sandbox/VisibilityMethodTransactionService.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,12 @@
22

33
import lombok.RequiredArgsConstructor;
44
import org.springframework.transaction.annotation.Transactional;
5-
import javax.persistence.EntityManager;
6-
import javax.persistence.EntityTransaction;
75

86
@RequiredArgsConstructor
97
class VisibilityMethodTransactionService {
108

119
private final LeadRepository leadRepository;
1210

13-
// private final EntityManager em;
14-
//
15-
// void run() {
16-
// EntityTransaction transaction = em.getTransaction();
17-
// try {
18-
// transaction.begin();
19-
//// code
20-
//// code
21-
//// code
22-
// transaction.commit();
23-
// } catch (Exception e) {
24-
// transaction.rollback();
25-
// }
26-
// }
27-
28-
29-
@Transactional
30-
public Lead createLeadUsingSaveMethod2(String comment) {
31-
Lead lead = new Lead();
32-
lead.setComment(comment);
33-
return lead;
34-
}
3511

3612
Lead createLeadUsingSaveMethod(String comment) {
3713
Lead lead = new Lead();
@@ -43,15 +19,8 @@ Lead createLeadUsingSaveMethod(String comment) {
4319
public void updateByPublicMethod(Long leadId, String comment) {
4420
Lead lead = leadRepository.getByIdOrThrow(leadId);
4521
lead.setComment(comment);
46-
// updateByPublicMethod1(...);
4722
}
4823

49-
// @Transactional
50-
// public void updateByPublicMethod1(Long leadId, String comment) {
51-
// Lead lead = leadRepository.getByIdOrThrow(leadId);
52-
// lead.setComment(comment);
53-
// }
54-
5524
@Transactional
5625
void updateByPackageMethod(Long leadId, String comment) {
5726
Lead lead = leadRepository.getByIdOrThrow(leadId);

src/test/java/com/example/demo/SandboxTransactionalApplicationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
@SpringBootTest
77
class SandboxTransactionalApplicationTests {
88

9-
@Test
10-
void contextLoads() {
11-
}
9+
@Test
10+
void contextLoads() {}
1211

1312
}

0 commit comments

Comments
 (0)