Package cn.fantasticmao.mundo.data.jdbc
Annotation Type RoutingSeed
-
@Target({PARAMETER,METHOD,TYPE,FIELD}) @Retention(RUNTIME) @Documented public @interface RoutingSeed
Annotation to declare theDataSourceroute seed. Used on domain type fields, method parameters, method and interface declarations ofSpring-Data Repositories.With
ShardingByMod Strategy, this annotation can be used to implement database sharding. For example:@Entity @Table(name = "t_user") public class User { @Id @RoutingSeed private Integer id; private String name; // ...... } public interface UserRepository extends CrudRepository<User, Integer> { @Override User save(User user); @Override Optional<User> findById(@RoutingSeed Integer id); }With
MultiTenant Strategy, this annotation can be used to implement the multi-tenant database pattern. For example:@Entity @Table(name = "t_employee") public class Employee { @Id private Integer id; private String name; // ...... } public interface EmployeeRepository extends CrudRepository<Employee, Integer> { String DEPARTMENT_SALE = "sale"; String DEPARTMENT_TECH = "tech"; @RoutingSeed(DEPARTMENT_SALE) @Query(value = "SELECT * FROM t_employee WHERE id = ?1", nativeQuery = true) Employee findByIdInSale(Integer id); @RoutingSeed(DEPARTMENT_TECH) @Query(value = "SELECT * FROM t_employee WHERE id = ?1", nativeQuery = true) Employee findByIdInTech(Integer id); }- Since:
- 2022-08-17
- Version:
- 1.0.6
- Author:
- fantasticmao
- See Also:
RoutingDataSource,RoutingSeedContext,RoutingSeedExtractor,RoutingStrategy
-
-
Element Detail
-
value
String value
Set the route seed directly, only works on method and interface declarations.- Returns:
- seed value that has been set
- Default:
- ""
-
-