我正在与Kotlin一起使用Jooq,我想编写一条语句,该语句从使用使用join语句的几个表的查询中获取数据(附加示例)
我面临的问题是我想将结果映射到我的复杂模型,该模型包含一对多的关系以及很多对很多的关系。
据我所知,我知道我可以在Jooq中使用fetchgroups操作来映射记录,但是我仍然不知道如何将结果放入模型中。
我的模型:
data class MicroserviceDto(
val microservice_id: Long = 1,
val microservice_name: String? = "",
val endpoint: String? = "",
val mappings: String? = "",
val solutionDefinitionMinimalDtoList: List<SolutionDefinitionDto> = emptyList(),
val projectFileDtoList: List<ProjectFileDto> = emptyList()
)
data class SolutionDefinitionDto(
val solution_definition_id: Long = 0L,
val solution_definition_name: String = "",
val solutionId: String = "",
val solutionVersion: String = ""
)
data class ProjectFileDto(
val project_file_id: Long = 1,
val model: String = "",
val relativePath: String = "",
val fileContentDtoList: List<FileContentDto> = emptyList()
)
data class FileContentDto(
val file_content_id: Long = 1,
val content: ByteArray = ByteArray(0)
)
链接到我的架构图 Database Diagram visualization
该图的说明:
微服务与 SolutionDefinistion
ProjectFile 与微服务
ProjectFile 与 SolutionDefinition
FileContent 与 ProjectFile
我已经创建了一个视图来代表我想要的查询,其中包含所有表以及它们之间的联接语句。
这是视图:
CREATE OR REPLACE VIEW Microservice_Metadata_by_Microservice_Id AS
select
# microservice
M.id as `microservice_id`,
M.name as `microservice_name`,
M.mappings,
M.endpoint,
# solution definition
SD.id as `solution_definition_id`,
SD.name as `solution_definition_name`,
SD.solutionId,
SD.solutionVersion,
# project file of microservice
PF.id as `project_file_id`,
PF.relativePath,
PF.model,
# file content data of project file
FC.id as `file_content_id`,
FC.content
from Microservice M
# get project file
left join Microservice_SolutionDefinition MSD
on MSD.microserviceId = M.id
left join ProjectFile PF
on PF.microserviceId = M.id
# get data content
left JOIN FileContent FC
on PF.id = FC.projectFileId
# get solutions of microservice
left join SolutionDefinition SD
on SD.id = MSD.solutionDefinitionId;
如何实现将ResultSet映射到我的数据模型的Jooq dsl查询