All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.anwen.mongo.context.MongoTransactionContext Maven / Gradle / Ivy

There is a newer version: 2.1.5
Show newest version
package com.anwen.mongo.context;

import com.mongodb.client.ClientSession;

/**
 * * @description TODO
 * * @author [email protected]
 * * @date 2023/09/17 17:42
 */
public class MongoTransactionContext {
    private static final ThreadLocal threadLocalHeaderMap = new ThreadLocal<>();

    public MongoTransactionContext() {
    }

    public static ClientSession getClientSessionContext() {
        MongoTransactionStatus status = getMongoTransactionStatus();
        if (status != null) {
            return status.getClientSession();
        }
        return null;
    }

    public static MongoTransactionStatus getMongoTransactionStatus() {
        return threadLocalHeaderMap.get();
    }

    public static void setTransactionStatus(MongoTransactionStatus mongoTransactionStatus) {
        threadLocalHeaderMap.set(mongoTransactionStatus);
    }

    public static void clear() {
        threadLocalHeaderMap.remove();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy