me.wuwenbin.modules.mongodb.support.MongoContextHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of template-modules-mongodb Show documentation
Show all versions of template-modules-mongodb Show documentation
提供对mongo数据源的高级操作,针对多数据源mongo和集群mongo
package me.wuwenbin.modules.mongodb.support;
import me.wuwenbin.modules.mongodb.support.bo.MongoContext;
/**
* 处理同一线程下的切换数据源的问题
* Created by wuwenbin on 2017/5/4.
*/
public class MongoContextHolder {
private static final ThreadLocal mongoContextHolder = new ThreadLocal<>();
public static void setHolder(String key, String database) {
mongoContextHolder.set(MongoContext.create(key, database));
}
public static MongoContext getHolder() {
return mongoContextHolder.get();
}
public static void clearHolder() {
mongoContextHolder.remove();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy