Giter Club home page Giter Club logo

ttxn's Introduction

Logo

Build Status

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:

    @Configuration
    @EnableAspectJAutoProxy
    public class AspectConfig {
    }

After that, we have to expose the TenantTransactionAOP bean with the strategy that your project need:

    @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

    @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

ttxn's People

Contributors

victorhsr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

thaingo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.