3 * Copyright (C) 2014 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
.cdm
.api
.cache
;
12 import java
.util
.Iterator
;
15 import org
.hibernate
.collection
.internal
.PersistentMap
;
16 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
17 import org
.springframework
.stereotype
.Component
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 public class LazyLoadingCachingUtils
{
30 private CdmEntityCacheManager cdmEntityCacheManager
;
32 public static enum CollectionType
{
38 public String
toString() {
39 return this.name().toLowerCase();
43 public void updatePersistentCollection(Map map
) {
44 if(map
== null || map
.isEmpty()) {
48 int originalMapSize
= map
.size();
49 Object
[] result
= new Object
[ map
.size() * 2 ];
50 Iterator iter
= map
.entrySet().iterator();
52 while ( iter
.hasNext() ) {
53 Map
.Entry e
= (Map
.Entry
) iter
.next();
54 result
[i
++] = e
.getKey();
55 result
[i
++] = e
.getValue();
58 for(i
=0; i
<result
.length
;i
++) {
59 if(result
[i
] instanceof CdmBase
) {
60 CdmBase cdmBase
= (CdmBase
)result
[i
];
61 CdmBase cachedCdmBase
= cdmEntityCacheManager
.getCdmTransientEntityCacher().put(cdmBase
.getClass(),cdmBase
.getId(), cdmBase
);
62 result
[i
] = cachedCdmBase
;
66 for(i
= 0; i
< originalMapSize
; i
+=2 ) {