-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
179 additions
and
136 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
26 changes: 25 additions & 1 deletion
26
game-server/src/main/kotlin/work/fking/pangya/game/persistence/PersistenceContext.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,11 +1,35 @@ | ||
package work.fking.pangya.game.persistence | ||
|
||
import org.jooq.DSLContext | ||
|
||
data class PersistenceContext( | ||
val jooq: DSLContext?, | ||
val playerRepository: PlayerRepository = InMemoryPlayerRepository(), | ||
val characterRepository: CharacterRepository = InMemoryCharacterRepository(), | ||
val caddieRepository: CaddieRepository = InMemoryCaddieRepository(), | ||
val inventoryRepository: InventoryRepository = InMemoryInventoryRepository(), | ||
val equipmentRepository: EquipmentRepository = InMemoryEquipmentRepository(), | ||
val statisticsRepository: StatisticsRepository = InMemoryStatisticsRepository(), | ||
val achievementsRepository: AchievementsRepository = InMemoryAchievementsRepository() | ||
) | ||
) { | ||
|
||
/** | ||
* Returns a transactional context without an active transaction. | ||
*/ | ||
fun noTxContext() = TransactionalContext(jooq) | ||
|
||
/** | ||
* Returns a transactional context with an active transaction. | ||
*/ | ||
fun transactional(transactional: (txContext: TransactionalContext) -> Unit) { | ||
if (jooq != null) { | ||
jooq.transaction { tx -> transactional(TransactionalContext(tx.dsl())) } | ||
} else { | ||
transactional(TransactionalContext()) | ||
} | ||
} | ||
} | ||
|
||
data class TransactionalContext(private val jooq: DSLContext? = null) { | ||
fun jooq(): DSLContext = jooq ?: throw IllegalStateException("no jooq context available") | ||
} |
Oops, something went wrong.