From 278709567ce2955d0f3670879576370a88d6a553 Mon Sep 17 00:00:00 2001 From: San Kim Date: Sun, 21 Jan 2024 20:02:57 +0900 Subject: [PATCH] =?UTF-8?q?[WEAV-31]=20=E2=9C=A8=20UUID=20Creator=20Util?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildSrc/src/main/kotlin/Version.kt | 1 + support/common/build.gradle.kts | 4 ++++ .../weave/support/common/uuid/UuidCreator.kt | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 support/common/src/main/kotlin/com/studentcenter/weave/support/common/uuid/UuidCreator.kt diff --git a/buildSrc/src/main/kotlin/Version.kt b/buildSrc/src/main/kotlin/Version.kt index c3320483..4b3e275b 100644 --- a/buildSrc/src/main/kotlin/Version.kt +++ b/buildSrc/src/main/kotlin/Version.kt @@ -9,6 +9,7 @@ object Version { const val SONAR_CLOUD = "4.4.1.3373" // dependencies + const val UUID_CREATOR = "5.3.3" const val MOCKK = "1.13.7" const val SPRING_MOCKK = "4.0.2" const val KOTEST = "5.6.0" diff --git a/support/common/build.gradle.kts b/support/common/build.gradle.kts index 16270d9b..7b46614d 100644 --- a/support/common/build.gradle.kts +++ b/support/common/build.gradle.kts @@ -5,3 +5,7 @@ val bootJar: BootJar by tasks bootJar.enabled = false jar.enabled = true + +dependencies { + implementation("com.github.f4b6a3:uuid-creator:${Version.UUID_CREATOR}") +} diff --git a/support/common/src/main/kotlin/com/studentcenter/weave/support/common/uuid/UuidCreator.kt b/support/common/src/main/kotlin/com/studentcenter/weave/support/common/uuid/UuidCreator.kt new file mode 100644 index 00000000..5524ee50 --- /dev/null +++ b/support/common/src/main/kotlin/com/studentcenter/weave/support/common/uuid/UuidCreator.kt @@ -0,0 +1,22 @@ +package com.studentcenter.weave.support.common.uuid + +import java.util.* +import com.github.f4b6a3.uuid.UuidCreator + +object UuidCreator { + + /** + * uuid version 7 기반으로 uuid 를 생성합니다. + * millisecond 단위로 정렬된 uuid 를 생성하며, + * 동일한 시간에 생성될 경우 단조 증가 counter를 활용해, unique 하게 생성됩니다. + * + * @return uuid version 7 type 2 + * @see Universally Unique IDentifiers (UUID) + * @see UuidCreator.getTimeOrdered() + * @author San Kim + */ + fun create(): UUID { + return UuidCreator.getTimeOrderedEpochPlus1() + } + +}