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
.List
;
13 import java
.util
.UUID
;
15 import org
.springframework
.stereotype
.Component
;
17 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteController
;
18 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
20 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
28 public class CachedCommonServiceImpl
implements ICachedCommonService
{
31 private static boolean cacheEnabled
= true;
33 public static boolean isCacheEnabled() {
37 public static void setCacheEnabled(boolean cacheEnabled
) {
38 CachedCommonServiceImpl
.cacheEnabled
= cacheEnabled
;
42 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#find(java.lang.Class, int)
45 public CdmBase
find(Class
<?
extends CdmBase
> clazz
, int id
) {
46 CdmBase cdmEntity
= CdmApplicationState
.getCurrentAppConfig().getCommonService().find(clazz
, id
, getPropertyPaths(clazz
));
47 if(cdmEntity
== null) {
48 throw new NullPointerException("CDM Entity of type " + clazz
.getName() + " with id " + id
+ " is null.");
55 private List
<String
> getPropertyPaths(Object obj
) {
56 List
<String
> propertyPaths
= null;
57 ICdmEntitySession cdmEntitySession
=
58 ((CdmApplicationRemoteController
)CdmApplicationState
.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession();
59 if(cdmEntitySession
!= null) {
60 propertyPaths
= cdmEntitySession
.getPropertyPaths(obj
);
66 * @see eu.etaxonomy.taxeditor.service.ICachedCommonService#initializeCollection(java.util.UUID, java.lang.String)
69 public Object
initializeCollection(UUID ownerUuid
, String fieldName
) {
70 return CdmApplicationState
.getCurrentAppConfig().getCommonService().initializeCollection(ownerUuid
, fieldName
, getPropertyPaths(fieldName
));
75 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#isEmpty(org.hibernate.collection.spi.PersistentCollection)
78 public boolean isEmpty(UUID ownerUuid
, String fieldName
) {
79 return CdmApplicationState
.getCurrentAppConfig().getCommonService().isEmpty(ownerUuid
, fieldName
);
85 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#size(org.hibernate.collection.spi.PersistentCollection)
88 public int size(UUID ownerUuid
, String fieldName
) {
89 return CdmApplicationState
.getCurrentAppConfig().getCommonService().size(ownerUuid
, fieldName
);
95 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#contains(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
98 public boolean contains(UUID ownerUuid
, String fieldName
, Object element
) {
99 return CdmApplicationState
.getCurrentAppConfig().getCommonService().contains(ownerUuid
, fieldName
, element
);
104 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsKey(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
107 public boolean containsKey(UUID ownerUuid
, String fieldName
, Object key
) {
108 return CdmApplicationState
.getCurrentAppConfig().getCommonService().containsKey(ownerUuid
, fieldName
, key
);
113 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsValue(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
116 public boolean containsValue(UUID ownerUuid
, String fieldName
, Object element
) {
117 return CdmApplicationState
.getCurrentAppConfig().getCommonService().containsValue(ownerUuid
, fieldName
, element
);