-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:修改适配hoj的user_info表,增加hoj的database配置函数
- Loading branch information
1 parent
4899b28
commit abf7fac
Showing
3 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
40 changes: 39 additions & 1 deletion
40
dbConvertor/src/main/kotlin/cn/kzoj/dbConvertor/hojData/Database.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
9 changes: 4 additions & 5 deletions
9
dbConvertor/src/main/kotlin/cn/kzoj/dbConvertor/hojData/user/UserInfoDAO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
dbConvertor/src/main/kotlin/cn/kzoj/dbConvertor/hojData/user/UserInfoTable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters