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 java
.util
.UUID
;
14 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
15 import org
.springframework
.stereotype
.Component
;
17 import eu
.etaxonomy
.cdm
.api
.service
.ICommonService
;
18 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
19 import eu
.etaxonomy
.taxeditor
.remoting
.cache
.ProxyUtils
.CollectionField
;
20 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionManager
;
28 public class CachedCommonServiceImpl
implements ICachedCommonService
{
32 private ICommonService commonService
;
34 private static boolean cacheEnabled
= true;
37 private ICdmEntitySessionManager cdmEntitySessionManager
;
40 public static boolean isCacheEnabled() {
44 public static void setCacheEnabled(boolean cacheEnabled
) {
45 CachedCommonServiceImpl
.cacheEnabled
= cacheEnabled
;
49 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#find(java.lang.Class, int)
52 public CdmBase
find(Class
<?
extends CdmBase
> clazz
, int id
) {
54 CdmBase cdmEntity
= CdmBase
.deproxy(commonService
.find(clazz
, id
),clazz
);
55 if(cdmEntity
== null) {
56 throw new NullPointerException("CDM Entity of type " + clazz
.getName() + " with id " + id
+ " is null.");
58 return cdmEntitySessionManager
.load(cdmEntity
, false);
60 return CdmBase
.deproxy(commonService
.find(clazz
, id
),clazz
);
66 public void updatePersistentCollection(CollectionField colf
) {
68 cdmEntitySessionManager
.load(colf
.getCollection(), false);
73 * @see eu.etaxonomy.taxeditor.service.ICachedCommonService#initializeCollection(java.util.UUID, java.lang.String)
76 public Object
initializeCollection(UUID ownerUuid
, String fieldName
) {
77 return commonService
.initializeCollection(ownerUuid
, fieldName
);
82 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#isEmpty(org.hibernate.collection.spi.PersistentCollection)
85 public boolean isEmpty(UUID ownerUuid
, String fieldName
) {
86 return commonService
.isEmpty(ownerUuid
, fieldName
);
92 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#size(org.hibernate.collection.spi.PersistentCollection)
95 public int size(UUID ownerUuid
, String fieldName
) {
96 return commonService
.size(ownerUuid
, fieldName
);
102 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#contains(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
105 public boolean contains(UUID ownerUuid
, String fieldName
, Object element
) {
106 return commonService
.contains(ownerUuid
, fieldName
, element
);
111 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsKey(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
114 public boolean containsKey(UUID ownerUuid
, String fieldName
, Object key
) {
115 return commonService
.containsKey(ownerUuid
, fieldName
, key
);
120 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsValue(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
123 public boolean containsValue(UUID ownerUuid
, String fieldName
, Object element
) {
124 return commonService
.containsValue(ownerUuid
, fieldName
, element
);