DynamicMultipleDataSource.java 501 Bytes
Newer Older
liqin's avatar
liqin committed
1
package cn.chnmuseum.party.common.multidatasource;
liqin's avatar
liqin committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

public class DynamicMultipleDataSource extends AbstractRoutingDataSource {

    @Override
    protected Object determineCurrentLookupKey() {
        String lookupKey = DbContextHolder.getDbType();
        if(lookupKey == null) {
            lookupKey = DBTypeEnum.datasource2.toString();
        }
        DbContextHolder.clearDbType();
        return lookupKey;
    }
}