Skip to content

Package: UnitOfWorkChangeSet

UnitOfWorkChangeSet

nameinstructionbranchcomplexitylinemethod
UnitOfWorkChangeSet()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
addDeletedObjectChangeSet(DeleteObjectChange)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addNewObjectChangeSet(NewObjectChange)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addObjectChangeSet(ObjectChangeSet)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
cancelObjectChanges(Object)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getDeletedObjects()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getExistingObjectChanges(Object)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getExistingObjectsChanges()
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%
getNewObjects()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasChanges()
M: 0 C: 14
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasDeleted()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasNew()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 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.sessions.change;
19:
20: import cz.cvut.kbss.jopa.sessions.UnitOfWork;
21:
22: import java.util.*;
23:
24: /**
25: * A set of changes made in a {@link UnitOfWork}.
26: */
27: public class UnitOfWorkChangeSet {
28:
29: private final Set<DeleteObjectChange> deletedObjects;
30: private final Map<Object, ObjectChangeSet> objectChanges;
31: private final Set<NewObjectChange> newObjectChanges;
32:
33: public UnitOfWorkChangeSet() {
34: this.objectChanges = new HashMap<>();
35: this.deletedObjects = new HashSet<>();
36: this.newObjectChanges = new HashSet<>();
37: }
38:
39: /**
40: * Add new ObjectChangeSet to this changeSet.
41: *
42: * @param objectChangeSet ObjectChangeSet
43: */
44: public void addObjectChangeSet(ObjectChangeSet objectChangeSet) {
45: objectChanges.put(objectChangeSet.getOriginal(), objectChangeSet);
46: }
47:
48: /**
49: * Adds a change set for deleted object.
50: *
51: * @param deletedObject The change set to add
52: */
53: public void addDeletedObjectChangeSet(DeleteObjectChange deletedObject) {
54: deletedObjects.add(deletedObject);
55: }
56:
57: /**
58: * Add a change set for newly created object. These changes are held in separate attribute and get special treatment
59: * when merged into shared session cache.
60: *
61: * @param newObject ObjectChangeSet
62: */
63: public void addNewObjectChangeSet(NewObjectChange newObject) {
64: newObjectChanges.add(newObject);
65: }
66:
67: /**
68: * Returns change sets for existing modified objects.
69: * <p>
70: * New object and deleted object change sets are not included.
71: *
72: * @return Collection of change sets
73: */
74: public Collection<ObjectChangeSet> getExistingObjectsChanges() {
75: return Collections.unmodifiableCollection(objectChanges.values());
76: }
77:
78: /**
79: * Removes change record of the specified original object, if present, cancelling the changes.
80: *
81: * @param original The object whose changes should be removed
82: */
83: public void cancelObjectChanges(Object original) {
84: objectChanges.remove(original);
85: }
86:
87: /**
88: * Gets changes for the specified original object (if there are any).
89: *
90: * @param original The object for which changes should be found
91: * @return Object change set or null, if the object has no changes
92: */
93: public ObjectChangeSet getExistingObjectChanges(Object original) {
94: return objectChanges.get(original);
95: }
96:
97: /**
98: * Returns the collection of deleted objects.
99: *
100: * @return Set of change sets
101: */
102: public Set<DeleteObjectChange> getDeletedObjects() {
103: return this.deletedObjects;
104: }
105:
106: /**
107: * Returns the collection of change sets for newly created objects.
108: *
109: * @return Set of change sets
110: */
111: public Set<NewObjectChange> getNewObjects() {
112: return this.newObjectChanges;
113: }
114:
115: /**
116: * Returns true if there are deleted objects in this change set.
117: *
118: * @return boolean
119: */
120: public boolean hasDeleted() {
121:• return !deletedObjects.isEmpty();
122: }
123:
124: /**
125: * Returns true if this changeSet has any changes.
126: *
127: * @return boolean
128: */
129: public boolean hasChanges() {
130:• return hasDeleted() || hasNew() || !objectChanges.isEmpty();
131: }
132:
133: /**
134: * Are there any new objects in the change set?
135: *
136: * @return boolean
137: */
138: public boolean hasNew() {
139:• return !this.newObjectChanges.isEmpty();
140: }
141: }