1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.client.bindings.impl;
20
21 import org.apache.chemistry.opencmis.client.bindings.cache.Cache;
22 import org.apache.chemistry.opencmis.client.bindings.cache.TypeDefinitionCache;
23 import org.apache.chemistry.opencmis.client.bindings.cache.impl.CacheImpl;
24 import org.apache.chemistry.opencmis.client.bindings.cache.impl.LruCacheLevelImpl;
25 import org.apache.chemistry.opencmis.client.bindings.cache.impl.MapCacheLevelImpl;
26 import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
27 import org.apache.chemistry.opencmis.commons.SessionParameter;
28 import org.apache.chemistry.opencmis.commons.SessionParameterDefaults;
29 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
30
31
32
33
34 public class TypeDefinitionCacheImpl implements TypeDefinitionCache {
35
36 private static final long serialVersionUID = 1L;
37
38 private Cache cache;
39
40
41
42
43 public TypeDefinitionCacheImpl() {
44
45 }
46
47 @Override
48 public void initialize(BindingSession session) {
49 assert session != null;
50
51 int repCount = session.get(SessionParameter.CACHE_SIZE_REPOSITORIES,
52 SessionParameterDefaults.CACHE_SIZE_REPOSITORIES);
53 if (repCount < 1) {
54 repCount = SessionParameterDefaults.CACHE_SIZE_REPOSITORIES;
55 }
56
57 int typeCount = session.get(SessionParameter.CACHE_SIZE_TYPES, SessionParameterDefaults.CACHE_SIZE_TYPES);
58 if (typeCount < 1) {
59 typeCount = SessionParameterDefaults.CACHE_SIZE_TYPES;
60 }
61
62 cache = new CacheImpl("Type Definition Cache");
63 cache.initialize(new String[] {
64 MapCacheLevelImpl.class.getName() + " " + MapCacheLevelImpl.CAPACITY + "=" + repCount,
65 LruCacheLevelImpl.class.getName() + " " + LruCacheLevelImpl.MAX_ENTRIES + "=" + typeCount
66 });
67 }
68
69 @Override
70 public void put(String repositoryId, TypeDefinition typeDefinition) {
71 if (repositoryId == null || typeDefinition == null || typeDefinition.getId() == null) {
72 return;
73 }
74
75 cache.put(typeDefinition, repositoryId, typeDefinition.getId());
76 }
77
78 @Override
79 public TypeDefinition get(String repositoryId, String typeId) {
80 if(repositoryId == null || typeId == null) {
81 throw new IllegalArgumentException("Invalid repository ot type ID!");
82 }
83
84 return (TypeDefinition) cache.get(repositoryId, typeId);
85 }
86
87 @Override
88 public void remove(String repositoryId, String typeId) {
89 cache.remove(repositoryId, typeId);
90 }
91
92 @Override
93 public void remove(String repositoryId) {
94 cache.remove(repositoryId);
95 }
96
97 @Override
98 public void removeAll() {
99 cache.removeAll();
100 }
101
102 @Override
103 public String toString() {
104 return cache.toString();
105 }
106
107 }