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
.taxeditor
.service
;
12 import org
.hibernate
.collection
.spi
.PersistentCollection
;
13 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
14 import org
.springframework
.stereotype
.Component
;
16 import eu
.etaxonomy
.cdm
.api
.service
.ICommonService
;
17 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
18 import eu
.etaxonomy
.taxeditor
.remoting
.cache
.ProxyUtils
.CollectionField
;
19 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionManager
;
27 public class CachedCommonServiceImpl
implements ICachedCommonService
{
31 private ICommonService commonService
;
33 private static boolean cacheEnabled
= true;
36 private ICdmEntitySessionManager cdmEntitySessionManager
;
39 public static boolean isCacheEnabled() {
43 public static void setCacheEnabled(boolean cacheEnabled
) {
44 CachedCommonServiceImpl
.cacheEnabled
= cacheEnabled
;
48 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#find(java.lang.Class, int)
51 public CdmBase
find(Class
<?
extends CdmBase
> clazz
, int id
) {
53 CdmBase cdmEntity
= CdmBase
.deproxy(commonService
.find(clazz
, id
),clazz
);
54 if(cdmEntity
== null) {
55 throw new NullPointerException("CDM Entity of type " + clazz
.getName() + " with id " + id
+ " is null.");
57 return cdmEntitySessionManager
.load(cdmEntity
, false);
59 return CdmBase
.deproxy(commonService
.find(clazz
, id
),clazz
);
64 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#initializeCollection(org.hibernate.collection.spi.PersistentCollection)
67 public PersistentCollection
initializeCollection(PersistentCollection col
) {
68 return commonService
.initializeCollection(col
);
72 public void updatePersistentCollection(CollectionField colf
) {
74 cdmEntitySessionManager
.load(colf
.getCollection(), false);
79 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#isEmpty(org.hibernate.collection.spi.PersistentCollection)
82 public boolean isEmpty(PersistentCollection col
) {
83 return commonService
.isEmpty(col
);
89 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#size(org.hibernate.collection.spi.PersistentCollection)
92 public int size(PersistentCollection col
) {
93 return commonService
.size(col
);
98 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#get(org.hibernate.collection.spi.PersistentCollection, int)
101 public Object
get(PersistentCollection col
, int index
) {
102 return commonService
.get(col
, index
);
107 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#contains(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
110 public boolean contains(PersistentCollection col
, Object element
) {
111 return commonService
.contains(col
, element
);
116 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsKey(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
119 public boolean containsKey(PersistentCollection col
, Object key
) {
120 return commonService
.containsKey(col
, key
);
125 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsValue(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
128 public boolean containsValue(PersistentCollection col
, Object element
) {
129 return commonService
.containsValue(col
, element
);