Created
January 25, 2023 01:19
-
-
Save brfrn169/b050a161914cff6927959ca147551840 to your computer and use it in GitHub Desktop.
Examples of Spring Data JDBC integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Repository | |
public interface NorthAccountRepository | |
extends PagingAndSortingRepository<NorthAccount, Integer>, | |
ScalarDbHelperRepository<NorthAccount> { | |
@Transactional | |
default void transferToSouthAccount( | |
@Nonnull SouthAccountRepository southAccountRepository, | |
int fromId, int toId, int value) { | |
NorthAccount fromEntity = | |
findById(fromId).orElseThrow(() -> new AssertionError("Not found: " + fromId)); | |
SouthAccount toEntity = | |
southAccountRepository | |
.findById(toId) | |
.orElseThrow(() -> new AssertionError("Not found: " + toId)); | |
update(new NorthAccount(fromEntity.id, fromEntity.balance - value)); | |
southAccountRepository.update(new SouthAccount(toEntity.id, toEntity.balance + value)); | |
} | |
@Transactional | |
default void deleteAfterSelect(int id) { | |
findById(id).ifPresent(this::delete); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment