Skip to content

Commit

Permalink
feat:修改适配hoj的user_info表,增加hoj的database配置函数
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoyuanyu committed Nov 2, 2024
1 parent 4899b28 commit abf7fac
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
package cn.kzoj.dbConvertor.hojData

fun configureDatabase() {
import cn.kzoj.dbConvertor.hojData.problem.ProblemTable
import cn.kzoj.dbConvertor.hojData.problemcase.ProblemCaseTable
import cn.kzoj.dbConvertor.hojData.user.UserInfoTable
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction

@Suppress("DuplicatedCode")
fun configureHojDatabase(
url: String,
driver: String,
user: String,
password: String
): Database {
// 配置HiKari
val dataSource = HikariDataSource(
HikariConfig().apply {
jdbcUrl = url
driverClassName = driver
username = user
this.password = password
maximumPoolSize = 6
isReadOnly = false
transactionIsolation = "TRANSACTION_SERIALIZABLE"
}
)

// 创建database实例
val database = Database.connect(datasource=dataSource)

// 第一次transaction与数据库建立连接
transaction(database) {
SchemaUtils.create(ProblemTable)
SchemaUtils.create(ProblemCaseTable)
SchemaUtils.create(UserInfoTable)
}

return database
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package cn.kzoj.dbConvertor.hojData.user

import org.jetbrains.exposed.dao.UUIDEntity
import org.jetbrains.exposed.dao.UUIDEntityClass
import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.EntityClass
import org.jetbrains.exposed.dao.id.EntityID
import java.util.UUID

@Suppress("unused")
class UserInfoDAO(uuid: EntityID<UUID>) : UUIDEntity(uuid) {
companion object: UUIDEntityClass<UserInfoDAO>(UserInfoTable)
class UserInfoDAO(uuid: EntityID<String>) : Entity<String>(uuid) {
companion object: EntityClass<String, UserInfoDAO>(UserInfoTable)

var username by UserInfoTable.username
var password by UserInfoTable.password
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cn.kzoj.dbConvertor.hojData.user

import org.jetbrains.exposed.dao.id.UUIDTable
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.sql.Column

object UserInfoTable: UUIDTable("user_info") {
object UserInfoTable: IdTable<String>("user_info") {

override val id: Column<EntityID<String>> = text("uuid").entityId()

val username: Column<String> = text("username")

Expand Down

0 comments on commit abf7fac

Please sign in to comment.