How newcubator/jdbc-excel works
Project type and purpose
• This is a pure-Java, Gradle-based library (jdbc-excel) whose sole purpose is to generate Excel spreadsheets from JDBC queries and expose an API for programmatic use.
• It is not a full-stack application or microservice; rather it is a reusable component (jar) with a core ExcelWriter, a family of CellWriter strategies, configuration objects, and tab abstractions.
File structure
• Top-level Gradle files and GitHub workflows automate build, test, and Maven Central releases.
• src/main/java/com/newcubator/jdbcexcel: the root package.
• ExcelWriter.java – the façade entry point.
• configuration/ExportConfiguration.java – holds user settings (sheet names, SQL, cell styles, etc.).
• tabs/ExcelTab.java & DefaultExcelTab.java – abstractions over a single worksheet.
• cellwriters/ – a strategy pattern: AbstractCellWriter + concrete writers for String, Number, Date, BigDecimal, Boolean, hintText, replaceableString, Object.
• src/test/groovy – integration and unit tests verifying interaction with a live H2 (data.sql) and cell-writer behavior.
Readme insights
• Confirms it’s a library hosted on Maven Central.
Diagramming the architecture
a. Main components:
• Client Code (your application)
• JDBC DataSource / Connection (e.g., H2, MySQL)
• ExportConfiguration (holds SQL, sheet metadata, style hints)
• ExcelWriter – orchestrator
• ExcelTab & DefaultExcelTab – per-sheet logic
• CellWriter hierarchy – strategy implementations
• Apache POI (or similar Excel engine)
• Output (FileSystem or OutputStream)
b. Relationships / interactions:
1. Client instantiates ExportConfiguration with a JDBC DataSource, SQL, sheet definitions.
2. Client calls ExcelWriter.export(ExportConfiguration).
3. ExcelWriter opens Connection, executes query, obtains ResultSet.
4. For each row and column:
– ExcelWriter delegates to DefaultExcelTab which picks the correct CellWriter (via cell type or user override).
– CellWriter writes value + style into a POI Workbook cell.
5. After iterating, ExcelWriter hands the populated Workbook to an output sink.
c. Architectural patterns / principles:
– Strategy pattern: CellWriter interface + concrete implementations.
– Single Responsibility: ExcelWriter orchestrates, ExportConfiguration holds settings, ExcelTab handles per-sheet logic.
– Dependency Injection: configuration passed into ExcelWriter.
d. Key technologies & libraries:
– Java 8+ (or compatible)
– Gradle build system
– JDBC API
– Apache POI (or similar) for Excel generation
– Groovy + Spock for testing (in tests)