2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.session
;
11 import java
.util
.Collection
;
12 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
17 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
18 import eu
.etaxonomy
.cdm
.cache
.EntityCacherDebugResult
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
20 import eu
.etaxonomy
.cdm
.persistence
.dto
.MergeResult
;
21 import net
.sf
.ehcache
.statistics
.LiveCacheStatistics
;
27 public class NullSession
implements ICdmEntitySession
{
29 private ICdmEntitySessionEnabled sessionOwner
;
30 private final CdmEntitySessionManager cdmEntitySessionManager
;
32 public NullSession(ICdmEntitySessionEnabled sessionOwner
, CdmEntitySessionManager cdmEntitySessionManager
) {
33 this.sessionOwner
= sessionOwner
;
34 this.cdmEntitySessionManager
= cdmEntitySessionManager
;
37 public void setOwner(ICdmEntitySessionEnabled sessionOwner
) {
38 this.sessionOwner
= sessionOwner
;
42 public ICdmEntitySessionEnabled
getOwner() {
47 public LiveCacheStatistics
getCacheStatistics() {
52 public <O
> O
load(O obj
, boolean update
) {
57 public <T
extends CdmBase
> T
load(T cdmBase
, boolean update
) {
62 public UpdateResult
load(UpdateResult updateResult
, boolean update
) {
67 public <T
extends CdmBase
> EntityCacherDebugResult
debug(T cdmBase
) {
72 public <T
extends CdmBase
> EntityCacherDebugResult
debug(Collection
<T
> cdmBase
, boolean includeIgnored
) {
77 public <T
extends CdmBase
> EntityCacherDebugResult
debug(boolean includeIgnored
) {
82 public <T
extends CdmBase
> Collection
<T
> load(Collection
<T
> cdmBaseList
, boolean update
) {
87 public void setEntitiesAsLatest() {
92 public <T
extends CdmBase
> Collection
<T
> getRootEntities() {
97 public void dispose() {
98 cdmEntitySessionManager
.remove(sessionOwner
);
103 cdmEntitySessionManager
.bindNullSession();
107 public <T
extends CdmBase
> T
remoteLoad(IService
<T
> service
, UUID uuid
) {
108 T cdmBase
= service
.load(uuid
);
109 return load(cdmBase
, false);
113 public <T
extends CdmBase
> T
remoteLoad(IService
<T
> service
, UUID uuid
, List
<String
> propertyPaths
) {
114 T cdmBase
= service
.load(uuid
, propertyPaths
);
115 return load(cdmBase
, false);
119 public <T
extends CdmBase
> UUID
remoteSave(IService
<T
> service
, T cdmBase
) {
120 UUID uuid
= service
.save(cdmBase
).getUuid();
126 public <T
extends CdmBase
> T
remoteUpdate(IService
<T
> service
, T cdmBase
) {
127 T mergedCdmBase
= service
.merge(cdmBase
, true).getMergedEntity();
128 return mergedCdmBase
;
132 public boolean isActive() {
133 return cdmEntitySessionManager
.getActiveSession() == this;
137 public <T
extends CdmBase
> void update() {
142 public List
<String
> getPropertyPaths(Object obj
) {
143 if(sessionOwner
== null) {
146 Map
<Object
, List
<String
>> propertyPathsMap
= sessionOwner
.getPropertyPathsMap();
147 if(propertyPathsMap
== null || propertyPathsMap
.isEmpty()) {
150 return propertyPathsMap
.get(obj
);
154 public void addNewCdmEntity(CdmBase newEntity
) {
159 public <T
extends CdmBase
> MergeResult
<T
> load(MergeResult
<T
> mergeResult
, boolean update
) {