blob: 0afccf724d188d7779653f74709191d74d9454b4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.core.model;
import java.util.Collection;
import java.util.HashSet;
import org.eclipse.osee.framework.core.enums.OseeCacheEnum;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.cache.ArtifactTypeCache;
import org.eclipse.osee.framework.core.model.cache.AttributeTypeCache;
import org.eclipse.osee.framework.core.model.cache.BranchCache;
import org.eclipse.osee.framework.core.model.cache.IOseeCache;
import org.eclipse.osee.framework.core.model.cache.OseeEnumTypeCache;
import org.eclipse.osee.framework.core.model.cache.RelationTypeCache;
import org.eclipse.osee.framework.core.model.cache.TransactionCache;
import org.eclipse.osee.framework.core.services.IOseeCachingService;
import org.eclipse.osee.framework.core.util.Conditions;
/**
* @author Roberto E. Escobar
*/
public class OseeCachingService implements IOseeCachingService {
private final BranchCache branchCache;
private final TransactionCache transactionCache;
private final ArtifactTypeCache artifactTypeCache;
private final AttributeTypeCache attributeTypeCache;
private final RelationTypeCache relationTypeCache;
private final OseeEnumTypeCache oseeEnumTypeCache;
private final Collection<IOseeCache<?>> caches;
public OseeCachingService(BranchCache branchCache, TransactionCache transactionCache, ArtifactTypeCache artifactTypeCache, AttributeTypeCache attributeTypeCache, RelationTypeCache relationTypeCache, OseeEnumTypeCache oseeEnumTypeCache) {
this.branchCache = branchCache;
this.transactionCache = transactionCache;
this.artifactTypeCache = artifactTypeCache;
this.attributeTypeCache = attributeTypeCache;
this.relationTypeCache = relationTypeCache;
this.oseeEnumTypeCache = oseeEnumTypeCache;
caches = new HashSet<IOseeCache<?>>();
caches.add(branchCache);
caches.add(transactionCache);
caches.add(artifactTypeCache);
caches.add(attributeTypeCache);
caches.add(relationTypeCache);
caches.add(oseeEnumTypeCache);
}
@Override
public BranchCache getBranchCache() {
return branchCache;
}
@Override
public TransactionCache getTransactionCache() {
return transactionCache;
}
@Override
public ArtifactTypeCache getArtifactTypeCache() {
return artifactTypeCache;
}
@Override
public AttributeTypeCache getAttributeTypeCache() {
return attributeTypeCache;
}
@Override
public OseeEnumTypeCache getEnumTypeCache() {
return oseeEnumTypeCache;
}
@Override
public RelationTypeCache getRelationTypeCache() {
return relationTypeCache;
}
@Override
public Collection<IOseeCache<?>> getCaches() {
return caches;
}
@Override
public IOseeCache<?> getCache(OseeCacheEnum cacheId) throws OseeCoreException {
Conditions.checkNotNull(cacheId, "cache id to find");
for (IOseeCache<?> cache : getCaches()) {
if (cache.getCacheId().equals(cacheId)) {
return cache;
}
}
throw new OseeArgumentException(String.format("Unable to find cache for id [%s]", cacheId));
}
@Override
public synchronized void reloadAll() throws OseeCoreException {
getBranchCache().reloadCache();
getTransactionCache().reloadCache();
getEnumTypeCache().reloadCache();
getAttributeTypeCache().reloadCache();
getArtifactTypeCache().reloadCache();
getRelationTypeCache().reloadCache();
}
@Override
public synchronized void clearAll() {
getBranchCache().decacheAll();
getTransactionCache().decacheAll();
getEnumTypeCache().decacheAll();
getAttributeTypeCache().decacheAll();
getArtifactTypeCache().decacheAll();
getRelationTypeCache().decacheAll();
}
}
|