Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/victorhsr/ttxn
Tenant Transaction is an almost zero-configuration and lightweight plugin for spring framework that allows to change the tenant that will be used in any transaction/queries dynamically
https://github.com/victorhsr/ttxn
aspect-oriented-programming aspectj jpa-hibernate library multitenancy multitenant plugin postgresql spring spring-boot spring-data spring-framework tenant tenant-management tenant-resolver transaction transaction-manager transactional
Last synced: 4 months ago
JSON representation
Tenant Transaction is an almost zero-configuration and lightweight plugin for spring framework that allows to change the tenant that will be used in any transaction/queries dynamically
- Host: GitHub
- URL: https://github.com/victorhsr/ttxn
- Owner: victorhsr
- License: mit
- Created: 2020-02-12T01:24:51.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-05T23:20:00.000Z (about 4 years ago)
- Last Synced: 2024-10-11T16:05:04.741Z (4 months ago)
- Topics: aspect-oriented-programming, aspectj, jpa-hibernate, library, multitenancy, multitenant, plugin, postgresql, spring, spring-boot, spring-data, spring-framework, tenant, tenant-management, tenant-resolver, transaction, transaction-manager, transactional
- Language: Java
- Homepage:
- Size: 58.6 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
![Logo](./ttxn.png)
![Build Status](https://travis-ci.com/victorhsr/TTXN.svg?branch=master)
Tenant Transaction is an almost zero-configuration and lightweight plugin for spring framework that allows to change the tenant that will be used in any transaction/queries dynamically. It still keep all the features of spring's `@Transactional` annotation
# Quickstart
First of all, the tenant transaction is build on top of AspectJ, so we need to allow them:
```Java
@Configuration
@EnableAspectJAutoProxy
public class AspectConfig {
}
```
After that, we have to expose the `TenantTransactionAOP` bean with the strategy that your project need:
```Java
@Configuration
public class TenantTransactionConfiguration {@PersistenceContext
private EntityManager entityManager;@Bean
public TenantTransactionAOP getAop(@Value("${myapp-default-schema}") final String defaultSchema){final TenantTransactionHandler ttxnHandler = new PostgresqlChangeSchemaTtxnHandler(this.entityManager);
return new TenantTransactionAOP(ttxnHandler, defaultSchema);
}}
```
# Usage
Similar to using `@Transactional`, we need to annotate the transactional method with `@TenantTransaction` and additionally, mark `@TenantWrapperIdentifier` which parameter contains the tenant to be used
```Java
@Repository
public class SomeRepository {
@TenantTransaction
public void persist(final @TenantWrapperIdentifier TenantWrapper tenantIdentifier, final Entity entity) {
// do persist
}}
```
# Strategies* `PostgresqlChangeSchemaTtxnHandler` the Postgresql supports multiple schemas in the same database, and this strategy take advantage of this feature and switch between schemas to execut the commands in database
* `MysqlChangeDatabaseTtxnHandler` the Mysql treats the database and schema as one, so, in this strategy the handler make a switch between databases to execut the commands