跳至内容
DFS Binder Database

DFS Binder Database

Transitional binder for small files when object storage is unavailable. S3 is recommended for production and large files.

<dependency>
  <groupId>io.github.loadup-cloud</groupId>
  <artifactId>loadup-components-dfs-binder-database</artifactId>
</dependency>

Select it with loadup.dfs.binder-type=database. Flyway creates the PostgreSQL dfs_file table. The binder uses Spring JDBC, stores file bytes in BYTEA, and stores JSON metadata as text. It supports the common CRUD and metadata capabilities only; presigned URLs and multipart upload are unsupported.

接入步骤

在引入 loadup-framework-bom BOM 的应用中添加:

<dependency><groupId>io.github.loadup-cloud</groupId><artifactId>loadup-components-dfs-binder-database</artifactId></dependency>

通过 loadup.dfs.binder-type 选择 local、s3 或 database;业务层注入 DfsTemplate。 此 jar 负责接入具体技术实现;业务模块继续面向 API/facade 编程。

对外契约

自动装配

设计边界与装配路径见 ARCHITECTURE.md。

最小配置

loadup:
  dfs:
    binder-type: database

同一应用只启用与该值对应的 binder;其他可选项见下方配置类及父模块 README。

默认时区

日期默认使用 JVM 系统本地时区;无偏移日期按本地时区解释,显式偏移和 epoch 时间保持绝对时间语义。

Spring 装配使用 loadup-components-runtime 提供的应用 JSON mapper / Clock;消费者通过参数注入,不创建默认兜底实例。独立测试需显式提供所需 Bean。


设计与实现

职责与边界

文件存储的具体后端适配模块;由集成方按需引入。

Maven 依赖边界

直接依赖的框架模块:

  • loadup-components-dfs-api
  • loadup-components-database

直接依赖的外部坐标(不含测试与 provided scope):

  • org.springframework.boot:spring-boot-starter-flyway
  • org.flywaydb:flyway-mysql
  • tools.jackson.core:jackson-databind
  • org.springframework.boot:spring-boot-autoconfigure

实现入口

主要入口文件:

分层与调用路径

DatabaseDfsTemplate 直接实现 DfsTemplate,通过 PostgreSQL 读写文件内容和元数据。

业务代码 → API/facade → 当前 binder → 第三方引擎或基础设施

binder 实现框架契约,把实现库及其配置隔离在业务 API 之外。

装配规则

  • DatabaseDfsAutoConfiguration 是自动配置入口。
    • @ConditionalOnClass({NamedParameterJdbcTemplate.class, ObjectMapper.class})
    • @ConditionalOnProperty(prefix = "loadup.dfs", name = "binder-type", havingValue = "database")
    • @ConditionalOnMissingBean(DfsTemplate.class)

扩展契约

  • DfsFileInsertMapper is generated from DfsFileInsert by MyBatis-Flex; DatabaseDfsTemplate uses it for file reads and inserts.

设计取舍

选择独立 binder,使文件存储实现的依赖留在集成应用;替换底层实现时,业务侧仍使用 DfsTemplate 契约。

集成方式与配置示例见 README.md。

默认时区

日期默认使用 JVM 系统本地时区;无偏移日期按本地时区解释,显式偏移和 epoch 时间保持绝对时间语义。