3 * Copyright (C) 2018 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.remoting
.cache
;
12 import java
.util
.HashSet
;
15 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
16 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
17 import eu
.etaxonomy
.cdm
.api
.service
.dto
.CdmEntityIdentifier
;
18 import eu
.etaxonomy
.cdm
.cache
.CdmEntityCacheKey
;
19 import eu
.etaxonomy
.cdm
.cache
.CdmTransientEntityCacher
;
20 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 public class ConversationalTransientEntityCacher
extends CdmTransientEntityCacher
{
32 public ConversationalTransientEntityCacher(Object sessionOwner
) {
36 private CdmBase
load(CdmEntityIdentifier cei
, boolean update
) {
37 return CdmApplicationState
.getCommonService().findWithUpdate(cei
.getCdmClass(), cei
.getId());
41 public UpdateResult
load(UpdateResult result
, boolean update
) {
42 // probably a good time to broadcast to other sessions
44 Set
<CdmBase
> updatedObjects
= result
.getUpdatedObjects();
45 Set
<CdmBase
> reloadedObjects
= new HashSet
<CdmBase
>();
46 Set
<CdmEntityIdentifier
> updatedCdmIds
= result
.getUpdatedCdmIds();
47 boolean updatedCdmIdsIsEmpty
= updatedCdmIds
.isEmpty();
49 // if the cdm identifier set contains identifiers of objects already
50 // present in the updated objects set reomve them
51 for(CdmBase updatedObject
: updatedObjects
) {
52 if(updatedObject
!= null && super.exists(new CdmEntityCacheKey(updatedObject
.getClass(), updatedObject
.getId()))) {
53 CdmEntityIdentifier cdmEntityIdentifier
= new CdmEntityIdentifier(updatedObject
.getId(), updatedObject
.getClass());
54 if(!updatedCdmIdsIsEmpty
&& updatedCdmIds
.contains(cdmEntityIdentifier
)) {
55 updatedCdmIds
.remove(cdmEntityIdentifier
);
57 reloadedObjects
.add(load(updatedObject
, update
));
61 // remote load cdm identifiers of objects which already exist
64 for(CdmEntityIdentifier cei
: updatedCdmIds
) {
65 if(exists(new CdmEntityCacheKey(cei
.getCdmClass(), cei
.getId()))) {
66 reloadedObjects
.add(load(cei
, update
));
70 updatedObjects
.clear();
71 result
.addUpdatedObjects(reloadedObjects
);