Skip to content

Package: Cache

Cache

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.sessions;
16:
17: import java.net.URI;
18:
19: /**
20: * Interface used to interact with the second-level cache. If a cache is not in
21: * use, the methods of this interface have no effect, except for contains, which
22: * returns false.
23: *
24: * Taken from JPA 2.
25: *
26: * @author kidney
27: *
28: */
29: public interface Cache {
30:
31:         /**
32:          * Checks whether the cache contains data for the given entity. </p>
33:          *
34:          * This method searches all the available contexts and returns true on
35:          * finding the first occurrence of matching entity.
36:          *
37:          * @param cls
38:          * entity class
39:          * @param primaryKey
40:          * primary key
41:          * @return {@code boolean} indicating whether the entity is in the cache
42:          * @see #contains(URI, Class, Object)
43:          */
44:         public boolean contains(Class<?> cls, Object primaryKey);
45:
46:         /**
47:          * Checks whether the cache contains data for the given entity (in the given
48:          * context only).
49:          *
50:          * @param cls
51:          * Entity class
52:          * @param primaryKey
53:          * Primary key
54:          * @param context
55:          * Context URI
56:          * @return {@code boolean} indicating whether the entity is in the cache
57:          */
58:         public boolean contains(Class<?> cls, Object primaryKey, URI context);
59:
60:         /**
61:          * Removes the data for the given entity from the cache.
62:          *
63:          * @param cls
64:          * Entity class
65:          * @param primaryKey
66:          * Primary key
67:          * @param context
68:          * Cotnext URI
69:          */
70:         public void evict(Class<?> cls, Object primaryKey, URI context);
71:
72:         /**
73:          * Removes the data for entities of the specified class (and its subclasses)
74:          * from the cache. </p>
75:          *
76:          * This method removes the entities from all available contexts.
77:          *
78:          * @param cls
79:          * entity class
80:          */
81:         public void evict(Class<?> cls);
82:
83:         /**
84:          * Removes the data for entities of the specified repository context from
85:          * the cache.
86:          *
87:          * @param context
88:          * URI of {@code Context}
89:          */
90:         public void evict(URI context);
91:
92:         /**
93:          * Clears the cache.
94:          */
95:         public void evictAll();
96:
97: }