Skip to content

Commit 57da18b

Browse files
committed
chore: simplify code by using spring context lazy annotation
1 parent 06424a0 commit 57da18b

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/main/kotlin/co/statu/rule/database/DatabaseManager.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.vertx.core.json.JsonObject
1010
import io.vertx.jdbcclient.JDBCPool
1111
import org.slf4j.Logger
1212
import org.springframework.beans.factory.config.ConfigurableBeanFactory
13+
import org.springframework.context.annotation.Lazy
1314
import org.springframework.context.annotation.Scope
1415
import org.springframework.stereotype.Component
1516
import java.sql.BatchUpdateException
@@ -20,12 +21,8 @@ import kotlin.system.exitProcess
2021
class DatabaseManager(
2122
private val vertx: Vertx,
2223
private val logger: Logger,
23-
private val databasePlugin: DatabasePlugin
24+
@Lazy private val pluginConfigManager: PluginConfigManager<DatabaseConfig>
2425
) {
25-
private val pluginConfigManager by lazy {
26-
databasePlugin.pluginBeanContext.getBean(PluginConfigManager::class.java) as PluginConfigManager<DatabaseConfig>
27-
}
28-
2926
private lateinit var pool: JDBCPool
3027

3128
private val tables = mutableMapOf<ParsekPlugin, MutableList<Dao<*>>>()

src/main/kotlin/co/statu/rule/database/CoreEventHandler.kt renamed to src/main/kotlin/co/statu/rule/database/event/CoreEventHandler.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
package co.statu.rule.database
1+
package co.statu.rule.database.event
22

33
import co.statu.parsek.PluginEventManager
44
import co.statu.parsek.api.annotation.EventListener
55
import co.statu.parsek.api.config.PluginConfigManager
66
import co.statu.parsek.api.event.CoreEventListener
77
import co.statu.parsek.config.ConfigManager
8-
import co.statu.rule.database.event.DatabaseEventListener
8+
import co.statu.rule.database.DatabaseConfig
9+
import co.statu.rule.database.DatabaseManager
10+
import co.statu.rule.database.DatabasePlugin
911
import org.slf4j.Logger
12+
import org.springframework.context.annotation.Lazy
1013

1114
@EventListener
1215
class CoreEventHandler(
1316
private val logger: Logger,
1417
private val databasePlugin: DatabasePlugin,
18+
@Lazy private val databaseManager: DatabaseManager
1519
) : CoreEventListener {
16-
private val databaseManager by lazy {
17-
databasePlugin.pluginBeanContext.getBean(DatabaseManager::class.java)
18-
}
19-
2020
override suspend fun onConfigManagerReady(configManager: ConfigManager) {
2121
val pluginConfigManager = PluginConfigManager(
2222
databasePlugin,

0 commit comments

Comments
 (0)