Skip to content

Method: getNewObjects()

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.sessions.change;
14:
15: import cz.cvut.kbss.jopa.sessions.ObjectChangeSet;
16: import cz.cvut.kbss.jopa.sessions.UnitOfWorkChangeSet;
17:
18: import java.util.*;
19:
20: public class UnitOfWorkChangeSetImpl implements UnitOfWorkChangeSet {
21:
22: private Set<ObjectChangeSet> deletedObjects;
23: private Map<Object, ObjectChangeSet> objectChanges;
24: private Set<ObjectChangeSet> newObjectChanges;
25:
26: public UnitOfWorkChangeSetImpl() {
27: super();
28: this.objectChanges = new HashMap<>();
29: this.deletedObjects = new HashSet<>();
30: this.newObjectChanges = new HashSet<>();
31: }
32:
33: @Override
34: public void addObjectChangeSet(ObjectChangeSet objectChangeSet) {
35: if (objectChangeSet.isNew()) {
36: addNewObjectChangeSet(objectChangeSet);
37: } else {
38: objectChanges.put(objectChangeSet.getChangedObject(), objectChangeSet);
39: }
40: }
41:
42: @Override
43: public void addDeletedObjectChangeSet(ObjectChangeSet deletedObject) {
44: deletedObjects.add(deletedObject);
45: }
46:
47: @Override
48: public void addNewObjectChangeSet(ObjectChangeSet newObject) {
49: newObject.setNew(true);
50: newObjectChanges.add(newObject);
51: }
52:
53: @Override
54: public Collection<ObjectChangeSet> getExistingObjectsChanges() {
55: return Collections.unmodifiableCollection(objectChanges.values());
56: }
57:
58: @Override
59: public ObjectChangeSet getExistingObjectChanges(Object original) {
60: return objectChanges.get(original);
61: }
62:
63: @Override
64: public Set<ObjectChangeSet> getDeletedObjects() {
65: return this.deletedObjects;
66: }
67:
68: @Override
69: public Set<ObjectChangeSet> getNewObjects() {
70: return this.newObjectChanges;
71: }
72:
73: @Override
74: public boolean hasDeleted() {
75: return !deletedObjects.isEmpty();
76: }
77:
78: @Override
79: public boolean hasChanges() {
80: return hasDeleted() || hasNew() || !objectChanges.isEmpty();
81: }
82:
83: @Override
84: public boolean hasNew() {
85: return !this.newObjectChanges.isEmpty();
86: }
87: }