OSDN Git Service

DBFlute-0.9.3に更新
[ea2ddl/ea2ddl.git] / ea2ddl-dao / src / main / java / jp / sourceforge / ea2ddl / dao / allcommon / InternalMapContext.java
1 package jp.sourceforge.ea2ddl.dao.allcommon;\r
2 \r
3 import java.util.Map;\r
4 import java.util.HashMap;\r
5 \r
6 /**\r
7  * The context of internal map.\r
8  * \r
9  * @author DBFlute(AutoGenerator)\r
10  */\r
11 public class InternalMapContext {\r
12 \r
13     // ===================================================================================\r
14     //                                                                        Thread Local\r
15     //                                                                        ============\r
16     /** The thread-local for this. */\r
17     private static final ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<Map<String, Object>>();\r
18 \r
19         protected static void initialize() {\r
20         if (threadLocal.get() != null) {\r
21             return;\r
22         }\r
23         threadLocal.set(new HashMap<String, Object>());\r
24     }\r
25                 \r
26     /**\r
27      * Get the value of the object by the key.\r
28          * @param key The key of the object. (NotNull)\r
29      * @return The value of the object. (Nullable)\r
30      */\r
31     public static Object getObject(String key) {\r
32             initialize();\r
33         return threadLocal.get().get(key);\r
34     }\r
35 \r
36     /**\r
37      * Set the value of the object.\r
38      * @param key The key of the object. (NotNull)\r
39          * @param value The value of the object. (Nullable)\r
40      */\r
41     public static void setObject(String key, Object value) {\r
42             initialize();\r
43         threadLocal.get().put(key, value);\r
44     }\r
45 \r
46     /**\r
47      * Is existing internal-map-context on thread?\r
48      * \r
49      * @return Determination.\r
50      */\r
51     public static boolean isExistInternalMapContextOnThread() {\r
52         return (threadLocal.get() != null);\r
53     }\r
54 \r
55     /**\r
56      * Clear internal-map-context on thread.\r
57      */\r
58     public static void clearInternalMapContextOnThread() {\r
59         threadLocal.set(null);\r
60     }\r
61 }\r