From 3e18d4bfbf2c657b08b21512c2d884cc9d59df7b Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期一, 14 十月 2024 16:29:49 +0800
Subject: [PATCH] 模型运行

---
 iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/context/DataContextHolder.java |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/context/DataContextHolder.java b/iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/context/DataContextHolder.java
new file mode 100644
index 0000000..297ed1d
--- /dev/null
+++ b/iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/context/DataContextHolder.java
@@ -0,0 +1,45 @@
+package com.iailab.framework.tenant.core.context;
+
+import com.alibaba.ttl.TransmittableThreadLocal;
+import com.iailab.framework.common.enums.DocumentEnum;
+
+/**
+ * 数据源上下文 Holder
+ *
+ * @author iailab
+ */
+public class DataContextHolder {
+
+    /**
+     * 数据源id
+     */
+    private static final ThreadLocal<Long> DATA_SOURCE_ID =  new TransmittableThreadLocal<>();
+
+    /**
+     * 数据源id
+     *
+     * @return 租户编号
+     */
+    public static Long getDataSourceId() {
+        return DATA_SOURCE_ID.get();
+    }
+
+    /**
+     * 数据源id。如果不存在,则抛出 NullPointerException 异常
+     *
+     * @return 租户编号
+     */
+    public static Long getRequiredDataSourceId() {
+        Long dataSourceId = getDataSourceId();
+        if (dataSourceId == null) {
+            throw new NullPointerException("DataContextHolder 不存在数据源id!可参考文档:"
+                + DocumentEnum.TENANT.getUrl());
+        }
+        return dataSourceId;
+    }
+
+    public static void setDataSourceId(Long dataSourceId) {
+        DATA_SOURCE_ID.set(dataSourceId);
+    }
+
+}

--
Gitblit v1.9.3