org.n3r.eql.mtcp.MtcpContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eql Show documentation
Show all versions of eql Show documentation
a simple wrapper framework for jdbc to seperate sql and java code
package org.n3r.eql.mtcp;
import org.slf4j.MDC;
public class MtcpContext {
public static final String TENANT_ID = "tenantId";
public static final String TENANT_CODE = "tenantCode";
private static ThreadLocal tenantIdLocal = new InheritableThreadLocal();
private static ThreadLocal tenantCodeLocal = new InheritableThreadLocal();
public static void setTenantId(String tenantId) {
tenantIdLocal.set(tenantId);
MDC.put(TENANT_ID, tenantId);
}
public static void setTenantCode(String tenantCode) {
tenantCodeLocal.set(tenantCode);
MDC.put(TENANT_CODE, tenantCode);
}
public static String getTenantId() {
return tenantIdLocal.get();
}
public static String getTenantCode() {
return tenantCodeLocal.get();
}
public static void clearTenant() {
clearTenantId();
clearTenantCode();
}
private static void clearTenantCode() {
String tenantCode = getTenantCode();
if (tenantCode != null) MDC.remove(TENANT_CODE);
tenantCodeLocal.remove();
}
private static void clearTenantId() {
String tenantId = getTenantId();
if (tenantId != null) MDC.remove(TENANT_ID);
tenantIdLocal.remove();
}
public static void clear() {
clearTenant();
}
}