{"id":14977571,"url":"https://github.com/victorhsr/ttxn","last_synced_at":"2025-07-09T13:08:26.951Z","repository":{"id":178487830,"uuid":"239901084","full_name":"victorhsr/TTXN","owner":"victorhsr","description":"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","archived":false,"fork":false,"pushed_at":"2020-11-05T23:20:00.000Z","size":60,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-09T13:08:13.863Z","etag":null,"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"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/victorhsr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-12T01:24:51.000Z","updated_at":"2024-01-14T00:00:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"a4fca86f-2c5e-49a2-a62e-e74b1ecbacdc","html_url":"https://github.com/victorhsr/TTXN","commit_stats":{"total_commits":25,"total_committers":1,"mean_commits":25.0,"dds":0.0,"last_synced_commit":"152d102c9eaa82e72e813af7c4dc5695725938d1"},"previous_names":["victorhsr/ttxn"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/victorhsr/TTXN","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorhsr%2FTTXN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorhsr%2FTTXN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorhsr%2FTTXN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorhsr%2FTTXN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/victorhsr","download_url":"https://codeload.github.com/victorhsr/TTXN/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorhsr%2FTTXN/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264465848,"owners_count":23612580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["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"],"created_at":"2024-09-24T13:55:55.463Z","updated_at":"2025-07-09T13:08:26.931Z","avatar_url":"https://github.com/victorhsr.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Logo](./ttxn.png)\n\n![Build Status](https://travis-ci.com/victorhsr/TTXN.svg?branch=master)\n\n\u003cb\u003eTenant Transaction\u003c/b\u003e 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\n\n# Quickstart\n\nFirst of all, the tenant transaction is build on top of AspectJ, so we need to allow them:\n```Java\n    @Configuration\n    @EnableAspectJAutoProxy\n    public class AspectConfig {\n    }\n```\nAfter that, we have to expose the `TenantTransactionAOP` bean with the strategy that your project need:\n```Java\n    @Configuration\n    public class TenantTransactionConfiguration {\n\n        @PersistenceContext\n        private EntityManager entityManager;\n\n        @Bean\n        public TenantTransactionAOP getAop(@Value(\"${myapp-default-schema}\") final String defaultSchema){\n\n            final TenantTransactionHandler ttxnHandler = new PostgresqlChangeSchemaTtxnHandler(this.entityManager);\n            return new TenantTransactionAOP(ttxnHandler, defaultSchema);\n        }\n\n    }\n```\n# Usage\nSimilar to using `@Transactional`, we need to annotate the transactional method with `@TenantTransaction` and additionally, mark `@TenantWrapperIdentifier` which parameter contains the tenant to be used\n```Java\n    @Repository\n    public class SomeRepository {\n        \n        @TenantTransaction\n        public void persist(final @TenantWrapperIdentifier TenantWrapper tenantIdentifier, final Entity entity) {\n           // do persist\n        }\n\n    }\n```\n# Strategies\n\n* `PostgresqlChangeSchemaTtxnHandler` the \u003ca href=\"https://www.postgresql.org/\"\u003ePostgresql\u003c/a\u003e 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\n\n* `MysqlChangeDatabaseTtxnHandler` the \u003ca href=\"https://www.mysql.com/\"\u003eMysql\u003c/a\u003e treats the database and schema as one, so, in this strategy the handler make a switch between databases to execut the commands\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorhsr%2Fttxn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorhsr%2Fttxn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorhsr%2Fttxn/lists"}