重构:使用 MyBatis-Flex 迁移应用 ORM
将应用自管表的 JdbcClient 数据访问迁移为实体、Mapper、构造器查询和必要的显式 SQL。 保留 AgentScope 自管表及原有业务语义,并补充事务、查询与数据库集成测试。
This commit is contained in:
37
server/src/main/resources/mapper/ArtifactMapper.xml
Normal file
37
server/src/main/resources/mapper/ArtifactMapper.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="tech.easyflow.manuagent.mapper.ArtifactMapper">
|
||||
|
||||
<!--
|
||||
PostgreSQL 的 INSERT ... RETURNING 属于会修改数据的查询语句。
|
||||
affectData 与 flushCache 确保 MyBatis 按 DML 事务语义处理并清理一级缓存。
|
||||
-->
|
||||
<select id="upsert"
|
||||
resultType="tech.easyflow.manuagent.entity.ArtifactEntity"
|
||||
affectData="true"
|
||||
flushCache="true">
|
||||
INSERT INTO app.artifact(
|
||||
id, project_id, run_id, kind, name, relative_path, mime_type,
|
||||
size_bytes, sha256, metadata_json)
|
||||
VALUES (
|
||||
#{artifact.id, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler},
|
||||
#{artifact.projectId, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler},
|
||||
#{artifact.runId, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler},
|
||||
#{artifact.kind}, #{artifact.name}, #{artifact.relativePath}, #{artifact.mimeType},
|
||||
#{artifact.sizeBytes}, #{artifact.sha256},
|
||||
#{artifact.metadataJson, jdbcType=OTHER, typeHandler=tech.easyflow.manuagent.typehandler.JsonbStringTypeHandler})
|
||||
ON CONFLICT (project_id, relative_path) DO UPDATE SET
|
||||
run_id = EXCLUDED.run_id,
|
||||
kind = EXCLUDED.kind,
|
||||
name = EXCLUDED.name,
|
||||
mime_type = EXCLUDED.mime_type,
|
||||
size_bytes = EXCLUDED.size_bytes,
|
||||
sha256 = EXCLUDED.sha256,
|
||||
metadata_json = EXCLUDED.metadata_json,
|
||||
published_at = CURRENT_TIMESTAMP
|
||||
<!-- 发布接口只需要产物视图字段,下载字段由独立下载查询按需读取。 -->
|
||||
RETURNING id, project_id, run_id, kind, name, size_bytes, metadata_json, published_at
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user