9efd8ec423c075402ad20772a9fdf5accd24c930
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / taxeditor / session / NullSession.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.session;
11
12 import java.util.Collection;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.UUID;
16
17 import net.sf.ehcache.statistics.LiveCacheStatistics;
18 import eu.etaxonomy.cdm.api.service.IService;
19 import eu.etaxonomy.cdm.api.service.UpdateResult;
20 import eu.etaxonomy.cdm.model.common.CdmBase;
21 import eu.etaxonomy.cdm.persistence.dto.MergeResult;
22 import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
23
24 /**
25 * @author cmathew
26 * @date 30 Jul 2015
27 *
28 */
29 public class NullSession implements ICdmEntitySession {
30
31 private ICdmEntitySessionEnabled sessionOwner;
32 private final CdmEntitySessionManager cdmEntitySessionManager;
33
34 public NullSession(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) {
35 this.sessionOwner = sessionOwner;
36 this.cdmEntitySessionManager = cdmEntitySessionManager;
37 }
38
39 public void setOwner(ICdmEntitySessionEnabled sessionOwner) {
40 this.sessionOwner = sessionOwner;
41 }
42
43 /* (non-Javadoc)
44 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getOwner()
45 */
46 @Override
47 public ICdmEntitySessionEnabled getOwner() {
48 return sessionOwner;
49 }
50
51 /* (non-Javadoc)
52 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getCacheStatistics()
53 */
54 @Override
55 public LiveCacheStatistics getCacheStatistics() {
56 // TODO Auto-generated method stub
57 return null;
58 }
59
60 /* (non-Javadoc)
61 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(java.lang.Object, boolean)
62 */
63 @Override
64 public <O> O load(O obj, boolean update) {
65 return obj;
66 }
67
68 /* (non-Javadoc)
69 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(eu.etaxonomy.cdm.model.common.CdmBase, boolean)
70 */
71 @Override
72 public <T extends CdmBase> T load(T cdmBase, boolean update) {
73 return cdmBase;
74 }
75
76 /* (non-Javadoc)
77 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(eu.etaxonomy.cdm.api.service.UpdateResult, boolean)
78 */
79 @Override
80 public UpdateResult load(UpdateResult updateResult, boolean update) {
81 return updateResult;
82 }
83
84 /* (non-Javadoc)
85 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#debug(eu.etaxonomy.cdm.model.common.CdmBase)
86 */
87 @Override
88 public <T extends CdmBase> EntityCacherDebugResult debug(T cdmBase) {
89 return null;
90 }
91
92 /* (non-Javadoc)
93 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#debug(java.util.Collection)
94 */
95 @Override
96 public <T extends CdmBase> EntityCacherDebugResult debug(Collection<T> cdmBase) {
97 return null;
98 }
99
100 /* (non-Javadoc)
101 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#debug()
102 */
103 @Override
104 public <T extends CdmBase> EntityCacherDebugResult debug() {
105 return null;
106 }
107
108 /* (non-Javadoc)
109 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(java.util.Collection, boolean)
110 */
111 @Override
112 public <T extends CdmBase> Collection<T> load(Collection<T> cdmBaseList, boolean update) {
113 return cdmBaseList;
114 }
115
116 /* (non-Javadoc)
117 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#setEntitiesAsLatest()
118 */
119 @Override
120 public void setEntitiesAsLatest() {
121
122 }
123
124 /* (non-Javadoc)
125 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getRootEntities()
126 */
127 @Override
128 public <T extends CdmBase> Collection<T> getRootEntities() {
129 return null;
130 }
131
132 /* (non-Javadoc)
133 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#dispose()
134 */
135 @Override
136 public void dispose() {
137 cdmEntitySessionManager.remove(sessionOwner);
138 }
139
140 /* (non-Javadoc)
141 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#bind()
142 */
143 @Override
144 public void bind() {
145 cdmEntitySessionManager.bindNullSession();
146 }
147
148 /* (non-Javadoc)
149 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#remoteLoad(eu.etaxonomy.cdm.api.service.IService, java.util.UUID)
150 */
151 @Override
152 public <T extends CdmBase> T remoteLoad(IService<T> service, UUID uuid) {
153 T cdmBase = service.load(uuid);
154 return load(cdmBase, false);
155 }
156
157 /* (non-Javadoc)
158 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#remoteLoad(eu.etaxonomy.cdm.api.service.IService, java.util.UUID, java.util.List)
159 */
160 @Override
161 public <T extends CdmBase> T remoteLoad(IService<T> service, UUID uuid, List<String> propertyPaths) {
162 T cdmBase = service.load(uuid, propertyPaths);
163 return load(cdmBase, false);
164 }
165
166 /* (non-Javadoc)
167 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#remoteSave(eu.etaxonomy.cdm.api.service.IService, eu.etaxonomy.cdm.model.common.CdmBase)
168 */
169 @Override
170 public <T extends CdmBase> UUID remoteSave(IService<T> service, T cdmBase) {
171 UUID uuid = service.save(cdmBase).getUuid();
172 load(cdmBase,false);
173 return uuid;
174 }
175
176 /* (non-Javadoc)
177 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#remoteUpdate(eu.etaxonomy.cdm.api.service.IService, eu.etaxonomy.cdm.model.common.CdmBase)
178 */
179 @Override
180 public <T extends CdmBase> T remoteUpdate(IService<T> service, T cdmBase) {
181 T mergedCdmBase = service.merge(cdmBase, true).getMergedEntity();
182 return mergedCdmBase;
183 }
184
185 /* (non-Javadoc)
186 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#isActive()
187 */
188 @Override
189 public boolean isActive() {
190 return cdmEntitySessionManager.getActiveSession() == this;
191 }
192
193 /* (non-Javadoc)
194 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#update()
195 */
196 @Override
197 public <T extends CdmBase> void update() {
198
199 }
200
201 /* (non-Javadoc)
202 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getPropertyPaths(java.lang.Object)
203 */
204 @Override
205 public List<String> getPropertyPaths(Object obj) {
206 Map<Object, List<String>> propertyPathsMap = sessionOwner.getPropertyPathsMap();
207 if(propertyPathsMap == null || propertyPathsMap.isEmpty()) {
208 return null;
209 }
210 return propertyPathsMap.get(obj);
211 }
212
213 /* (non-Javadoc)
214 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#addNewCdmEntity(eu.etaxonomy.cdm.model.common.CdmBase)
215 */
216 @Override
217 public void addNewCdmEntity(CdmBase newEntity) {
218 // TODO Auto-generated method stub
219
220 }
221
222 /* (non-Javadoc)
223 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(eu.etaxonomy.cdm.persistence.dto.MergeResult, boolean)
224 */
225 @Override
226 public <T extends CdmBase> MergeResult<T> load(MergeResult<T> mergeResult, boolean update) {
227 return mergeResult;
228 }
229
230 }