The Best Multi-Tenant Plugin - druid-multi-tenant-starter

The Best Multi-Tenant Plugin - druid-multi-tenant-starter

Since July 16, 2024 The druid-multi-tenant-starter plugin has been released for more than two years. The launch of this new tool marks the birth of an efficient and convenient SaaS multi-tenant management solution, providing developers with a brand new convenient experience.

What is druid-multi-tenant-starter?

druid-multi-tenant-starter is a multi-tenant plugin based on MyBatis interceptor and alibaba Druid SQL parser. It aims to simplify multi-tenant management in SaaS (Software as a Service) platforms, providing an out-of-the-box, easy-to-configure solution that enables developers to easily achieve multi-tenant data isolation and management.

Main Features and Advantages

  1. Seamless Integration: As an out-of-the-box plugin, druid-multi-tenant-starter can be perfectly integrated with the existing MyBatis framework, avoiding cumbersome configuration and code modification. Just a small amount of configuration is required to enable multi-tenant functionality, greatly improving development efficiency.

  2. Powerful SQL Parsing: Utilizing the powerful SQL parsing ability of alibaba Druid, druid-multi-tenant-starter can accurately parse and handle SQL statements, ensuring data isolation and security in a multi-tenant environment. Whether it's query, update, or delete operations, they can all be effectively managed and controlled.

  3. Flexible Tenant Management: The plugin provides a variety of flexible tenant management strategies, allowing developers to define and adjust tenant identification methods according to actual needs. This makes it adaptable to different application scenarios and provides personalized solutions.

  4. Performance Optimization: druid-multi-tenant-starter parses SQL statements based on the alibaba Druid SQL parsing library, which is more powerful in performance than a certain tenant plugin that parses SQL statements based on JSQLParser.

Usage Scenarios

  • SaaS Application Platforms: druid-multi-tenant-starter is particularly suitable for SaaS platforms that need to support multiple tenants. It can ensure the data security and isolation of different tenants and prevent data crossover and leakage.

  • Enterprise Systems: For enterprises that need to manage the data of multiple business units or subsidiaries in the same system, druid-multi-tenant-starter provides an ideal solution, simplifying data management and maintenance work.

  • Data Sharing Platforms: In scenarios where multi-party data sharing is required while data isolation needs to be ensured, druid-multi-tenant-starter can effectively support the management needs of different data sources.

Support for Ignoring TenantId Strategy

  • Support skipping if the tenantId field condition already exists in the original SQL statement.
  • Support ignoring the addition of the tenantId field condition for the specified table name.
  • Support ignoring the addition of the tenantId field condition for the specified Mapper interface SQL statement.
  • Support specifying the table name to ignore the addition of the tenantId field condition in the SQL statement.
  • Support specifying the alias to ignore the addition of the tenantId field condition in the SQL statement.
  • Support tenant ID to be passed in from the Mapper interface method parameter.

Quick Start

  • In the already integrated Mybatis project, introduce the following dependency.

<dependency> <groupId>io.github.osinn</groupId> <artifactId>druid-multi-tenant-starter</artifactId> <version>1.4.7</version></dependency>

Configuration

-- Basic configurationmybatis:  tenant: config:# Whether to enable the multi-tenant pluginenable: true# The column name of the tenant ID in the databasetenant-id-column: tenant_id

Implement the Interface for Providing the Multi-Tenant Value

  • Need to implement the ITenantService interface to provide the value of the multi-tenant ID.
/** * Demonstration: Provide the multi-tenant ID service interface * * @author wency_cai */@Servicepublic class TenantServiceImpl implements ITenantService<Integer>{ @Override public List<Integer> getTenantIds() {  // Query the multi-tenant id of the system, and if there are multiple, return multiple values.  int tenantId = 1;  return Lists.newArrayList(tenantId); }}
  • So far, the integration of the druid-multi-tenant-starter tenant plugin is completed.
  • In the SQL statements written in the project, there is no need to care about the tenant ID field. Just write the SQL statements as usual, and the underlying will tamper with the SQL statements to generate new SQL statements for execution.

Conclusion

The druid-multi-tenant-starter has been running normally in the production environment for more than two years since its release. It not only simplifies the development work in the multi-tenant environment but also improves the performance and security of the system. We look forward to this plugin helping more developers and enterprises manage their multi-tenant systems efficiently and achieve rapid business development and success.

Project address: Click

Likes