260212_01_DOC: 프로젝트 전체에 구글 java 스타일 적용
This commit is contained in:
@@ -2,36 +2,41 @@ package com.kri.common.jpa;
|
||||
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.persistence.PrePersist;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract class BaseUuidEntity {
|
||||
protected abstract String getId();
|
||||
protected abstract void setId(String id);
|
||||
|
||||
/** 엔티티마다 컬럼 길이에 맞춰 오버라이드 */
|
||||
protected int idLength() { return 32; }
|
||||
private static String generateId(int length) {
|
||||
String base = UUID.randomUUID().toString().replace("-", ""); // 32 chars
|
||||
|
||||
@PrePersist
|
||||
protected void prePersistId() {
|
||||
if (getId() == null || getId().isBlank()) {
|
||||
setId(generateId(idLength()));
|
||||
}
|
||||
if (length <= 32) {
|
||||
return base.substring(0, length);
|
||||
}
|
||||
|
||||
private static String generateId(int length) {
|
||||
String base = UUID.randomUUID().toString().replace("-", ""); // 32 chars
|
||||
|
||||
if (length <= 32) {
|
||||
return base.substring(0, length);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
sb.append(base);
|
||||
while (sb.length() < length) {
|
||||
sb.append(UUID.randomUUID().toString().replace("-", ""));
|
||||
}
|
||||
return sb.substring(0, length);
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
sb.append(base);
|
||||
while (sb.length() < length) {
|
||||
sb.append(UUID.randomUUID().toString().replace("-", ""));
|
||||
}
|
||||
return sb.substring(0, length);
|
||||
}
|
||||
|
||||
protected abstract String getId();
|
||||
|
||||
protected abstract void setId(String id);
|
||||
|
||||
/**
|
||||
* 엔티티마다 컬럼 길이에 맞춰 오버라이드
|
||||
*/
|
||||
protected int idLength() {
|
||||
return 32;
|
||||
}
|
||||
|
||||
@PrePersist
|
||||
protected void prePersistId() {
|
||||
if (getId() == null || getId().isBlank()) {
|
||||
setId(generateId(idLength()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user