mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
move hibernate to exposed...
This commit is contained in:
parent
bcf0cc6c8d
commit
315a61aecf
@ -1,5 +1,3 @@
|
||||
import org.jetbrains.kotlin.gradle.targets.native.NativeCompilerOptions
|
||||
|
||||
plugins {
|
||||
val kotlinVersion = "2.0.0"
|
||||
|
||||
@ -7,7 +5,6 @@ plugins {
|
||||
id("application")
|
||||
kotlin("jvm") version kotlinVersion
|
||||
kotlin("plugin.jpa") version kotlinVersion
|
||||
id("org.hibernate.orm") version "6.5.2.Final"
|
||||
id("org.graalvm.buildtools.native") version "0.10.2"
|
||||
}
|
||||
|
||||
@ -42,6 +39,7 @@ graalvmNative {
|
||||
named("main") {
|
||||
useFatJar.set(true)
|
||||
sharedLibrary.set(false)
|
||||
buildArgs.add("--initialize-at-build-time=org.hibernate.*")
|
||||
}
|
||||
}
|
||||
metadataRepository {
|
||||
@ -62,10 +60,16 @@ dependencies {
|
||||
implementation("io.github.R2turnTrue:chzzk4j:0.0.7")
|
||||
implementation("ch.qos.logback:logback-classic:1.4.14")
|
||||
|
||||
// https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core
|
||||
implementation("org.hibernate.orm:hibernate-core:6.5.2.Final")
|
||||
implementation("org.hibernate:hibernate-hikaricp:6.5.2.Final")
|
||||
implementation("org.hibernate:hibernate-graalvm:6.5.2.Final")
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.exposed/exposed-core
|
||||
implementation("org.jetbrains.exposed:exposed-core:0.51.1")
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.exposed/exposed-dao
|
||||
implementation("org.jetbrains.exposed:exposed-dao:0.51.1")
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.exposed/exposed-jdbc
|
||||
runtimeOnly("org.jetbrains.exposed:exposed-jdbc:0.51.1")
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.exposed/exposed-kotlin-datetime
|
||||
runtimeOnly("org.jetbrains.exposed:exposed-kotlin-datetime:0.51.1")
|
||||
|
||||
|
||||
|
||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||
implementation("com.zaxxer:HikariCP:5.1.0")
|
||||
|
30
src/main/kotlin/space/mori/chzzk_bot/Connector.kt
Normal file
30
src/main/kotlin/space/mori/chzzk_bot/Connector.kt
Normal file
@ -0,0 +1,30 @@
|
||||
package space.mori.chzzk_bot
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import io.github.cdimascio.dotenv.dotenv
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.jetbrains.exposed.sql.SchemaUtils
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import space.mori.chzzk_bot.models.Users
|
||||
|
||||
object Connector {
|
||||
private val dotenv = dotenv()
|
||||
|
||||
val hikariConfig = HikariConfig().apply {
|
||||
jdbcUrl = dotenv["DB_URL"]
|
||||
driverClassName = "org.mariadb.jdbc.Driver"
|
||||
username = dotenv["DB_USER"]
|
||||
password = dotenv["DB_PASS"]
|
||||
maximumPoolSize = 10
|
||||
}
|
||||
val dataSource = HikariDataSource(hikariConfig)
|
||||
|
||||
init {
|
||||
Database.connect(dataSource)
|
||||
|
||||
transaction {
|
||||
SchemaUtils.createMissingTablesAndColumns(Users)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package space.mori.chzzk_bot
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import io.github.cdimascio.dotenv.dotenv
|
||||
import org.hibernate.SessionFactory
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder
|
||||
import org.hibernate.cfg.Configuration
|
||||
import org.hibernate.service.ServiceRegistry
|
||||
import space.mori.chzzk_bot.discord.User
|
||||
|
||||
object Database {
|
||||
private val dotenv = dotenv()
|
||||
|
||||
val configuration = Configuration().apply {
|
||||
addAnnotatedClass(User::class.java)
|
||||
setProperty("hibernate.dialect", "org.hibernate.dialect.MariaDBDialect")
|
||||
setProperty("hibernate.show_sql", "true")
|
||||
setProperty("hibernate.format_sql", "true")
|
||||
setProperty("hibernate.hbm2ddl.auto", "update")
|
||||
setProperty("hibernate.hbm2ddl.jdbc", "update")
|
||||
|
||||
setProperty("hibernate.bytecode.use-bytebuddy", "false")
|
||||
|
||||
// HikariCP를 사용하도록 설정
|
||||
setProperty("hibernate.connection.provider_class", "org.hibernate.hikaricp.internal.HikariCPConnectionProvider")
|
||||
setProperty("hibernate.hikari.dataSourceClassName", "org.mariadb.jdbc.MariaDbDataSource")
|
||||
setProperty("hibernate.hikari.dataSource.url", dotenv["DB_URL"])
|
||||
setProperty("hibernate.hikari.dataSource.user", dotenv["DB_USER"])
|
||||
setProperty("hibernate.hikari.dataSource.password", dotenv["DB_PASS"])
|
||||
setProperty("hibernate.hikari.maximumPoolSize", "10")
|
||||
}
|
||||
|
||||
private val serviceRegistry: ServiceRegistry = StandardServiceRegistryBuilder()
|
||||
.applySettings(configuration.properties)
|
||||
.build()
|
||||
|
||||
val sessionFactory: SessionFactory = configuration.buildSessionFactory(serviceRegistry)
|
||||
}
|
@ -13,13 +13,13 @@ val logger: Logger = LoggerFactory.getLogger("main")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val discord = Discord()
|
||||
Database
|
||||
|
||||
Connector
|
||||
discord.enable()
|
||||
|
||||
if(dotenv.get("RUN_AGENT", "false").toBoolean()) {
|
||||
runBlocking {
|
||||
delay(TimeUnit.SECONDS.toMillis(10))
|
||||
delay(TimeUnit.MINUTES.toMillis(1))
|
||||
discord.disable()
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
package space.mori.chzzk_bot.discord
|
||||
|
||||
import jakarta.persistence.*
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
data class User(
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val id: Long?,
|
||||
|
||||
@Column(length = 255)
|
||||
val username: String,
|
||||
|
||||
@Column(length = 64)
|
||||
val token: String,
|
||||
|
||||
val discord: Long
|
||||
)
|
21
src/main/kotlin/space/mori/chzzk_bot/models/User.kt
Normal file
21
src/main/kotlin/space/mori/chzzk_bot/models/User.kt
Normal file
@ -0,0 +1,21 @@
|
||||
package space.mori.chzzk_bot.models
|
||||
|
||||
import org.jetbrains.exposed.dao.IntEntity
|
||||
import org.jetbrains.exposed.dao.IntEntityClass
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
|
||||
|
||||
object Users: IntIdTable("users") {
|
||||
val username = varchar("username", 255)
|
||||
val token = varchar("token", 64)
|
||||
val discord = long("discord")
|
||||
}
|
||||
|
||||
class User(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<User>(Users)
|
||||
|
||||
var username by Users.username
|
||||
var token by Users.token
|
||||
var discord by Users.discord
|
||||
}
|
@ -1,21 +1,25 @@
|
||||
package space.mori.chzzk_bot.services
|
||||
|
||||
import space.mori.chzzk_bot.Database
|
||||
import space.mori.chzzk_bot.discord.User
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import space.mori.chzzk_bot.models.User
|
||||
import space.mori.chzzk_bot.models.Users
|
||||
|
||||
class UserService {
|
||||
fun saveUser(user: User) {
|
||||
val session = Database.sessionFactory.openSession()
|
||||
session.beginTransaction()
|
||||
session.persist(user)
|
||||
session.transaction.commit()
|
||||
session.close()
|
||||
User.new {
|
||||
username = user.username
|
||||
token = user.token
|
||||
discord = user.discord
|
||||
}
|
||||
}
|
||||
|
||||
fun getUser(id: Long): User? {
|
||||
val session = Database.sessionFactory.openSession()
|
||||
val user = session.get(User::class.java, id)
|
||||
session.close()
|
||||
return user
|
||||
fun getUser(id: Int): User? {
|
||||
return User.findById(id)
|
||||
}
|
||||
|
||||
fun getUser(discordID: Long): User? {
|
||||
val users = User.find(Users.discord eq discordID)
|
||||
|
||||
return users.firstOrNull()
|
||||
}
|
||||
}
|
@ -1,47 +1,5 @@
|
||||
[
|
||||
{
|
||||
"interfaces":["java.sql.Connection"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$Executable"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.method.ParameterDescription$ForLoadedParameter$Parameter"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.method.ParameterList$ForLoadedExecutable$Executable"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.type.TypeDefinition$Sort$AnnotatedType"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.type.TypeDescription"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.type.TypeDescription$ForLoadedType$Dispatcher"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.type.TypeDescription$Generic"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.type.TypeDescription$Generic$AnnotationReader$Delegator$ForLoadedExecutableParameterType$Dispatcher"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.type.TypeDescription$Generic$AnnotationReader$Delegator$ForLoadedMethodReturnType$Dispatcher"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.description.type.TypeDescription$Generic$AnnotationReader$ForComponentType$AnnotatedParameterizedType"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.dynamic.loading.ClassInjector$UsingLookup$MethodHandles"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.dynamic.loading.ClassInjector$UsingLookup$MethodHandles$Lookup"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.utility.JavaModule$Module"]
|
||||
},
|
||||
{
|
||||
"interfaces":["net.bytebuddy.utility.JavaModule$Resolver"]
|
||||
}
|
||||
]
|
File diff suppressed because it is too large
Load Diff
@ -2,12 +2,6 @@
|
||||
"resources":{
|
||||
"includes":[{
|
||||
"pattern":"\\QMETA-INF/services/ch.qos.logback.classic.spi.Configurator\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/com.fasterxml.jackson.databind.Module\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/jakarta.validation.spi.ValidationProvider\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/jakarta.validation.valueextraction.ValueExtractor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/java.lang.System$LoggerFinder\\E"
|
||||
}, {
|
||||
@ -19,59 +13,13 @@
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/java.time.zone.ZoneRulesProvider\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/javax.xml.stream.XMLEventFactory\\E"
|
||||
"pattern":"\\QMETA-INF/services/org.jetbrains.exposed.sql.DatabaseConnectionAutoRegistration\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.model.FunctionContributor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.model.TypeContributor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.registry.selector.StrategyRegistrationProvider\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.registry.selector.spi.DialectSelector\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.spi.AdditionalJaxbMappingProducer\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.spi.AdditionalMappingContributor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.spi.MetadataBuilderFactory\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.spi.MetadataBuilderInitializer\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.spi.MetadataContributor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.spi.MetadataSourcesContributor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.boot.spi.SessionFactoryBuilderFactory\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.bytecode.spi.BytecodeProvider\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.engine.jdbc.dialect.spi.DialectResolver\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.event.spi.EventEngineContributor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.event.spi.EventManager\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.id.factory.spi.GenerationTypeStrategyRegistration\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.integrator.spi.Integrator\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.query.criteria.spi.CriteriaBuilderExtension\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.service.spi.ServiceContributor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.hibernate.service.spi.SessionFactoryServiceContributor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.jboss.logging.LoggerProvider\\E"
|
||||
"pattern":"\\QMETA-INF/services/org.jetbrains.exposed.sql.statements.GlobalStatementInterceptor\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.mariadb.jdbc.plugin.Codec\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/services/org.slf4j.spi.SLF4JServiceProvider\\E"
|
||||
}, {
|
||||
"pattern":"\\QMETA-INF/validation.xml\\E"
|
||||
}, {
|
||||
"pattern":"\\Qhibernate.properties\\E"
|
||||
}, {
|
||||
"pattern":"\\Qlogback-test.scmo\\E"
|
||||
}, {
|
||||
@ -82,34 +30,6 @@
|
||||
"pattern":"\\Qlogback.xml\\E"
|
||||
}, {
|
||||
"pattern":"\\Qmariadb.properties\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$AreFieldsDirty.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$AreFieldsDirtyWithoutCollections.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$ClearDirtyAttributes.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$ClearDirtyAttributesWithoutCollections.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$ClearOwner.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$GetCollectionTrackerWithoutCollections.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$GetDirtyAttributes.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$GetDirtyAttributesWithoutCollections.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$InitializeLazyAttributeLoadingInterceptor.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$SetOwner.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$SuspendDirtyTracking.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/bytecode/enhance/internal/bytebuddy/CodeTemplates$TrackChange.class\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/hibernate-configuration-3.0.dtd\\E"
|
||||
}, {
|
||||
"pattern":"\\Qorg/hibernate/hibernate-mapping-3.0.dtd\\E"
|
||||
}, {
|
||||
"pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt72b/nfc.nrm\\E"
|
||||
}, {
|
||||
|
Loading…
x
Reference in New Issue
Block a user