Skip to contentMethod: isNew()
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.change;
16:
17: import cz.cvut.kbss.jopa.sessions.ChangeRecord;
18: import cz.cvut.kbss.jopa.sessions.ObjectChangeSet;
19:
20: import java.net.URI;
21: import java.util.HashMap;
22: import java.util.Map;
23:
24: public class ObjectChangeSetImpl implements ObjectChangeSet {
25:
26: // Class this ObjectChangeSet represents
27: private Class<?> objectClass;
28:
29: // The object the changes are bound to
30: private Object changedObject;
31:
32: // Reference to the clone
33: private Object cloneObject;
34:
35: // A map of attributeName-changeRecord pairs to easily find the attributes
36: // to change
37: private Map<String, ChangeRecord> attributesToChange = new HashMap<>();
38:
39: // Does this change set represent a new object
40: private boolean isNew;
41:
42: private URI context;
43:
44: public ObjectChangeSetImpl(Object changedObject, Object cloneObject, URI context) {
45: this.changedObject = changedObject;
46: this.cloneObject = cloneObject;
47: this.objectClass = cloneObject.getClass();
48: this.context = context;
49: }
50:
51: /**
52: * Add a change record to this change set
53: *
54: * @param record ChangeRecord
55: */
56: public void addChangeRecord(ChangeRecord record) {
57: if (record == null)
58: return;
59: String attributeName = record.getAttributeName();
60: attributesToChange.put(attributeName, record);
61: }
62:
63: /**
64: * Returns the map with attribute names and changes made to them.
65: *
66: * @return java.util.Map
67: */
68: public Map<String, ChangeRecord> getChanges() {
69: return this.attributesToChange;
70: }
71:
72: public Class<?> getObjectClass() {
73: return objectClass;
74: }
75:
76: public Object getChangedObject() {
77: return changedObject;
78: }
79:
80: public Object getCloneObject() {
81: return cloneObject;
82: }
83:
84: public void setCloneObject(Object cloneObject) {
85: this.cloneObject = cloneObject;
86: }
87:
88: public void setNew(boolean isNew) {
89: this.isNew = isNew;
90: }
91:
92: /**
93: * Returns true if this change set represents a new object
94: *
95: * @return boolean
96: */
97: public boolean isNew() {
98: return isNew;
99: }
100:
101: @Override
102: public URI getEntityContext() {
103: return context;
104: }
105: }