Skip to content

Package: ChangeTrackingMode

ChangeTrackingMode

nameinstructionbranchcomplexitylinemethod
lambda$resolve$0(String, ChangeTrackingMode)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$resolve$1(Configuration)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
resolve(Configuration)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.utils;
19:
20: import cz.cvut.kbss.jopa.model.JOPAPersistenceProperties;
21:
22: import java.util.Objects;
23: import java.util.Optional;
24: import java.util.stream.Stream;
25:
26: /**
27: * Specifies how changes to managed objects are tracked in transactions.
28: */
29: public enum ChangeTrackingMode {
30:
31: /**
32: * Tracks changes immediately as they are made and propagates them to a transaction snapshot of the repository
33: * managed by the underlying OntoDriver.
34: */
35: IMMEDIATE,
36: /**
37: * Calculates changes on commit, propagating them immediately to the underlying repository.
38: */
39: ON_COMMIT;
40:
41: /**
42: * Resolves change tracking mode from the specified configuration.
43: *
44: * @param configuration Configuration to resolve change tracking mode from
45: * @return Resolved {@code ChangeTrackingMode}
46: */
47: public static ChangeTrackingMode resolve(Configuration configuration) {
48: Objects.requireNonNull(configuration);
49: final String configValue = configuration.get(JOPAPersistenceProperties.CHANGE_TRACKING_MODE);
50: final Optional<ChangeTrackingMode> result = Stream.of(values())
51: .filter(m -> m.toString().equalsIgnoreCase(configValue))
52: .findAny();
53: return result.orElseGet(() -> {
54: // For RDF4J driver, no other mode makes sense as the driver does not support transactional snapshots
55:• if ("cz.cvut.kbss.ontodriver.rdf4j.Rdf4jDataSource".equals(configuration.get(JOPAPersistenceProperties.DATA_SOURCE_CLASS))) {
56: return ON_COMMIT;
57: }
58: // Default legacy mode
59: return IMMEDIATE;
60: });
61: }
62: }