基于Java的高性能轻量化数据库设计与实现 扩展篇:模块设计

1. Gradle构建结构(Kotlin DSL)

根目录 build.gradle.kts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
plugins {
    `java-library` apply false
}

allprojects {
    group = "com.yinlongfei.lightweight.database"
    version = "1.0.0-SNAPSHOT"
}

subprojects {
    apply(plugin = "java-library")

    java {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    repositories {
        mavenCentral()
    }
}

子模块 settings.gradle.kts

1
2
3
4
5
6
7
8
9
rootProject.name = "lightweight-database"

include("jdbc-driver")
include("sql-parser")
include("query-optimizer")
include("execution-engine")
include("storage-engine")
include("transaction-manager")
include("metadata-manager")

子模块 build.gradle.kts 示例

以下是每个子模块的build.gradle.kts配置,包含外部和内部依赖:

  • jdbc-driver/build.gradle.kts

    1
    2
    3
    4
    5
    6
    
    dependencies {
        implementation(project(":sql-parser"))
        implementation(project(":execution-engine"))
        api("javax.json:javax.json-api:1.1.4")
        implementation("org.glassfish:javax.json:1.1.4")
    }
    
  • sql-parser/build.gradle.kts

    1
    2
    3
    
    dependencies {
        implementation("org.antlr:antlr4-runtime:4.13.1")
    }
    
  • query-optimizer/build.gradle.kts

    1
    
    // 暂无依赖
    
  • execution-engine/build.gradle.kts

    1
    2
    3
    4
    5
    
    dependencies {
        implementation(project(":query-optimizer"))
        implementation(project(":storage-engine"))
        implementation(project(":transaction-manager"))
    }
    
  • storage-engine/build.gradle.kts

    1
    2
    3
    4
    
    dependencies {
        implementation(project(":metadata-manager"))
        implementation("org.roaringbitmap:RoaringBitmap:0.9.45")
    }
    
  • transaction-manager/build.gradle.kts

    1
    
    // 暂无依赖
    
  • metadata-manager/build.gradle.kts

    1
    
    // 暂无依赖
    

2. 外部依赖关系图

外部依赖保持不变,使用Mermaid展示:

graph TD
    A[jdbc-driver] --> B[javax.json-api:1.1.4]
    A --> C[javax.json:1.1.4]
    D[sql-parser] --> E[antlr4-runtime:4.13.1]
    F[storage-engine] --> G[RoaringBitmap:0.9.45]
  • 说明
    • jdbc-driver:依赖JSON-P处理JSON数据。
    • sql-parser:依赖ANTLR解析SQL。
    • storage-engine:依赖RoaringBitmap优化索引。

3. 内部模块依赖关系图

内部依赖关系不变,使用Mermaid展示:

graph TD
    A[jdbc-driver] --> B[sql-parser]
    A --> C[execution-engine]
    C --> D[query-optimizer]
    C --> E[storage-engine]
    C --> F[transaction-manager]
    E --> G[metadata-manager]
  • 依赖说明
    • jdbc-driver:依赖sql-parserexecution-engine
    • execution-engine:依赖query-optimizerstorage-enginetransaction-manager
    • storage-engine:依赖metadata-manager

4. 项目目录结构

目录结构保持不变:

lightweight-database/
├── jdbc-driver/
│   └── src/main/java/com/yinlongfei/lightweight/database/jdbc/
│   └── build.gradle.kts
├── sql-parser/
│   └── src/main/java/com/yinlongfei/lightweight/database/parser/
│   └── build.gradle.kts
├── query-optimizer/
│   └── src/main/java/com/yinlongfei/lightweight/database/optimizer/
│   └── build.gradle.kts
├── execution-engine/
│   └── src/main/java/com/yinlongfei/lightweight/database/execution/
│   └── build.gradle.kts
├── storage-engine/
│   └── src/main/java/com/yinlongfei/lightweight/database/storage/
│   └── build.gradle.kts
├── transaction-manager/
│   └── src/main/java/com/yinlongfei/lightweight/database/transaction/
│   └── build.gradle.kts
├── metadata-manager/
│   └── src/main/java/com/yinlongfei/lightweight/database/metadata/
│   └── build.gradle.kts
├── build.gradle.kts
└── settings.gradle.kts

5. 使用Kotlin DSL的优势

  • 类型安全:Kotlin DSL提供更好的类型检查,减少配置错误。
  • 可读性:语法更简洁,接近现代编程风格。
  • IDE支持:IntelliJ IDEA对Kotlin DSL有更好的自动补全支持。

6. 验证与运行

在根目录运行以下命令验证构建:

1
./gradlew build

编译并打包所有模块:

1
./gradlew assemble
updatedupdated2025-03-312025-03-31