Extending MyBatis-Plus for ClickHouse: Custom SqlMethodDiv, UpdateByIdClickHouse, and Injector Implementation

This article demonstrates how to extend MyBatis-Plus to support ClickHouse-specific DML operations by defining custom SQL method enums, implementing UpdateByIdClickHouse and ClickHouseSqlInjector classes, creating a SuperMapper interface with new CRUD methods, and providing unit tests to verify the integration.

Top Architect
Top Architect
Top Architect
Extending MyBatis-Plus for ClickHouse: Custom SqlMethodDiv, UpdateByIdClickHouse, and Injector Implementation

Project scenario: extending MyBatis‑Plus to support ClickHouse DML operations that differ from MySQL.

Custom enum SqlMethodDiv defines SQL templates for delete, logic delete, update by ID, and generic update.

Class UpdateByIdClickHouse extends AbstractMethod and overrides injectMappedStatement to generate ClickHouse‑specific UPDATE statements, handling optimistic lock and logical delete.

Utility method convertSet trims trailing commas in generated SET clauses.

Injector ClickHouseSqlInjector registers the custom methods by extending DefaultSqlInjector.

Interface SuperMapper extends BaseMapper and declares custom methods updateByIdClickHouse, updateClickHouse, and deleteByIdClickHouse.

Unit tests demonstrate CRUD operations using the extended mapper in a Spring Boot test context.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaClickHouseSpring Bootmybatis-plus
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.