Revision 80de230c
Added by Cherian Mathew over 9 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import java.util.Collection; |
13 | 13 |
import java.util.HashMap; |
14 |
import java.util.HashSet; |
|
15 |
import java.util.List; |
|
16 | 14 |
import java.util.Map; |
17 | 15 |
|
18 | 16 |
import org.apache.log4j.Logger; |
19 | 17 |
import org.springframework.stereotype.Component; |
20 | 18 |
|
21 |
import eu.etaxonomy.cdm.api.cache.CachedCommonServiceImpl; |
|
22 |
import eu.etaxonomy.cdm.api.cache.CdmClientCacheException; |
|
23 |
import eu.etaxonomy.cdm.api.cache.CdmClientCachingTest; |
|
24 | 19 |
import eu.etaxonomy.cdm.api.cache.CdmTransientEntityCacher; |
25 |
import eu.etaxonomy.cdm.api.service.IService; |
|
26 | 20 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
27 | 21 |
|
28 | 22 |
/** |
... | ... | |
43 | 37 |
private CdmTransientEntityCacher latestEntityCacher = |
44 | 38 |
new CdmTransientEntityCacher("latestEntityCacher", this); |
45 | 39 |
|
46 |
private CdmEntitySession activeSession; |
|
40 |
private ICdmEntitySession activeSession; |
|
41 |
|
|
47 | 42 |
|
48 | 43 |
/* (non-Javadoc) |
49 | 44 |
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#getActiveSession() |
50 | 45 |
*/ |
51 | 46 |
@Override |
52 |
public CdmEntitySession getActiveSession() { |
|
47 |
public ICdmEntitySession getActiveSession() {
|
|
53 | 48 |
return activeSession; |
54 | 49 |
} |
55 | 50 |
|
... | ... | |
57 | 52 |
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#getSession(eu.etaxonomy.taxeditor.session.ISessionEventListener) |
58 | 53 |
*/ |
59 | 54 |
@Override |
60 |
public CdmEntitySession getSession(ISessionEventListener sessionOwner) { |
|
55 |
public ICdmEntitySession getSession(ISessionEventListener sessionOwner) {
|
|
61 | 56 |
if(sessionOwner == null) { |
62 | 57 |
return null; |
63 | 58 |
} |
64 | 59 |
|
65 |
CdmEntitySession session = ownerSessionMap.get(sessionOwner); |
|
60 |
ICdmEntitySession session = ownerSessionMap.get(sessionOwner);
|
|
66 | 61 |
if(session == null) { |
67 | 62 |
logger.info("No session exists for session owner with class : " + sessionOwner.getClass().getName()); |
68 | 63 |
} |
69 | 64 |
return session; |
70 | 65 |
} |
71 | 66 |
|
72 |
private CdmEntitySession newSession(ISessionEventListener sessionOwner, boolean setAsActive) { |
|
67 |
private ICdmEntitySession newSession(ISessionEventListener sessionOwner, boolean setAsActive) {
|
|
73 | 68 |
CdmEntitySession session = ownerSessionMap.get(sessionOwner); |
74 | 69 |
if(session == null) { |
75 | 70 |
session = new CdmEntitySession(sessionOwner, this); |
... | ... | |
87 | 82 |
*/ |
88 | 83 |
@Override |
89 | 84 |
public void bind(ISessionEventListener sessionOwner) { |
90 |
CdmEntitySession session = ownerSessionMap.get(sessionOwner); |
|
85 |
if(sessionOwner == null) { |
|
86 |
activeSession = null; |
|
87 |
return; |
|
88 |
} |
|
89 |
ICdmEntitySession session = ownerSessionMap.get(sessionOwner); |
|
91 | 90 |
if(session == null) { |
92 | 91 |
session = newSession(sessionOwner,true); |
93 | 92 |
} |
... | ... | |
99 | 98 |
*/ |
100 | 99 |
@Override |
101 | 100 |
public <T extends Object> T load(ISessionEventListener sessionOwner, T obj) { |
102 |
CdmEntitySession session = newSession(sessionOwner,true);
|
|
101 |
ICdmEntitySession session = newSession(sessionOwner,true);
|
|
103 | 102 |
return (T) session.load(obj); |
104 | 103 |
} |
105 | 104 |
|
... | ... | |
109 | 108 |
@Override |
110 | 109 |
public <T extends Object> T load(T obj) { |
111 | 110 |
if(activeSession == null) { |
112 |
throw new CdmClientSessionException("No active session has been bound, cannot load cdm entity"); |
|
111 |
return obj; |
|
112 |
} else { |
|
113 |
return (T)activeSession.load(obj); |
|
113 | 114 |
} |
114 |
return (T)activeSession.load(obj); |
|
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
/* (non-Javadoc) |
... | ... | |
119 | 119 |
*/ |
120 | 120 |
@Override |
121 | 121 |
public <T extends CdmBase> T load(ISessionEventListener sessionOwner, T cdmBase) { |
122 |
CdmEntitySession session = newSession(sessionOwner,true); |
|
122 |
ICdmEntitySession session = newSession(sessionOwner,true);
|
|
123 | 123 |
return (T)session.load(cdmBase); |
124 | 124 |
} |
125 | 125 |
|
... | ... | |
129 | 129 |
@Override |
130 | 130 |
public <T extends CdmBase> T load(T cdmBase) { |
131 | 131 |
if(activeSession == null) { |
132 |
throw new CdmClientSessionException("No active session has been bound, cannot load cdm entity");
|
|
132 |
return cdmBase;
|
|
133 | 133 |
} |
134 | 134 |
return (T)activeSession.load(cdmBase); |
135 | 135 |
} |
... | ... | |
140 | 140 |
*/ |
141 | 141 |
@Override |
142 | 142 |
public <T extends CdmBase> Collection<T> load(ISessionEventListener sessionOwner, Collection<T> cdmBaseList) { |
143 |
CdmEntitySession session = newSession(sessionOwner,true); |
|
143 |
ICdmEntitySession session = newSession(sessionOwner,true);
|
|
144 | 144 |
return session.load(cdmBaseList); |
145 | 145 |
} |
146 | 146 |
|
... | ... | |
151 | 151 |
@Override |
152 | 152 |
public <T extends CdmBase> Collection<T> load(Collection<T> cdmBaseList) { |
153 | 153 |
if(activeSession == null) { |
154 |
throw new CdmClientSessionException("No active session has been bound, cannot load cdm entity list");
|
|
154 |
return cdmBaseList;
|
|
155 | 155 |
} |
156 | 156 |
return activeSession.load(cdmBaseList); |
157 | 157 |
} |
158 |
|
|
159 |
/* (non-Javadoc) |
|
160 |
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#addRootEntity(T) |
|
161 |
*/ |
|
162 |
@Override |
|
163 |
@SuppressWarnings("unchecked") |
|
164 |
public <T extends CdmBase> void addRootEntity(T cdmBase) { |
|
165 |
if(activeSession == null) { |
|
166 |
throw new CdmClientSessionException("No active session has been bound, cannot add root cdm entity"); |
|
167 |
} |
|
168 |
activeSession.addRootEntity(cdmBase); |
|
169 |
} |
|
170 |
|
|
171 |
/* (non-Javadoc) |
|
172 |
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#addRootEntities(java.util.Collection) |
|
173 |
*/ |
|
174 |
@Override |
|
175 |
@SuppressWarnings("unchecked") |
|
176 |
public <T extends Object> void addRootEntities(Collection<T> cdmBaseList) { |
|
177 |
if(activeSession == null) { |
|
178 |
throw new CdmClientSessionException("No active session has been bound, cannot add root cdm entity"); |
|
179 |
} |
|
180 |
activeSession.addRootEntities(cdmBaseList); |
|
181 |
} |
|
182 | 158 |
|
183 |
// /* (non-Javadoc) |
|
184 |
// * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#commit() |
|
185 |
// */ |
|
186 |
// @Override |
|
187 |
// public void commit() { |
|
188 |
// if(activeSession == null) { |
|
189 |
// logger.info("No active session has been bound, nothing to commit"); |
|
190 |
// } |
|
191 |
// activeSession.commit(); |
|
192 |
// } |
|
193 |
// |
|
194 |
// |
|
195 |
// /* (non-Javadoc) |
|
196 |
// * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#commit(eu.etaxonomy.taxeditor.session.ISessionEventListener) |
|
197 |
// */ |
|
198 |
// @Override |
|
199 |
// public void commit(ISessionEventListener sessionOwner) { |
|
200 |
// if(sessionOwner == null) { |
|
201 |
// return ; |
|
202 |
// } |
|
203 |
// |
|
204 |
// CdmEntitySession session = ownerSessionMap.get(sessionOwner); |
|
205 |
// if(session == null) { |
|
206 |
// logger.info("No session exists for session owner with class : " + sessionOwner.getClass().getName()); |
|
207 |
// } else { |
|
208 |
// session.commit(); |
|
209 |
// } |
|
210 |
// } |
|
211 |
|
|
212 | 159 |
|
213 | 160 |
/* (non-Javadoc) |
214 | 161 |
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#dispose(eu.etaxonomy.taxeditor.session.ISessionEventListener) |
215 | 162 |
*/ |
216 | 163 |
@Override |
217 | 164 |
public void dispose(ISessionEventListener owner) { |
218 |
CdmEntitySession session = ownerSessionMap.get(owner); |
|
165 |
ICdmEntitySession session = ownerSessionMap.get(owner);
|
|
219 | 166 |
if(session == null) { |
220 | 167 |
logger.info("No Session connected to owner, nothing to dispose"); |
221 | 168 |
return; |
... | ... | |
227 | 174 |
ownerSessionMap.put(owner, session); |
228 | 175 |
} |
229 | 176 |
|
230 |
// void addToLinkedEntities(T cdmBase) { |
|
231 |
// if(cdmBase == null) { |
|
232 |
// return; |
|
233 |
// } |
|
234 |
// String id = CdmTransientEntityCacher.generateId(cdmBase); |
|
235 |
// HashSet<CdmClientBase<T>> linkedEntities = entitiesMap.get(id); |
|
236 |
// if(linkedEntities == null) { |
|
237 |
// linkedEntities = new HashSet<CdmClientBase<T>>(); |
|
238 |
// } |
|
239 |
// linkedEntities.add(cdmBase); |
|
240 |
// } |
|
241 |
|
|
242 | 177 |
|
243 | 178 |
void setEntityAsLatest(CdmBase cdmBase) { |
244 | 179 |
latestEntityCacher.put(cdmBase); |
245 | 180 |
} |
246 | 181 |
|
247 | 182 |
void promoteSessionEntitiesToLatest(ISessionEventListener owner) { |
248 |
CdmEntitySession session = ownerSessionMap.get(owner); |
|
183 |
ICdmEntitySession session = ownerSessionMap.get(owner);
|
|
249 | 184 |
if(session != null) { |
250 | 185 |
session.setEntitiesAsLatest(); |
251 | 186 |
} |
Also available in: Unified diff
updated manifest for deleted test dir
removed unnecessary commit root entity methods in session and session manager