2023-07-20-TIL
2023-07-20-TIL
Today I Learned
JSR-305
- https://skyul.tistory.com/68
- https://jcp.org/en/jsr/detail?id=305
- https://code.google.com/archive/p/jsr-305/
- https://dzone.com/articles/when-to-use-jsr-305-for-nullability-in-java
- https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/latest/javax/annotation/package-summary.html
- https://www.jenkins.io/doc/developer/tutorial-improve/replace-jsr-305-annotations/
- https://stackoverflow.com/questions/2289694/what-is-the-status-of-jsr-305
JSpecify
- https://jspecify.dev/
- https://github.com/jspecify/jspecify
- https://jspecify.dev/docs/start-here/
JPA @Version Property
하나의 페이지를 여러명이 보고있다가 저장을 누르면 먼저 저장했던 사람의 정보가 사라질 위험이 있다. 이를 대비하기 위해서 버전 필드를 관리함으로써(API를 통해 주고받고 DB에 저장함으로써) 충돌을 방지할 수 있다.
- https://vladmihalcea.com/jpa-entity-version-property-hibernate/
- https://javatute.com/hibernate/version-annotation-example-in-hibernate/
- https://stackoverflow.com/questions/2572566/java-jpa-version-annotation
- https://junhyunny.github.io/spring-boot/jpa/junit/version-annotation-warning/
JPA Auditing
JPA의 Auditing 기능을 사용하려면 @EnableJpaAuditing을 전역적으로 설정하고, 현재의 auditor를 얻어내는 메서드를 구현해야한다.
1
2
3
4
5
6
7
8
9
@Configuration
@EnableJpaAuditing
class Config {
@Bean
public AuditorAware<AuditableUser> auditorProvider() {
return new AuditorAwareImpl();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
class SpringSecurityAuditorAware implements AuditorAware<User> {
public User getCurrentAuditor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || !authentication.isAuthenticated()) {
return null;
}
return ((MyUserDetails) authentication.getPrincipal()).getUser();
}
}
이런식으로 설정하고 실험을 해보면 dirty checking이 발생하지 않는다면 update 쿼리가 실제로 실행되지 않는다. 즉, @LastModifiedDate, @LastModifiedBy는 변경되지 않는다는 것이다. 이는 기본적으로 @Version필드도 동일하게 동작한다.
그렇다면 ‘저장’버튼을 누르게되면 dirty checking을 무시하고 무조건 update 쿼리가 날아가게 하는건 가능할까?
- https://docs.spring.io/spring-data/jpa/docs/1.7.0.DATAJPA-580-SNAPSHOT/reference/html/auditing.html
- https://wonit.tistory.com/484
Epoch Time
- https://m.blog.naver.com/techtrip/221672212122
- https://www.epochconverter.com/
강업?
강제 업데이트라는 뜻의 줄임말이다..
Today I Studied
Twitter Snowflake Id Generation
- https://developer.twitter.com/en/docs/twitter-ids
- https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake
- https://github.com/twitter-archive/snowflake
- https://en.wikipedia.org/wiki/Snowflake_ID
- https://github.com/twitter-archive/snowflake/tree/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231
- https://dev.to/kkrypt0nn/generating-unique-ids-with-the-snowflake-algorithm-5889
- https://atakde.medium.com/twitter-snowflake-approach-is-cool-3156f78017cb
- https://jeong-pro.tistory.com/251
- https://www.youtube.com/watch?v=aLYKd7h7vgY
This post is licensed under CC BY 4.0 by the author.