Source Code Cross Referenced for ThreadSession.java in  » Database-ORM » ODAL » com » completex » objective » components » persistency » mapper » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » ODAL » com.completex.objective.components.persistency.mapper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.completex.objective.components.persistency.mapper;
002:
003:        import com.completex.objective.components.persistency.mapper.Mapper;
004:
005:        import java.util.HashMap;
006:        import java.util.Iterator;
007:        import java.util.Map;
008:
009:        /**
010:         * Class that holds references to Persistent OBjects and the corresponding POJO beans called 
011:         * for modification in current thread.
012:         * 
013:         * @author Gennady Krizhevsky
014:         */
015:        public class ThreadSession {
016:
017:            private static ThreadLocal sessionContext = new ThreadLocal() {
018:                protected synchronized Object initialValue() {
019:                    return new MapperContextsMap();
020:                }
021:            };
022:
023:            public static void set(Mapper mapper, Object bean, Object po) {
024:                if (bean != null && po != null) {
025:                    MapperContextsMap map = getContextMap();
026:                    map.put(mapper, bean, po);
027:                }
028:            }
029:
030:            public static Object getPo(Mapper mapper, Object bean) {
031:                Object po = null;
032:                if (bean != null) {
033:                    MapperContextsMap map = getContextMap();
034:                    po = map.getByBean(mapper, bean);
035:                }
036:                return po;
037:            }
038:
039:            public static Object getBean(Mapper mapper, Object po) {
040:                Object bean = null;
041:                if (po != null) {
042:                    MapperContextsMap map = getContextMap();
043:                    bean = map.getByPo(mapper, po);
044:                }
045:                return bean;
046:            }
047:
048:            public static void unsetByBean(Mapper mapper, Object bean) {
049:                if (bean != null) {
050:                    MapperContextsMap map = getContextMap();
051:                    map.removeByBean(mapper, bean);
052:                }
053:            }
054:
055:            public static void unsetByPo(Mapper mapper, Object po) {
056:                if (po != null) {
057:                    MapperContextsMap map = getContextMap();
058:                    map.removeByPo(mapper, po);
059:                }
060:            }
061:
062:            public static String dump() {
063:                return getContextMap().toString();
064:            }
065:
066:            public static boolean containsPo(Mapper mapper, Object po) {
067:                return getBean(mapper, po) != null;
068:            }
069:
070:            public static boolean containsBean(Mapper mapper, Object bean) {
071:                return getPo(mapper, bean) != null;
072:            }
073:
074:            public static void clear(Mapper mapper) {
075:                getContextMap().clear(mapper);
076:            }
077:
078:            public static void clear() {
079:                getContextMap().clear();
080:            }
081:
082:            public static void clearAll() {
083:                getContextMap().clearAll();
084:            }
085:
086:            public static MapperContextsMap getContextMap() {
087:                return (MapperContextsMap) (sessionContext.get());
088:            }
089:
090:            /**
091:             * Map of ContextMaps: Map<mapper.class, ContextMaps>
092:             */
093:            static class MapperContextsMap {
094:                private HashMap mapperContexts = new HashMap();
095:
096:                public void put(Mapper mapper, Object bean, Object po) {
097:                    ContextMap contextMap = lazyContextMap(mapper);
098:                    contextMap.put(bean, po);
099:                }
100:
101:                public void removeByBean(Mapper mapper, Object bean) {
102:                    ContextMap contextMap = lazyContextMap(mapper);
103:                    contextMap.removeByBean(bean);
104:                }
105:
106:                public void removeByPo(Mapper mapper, Object po) {
107:                    ContextMap contextMap = lazyContextMap(mapper);
108:                    contextMap.removeByPo(po);
109:                }
110:
111:                public Object getByBean(Mapper mapper, Object bean) {
112:                    ContextMap contextMap = lazyContextMap(mapper);
113:                    return contextMap.getByBean(bean);
114:                }
115:
116:                public Object getByPo(Mapper mapper, Object po) {
117:                    ContextMap contextMap = lazyContextMap(mapper);
118:                    return contextMap.getByPo(po);
119:                }
120:
121:                public void clear(Mapper mapper) {
122:                    Class aClass = mapper.getClass();
123:                    clear(aClass);
124:                }
125:
126:                protected void clear(Class aClass) {
127:                    ContextMap contextMap = (ContextMap) mapperContexts
128:                            .get(aClass);
129:                    if (contextMap != null) {
130:                        contextMap.clear();
131:                    }
132:                }
133:
134:                public void clear() {
135:                    for (Iterator it = mapperContexts.keySet().iterator(); it
136:                            .hasNext();) {
137:                        Class key = (Class) it.next();
138:                        clear(key);
139:                    }
140:                }
141:
142:                public void clearAll() {
143:                    clear();
144:                    mapperContexts.clear();
145:                }
146:
147:                private ContextMap lazyContextMap(Mapper mapper) {
148:                    ContextMap contextMap = (ContextMap) mapperContexts
149:                            .get(mapper.getClass());
150:                    if (contextMap == null) {
151:                        contextMap = new ContextMap();
152:                        mapperContexts.put(mapper.getClass(), contextMap);
153:                    }
154:                    return contextMap;
155:                }
156:
157:                public HashMap getMapperContexts() {
158:                    return mapperContexts;
159:                }
160:
161:                public String toString() {
162:                    return super .toString() + mapperContexts.toString();
163:                }
164:            }
165:
166:            /**
167:             *  The ContextMap implementation guaranties for mamory to be limited in size as long 
168:             *  as outside hard references (to the objects stored in it) number is limited.
169:             */
170:            public static class ContextMap {
171:                private Map beanPoMap = new HashMap();
172:                private Map poBeanMap = new HashMap();
173:
174:                public Map getBeanPoMap() {
175:                    return beanPoMap;
176:                }
177:
178:                public Map getPoBeanMap() {
179:                    return poBeanMap;
180:                }
181:
182:                public void put(Object bean, Object po) {
183:                    beanPoMap.put(bean, po);
184:                    poBeanMap.put(po, bean);
185:                }
186:
187:                public void removeByBean(Object bean) {
188:                    Object po = beanPoMap.remove(bean);
189:                    poBeanMap.remove(po);
190:                }
191:
192:                public void removeByPo(Object po) {
193:                    Object bean = beanPoMap.remove(po);
194:                    poBeanMap.remove(bean);
195:                }
196:
197:                public Object getByBean(Object bean) {
198:                    return beanPoMap.get(bean);
199:                }
200:
201:                public Object getByPo(Object po) {
202:                    return poBeanMap.get(po);
203:                }
204:
205:                public void clear() {
206:                    beanPoMap.clear();
207:                    poBeanMap.clear();
208:                }
209:
210:                public int beanPoMapSize() {
211:                    return beanPoMap.size();
212:                }
213:
214:                public int poBeanMapSize() {
215:                    return poBeanMap.size();
216:                }
217:
218:                public String toString() {
219:                    return super.toString() + beanPoMap.toString();
220:                }
221:
222:            }
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.