wuxw
2020-07-05 b0263fef69e3d3cd38099f5ef098706ac96e6070
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.java110.core.factory;
 
import com.java110.utils.util.StringUtil;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * @ClassName Java110TransactionalFactory
 * @Description TODO
 * @Author wuxw
 * @Date 2020/7/3 22:30
 * @Version 1.0
 * add by wuxw 2020/7/3
 **/
public class Java110TransactionalFactory {
 
    //全局事务ID
    public static final String T_ID = "t-id";
 
    //当前服务ID
    public static final String SERVICE_ID = "service-id";
 
    private static ThreadLocal<Map<String, String>> threadLocal = new ThreadLocal<Map<String, String>>() {
        @Override
        protected Map<String, String> initialValue() {
            return new HashMap<String, String>();
        }
    };
 
    public static String put(String key, String value) {
        return threadLocal.get().put(key, value);
    }
 
    public static String get(String key) {
        return threadLocal.get().get(key);
    }
 
    public static String remove(String key) {
        return threadLocal.get().remove(key);
    }
 
    public static Map<String, String> entries() {
        return threadLocal.get();
    }
 
    public static String getOrCreateTId(){
        String tId = get(T_ID);
 
        if(StringUtil.isEmpty(tId)){
 
        }
        return "";
    }
 
    private void createTId(){
 
    }
 
}