Skip to contentMethod: bypassCache()
1: /**
2: * Copyright (C) 2020 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 cz.cvut.kbss.jopa.model.descriptors.Descriptor;
18:
19: import java.net.URI;
20: import java.util.Objects;
21:
22: public final class LoadingParameters<T> {
23:
24: private final Class<T> cls;
25: private final URI identifier;
26: private final Descriptor descriptor;
27: private final boolean forceEager;
28: private boolean bypassCache;
29:
30: public LoadingParameters(Class<T> cls, URI identifier, Descriptor descriptor) {
31: this.cls = cls;
32: this.identifier = identifier;
33: this.descriptor = descriptor;
34: this.forceEager = false;
35: assert paramsLoaded();
36: }
37:
38: public LoadingParameters(Class<T> cls, URI identifier, Descriptor descriptor, boolean forceEager) {
39: this.cls = cls;
40: this.identifier = identifier;
41: this.descriptor = descriptor;
42: this.forceEager = forceEager;
43: assert paramsLoaded();
44: }
45:
46: private boolean paramsLoaded() {
47: return cls != null && identifier != null && descriptor != null;
48: }
49:
50: public Class<T> getEntityType() {
51: return cls;
52: }
53:
54: public URI getIdentifier() {
55: return identifier;
56: }
57:
58: public Descriptor getDescriptor() {
59: return descriptor;
60: }
61:
62: public boolean isForceEager() {
63: return forceEager;
64: }
65:
66: public boolean shouldBypassCache() {
67: return bypassCache;
68: }
69:
70: public void bypassCache() {
71: this.bypassCache = true;
72: }
73:
74: @Override
75: public boolean equals(Object o) {
76: if (this == o) {
77: return true;
78: }
79: if (!(o instanceof LoadingParameters)) {
80: return false;
81: }
82: LoadingParameters<?> that = (LoadingParameters<?>) o;
83: if (forceEager != that.forceEager) {
84: return false;
85: }
86: if (bypassCache != that.bypassCache) {
87: return false;
88: }
89: return Objects.equals(cls, that.cls) && Objects.equals(identifier, that.identifier) &&
90: Objects.equals(descriptor, that.descriptor);
91: }
92:
93: @Override
94: public int hashCode() {
95: int result = cls.hashCode();
96: result = 31 * result + identifier.hashCode();
97: result = 31 * result + descriptor.hashCode();
98: result = 31 * result + (forceEager ? 1 : 0);
99: result = 31 * result + (bypassCache ? 1 : 0);
100: return result;
101: }
102: }